示例#1
0
        public void update2()
        {
            var callback    = new TestCallback();
            var context     = new InstanceContext(callback);
            var pipeFactory =
                new DuplexChannelFactory <ITestService>(context,
                                                        new NetNamedPipeBinding(),
                                                        new EndpointAddress("net.pipe://localhost/Test" + channel.ToString()));

            try {
                var service = pipeFactory.CreateChannel();

                service.Connect();
                //service.SendMessage("Hi, I'm the client");
                int chunk = 50000;
                int total = TransitFunctions._json.Length / chunk;
                service.SendMessage("START," + total.ToString());

                for (int i = 0; i < TransitFunctions._json.Length; i += chunk)
                {
                    int endindex = i + chunk;
                    int length   = 0;
                    if (endindex >= TransitFunctions._json.Length)
                    {
                        length = TransitFunctions._json.Length - i;
                    }
                    else
                    {
                        length = chunk;
                    }
                    service.SendMessage(TransitFunctions._json.Substring(i, length));
                }
                service.SendMessage("END");
                pipeFactory.Close();
            }
            catch (Exception e)
            {
                pipeFactory.Close();
                return;
            }
            this.MarkNodeAsModified(forceExecute: true);
        }
示例#2
0
        public void update()
        {
            List <item> ppp = new List <item>();


            var callback = new TestCallback();
            var context  = new InstanceContext(callback);

            for (int i = 0; i < 10; i++)
            {
                var pipeFactory =
                    new DuplexChannelFactory <ITestService>(context,
                                                            new NetNamedPipeBinding(),
                                                            new EndpointAddress("net.pipe://localhost/Test" + i.ToString()));
                try
                {
                    var service = pipeFactory.CreateChannel();
                    service.Connect();
                    ppp.Add(new item(i.ToString(), item.color.black));
                    pipeFactory.Close();
                }
                catch
                {
                    ppp.Add(new item(i.ToString(), item.color.purple));
                    try
                    {
                        if (pipeFactory.State != CommunicationState.Faulted)
                        {
                            pipeFactory.Close();
                        }
                    }
                    catch
                    {
                    }
                }
            }
            channels = ppp;
        }