aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.UITests/MainWindow.xaml.cs
blob: 4ac7bffa28be81da7c70651cf07843216d727d50 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using EFCache;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using Tango.BL;
using Tango.BL.Builders;
using Tango.BL.Catalogs;
using Tango.BL.Entities;
using Tango.Core;
using Tango.Core.Commands;
using Tango.DragAndDrop;
using Tango.FirmwareUpdateLib;
using Tango.FirmwareUpdateLib.WPF;
using Tango.Logging;
using Tango.SharedUI;
using Tango.Web;
using System.Data;
using System.Data.SqlClient;
using System.Security.Permissions;
using TableDependency.SqlClient.Base;
using TableDependency.SqlClient;
using TableDependency.SqlClient.Base.EventArgs;

namespace Tango.UITests
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            EntityFrameworkCache.Initialize(new InMemoryCache());


        }

        private static string _con = "data source=localhost\\SQLEXPRESS; initial catalog=Tango; integrated security=False;User Id=SqlDependency;Password=Aa123456";


        private void btnStart_Click(object sender, RoutedEventArgs e)
        {
            //var dataSource = new DataSource()
            //{
            //    Address = "localhost\\SQLEXPRESS",
            //    Catalog = "Tango",
            //    Type = DataSourceType.SQLServer,
            //    IntegratedSecurity = false,
            //    UserName = "Developer",
            //    Password = "Aa123456",
            //};

            //var connection = dataSource.ToConnection();

            String str = _con;

            //var mapper = new ModelToTableMapper<User>();
            //mapper.AddMapping(c => c.ID, "ID");
            //mapper.AddMapping(c => c.Email, "EMAIL");

            var dep = new SqlTableDependency<DAL.Remote.DB.USER>(str, "USERS", "dbo");
            dep.TraceLevel = TraceLevel.Verbose;
            dep.TraceListener = new TextWriterTraceListener(Console.Out); 

            dep.OnChanged += Changed;
            dep.Start();

            //SqlClientPermission clientPermission =
            //       new SqlClientPermission(PermissionState.Unrestricted);
            //clientPermission.Demand();

            //System.Data.SqlClient.SqlDependency.Start(str);

            //String commandText = "SELECT [dbo].[USERS].[EMAIL] FROM [dbo].[USERS];";
            //SqlCommand command = new SqlCommand(commandText, connection as SqlConnection);
            //command.Notification = null;
            //command.CommandType = CommandType.Text;

            //command.Connection.Open();

            //SqlDependency dependency = new SqlDependency(command);
            //dependency.OnChange += (s, args) =>
            //{

            //};

            //command.ExecuteReader();
            //String a = "!23";

            //Stopwatch watch = Stopwatch.StartNew();

            //using (ObservablesContext db = ObservablesContext.CreateDefault(new DataSource()
            //{
            //    Address = "localhost\\SQLEXPRESS",
            //    Catalog = "Tango",
            //    Type = DataSourceType.SQLServer,
            //    UserName = "Roy",
            //    Password = "Aa123456",
            //    IntegratedSecurity = true,
            //}))
            //{
            //    var users = db.Users.ToList();
            //    var jobs = new JobsCollectionBuilder(db).SetAll().WithSegments().WithBrushStops().Build();
            //    var first_job = jobs.First();

            //    if (first_job.Name == "Changed Name 2")
            //    {
            //        Debug.WriteLine("Changed and cached !!!");
            //    }
            //    else
            //    {
            //        Debug.WriteLine("Not working.");
            //    }
            //}

            //Debug.WriteLine($"Time to complete: {watch.Elapsed.TotalSeconds} seconds");
        }

        private void Changed(object sender, RecordChangedEventArgs<DAL.Remote.DB.USER> e)
        {
            var changedEntity = e.Entity;

            Console.WriteLine("DML operation: " + e.ChangeType);

            Console.WriteLine(changedEntity.ToJsonString());
        }

        private void btnChange_Click(object sender, RoutedEventArgs e)
        {
            using (ObservablesContext db = ObservablesContext.CreateDefault(new DataSource()
            {
                Address = "twine.database.windows.net",
                Catalog = "Tango_DEV",
                Type = DataSourceType.SQLServer,
                UserName = "Roy",
                Password = "Aa123456",
                IntegratedSecurity = false,
            }))
            {
                var jobs = new JobsCollectionBuilder(db).SetAll().WithSegments().WithBrushStops().Build();
                var first_job = jobs.First();
                first_job.Name = "Changed Name 2";
                db.SaveChanges();
            }
        }
    }
}