public ConnectionViewModel(ConnectionModel connection) { DataModel = connection; Connection = new Common.Connection(); Connection.ErrorOccured += (a, b) => Application.Current.Dispatcher.Invoke(() => { ErrorInfo = b.Exception.Message; RaisePropertyChanged(() => ConnectMode); }); Connection.ConnectModeChanged += (sender, mode) => Application.Current.Dispatcher.Invoke(() => { ErrorInfo = string.Empty; RaisePropertyChanged(() => ConnectMode); }); Connection.UnitIdChanged += (sender, args) => UnitId = args.UnitId; #if DEBUG if (ConnectType == ConnectType.Ethernet) { Ipaddress = "127.0.0.1"; } #endif }
public void BulkDataSequentialTest() { var connection = new Connection(); var modeChanged = new AutoResetEvent(false); CreateConnection(connection, modeChanged); var p = SendSequential(connection); DisConnection(connection, modeChanged); Assert.AreEqual(Packagecount, p); }
public static void ModifyConfigurations(Common.Connection connection) { //String configFile = Application.ExecutablePath + ".config"; //XmlDocument document = new XmlDocument(); //document.Load(configFile); //XmlNodeList nodes = document.SelectNodes("/configuration/userSettings/Book.UI.Properties.Settings/setting"); //foreach (XmlNode node in nodes) //{ // if (node.Attributes["name"].Value == "accessorImplementionsLocation") // node.FirstChild.InnerText = "Book.DA." + connection.Type; //} //document.Save(configFile); System.Configuration.Configuration cfa = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); KeyValueConfigurationElement accessorImplementionsLocation = cfa.AppSettings.Settings["accessorImplementionsLocation"]; if (accessorImplementionsLocation == null) { cfa.AppSettings.Settings.Add("accessorImplementionsLocation", string.Format("Book.DA.{0}", connection.Type)); } else { cfa.AppSettings.Settings["accessorImplementionsLocation"].Value = string.Format("Book.DA.{0}", connection.Type); } cfa.Save(); XmlDocument document1 = new XmlDocument(); String configFile = string.Format("Book.{0}.SQLMap.config", connection.Type); document1.Load(configFile); XmlNamespaceManager nm = new XmlNamespaceManager(document1.NameTable); nm.AddNamespace("aa", "http://ibatis.apache.org/dataMapper"); XmlNode datasourceNode = document1.SelectSingleNode("/aa:sqlMapConfig/aa:database/aa:dataSource", nm); if (datasourceNode != null) { datasourceNode.Attributes["connectionString"].Value = connection.ToString("r"); } document1.Save(configFile); }
private static int SendSequential(Connection c) { var counter = 0; foreach (var data in TestData()) { c.EnQueue(data); data.WaitAsync().Wait(); Assert.IsTrue(data.ModuleDataCheckOk, "data received incorrect"); Console.WriteLine(data.ModuleName + "send"); counter++; } return counter; }
private static int SendParallel(Connection c) { int counter = 0; List<GetE2PromExt> td = TestData().ToList(); foreach (var data in td) { c.EnQueue(data); Console.WriteLine(data.ModuleName + "send"); } foreach (var dispatchData in td) { dispatchData.WaitAsync().Wait(); Assert.IsTrue(dispatchData.ModuleDataCheckOk, "data received incorrect"); counter++; } return counter; }
private static void DisConnection(Connection connection, WaitHandle modeChanged) { connection.Disconnect(); modeChanged.WaitOne(); Assert.IsTrue(connection.Mode == ConnectMode.None, "Mode is: " + connection.Mode); }
static void CreateConnection(Connection connection, EventWaitHandle modeChanged) { string error = null; connection.ConnectModeChanged += (sender, mode) => modeChanged.Set(); connection.ErrorOccured += (s,b) => { error = b.Exception.Message.ToString(); modeChanged.Set(); }; connection.QueueEmtpy += (sender, args) => { Console.WriteLine("Queue EMPTy"); }; var escx = "192.168.1.200"; var local = "127.0.0.1"; var usb = "COM4"; //connection.CreateConnection(local, ConnectType.Ethernet, ConnectMode.Install); connection.CreateConnection(usb, ConnectType.USB, ConnectMode.Install); modeChanged.WaitOne(); Assert.IsTrue(string.IsNullOrEmpty(error), error); Assert.IsTrue(connection.Mode == ConnectMode.Install, "Mode is: " + connection.Mode); }
public void SwitchModeTest() { var are = new AutoResetEvent(false); var exit = new AutoResetEvent(false); var z = new Connection(); string error = null; z.ConnectModeChanged += (sender, mode) => { Debug.WriteLine("Mode changed" + mode); if (mode.Mode == ConnectMode.Install) are.Set(); else exit.Set(); }; z.ErrorOccured += (o,message) => { Debug.WriteLine("Error occured"); error = message.Exception.Message.ToString(); are.Set(); }; for (int i = 0; i < 4; i++) { z.CreateConnection("127.0.0.1", ConnectType.Ethernet, ConnectMode.Install); are.WaitOne(); Assert.IsTrue(string.IsNullOrEmpty(error), error); Assert.IsTrue(z.Mode == ConnectMode.Install, "Mode is: " + z.Mode); z.Disconnect(); exit.WaitOne(); Assert.IsTrue(string.IsNullOrEmpty(error), error); Assert.IsTrue(z.Mode == ConnectMode.None, "Mode is: " + z.Mode); } }
public void MessageSelectionTest() { var z = new List<MessageSelectModel>(Enumerable.Range(0, 3).Select(n => new MessageSelectModel())); z[0].ButtonA1 = 0; z[0].ButtonA2 = 1; z[0].ButtonB1 = 2; z[0].ButtonB2 = 3; z[0].ButtonC1 = 4; z[0].ButtonC2 = 5; z[0].ButtonD1 = 6; z[0].ButtonD2 = 7; z[1].ButtonC1 = 255; z[1].ButtonC2 = 254; // z[1].ButtonD1 = 253; //==no message; z[1].ButtonD2 = 252; z[2].ButtonB2 = 3; z[2].ButtonC1 = 0; int a = 4; var sendPacket = new SetMessageSelection(z, a, a, a, a, 250, 255, 0); var receivePacket = new GetMessageSelection(0); var connection = new Connection(); var modeChanged = new AutoResetEvent(false); CreateConnection(connection, modeChanged); connection.EnQueue(sendPacket); sendPacket.WaitAsync().Wait(); connection.EnQueue(receivePacket); receivePacket.WaitAsync().Wait(); DisConnection(connection, modeChanged); Assert.AreEqual(a, receivePacket.PreannounceEP); Assert.AreEqual(255, receivePacket.PreannounceExtAudio); Assert.AreEqual(250, receivePacket.PreannounceFDS); Assert.AreEqual(a, receivePacket.PreannounceFP); Assert.AreEqual(a, receivePacket.AlarmTrack); Assert.AreEqual(a, receivePacket.AlertTrack); for (int i = 0; i < 3; i++) { Assert.AreEqual(z[i], receivePacket.MessageSelectModels[i]); } }