Esempio n. 1
0
        private void mniEnter_Click(object sender, EventArgs e)
        {
            if (this.mniEnter.Text == "Login")
            {
                frmLogin dlg = new frmLogin(IPAddress.Parse("192.168.238.3"), 2324);
                dlg.ShowDialog();
                this.client = dlg.Client;

                if (this.client.Connected)
                {
                    this.client.CommandReceived += new Proshot.CommandClient.CommandReceivedEventHandler(client_CommandReceived);
                    this.client.SendCommand(new Command(CommandType.FreeCommand, IPAddress.Broadcast, this.client.IP + ":" + this.client.NetworkName));
                    this.client.SendCommand(new Proshot.CommandClient.Command(Proshot.CommandClient.CommandType.SendClientList, this.client.ServerIP));
                    this.AddToList(this.client.IP.ToString(), this.client.NetworkName);
                    this.mniEnter.Text = "Log Off";
                }
            }
            else
            {
                this.mniEnter.Text = "Login";
                this.privateWindowsList.Clear();
                this.client.Disconnect();
                this.lstViwUsers.Items.Clear();
                this.txtNewMessage.Clear();
                this.txtNewMessage.Focus();
            }
        }
Esempio n. 2
0
        public void TestSemaphoreReleaseOnExceptionalOperation()
        {
            CMDClient client = new CMDClient(null, "Some network");

            var sem = mocks.DynamicMock<System.Threading.Semaphore>();
            var stream = mocks.DynamicMock<System.IO.Stream>();

            using (mocks.Record())
            {
                Expect.Call(sem.WaitOne()).Return(true);
                Expect.Call(sem.Release()).Return(0);

                stream.Flush();
                LastCall.On(stream).Throw(new Exception());
            }

            typeof(CMDClient).GetField("networkStream", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, stream);
            typeof(CMDClient).GetField("semaphore", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, sem);

            Command command = new Command(CommandType.UserExit, IPAddress.Parse("127.0.0.1"), null);
            try
            {
                client.SendCommandToServerUnthreaded(command);
            }
            catch (Exception e) { }

            mocks.VerifyAll();
        }
Esempio n. 3
0
 public frmPrivate(CMDClient cmdClient, IPAddress friendIP, string name)
 {
     InitializeComponent();
     _remoteClient = cmdClient;
     _targetIp = friendIP;
     _remoteName = name;
     Text += " With " + name;
     _remoteClient.CommandReceived += private_CommandReceived;
 }
Esempio n. 4
0
 public frmPrivate(CMDClient cmdClient , IPAddress friendIP , string name)
 {
     InitializeComponent();
     this.remoteClient = cmdClient;
     this.targetIP = friendIP;
     this.remoteName = name;
     this.Text += " With " + name;
     this.remoteClient.CommandReceived += new CommandReceivedEventHandler(private_CommandReceived);
 }
Esempio n. 5
0
 public frmPrivate(CMDClient cmdClient, IPAddress friendIP, string name, string initialMessage)
 {
     InitializeComponent();
     _remoteClient = cmdClient;
     _targetIp = friendIP;
     _remoteName = name;
     Text += " With " + name;
     txtMessages.Text = _remoteName + ": " + initialMessage + Environment.NewLine;
     _remoteClient.CommandReceived += private_CommandReceived;
 }
Esempio n. 6
0
 public frmLogin(IPAddress serverIp, int serverPort)
 {
     InitializeComponent();
     _canClose = false;
     CheckForIllegalCrossThreadCalls = false;
     Client = new CMDClient(serverIp, serverPort, "None");
     Client.CommandReceived += CommandReceived;
     Client.ConnectingSuccessed += client_ConnectingSuccessed;
     Client.ConnectingFailed += client_ConnectingFailed;
 }
Esempio n. 7
0
 public frmPrivate(CMDClient cmdClient,IPAddress friendIP,string name,string initialMessage)
 {
     InitializeComponent();
     this.remoteClient = cmdClient;
     this.targetIP = friendIP;
     this.remoteName = name;
     this.Text += " With " + name;
     this.txtMessages.Text = this.remoteName + ": " + initialMessage +Environment.NewLine;
     this.remoteClient.CommandReceived += new CommandReceivedEventHandler(private_CommandReceived);
 }
        public void TestSemaphoreReleaseOnExceptionalOperation()
        {
            IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
            Command command = new Command(CommandType.UserExit, ipaddress, null);
            System.IO.Stream fakeStream = mocks.DynamicMock<System.IO.Stream>();
            System.Threading.Semaphore fakeSemaphore = mocks.DynamicMock<System.Threading.Semaphore>();
            byte[] commandBytes = { 0, 0, 0, 0 };
            byte[] ipLength = { 9, 0, 0, 0 };
            byte[] ip = { 49, 50, 55, 46, 48, 46, 48, 46, 49 };
            byte[] metaDataLength = { 2, 0, 0, 0 };
            byte[] metaData = { 10, 0 };

            using (mocks.Ordered())
            {
                Expect.Call(fakeSemaphore.WaitOne()).Return(true);
                fakeStream.Write(commandBytes, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ipLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ip, 0, 9);
                fakeStream.Flush();
                fakeStream.Write(metaDataLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(metaData, 0, 2);
                fakeStream.Flush();
                LastCall.On(fakeStream).Throw(new Exception());
                Expect.Call(fakeSemaphore.Release()).Return(1);
            }
            mocks.ReplayAll();
            CMDClient client = new CMDClient(null, "Bogus network name");

            // we need to set the private variable here
            typeof(CMDClient).GetField("networkStream", BindingFlags.NonPublic | BindingFlags.Instance)
                .SetValue(client, fakeStream);
            typeof(CMDClient).GetField("semaphore", BindingFlags.NonPublic | BindingFlags.Instance)
                .SetValue(client, fakeSemaphore);

            try
            {
                client.SendCommandToServerUnthreaded(command);
            }
            catch (Exception e)
            {
                Console.Write("Exception caught");
            }
            mocks.VerifyAll();
        }
Esempio n. 9
0
        public void TestSemaphoreReleaseOnNormalOperation()
        {
            CMDClient client = new CMDClient(null, "Some network");

            var sem = mocks.DynamicMock<System.Threading.Semaphore>();
            using (mocks.Record())
            {
                Expect.Call(sem.WaitOne()).Return(true);
                Expect.Call(sem.Release()).Return(0);
            }

            using (MemoryStream ms = new MemoryStream())
            {
                typeof(CMDClient).GetField("networkStream", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, ms);
                typeof(CMDClient).GetField("semaphore", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, sem);

                Command command = new Command(CommandType.UserExit, IPAddress.Parse("127.0.0.1"), null);
                client.SendCommandToServerUnthreaded(command);

                mocks.VerifyAll();
            }
        }
Esempio n. 10
0
        public void TestUserExitCommandWithoutMocks()
        {
            byte[] commandBytes = { 0, 0, 0, 0 };
            byte[] ipLength = { 9, 0, 0, 0 };
            byte[] ip = { 49, 50, 55, 46, 48, 46, 48, 46, 49 };
            byte[] metaDataLength = { 2, 0, 0, 0 };
            byte[] metaData = { 10, 0 };

            using (MemoryStream expectedStream = new MemoryStream(),
                   actualStream = new MemoryStream())
            {
                expectedStream.Write(commandBytes, 0, 4);
                expectedStream.Write(ipLength, 0, 4);
                expectedStream.Write(ip, 0, 9);
                expectedStream.Write(metaDataLength, 0, 4);
                expectedStream.Write(metaData, 0, 2);

                CMDClient client = new CMDClient(null, "Bogus network name");

                typeof(CMDClient).GetField("networkStream", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, actualStream);

                IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
                Command command = new Command(CommandType.UserExit, ipaddress, null);
                client.SendCommandToServerUnthreaded(command);

                Assert.AreEqual(expectedStream.ToArray().Length, actualStream.ToArray().Length);

                expectedStream.Position = 0;
                actualStream.Position = 0;
                int buf;
                while ((buf = expectedStream.ReadByte()) >= 0)
                    Assert.AreEqual(buf, actualStream.ReadByte());
            }
        }
Esempio n. 11
0
        public void TestUserExitCommandWithoutMocks()
        {
            IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
            Command command = new Command(CommandType.UserExit, ipaddress, null);
            MemoryStream stream = new MemoryStream();

            byte[] commandBytes = { 0, 0, 0, 0 };
            byte[] ipLength = { 9, 0, 0, 0 };
            byte[] ip = { 49, 50, 55, 46, 48, 46, 48, 46, 49 };
            byte[] metaDataLength = { 2, 0, 0, 0 };
            byte[] metaData = { 10, 0 };

            stream.Write(commandBytes, 0, 4);
            stream.Write(ipLength, 0, 4);
            stream.Write(ip, 0, 9);
            stream.Write(metaDataLength, 0, 4);
            stream.Write(metaData, 0, 2);

            CMDClient client = new CMDClient(null, "Bogus network name");

            // we need to set the private variable here
            typeof(CMDClient).GetField("networkStream", BindingFlags.NonPublic | BindingFlags.Instance)
                .SetValue(client, stream);

            client.SendCommandToServerUnthreaded(command);
            mocks.VerifyAll();
        }
Esempio n. 12
0
 public frmMain()
 {
     InitializeComponent();
     this.privateWindowsList = new List <frmPrivate>();
     this.client             = new Proshot.CommandClient.CMDClient(IPAddress.Parse("192.168.238.3"), 2324, "None");
 }
Esempio n. 13
0
        private void mniEnter_Click(object sender, EventArgs e)
        {
            if (mniEnter.Text == "Login")
            {
                var dlg = new frmLogin(IPAddress.Parse("192.168.0.105"), 8001);
                dlg.ShowDialog();
                _client = dlg.Client;

                if (_client.Connected)
                {
                    _client.CommandReceived += client_CommandReceived;
                    _client.SendCommand(new Command(CommandType.FreeCommand, IPAddress.Broadcast, _client.Ip + ":" + _client.NetworkName));
                    _client.SendCommand(new Command(CommandType.SendClientList, _client.ServerIp));
                    AddToList(_client.Ip.ToString(), _client.NetworkName);
                    mniEnter.Text = "Log Off";
                }
            }
            else
            {
                mniEnter.Text = "Login";
                _privateWindowsList.Clear();
                _client.Disconnect();
                lstViwUsers.Items.Clear();
                txtNewMessage.Clear();
                txtNewMessage.Focus();
            }
        }
Esempio n. 14
0
 public static void StartClient()
 {
     _client = new CMDClient(IPAddress.Parse(GetIp()), 8001, "None") {NetworkName = _myName};
     _client.ConnectToServer();
     _client.CommandReceived += SetMessage;
 }
Esempio n. 15
0
 public frmMain()
 {
     InitializeComponent();
     this.privateWindowsList = new List <frmPrivate>();
     this.client             = new Proshot.CommandClient.CMDClient(IPAddress.Parse("127.0.0.1"), 8000, "None");
 }
Esempio n. 16
0
 private void StartListening()
 {
     if (_hasServerIp)
     {
         _newClient = new TcpClient();
         try
         {
             _client = new CMDClient(IPAddress.Parse(_serverIp), 8001, "None");
             _newClient.Connect(_serverIp, 8002);
             var readingThread = new Thread(StartReading);
             readingThread.Start();
             _hasServerIp = true;
         }
         catch
         {
             _hasServerIp = false;
         }
     }
     BlockEdit();
 }
Esempio n. 17
0
 public void Client()
 {
     if (!Process.GetProcesses().ToList().Where(item => item.ProcessName == "ConsoleServer").Any())
     {
         ConsoleServer.BatchMode.StartServer("8001");
         ChatClient.BatchMode.StartClient();
         _client = ChatClient.BatchMode.GetClient();
         _client.CommandReceived += SetMessage;
     }
 }
Esempio n. 18
0
 public void VerySimpleTest()
 {
     CMDClient client = new CMDClient(null, "Bogus network name");
     Assert.AreEqual("Bogus network name", client.NetworkName);
 }
Esempio n. 19
0
 public frmMain()
 {
     InitializeComponent();
     this.privateWindowsList = new List<frmPrivate>();
     this.client = new Proshot.CommandClient.CMDClient(IPAddress.Parse("127.0.0.1") , 8000,"None");
 }
Esempio n. 20
0
        private void mniEnter_Click(object sender , EventArgs e)
        {
            if ( this.mniEnter.Text == "Login" )
            {
                frmLogin dlg = new frmLogin(IPAddress.Parse("127.0.0.1") , 8000);
                dlg.ShowDialog();
                this.client = dlg.Client;

                if ( this.client.Connected )
                {
                    this.client.CommandReceived += new Proshot.CommandClient.CommandReceivedEventHandler(client_CommandReceived);
                    this.client.SendCommand(new Command(CommandType.FreeCommand , IPAddress.Broadcast , this.client.IP + ":" + this.client.NetworkName));
                    this.client.SendCommand(new Proshot.CommandClient.Command(Proshot.CommandClient.CommandType.SendClientList , this.client.ServerIP));
                    this.AddToList(this.client.IP.ToString() , this.client.NetworkName);
                    this.mniEnter.Text = "Log Off";
                }
            }
            else
            {
                this.mniEnter.Text = "Login";
                this.privateWindowsList.Clear();
                this.client.Disconnect();
                this.lstViwUsers.Items.Clear();
                this.txtNewMessage.Clear();
                this.txtNewMessage.Focus();
            }
        }
Esempio n. 21
0
 public frmMain()
 {
     InitializeComponent();
     _privateWindowsList = new List<frmPrivate>();
     _client = new CMDClient(IPAddress.Parse("192.168.0.105"), 8001, "None");
 }
Esempio n. 22
0
        public void TestUserExitCommand()
        {
            IPAddress ipaddress = IPAddress.Parse("127.0.0.1");
            Command command = new Command(CommandType.UserExit, ipaddress, null);
            System.IO.Stream fakeStream = mocks.DynamicMock<System.IO.Stream>();
            byte[] commandBytes = { 0, 0, 0, 0 };
            byte[] ipLength = { 9, 0, 0, 0 };
            byte[] ip = { 49, 50, 55, 46, 48, 46, 48, 46, 49 };
            byte[] metaDataLength = { 2, 0, 0, 0 };
            byte[] metaData = { 10, 0 };

            using (mocks.Ordered())
            {
                fakeStream.Write(commandBytes, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ipLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(ip, 0, 9);
                fakeStream.Flush();
                fakeStream.Write(metaDataLength, 0, 4);
                fakeStream.Flush();
                fakeStream.Write(metaData, 0, 2);
                fakeStream.Flush();
            }
            mocks.ReplayAll();
            CMDClient client = new CMDClient(null, "Bogus network name");

            // we need to set the private variable here
            typeof(CMDClient).GetField("networkStream", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(client, fakeStream);

            client.SendCommandToServerUnthreaded(command);
            mocks.VerifyAll();
        }
Esempio n. 23
0
 private void mniEnter_Click(object sender, EventArgs e)
 {
     if (mniEnter.Text == "Вход")
     {
         if (!string.IsNullOrEmpty(_serverIp))
         {
             Messages.Text = secondMessage;
             var dlg = new frmLogin(IPAddress.Parse(_serverIp), 8001);
             dlg.ShowDialog();
             _client = dlg.Client;
             Messages.Text = thirdMessage;
             if (_client.Connected)
             {
                 _client.CommandReceived += client_CommandReceived;
                 _client.SendCommand(new Command(CommandType.FreeCommand, IPAddress.Broadcast,
                                                 _client.Ip + ":" + _client.NetworkName));
                 _client.SendCommand(new Command(CommandType.SendClientList, _client.ServerIp));
                 AddToList(_client.Ip.ToString(), _client.NetworkName);
                 mniEnter.Text = "Выход";
                 mniEnter.Enabled = splitContainer.Enabled = false;
                 Messages.Text = fourthMessage;
             }
         }
     }
     else
     {
         mniEnter.Text = "Вход";
         _privateWindowsList.Clear();
         _client.Disconnect();
         lstViwUsers.Items.Clear();
         mniEnter.Enabled = splitContainer.Enabled = true;
     }
 }