Ejemplo n.º 1
0
    public void TestAbortNotInitialized()
    {
        // Execution
        client.Abort();

        // Expected
        request.Received(0).Abort();
    }
Ejemplo n.º 2
0
        public async Task Test9()
        {
            IPAddress   iPAddress = (await Dns.GetHostAddressesAsync("127.0.0.1"))[0];
            TcpListener server    = new TcpListener(iPAddress, 8426);

            server.Start();
            var service = new Service();

            service.Add(
                (ServiceContext context) =>
                (context.RemoteEndPoint as IPEndPoint).Address + ":" + (context.RemoteEndPoint as IPEndPoint).Port,
                "getAddress"
                );
            service.Bind(server);
            var client = new Client("tcp4://127.0.0.1:8426");
            var log    = new Log();

            client.Use(log.IOHandler).Use(log.InvokeHandler);
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            await client.Abort();

            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            server.Stop();
        }
Ejemplo n.º 3
0
        public async Task Test8()
        {
            HttpListener server = new HttpListener();

            server.Prefixes.Add("http://127.0.0.1:8090/");
            server.Start();
            var service = new Service();

            service.Add(
                (ServiceContext context) => context.RemoteEndPoint.ToString(),
                "getAddress"
                );
            service.Bind(server);
            var client = new Client("http://127.0.0.1:8090/");
            var log    = new Log();

            client.Use(log.IOHandler).Use(log.InvokeHandler);
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            await client.Abort().ConfigureAwait(false);

            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            server.Stop();
        }
Ejemplo n.º 4
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (Server != null)
     {
         Server.Abort();
     }
 }
Ejemplo n.º 5
0
 public void StopUpload()
 {
     if (Client != null && Client.IsConnected)
     {
         Client.Abort();
     }
 }
Ejemplo n.º 6
0
 public void Close(bool callDisconnect = true)
 {
     Client?.Abort();
     _stopServices = callDisconnect;
     CleanupServices();
     InitializeClient();
     OnDisconnected?.Invoke(this, new OnDisconnectedEventArgs());
 }
Ejemplo n.º 7
0
        private void ClientStateChangedEventHandler(object sender, StateChangedEventArgs e)
        {
            EventRequest request = new EventRequest();

            request.Events   = e.Events.ToArray();
            request.HashCode = _hashCode;

            EscapeControlChars(request);

            _stateRequestEvent.Reset();
            Client.Abort();

            int callCount = 0;

            while (true)
            {
                DateTime startTime = DateTime.Now;

                try
                {
                    callCount++;
                    Client.Invoke <EventRequest, EventResponse>(request);
                    _stateRequestEvent.Set();
                    break;
                }
                catch (ServerFaultException ex)
                {
                    HandleServerFaultException(ex);

                    break;
                }
                catch (Exception ex)
                {
                    if (callCount >= _config.RetryCount + 1)
                    {
                        callCount = 0;

                        if (MessageBox.Show(string.Format("Unable to contact the server. Do you want to retry?\n\n{0}", ex.Message), "IMI iWMS Thin Client", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1) == System.Windows.Forms.DialogResult.Cancel)
                        {
                            _form.Close();
                            break;
                        }
                    }
                    else
                    {
                        TimeSpan processingTime = DateTime.Now - startTime;

                        if (processingTime.TotalMilliseconds < Client.ConnectTimeout)
                        {
                            int sleepTime = Client.ConnectTimeout - (int)processingTime.TotalMilliseconds;
                            Thread.Sleep(sleepTime);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void InitializeClient()
        {
            Client?.Abort();
            Client = new ClientWebSocket();

            if (_monitorTask == null)
            {
                _monitorTask = StartMonitorTask();
                return;
            }

            if (_monitorTask.IsCompleted)
            {
                _monitorTask = StartMonitorTask();
            }
        }
Ejemplo n.º 9
0
 internal override void OnMessageReceived(CastMessage castMessage)
 {
     if (castMessage.GetJsonType() == "CLOSE")
     {
         Task.Run(async() =>
         {
             try
             {
                 await Client.Abort().ConfigureAwait(false);
             }
             catch (ObjectDisposedException)
             { }
         });
     }
     ;
 }
Ejemplo n.º 10
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     try
     {
         if ((this.server != null) && this.server.IsBound)
         {
             string str;
             this.listView1.Items.Clear();
             for (int i = 0; i < this.server.ClientCount; i++)
             {
                 Client client = this.server.GetClient(i);
                 if (client != null)
                 {
                     if (client.Connected)
                     {
                         if (DateTime.Now.Subtract(client.LastReceiveTime).TotalMilliseconds > this.timeout)
                         {
                             client.Abort();
                         }
                         else
                         {
                             this.listView1.Items.Add(client.CallingEntityTitle + "[" + client.RemoteAddress + "]", 1);
                         }
                     }
                     else
                     {
                         this.listView1.Items.Add(client.LastReceiveTime.ToString(), 2);
                     }
                 }
             }
             while ((str = Network.GetMessage()) != null)
             {
                 if (this.listBox1.Items.Count > 0x3e8)
                 {
                     this.listBox1.Items.Clear();
                 }
                 this.listBox1.SelectedIndex = this.listBox1.Items.Add(str);
                 Console.WriteLine(str);
             }
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception.ToString());
     }
 }
Ejemplo n.º 11
0
        void PowerSwitch(object sender, RoutedEventArgs e)
        {
            try
            {
                using (new OperationContextScope((IContextChannel)Client.InnerChannel))
                {
                    if (PowerOn)
                    {
                        PowerOn = false;
                        if (!contextApplied)
                        {
                            ContextManager.ApplyContextToChannel(Context, Client.InnerChannel);
                            contextApplied = true;
                        }
                        Context = null;
                        ContextManager.DeleteContext(contextFile);
                        Client.PowerOff();
                        Client.Close();
                        client = null;
                    }
                    else
                    {
                        Client.PowerOn();

                        // At this point the channel has the context from the operation called
                        contextApplied = true;
                        // extract and persist context
                        Context = ContextManager.ExtractContextFromChannel(client.InnerChannel);
                        ContextManager.PersistContext(Context, contextFile);
                        PowerOn = true;
                    }
                }
            }
            catch (CommunicationException ce)
            {
                MessageBox.Show(ce.Message);
                Client.Abort();
                client = null;
            }
        }
Ejemplo n.º 12
0
        public async Task Test8()
        {
            UdpClient server  = new UdpClient(8422);
            var       service = new Service();

            service.Add(
                (ServiceContext context) => context.RemoteEndPoint.ToString(),
                "getAddress"
                );
            service.Bind(server);
            var client = new Client("udp4://127.0.0.1:8422");
            var log    = new Log();

            client.Use(log.IOHandler).Use(log.InvokeHandler);
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            await client.Abort().ConfigureAwait(false);

            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress").ConfigureAwait(false));
            server.Close();
        }
Ejemplo n.º 13
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            if (buttonStart.Text == "Stop")
            {
                client.Abort();
                buttonStart.Text = "Start";
                return;
            }
            buttonStart.Text    = "Stop";
            buttonStart.Enabled = false;

            client.Me.Name = textBoxId.Text;

            var listeningAddress = GetHostAddresses(txtIPEndPoint.Text);

            client.Me.EndPoint = new IPEndPoint(listeningAddress, Int32.Parse(uxServerPortUdp.Text));

            // TODO: dovrebbe essere asyncrona perche' ci mette un po' ad aprire le porte
            // O forse bloccante?
            if (uxCbUpnp.Checked)
            {
                UseUPNP(Convert.ToInt32(uxServerPortUdp.Text));
            }

            client.Start();

            //MulticastBootstrap multicast = new MulticastBootstrap();
            //multicast.Start();
            //multicast.Send(Dreams.Kademlia.Message.CreatePingRequest(client.Me));

            textBoxNodeHexId.Text = client.Me.Id.ToString();
            uxServerPortUdp.Text  = client.Me.EndPoint.Port.ToString();
            logger.Info("Client started");

            client.DownloadNodes();
            client.AnnounceToHive(uxServerPortUdp.Text);

            buttonStart.Enabled = true;
        }
Ejemplo n.º 14
0
        public async Task Test8()
        {
            MockServer server  = new MockServer("test8");
            var        service = new Service();

            service.Add(
                (ServiceContext context) => context.RemoteEndPoint.ToString(),
                "getAddress"
                );
            service.Bind(server);
            var client = new Client("mock://test8");
            var log    = new Log();

            client.Use(log.IOHandler).Use(log.InvokeHandler);
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            await client.Abort();

            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            Console.WriteLine(await client.InvokeAsync <string>("getAddress"));
            server.Close();
        }
Ejemplo n.º 15
0
        public string Connect(string address, int port)
        {
            if (Client != null && Client.State == CommunicationState.Opened)
            {
                Client.Abort();
            }

            Client = new ServiceManagerClient(address, port);
            try
            {
                Client.RegisterClient();
            }
            catch (EndpointNotFoundException)
            {
                return("%!Unable to connect to " + address + ":" + port);
            }
            Client.Disconnected                  += OnServiceDisconnected;
            Client.NotificationReceived          += OnNotificationReceived;
            Client.ExtensionNotificationReceived += OnExtensionNotificationReceived;

            var dt = Client.GetServerTime();

            return("%~Connected. Server time is " + dt + ".");
        }
Ejemplo n.º 16
0
        protected virtual void Run()
        {
            Task.Run(async() =>
            {
                try
                {
                    QueuedEvent.OnNew = (e) =>
                    {
                        OnClientEvent?.Invoke(e);
                    };
                    var inFault = false;
                    var running = true;
                    RunOpen();
                    while (running)
                    {
                        if (await QueuedEvent.Next() is var nextEvent && nextEvent.Ok)
                        {
                            switch (nextEvent.Value)
                            {
                            case ClientEvent.Dispose:
                                RunClose();
                                running = false;
                                break;

                            case ClientEvent.Opening:
                                break;

                            case ClientEvent.Opened:
                                IsConnected = true;
                                break;

                            case ClientEvent.Restart:
                            case ClientEvent.Faulted:
                                if (!inFault)
                                {
                                    inFault = true;
                                    Client.Abort();
                                    RunClose();
                                    await Task.Delay(WaitOnFault.Milliseconds);
                                    RunOpen();
                                    inFault = false;
                                }
                                break;

                            case ClientEvent.Closing:
                                break;

                            case ClientEvent.Closed:
                                break;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.LogException();
                    QueuedEvent.New(ClientEvent.Exception);
                }
                finally
                {
                    RunClose();
                    Disposed          = true;
                    QueuedEvent.OnNew = null;
                }
            });
        }
        static void Main(string[] args)
        {
            while (true)
            {
                var         context           = new ZContext();
                Thread      broker1           = new Thread(() => BrokerCreator.Broker(context, broker1AddrRequest, broker1AddrResponse, broker1AddrRequestPush, broker1AddrResponsePull, broker1AddrRequestPub, broker1AddrResponseSub, AddrToBroker2, AddrToBroker3, broker1AddrFromBrokers, brokerIdentity1));
                Thread      broker2           = new Thread(() => BrokerCreator.Broker(context, broker2AddrRequest, broker2AddrResponse, broker2AddrRequestPush, broker2AddrResponsePull, broker2AddrRequestPub, broker2AddrResponseSub, AddrToBroker1, AddrToBroker3, broker2AddrFromBrokers, brokerIdentity2));
                Thread      broker3           = new Thread(() => BrokerCreator.Broker(context, broker3AddrRequest, broker3AddrResponse, broker3AddrRequestPush, broker3AddrResponsePull, broker3AddrRequestPub, broker3AddrResponseSub, AddrToBroker1, AddrToBroker2, broker3AddrFromBrokers, brokerIdentity3));
                ZSocketType socketTypeClient  = ZSocketType.None;
                ZSocketType socketTypeServer  = ZSocketType.None;
                string      AddressforClient  = "";
                string      AddressforServer  = "";
                ZSocketType socketTypeClient2 = ZSocketType.None;
                ZSocketType socketTypeServer2 = ZSocketType.None;
                string      AddressforClient2 = "";
                string      AddressforServer2 = "";
                ZSocketType socketTypeClient3 = ZSocketType.None;
                ZSocketType socketTypeServer3 = ZSocketType.None;
                string      AddressforClient3 = "";
                string      AddressforServer3 = "";
                Thread      Client2           = null;
                Thread      Server2           = null;
                Thread      Client3           = null;
                Thread      Server3           = null;
                Thread      Client            = null;
                Thread      Server            = null;
                string      ClientIdentity    = "Client";
                string      ServerIdentity    = "Server";
                string      ClientIdentity2   = "Client2";
                string      ServerIdentity2   = "Server2";
                string      ClientIdentity3   = "Client3";
                string      ServerIdentity3   = "Server3";
                string      AddrForSub        = "";

                Random random = new Random();

                Console.WriteLine("\nPress number to choose type of clients sockets.");
                Console.WriteLine("1 - REQ-REP");
                Console.WriteLine("2 - PUSH-PULL");
                Console.WriteLine("3 - PUB-SUB");
                Console.WriteLine("4 - All sockets different");
                Console.WriteLine("5 - All sockets REQ-REP");
                Console.WriteLine("6 - All sockets PUSH-PULL");
                Console.WriteLine("7 - All sockets PUB-SUB\n");

                ConsoleKey key2 = Console.ReadKey(true).Key;

                if (key2 == ConsoleKey.D1)
                {
                    socketTypeClient = ZSocketType.REQ;
                    socketTypeServer = ZSocketType.REP;
                    AddressforClient = AddressforClientReq[random.Next(0, AddressforClientReq.Length)];
                    AddressforServer = AddressforServerRep[0];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                }
                else if (key2 == ConsoleKey.D2)
                {
                    socketTypeClient = ZSocketType.PUSH;
                    socketTypeServer = ZSocketType.PULL;
                    AddressforClient = AddressforClientPush[random.Next(0, AddressforClientPush.Length)];
                    AddressforServer = AddressforServerPull[0];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                }
                else if (key2 == ConsoleKey.D3)
                {
                    int randIndex = random.Next(0, AddressforServerSub.Length);

                    socketTypeClient = ZSocketType.PUB;
                    socketTypeServer = ZSocketType.SUB;
                    AddressforClient = AddressforClientPub[random.Next(0, AddressforClientPub.Length)];
                    AddressforServer = AddressforServerSub[randIndex];
                    AddrForSub       = AddressforClientReq[randIndex];

                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer, socketTypeServer, AddrForSub));
                }
                else if (key2 == ConsoleKey.D4)
                {
                    socketTypeClient  = ZSocketType.REQ;
                    socketTypeServer  = ZSocketType.REP;
                    AddressforClient  = AddressforClientReq[0];
                    AddressforServer  = AddressforServerRep[1];
                    socketTypeClient2 = ZSocketType.PUSH;
                    socketTypeServer2 = ZSocketType.PULL;
                    AddressforClient2 = AddressforClientPush[1];
                    AddressforServer2 = AddressforServerPull[2];
                    socketTypeClient3 = ZSocketType.PUB;
                    socketTypeServer3 = ZSocketType.SUB;
                    AddressforClient3 = AddressforClientPub[2];
                    AddressforServer3 = AddressforServerSub[0];
                    AddrForSub        = AddressforClientReq[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, ""));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, AddrForSub));
                }
                else if (key2 == ConsoleKey.D5)
                {
                    socketTypeClient  = ZSocketType.REQ;
                    socketTypeServer  = ZSocketType.REP;
                    AddressforClient  = AddressforClientReq[0];
                    AddressforServer  = AddressforServerRep[1];
                    socketTypeClient2 = ZSocketType.REQ;
                    socketTypeServer2 = ZSocketType.REP;
                    AddressforClient2 = AddressforClientReq[1];
                    AddressforServer2 = AddressforServerRep[2];
                    socketTypeClient3 = ZSocketType.REQ;
                    socketTypeServer3 = ZSocketType.REP;
                    AddressforClient3 = AddressforClientReq[2];
                    AddressforServer3 = AddressforServerRep[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, AddressforServer3));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, ""));
                }
                else if (key2 == ConsoleKey.D6)
                {
                    socketTypeClient  = ZSocketType.PUSH;
                    socketTypeServer  = ZSocketType.PULL;
                    AddressforClient  = AddressforClientPush[0];
                    AddressforServer  = AddressforServerPull[1];
                    socketTypeClient2 = ZSocketType.PUSH;
                    socketTypeServer2 = ZSocketType.PULL;
                    AddressforClient2 = AddressforClientPush[1];
                    AddressforServer2 = AddressforServerPull[2];
                    socketTypeClient3 = ZSocketType.PUSH;
                    socketTypeServer3 = ZSocketType.PULL;
                    AddressforClient3 = AddressforClientPush[2];
                    AddressforServer3 = AddressforServerPull[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, ""));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, AddressforServer2));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, ""));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, AddressforServer3));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, ""));
                }
                else if (key2 == ConsoleKey.D7)
                {
                    socketTypeClient  = ZSocketType.PUB;
                    socketTypeServer  = ZSocketType.SUB;
                    AddressforClient  = AddressforClientPub[0];
                    AddressforServer  = AddressforServerSub[1];
                    socketTypeClient2 = ZSocketType.PUB;
                    socketTypeServer2 = ZSocketType.SUB;
                    AddressforClient2 = AddressforClientPub[1];
                    AddressforServer2 = AddressforServerSub[2];
                    socketTypeClient3 = ZSocketType.PUB;
                    socketTypeServer3 = ZSocketType.SUB;
                    AddressforClient3 = AddressforClientPub[2];
                    AddressforServer3 = AddressforServerSub[0];
                    AddrForSub        = AddressforClientReq[1];
                    string AddrForSub2 = AddressforClientReq[2];
                    string AddrForSub3 = AddressforClientReq[0];

                    Client  = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, ""));
                    Server  = new Thread(() => ServerCreator.Server(context, ServerIdentity, AddressforServer, socketTypeServer, AddrForSub));
                    Client2 = new Thread(() => ClientCreator.Client(context, ClientIdentity2, AddressforClient2, socketTypeClient2, ""));
                    Server2 = new Thread(() => ServerCreator.Server(context, ServerIdentity2, AddressforServer2, socketTypeServer2, AddrForSub2));
                    Client3 = new Thread(() => ClientCreator.Client(context, ClientIdentity3, AddressforClient3, socketTypeClient3, ""));
                    Server3 = new Thread(() => ServerCreator.Server(context, ServerIdentity3, AddressforServer3, socketTypeServer3, AddrForSub3));
                }

                Console.WriteLine("Press number to choose test. Press S to stop.");
                Console.WriteLine("1 - all components active");
                if (key2 == ConsoleKey.D1 || key2 == ConsoleKey.D2 || key2 == ConsoleKey.D3)
                {
                    Console.WriteLine("2 - passive sending client after sending and active receiving client after 5 sec\n");
                }
                else
                {
                    Console.WriteLine("\n");
                }

                ConsoleKey key = Console.ReadKey(true).Key;

                broker1.Start();
                broker2.Start();
                broker3.Start();

                if (key == ConsoleKey.D1)
                {
                    Server.Start();
                    Client.Start();

                    if (AddressforClient2 != "")
                    {
                        Server2.Start();
                        Server3.Start();
                        Client2.Start();
                        Client3.Start();
                    }
                }
                else if (key == ConsoleKey.D2)
                {
                    Client.Start();
                    Thread.Sleep(10 * 1000);
                    Client.Abort();
                    Thread.Sleep(5 * 1000);
                    Server.Start();
                    Thread.Sleep(5 * 1000);
                    Client = new Thread(() => ClientCreator.Client(context, ClientIdentity, AddressforClient, socketTypeClient, AddressforServer));
                    Client.Start();
                }

                while (Console.ReadKey(true).Key != ConsoleKey.S)
                {
                    Thread.Sleep(1);
                }
                Client.Abort();
                Server.Abort();
                if (Client2 != null)
                {
                    Client2.Abort();
                    Server2.Abort();
                    Client3.Abort();
                    Server3.Abort();
                }
                broker1.Abort();
                broker2.Abort();
                broker3.Abort();
            }
        }
Ejemplo n.º 18
0
 private void Abort()
 {
     _abort = true;
     Client.Abort();
     _stateRequestEvent.Set();
 }
Ejemplo n.º 19
0
        public void Abort(string reason)
        {
            var pair = new CommandParameterPair("DISCONN", Uri.EscapeDataString(reason));

            Client.Abort();
        }
Ejemplo n.º 20
0
        void DoOperation(object sender, RoutedEventArgs e)
        {
            int    value     = 0;
            string operation = ((Button)sender).Content.ToString();

            if (!operation.StartsWith("=") && !int.TryParse(Display.Text, out value))
            {
                MessageBox.Show("Invalid input! Try again.");
                Display.Text = String.Empty;
            }

            try
            {
                if (!PowerOn)
                {
                    PowerSwitch(ButtonC, null);
                }

                using (new OperationContextScope((IContextChannel)Client.InnerChannel))
                {
                    if (!contextApplied)
                    {
                        ContextManager.ApplyContextToChannel(Context, Client.InnerChannel);
                        contextApplied = true;
                    }

                    switch (operation)
                    {
                    case "=": { value = Client.Add(0); break; }

                    case "+": { value = Client.Add(value); break; }

                    case "-": { value = Client.Subtract(value); break; }

                    case "x": { value = Client.Multiply(value); break; }

                    case "/": {
                        if (value == 0)
                        {
                            MessageBox.Show("Divide By Zero is not allowed");
                            value = client.Add(0);
                            break;
                        }
                        else
                        {
                            value = Client.Divide(value);
                            break;
                        }
                    }
                    }
                }
            }
            catch (CommunicationException ce)
            {
                MessageBox.Show(ce.Message);
                Client.Abort();
                client = null;
            }

            Display.Background = onBrush;
            Display.Text       = value.ToString();
            displayNew         = true;
        }