public void TestDataTransferFunctions() { _dtpFactory = new DtpFactory(SendData); _dtpProcessor = new DtpProcessor(); _dtpProcessor.RegisterFunction("TestFunction1", parameters => { Trace.WriteLine("Parameterless function with int returning type successfully executed"); return(0); }); _dtpProcessor.RegisterFunction("TestFunction2", parameters => { Assert.AreEqual(parameters.GetInt32(0), 19); Trace.WriteLine("Function with int parameter and string returning type successfully executed"); return("wtf"); }); _dtpProcessor.RegisterFunction("TestFunction3", parameters => { var result = parameters.GetValue <List <ClientInformation> >(0, typeof(OnlineClientInformation), typeof(OfflineClientInformation)); Assert.IsNotNull(result); Assert.AreEqual(result.Count, 3); Assert.AreEqual(result[1].Group, "test"); Trace.WriteLine("Function with complex parameter and complex returning successfully executed"); return(new List <ClientInformation> { new OnlineClientInformation(), new OfflineClientInformation(), new OnlineClientInformation() }); }, typeof(OfflineClientInformation), typeof(OnlineClientInformation)); Trace.WriteLine("Executing parameterless method"); Assert.AreEqual(_dtpFactory.ExecuteFunction <int>("TestFunction1"), 0); Trace.WriteLine("Executing method with in parameter"); Assert.AreEqual(_dtpFactory.ExecuteFunction <string>("TestFunction2", 19), "wtf"); Trace.WriteLine("Executing method with complex parameter"); Assert.AreEqual(_dtpFactory.ExecuteFunction <List <ClientInformation> >("TestFunction3", new List <Type> { typeof(OnlineClientInformation), typeof(OfflineClientInformation) }, new List <Type> { typeof(OfflineClientInformation), typeof(OnlineClientInformation) }, new List <ClientInformation> { new OnlineClientInformation(), new OfflineClientInformation { Group = "test" }, new OnlineClientInformation() }).Count, 3); }
public void RequestClientInformation(List <ClientViewModel> clients) { lock (_clientUpdateLock) { foreach (var client in clients) { if (_clientsUpdating.Contains(client.Id)) { clients.Remove(client); } else { _clientsUpdating.Add(client.Id); } } } if (clients.Count == 0) { return; } Debug.Print("Request: " + clients.Count); var result = _dtpFactory.ExecuteFunction <List <ClientInformation> >("GetClientDetails", null, new List <Type> { typeof(List <ClientInformation>), typeof(OnlineClientInformation), typeof(OfflineClientInformation) }, clients.Select(x => x.Id).ToList()); lock (_clientUpdateLock) { foreach (var clientViewModel in clients) { _clientsUpdating.Remove(clientViewModel.Id); var updatedEntry = result.FirstOrDefault(x => x.Id == clientViewModel.Id); if (updatedEntry == null) #if DEBUG { throw new Exception("Something went wrong"); } #else { continue; } #endif var offlineClient = updatedEntry as OfflineClientInformation; if (offlineClient != null) { offlineClient.LastSeen = offlineClient.LastSeen.ToLocalTime(); } else { var onlineClient = (OnlineClientInformation)updatedEntry; onlineClient.OnlineSince = onlineClient.OnlineSince.ToLocalTime(); } clientViewModel.Update(updatedEntry); _clientData[clientViewModel] = updatedEntry; } } }
public async Task Initialize(ConnectionProtocol connectionProtocol) { if (_remoteConnectionInformation == null) { var result = await Task.Run( () => _dtpFactory.ExecuteFunction <RemoteConnectionInformation>("GetCoreInformation", connectionProtocol)); if ((connectionProtocol & (ConnectionProtocol.Tcp | ConnectionProtocol.Udp)) != (ConnectionProtocol.Tcp | ConnectionProtocol.Udp) && _remoteConnectionInformation != null) { if ((connectionProtocol & ConnectionProtocol.Tcp) == ConnectionProtocol.Tcp) { result.UdpConnectionInformation = _remoteConnectionInformation.UdpConnectionInformation; } //else if((connectionProtocol & ConnectionProtocol.Udp) == ConnectionProtocol.Udp) // result.Tcp = asdasdasd } _remoteConnectionInformation = result; } }
private ConnectionManager(BinaryReader binaryReader, BinaryWriter binaryWriter, SslStream sslStream, TcpClient tcpClient) { DataTransferProtocolFactory = new DtpFactory(SendData); Sender = new Sender(binaryReader, binaryWriter, sslStream); StaticCommander = new StaticCommander(this); _tcpClient = tcpClient; var serializer = new Serializer(new[] { typeof(WelcomePackage) }); var welcomePackage = (WelcomePackage)serializer.Deserialize(sslStream); _readByteDelegate += Sender.BinaryReader.ReadByte; _readByteDelegate.BeginInvoke(EndRead, null); var lightInfo = DataTransferProtocolFactory.ExecuteFunction <LightInformationApp> ("GetAllClientsLightApp"); Clients = lightInfo.Clients.Select(x => { x.Group = lightInfo.Groups[x.GroupId]; x.OsName = lightInfo.OperatingSystems[x.OsNameId]; return(x); }).ToList(); }
private ConnectionManager(string ip, int port, string password, IConnection connection) { DataTransferProtocolFactory = new DtpFactory(SendData); Ip = ip; Port = port; Password = password; Sender = new Sender(connection); var serializer = new Serializer(new[] { typeof(WelcomePackage) }); StaticCommander = new StaticCommander(this); var welcomePackage = (WelcomePackage)serializer.Deserialize(connection.BaseStream); _readByteDelegate += Sender.Connection.BinaryReader.ReadByte; _readByteDelegate.BeginInvoke(EndRead, null); var data = DataTransferProtocolFactory.ExecuteFunction <LightInformation>("GetAllClientsLight"); ClientProvider = new ClientProvider(data, DataTransferProtocolFactory); IpAddresses = welcomePackage.IpAddresses; ExceptionsCount = welcomePackage.ExceptionCount; }
public RootEntryCollection GetRootElements() { LogService.Send((string)Application.Current.Resources["GetRootElements"]); var rootCollection = _dtpFactory.ExecuteFunction <RootEntryCollection>("GetRootElements", null, new List <Type> { typeof(RootEntryCollection), typeof(FileEntry), typeof(DirectoryEntry), typeof(DriveDirectoryEntry), typeof(ProcessingEntry) }); LogService.Receive(string.Format((string)Application.Current.Resources["RootElementsReceived"], rootCollection.RootDirectories.Count)); foreach (var directoryEntry in rootCollection.RootDirectories) { directoryEntry.Unpack(null); } foreach (var entry in rootCollection.ComputerDirectoryEntries) { entry.Unpack(rootCollection.ComputerDirectory); } return(rootCollection); }