public FileExplorerCommand()
 {
     _dtpFactory = new DtpFactory(SendData)
     {
         Timeout = 1000 * 60 * 5
     };                                                            //5 min. timeout
 }
        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);
        }
예제 #3
0
        public ClientProvider(LightInformation clientInfo, DtpFactory dtpFactory)
        {
            _clientData = clientInfo.Clients.Select(x =>
            {
                x.Group  = clientInfo.Groups[x.GroupId];
                x.OsName = clientInfo.OperatingSystems[x.OsNameId];
                return(x);
            }).ToDictionary(x => new ClientViewModel(x), y => (BaseClientInformation)y);

            Clients = new ObservableCollection <ClientViewModel>(_clientData.Select(x => x.Key));

            _clientsUpdating = new List <int>();
            _dtpFactory      = dtpFactory;
            Groups           = new ObservableCollection <string>(Clients.GroupBy(x => x.Group).Select(x => x.Key));
        }
예제 #4
0
        private void SendData(byte[] data)
        {
            if (_isDisposed)
            {
                return;
            }

            lock (Sender.WriterLock)
            {
                Sender.Connection.BinaryWriter.Write((byte)FromAdministrationPackage.DataTransferProtocol);
                Sender.Connection.BinaryWriter.Write(data.Length);
                Sender.Connection.BinaryWriter.Write(data);
            }

            if (_packageSentEventHandler != null)
            {
                OnPackageSent(DtpFactory.DescribeSentData(data, 0), data.Length + 5);
            }
        }
        public void TestDataTransferMethods()
        {
            _dtpFactory   = new DtpFactory(SendData);
            _dtpProcessor = new DtpProcessor();

            _dtpProcessor.RegisterProcedure("TestMethod1",
                                            parameters => Trace.WriteLine("Parameterless method successfully executed"));
            _dtpProcessor.RegisterProcedure("TestMethod2", parameters =>
            {
                Assert.AreEqual(parameters.GetInt32(0), 19);
                Trace.WriteLine("Method with int parameter successfully executed");
            });
            _dtpProcessor.RegisterProcedure("TestMethod3",
                                            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("Method with complex parameter successfully executed");
            });


            Trace.WriteLine("Executing parameterless method");
            _dtpFactory.ExecuteProcedure("TestMethod1");
            Trace.WriteLine("Executing method with in parameter");
            _dtpFactory.ExecuteProcedure("TestMethod2", 19);
            Trace.WriteLine("Executing method with complex parameter");
            _dtpFactory.ExecuteProcedure("TestMethod3",
                                         new List <Type> {
                typeof(OnlineClientInformation), typeof(OfflineClientInformation)
            }, null,
                                         new List <ClientInformation>
            {
                new OnlineClientInformation(),
                new OfflineClientInformation {
                    Group = "test"
                },
                new OnlineClientInformation()
            });
        }
        public override string DescribePackage(byte[] data, bool isReceived)
        {
            var responseType = (FileExplorerCommunication)data[0];

            if (isReceived)
            {
                if (responseType != FileExplorerCommunication.ResponseDtpPackage)
                {
                    return(responseType.ToString());
                }
                return("ResponseDtpPackage - " + _dtpFactory.DescribeReceivedData(data, 1));
            }
            else
            {
                if (responseType != FileExplorerCommunication.SendDtpPackage)
                {
                    return(responseType.ToString());
                }
                return("SendDtpPackage - " + DtpFactory.DescribeSentData(data, 1));
            }
        }
예제 #7
0
        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();
        }
예제 #8
0
        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 ConnectionInitializerCommand()
 {
     _dtpFactory = new DtpFactory(SendDataAction);
 }