aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.SQLiteGenerator.CLI/Program.cs
blob: b971621abb4c5e3a203d76abfbd10bd7298d02e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.DAL.Remote.DB;
using Tango.Settings;
using Tango.Synchronization;
using Tango.Synchronization.Conversion;

namespace Tango.SQLiteGenerator.CLI
{
    public enum Config
    {
        Default,
        CopyAll,
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Tango SQLite Generator";

#if DEBUG
            args = new string[]
            {
                    Path.GetFullPath( "..\\..\\..\\..\\DB\\Tango.db"),
                    "CopyAll"
            };
#endif

            String sqlitePath = args[0];
            Config conf = args.Length > 1 ? (Config)Enum.Parse(typeof(Config), args[1]) : Config.Default;

            sqlitePath = Path.GetFullPath(sqlitePath);

            Console.WriteLine("Generating " + sqlitePath + "...");

            bool completed = false;

            String connectionString = SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource.ToConnection().ConnectionString;

            Console.WriteLine("Connecting to " + connectionString + "...");

            connectionString = String.Format("Data Source={0};Initial Catalog=Tango;Integrated Security=SSPI;", connectionString);

            List<SYNC_CONFIGURATIONS> sync_configurations = new List<SYNC_CONFIGURATIONS>();

            using (RemoteDB db = new RemoteDB(SettingsManager.Default.GetOrCreate<CoreSettings>().DataSource))
            {
                sync_configurations = db.SYNC_CONFIGURATIONS.ToList();
            }

            SqlConversionHandler handler = new SqlConversionHandler(delegate (bool done, bool success, int percent, string msg)
            {
                Console.WriteLine(String.Format("{0}  [%{1}]", msg, percent));

                if (done)
                {
                    if (success)
                    {
                        Console.WriteLine("SQLite database has been generated successfully on " + sqlitePath);
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.WriteLine("SQLite database generation failed!");
                        Environment.Exit(-1);
                    }

                    completed = true;
                }
            });

            SqlTableSelectionHandler selectionHandler = new SqlTableSelectionHandler(delegate (List<TableSchema> schema)
            {
                List<TableSchema> updated = schema.Where(x => x.TableName.ToLower() != "sysdiagrams").ToList();

                if (conf == Config.Default)
                {
                    updated
                    .Where(table => sync_configurations.Where(config => (SyncConfiguration)config.SYNC_TYPE == SyncConfiguration.OverwriteLocal).ToList()
                    .Exists(config => config.TABLE_NAME == table.TableName)).ToList().ForEach(x => x.CopyData = true);
                }
                else if (conf == Config.CopyAll)
                {
                    updated.ForEach(x => x.CopyData = true);
                }

                return updated;
            });

            SqlServerToSQLiteConverter converter = new SqlServerToSQLiteConverter();
            converter.GenerateForeignKeys = true;
            converter.GenerateIndexes = true;

            converter.ConvertSqlServerToSQLiteDatabase(connectionString, sqlitePath, null, handler, selectionHandler, null, false, false);

            while (!completed)
            {
                Console.ReadLine();
            }
        }
    }
}
} else if (value >= 30) { _smallStep = 0.5; _bigStep = 2; } else if (value >= 20) { _smallStep = 1; _bigStep = 5; } else if (value >= 10) { _smallStep = 1; _bigStep = 10; } else if (value >= 5) { _smallStep = 2; _bigStep = 20; } else if (value >= 3) { _smallStep = 5; _bigStep = 30; } else if (value >= 1) { _smallStep = 30; _bigStep = 300; } else if (value >= 0.5) { _smallStep = 60; _bigStep = 600; } } /// <summary> /// Identifies the Zoom dependency property. /// </summary> public static readonly DependencyProperty ZoomProperty = DependencyProperty.Register("Zoom", typeof(double), typeof(TimeRuler), new FrameworkPropertyMetadata((double)1.0, FrameworkPropertyMetadataOptions.AffectsRender, new PropertyChangedCallback(ZoomChanged))); private static void ZoomChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as TimeRuler).SetSteps((double)e.NewValue); } #endregion #endregion #region Constructor public TimeRuler() { _smallStep = 1; _bigStep = 10; FontSize = 10; this.Loaded += TimeRuler_Loaded; } private void TimeRuler_Loaded(object sender, RoutedEventArgs e) { this.InvalidateVisual(); } #endregion #region Methods /// <summary> /// Participates in rendering operations. /// </summary> /// <param name="drawingContext">The drawing instructions for a specific element. This context is provided to the layout system.</param> protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); double xDest = RenderWidth; int start = (int)(HorizontalOffset / Zoom); drawingContext.DrawRectangle(Background, new Pen(BorderBrush, 0), new Rect(new Point(start * Zoom, 0.0), new Point(xDest + (start * Zoom) + 100, Height))); drawingContext.DrawLine(new Pen(BorderBrush, 1), new Point(start * Zoom, Height - 1), new Point(xDest + (start * Zoom) + 100, Height)); double l = (start % _smallStep); while (l != 0) //I don't know why, but this is needed in order to prevent ruler from flickering on some lower scale factors :/ { start += 1; l = (start % _smallStep); } for (double dUnit = start; dUnit < (RenderWidth / Zoom) + (start) + 10; dUnit += _smallStep) { double d = dUnit * (this.Zoom); double startHeight; double endHeight; startHeight = Height; endHeight = ((dUnit % _bigStep == 0) ? (this.ActualHeight / 5) * 1.5 : this.ActualHeight / 5); drawingContext.DrawLine(new Pen(Foreground, 1), new Point(d, startHeight), new Point(d, (startHeight - endHeight))); double uu = (dUnit % _bigStep); if ((dUnit != 0.0) && (uu == 0) && (dUnit < (RenderWidth / Zoom) + start + 10)) { double u = dUnit; TimeSpan t = TimeSpan.FromSeconds((u)); FormattedText ft = new FormattedText(t.ToString("g"), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface(FontFamily.ToString()), FontSize, Foreground); ft.SetFontWeight(FontWeight); ft.TextAlignment = TextAlignment.Center; drawingContext.DrawText(ft, new Point(d, (Height / 2) - (ft.Height / 2) - 2)); } } } #endregion } }