Esempio n. 1
0
        /// <summary>
        /// 网络频道
        /// </summary>
        /// <param name="socket">网络套接字</param>
        /// <param name="packer">拆包打包器</param>
        /// <param name="name">频道名字</param>
        public NetworkChannel(ISocket socket, IPacker packer, string name)
        {
            Guard.Requires <ArgumentNullException>(socket != null);
            Guard.Requires <ArgumentNullException>(packer != null);
            Guard.NotEmptyOrNull(name, "name");

            Name           = name;
            this.socket    = socket;
            this.packer    = packer;
            receiveState   = new ReceiveState(packer);
            heartBeatState = new HeartBeatState(0);
            lastException  = null;

            heartBeatState.OnMissHeartBeat += (count) =>
            {
                if (OnMissHeartBeat != null)
                {
                    OnMissHeartBeat.Invoke(this, count);
                }
            };

            socket.On(SocketEvents.Connect, OnSocketConnect);
            socket.On(SocketEvents.Error, OnSocketError);
            socket.On(SocketEvents.Closed, OnSocketClosed);
            socket.On(SocketEvents.Message, OnSocketMessage);
            socket.On(SocketEvents.Disconnect, OnSocketDisconnect);
            socket.On(SocketEvents.Sent, OnSocketSent);
        }
        private void Start()
        {
            IPackImage[] imgs = new IPackImage[_textures.Length];

            for (int i = 0; i < _textures.Length; i++)
            {
                imgs[i] = new PackImage(_textures[i]);
            }

            // Create dummy images.
            //
            // int min = 10;
            // int max = 50;
            // int count = 955;
            // IPackImage[] imgs = new IPackImage[count];
            // for (int i = 0; i < imgs.Length; i++)
            // {
            //     imgs[i] = new DummyPackImage(Random.Range(min, max), Random.Range(min, max), Random.ColorHSV());
            // };

            _packer        = new Packer(_material);
            _packerService = new PackService(_packer);
            _infos         = _packerService.PackImages(imgs);

            // Show a packed texture as preview.
            _tex = _packerService.GetPackedImage();

            _targetMaterial             = _target.GetComponent <Renderer>().material;
            _targetMaterial.mainTexture = _tex;

            ShowTex(0);
        }
Esempio n. 3
0
        public ExportImportManager( IPacker packer )
        {
            if(packer == null)
                throw new CoreArgumentException( Resources.ResourceManager.GetString( "PackingException" ) );

            m_packer = packer;
        }
Esempio n. 4
0
 /// <summary>
 /// 接收状态
 /// </summary>
 public ReceiveState(IPacker packer)
 {
     packet       = new Queue <object>(32);
     stream       = new MemoryStream(1024 * 64);
     packetLength = 0;
     this.packer  = packer;
 }
Esempio n. 5
0
 public static byte[] Pack <TDefinition>(this IPacker <TDefinition> packer, IReadOnlyList <TDefinition> data)
 {
     using (var m = new MemoryStream())
     {
         packer.Pack(data, m);
         return(m.ToArray());
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 生成网络频道
        /// </summary>
        /// <param name="nsp">网络提供商</param>
        /// <param name="packer">打包解包器</param>
        /// <param name="name">名字</param>
        /// <returns>网络频道</returns>
        private INetworkChannel MakeChannel(string nsp, IPacker packer, string name)
        {
            if (packer == null)
            {
                throw new ArgumentNullException("packer", "Please call : Make(string, IPacker, string)");
            }
            var socketFactory = App.Make <ISocketManager>();
            var socket        = socketFactory.Make(nsp, name);

            return(new NetworkChannel(socket, packer, name));
        }
Esempio n. 7
0
        /// <summary>
        /// 拓展Channel
        /// </summary>
        /// <param name="nsp">拓展端口</param>
        /// <param name="packer">打包解包器</param>
        /// <param name="name">名字</param>
        private void ExtendChannel(string nsp, IPacker packer, string name)
        {
            var uri = new Uri(nsp);
            Func <Uri, IPacker, string, INetworkChannel> maker;

            if (!channelMaker.TryGetValue(NormalProtocol(uri.Scheme), out maker))
            {
                throw new RuntimeException("Undefined network protocol [" + uri.Scheme + "]");
            }

            Extend(() => maker.Invoke(uri, packer, name), name);
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;
            LogAction.LogOut      += LogAction_LogOut;
            CloudClient client = new CloudClient(new SocketClient(), 500000, 1024 * 1024); //最大数据包能够接收 1M
            PackHander  tmp    = new PackHander();

            client.Install(tmp);
            client.Disconnect += Client_Disconnect;

            if (client.Connect("127.0.0.1", 2285))
            {
                ZYSync  Sync       = client.Sync;
                IPacker ServerPack = Sync.Get <IPacker>();

                var res = ServerPack.IsLogOn("AAA", "BBB")?[0]?.Value <bool>();

                if (res != null && res == true)
                {
                    var html = ServerPack.StartDown("http://www.baidu.com")?[0]?.Value <string>();
                    if (html != null)
                    {
                        Console.WriteLine("BaiduHtml:" + html.Length);

                        var time = ServerPack.GetTime();

                        Console.WriteLine("ServerTime:" + time);

                        ServerPack.SetPassWord("123123");

                        var x = ServerPack.StartDown("http://www.qq.com");

                        Console.WriteLine("QQHtml:" + x.First.Value <string>().Length);

                        System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                        stop.Start();
                        var rec = ServerPack.TestRec2(1000);
                        stop.Stop();

                        Console.WriteLine("Rec:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);
                        TestRun(client);
                    }
                }
                Console.WriteLine("Close");
                Console.ReadLine();
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 建立链接
        /// </summary>
        /// <param name="nsp">网络服务提供商</param>
        /// <param name="packer">打包解包器</param>
        /// <param name="name">名字</param>
        /// <returns>网络频道</returns>
        public INetworkChannel Make(string nsp, IPacker packer, string name = null)
        {
            lock (syncRoot)
            {
                Guard.NotEmptyOrNull(nsp, "nsp");
                name = string.IsNullOrEmpty(name) ? GetDefaultName() : name;

                if (!ContainsExtend(name))
                {
                    ExtendChannel(nsp, packer, name);
                }

                makeHash.Add(name);

                return(AddChannelTick(name));
            }
        }
Esempio n. 10
0
 /// <summary>
 /// 设置消息打包器
 /// </summary>
 /// <param name="converter"></param>
 public void SetPacker(IPacker packer)
 {
     this.packer = packer;
     packer.SetMessagePool(messagePool);
 }
Esempio n. 11
0
 /// <summary>
 /// 接收状态
 /// </summary>
 public ReceiveState(IPacker packer)
 {
     stream       = new MemoryStream(1024 * 64);
     packetLength = 0;
     this.packer  = packer;
 }
Esempio n. 12
0
 public PacketConverter(IPacker packer, IUnpacker unpacker)
 {
     _packer   = packer;
     _unpacker = unpacker;
 }
        /// <summary>
        /// 构造函数根,所有其他构造函数都从此进入
        /// </summary>
        /// <param name="socket">核心socket,必须是已经打开的TCP socket</param>
        /// <param name="eventArgsfactory">
        /// <para>获得异步事件对象和回收该对象的方法。</para>
        /// <para>输入空值会创建默认新建和销毁逻辑.</para></param>
        /// <param name="byteSegmentLocator">
        /// <para>收到数据后创建和定位目标数据片段的定位器。</para>
        /// <para>输入空值会创建默认创建新数组的逻辑</para>
        /// </param>
        /// <param name="byteSegmentLocator">
        /// <para>事件容器,负责处理统一的事件相应。</para>
        /// <para>输入空值会使用静态的默认容器,可以为一组client指定同一个容器进行分流</para>
        /// </param>
        public ReactiveTcpClient(
            Socket socket,
            ICutter <TPacket> dataCutter,
            IPacker <TPacket> dataPacker,
            Func <Disposable <SocketAsyncEventArgs> > eventArgsfactory = null,
            IByteSegmentLocator byteSegmentLocator  = null,
            ITcpClientEventContainer eventContainer = null
            )
        {
            //Contract.Requires<ArgumentNullException>(dataCutter != null, "Parameter dataCutter cannot be null.");
            //Contract.Requires<ArgumentNullException>(dataPacker != null, "Parameter dataPacker cannot be null.");
            //Contract.Requires<ArgumentNullException>(eventArgsfactory != null, "Parameter eventArgsfactory cannot be null.");
            //Contract.Requires<ArgumentNullException>(socket != null, "Parameter socket cannot be null.");
            //Contract.Requires<ArgumentException>(socket.ProtocolType.HasFlag(ProtocolType.Tcp), "Parameter socket should be TCP socket.");
            //Contract.Requires<ArgumentException>(socket.Connected, "Parameter socket must be open.");

            //_disposeActionList.Push(() => socket.Dispose());
            ExecutionSchedulerPair = new ConcurrentExclusiveSchedulerPair();

            _dataCutter = dataCutter;
            _dataPacker = dataPacker;

            //默认创建销毁逻辑。
            eventArgsfactory =
                eventArgsfactory ??
                new Func <Disposable <SocketAsyncEventArgs> >(
                    () =>
                    new Disposable <SocketAsyncEventArgs>(
                        ea => ea.Dispose(),
                        new SocketAsyncEventArgs()
                        )
                    );

            //默认创建新数组逻辑
            _byteSegmentLocator = byteSegmentLocator ?? new NewArrayByteSegmentLocator();

            //默认事件订阅容器
            EventContainer = eventContainer ?? TcpClientEventContainer.DefaultInstance;

            //创建字段对象


            _socket = socket;
            _disposeActionList.Push(() => _socket.Dispose());

            _disposed = false;
            //_asyncSupport = new ObservableToAsync<TPacket>();
            _sendingQueue = new ConcurrentQueue <Tuple <Queue <ArraySegment <byte> >, AsyncCallback, AbortionChecker> >();


            _packetReceivedBuffer     = new BufferBlock <TPacket>();
            _packetReceivedObservable = _packetReceivedBuffer.AsObservable();
            _packetReceivedObserver   = _packetReceivedBuffer.AsObserver();
            _sendLaucherSubject       = new Subject <SocketAsyncEventArgs>();


            _disposeActionList.Push(() => _sendLaucherSubject.Dispose());



            //获得发送的事件参数并且登记销毁
            var tokenSend = eventArgsfactory();

            _sendEventArgs = tokenSend.StateObject;
            _disposeActionList.Push(
                () =>
            {
                tokenSend.Dispose();
                _sendEventArgs = null;
            });

            //获得接收的事件参数并且登记销毁
            var tokenReceive = eventArgsfactory();

            _receiveEventArgs = tokenReceive.StateObject;
            _disposeActionList.Push(
                () =>
            {
                tokenReceive.Dispose();
                _receiveEventArgs = null;
            });


            //设置接收订阅
            ConfigReceive();
            //设置发送订阅
            ConfigSend();
        }
Esempio n. 14
0
 public Redis(IPacker pack, RedisConfig config)
 {
     RedisClientManager.Init(config);
     this.pack    = pack;
     this.factory = new CmdFactory(pack);
 }
Esempio n. 15
0
 public static void AddPacker(IPacker packer)
 {
     ActualCustomPackers.Add(packer);
 }
Esempio n. 16
0
 public CmdFactory(IPacker pack)
 {
     this.pack = pack;
 }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            CloudClient client = new ClientBuilder().Bulid();
            PackHander  tmp    = new PackHander();

            client.Install(tmp);
            client.Disconnect += Client_Disconnect;

            if (client.Init("127.0.0.1", 2285))
            {
                IPacker ServerPack = client.Get <IPacker>();


                //re:
                try
                {
                    var res = ServerPack.IsLogOn("AAA", "BBB")?[0]?.Value <bool>();

                    if (res != null && res == true)
                    {
                        var html = ServerPack.StartDown("http://www.baidu.com")?[0]?.Value <string>();
                        if (html != null)
                        {
                            Console.WriteLine("BaiduHtml:" + html.Length);

                            var time = ServerPack.GetTime();

                            Console.WriteLine("ServerTime:" + time);

                            ServerPack.SetPassWord("123123");

                            string cc = ServerPack.SetMessage("HEIIO", "WORD");
                            Console.WriteLine(cc);

                            ServerPack.SetMessage();

                            var x = ServerPack.StartDown("http://www.qq.com");

                            Console.WriteLine("QQHtml:" + x.First.Value <string>().Length);

                            System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                            stop.Start();
                            var rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);
                            stop.Restart();
                            rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);
                            stop.Restart();
                            rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);

                            stop.Restart();

                            long cf = 0;
                            while (cf < 100000)
                            {
                                cf = ServerPack.Adds(cf);
                            }

                            stop.Stop();
                            Console.WriteLine("ADD:{0} time:{1} MS", cf, stop.ElapsedMilliseconds);

                            stop.Restart();
                            for (int j = 0; j < 100000; j++)
                            {
                                ServerPack.Add(10);
                                ServerPack.Sub(5);
                            }

                            int i = ServerPack.GitIt();

                            stop.Stop();



                            Console.WriteLine("ADD:{0} time:{1} MS", i, stop.ElapsedMilliseconds);


                            stop.Restart();

                            Parallel.For(0, 100000, (xxxx) =>
                            {
                                ServerPack.Add(10);
                            });

                            i = ServerPack.GitIt();

                            stop.Stop();



                            Console.WriteLine("ADDASYN:{0} time:{1} MS", i, stop.ElapsedMilliseconds);

                            stop.Restart();
                            Parallel.For(0, 100000, (num) =>
                            {
                                long a = ServerPack.AddRet(num);
                            });

                            stop.Stop();

                            var l = ServerPack.Gitnum();
                            Console.WriteLine("AddRetASYN:{0} time:{1} MS", l, stop.ElapsedMilliseconds);

                            TestRun(client);
                            //TestRun(client);
                            //TestRun(client);
                        }
                    }
                }
                catch (TimeoutException er)
                {
                    Console.WriteLine(er.ToString());
                }

                Console.WriteLine("Close");
                Console.ReadLine();
            }
        }
Esempio n. 18
0
 public PackService(IPacker packer)
 {
     _packer = packer;
 }
Esempio n. 19
0
 public Pack(IServiceProvider services)
     : base(services)
 {
     _packer = services.GetService <IPacker>();
 }
Esempio n. 20
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;


            CloudClient client = new ClientBuilder().Bulid();
            PackHander  tmp    = new PackHander();

            client.Install(tmp);
            client.Disconnect += Client_Disconnect;


            if (client.Init("127.0.0.1", 2285))
            {
                IPacker ServerPack = client.GetForEmit <IPacker>();
re:
                try
                {
                    var res = ServerPack.IsLogOn("AAA", "BBB")?[0]?.Value <bool>();

                    if (res != null && res == true)
                    {
                        var html = ServerPack.StartDown("http://www.baidu.com");



                        if (html != null)
                        {
                            Console.WriteLine("BaiduHtml:" + html.Length);


                            var time = ServerPack.GetTime();


                            ServerPack.ShowMessage("ff");


                            Console.WriteLine("ServerTime:" + time);

                            ServerPack.SetPassWord("123123");

                            var x = ServerPack.StartDown("http://www.qq.com");

                            Console.WriteLine("QQHtml:" + x.Length);

                            System.Diagnostics.Stopwatch stop = new System.Diagnostics.Stopwatch();
                            stop.Start();
                            var rec = ServerPack.TestRec(10000);
                            stop.Stop();

                            Console.WriteLine("Rec1:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);


                            stop.Restart();
                            rec = ServerPack.TestRec(10000);
                            stop.Stop();
                            Console.WriteLine("Rec1:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);

                            stop.Restart();
                            rec = ServerPack.TestRec(10000);
                            stop.Stop();
                            Console.WriteLine("Rec1:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);

                            Console.WriteLine();
                            stop.Restart();
                            rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec2:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);

                            stop.Restart();
                            rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec2:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);

                            stop.Restart();
                            rec = ServerPack.TestRec2(10000);
                            stop.Stop();
                            Console.WriteLine("Rec2:{0} time:{1} MS", rec, stop.ElapsedMilliseconds);


                            TestRun(client);
                        }
                    }
                }
                catch (TimeoutException er)
                {
                    Console.WriteLine(er.ToString());
                }

                Console.WriteLine("Close");
                Console.ReadLine();

                goto re;
            }
        }
Esempio n. 21
0
 static extern int CreateShetabPacker(out IPacker ppstgOpen);
Esempio n. 22
0
 /// <summary>
 /// Инициализация необходимых объектов для работы.
 /// </summary>
 /// <param name="name">Название стеганографического
 ///     алгоритма упаковки.</param>
 /// <param name="packer">Стеганографический упаковщик.</param>
 public PackerViewModel(IPacker packer, string name)
 {
     _packer   = packer;
     _helperIO = new HelperIO();
     Name      = name;
 }