Пример #1
0
        public void Run()
        {
            try
            {
                while (true)
                {
                    using (SubscriberSocket sock = new SubscriberSocket())
                    {
                        sock.Connect("tcp://eddn-relay.elite-markets.net:9500");
                        sock.SubscribeToAnyTopic();

                        Msg msg = new Msg();
                        msg.InitEmpty();

                        while (sock.TryReceive(ref msg, TimeSpan.FromMinutes(10)))
                        {
                            Process(msg);
                            msg.Close();
                            msg.InitEmpty();
                        }
                    }
                }
            }
            finally
            {
                NetMQConfig.Cleanup();
            }
        }
Пример #2
0
        private void ReceiveMessage(IObserver <TMessage> observer, SubscriberSocket socket)
        {
            try
            {
                string topic;
                byte[] rawMessage;
                string typeName;

                if (socket.TryReceive(_receiveTimeout, out topic, out typeName, out rawMessage) && MatchesTopic(topic))
                {
                    var message = typeName == null
                        ? _deserializers.Values.Single().Deserialize(rawMessage)
                        : _deserializers[typeName].Deserialize(rawMessage);

                    observer.OnNext(message);
                }
            }
            catch (Exception exception)
            {
                observer.OnError(exception);
            }
        }
Пример #3
0
    void zmqSubThread()
    {
        while (app_exit_sub == false && subscriber != null)
        {
            try
            {
                Msg msg = new Msg();
                msg.InitEmpty();
                bool dresult = subscriber.TryReceive(ref msg, new TimeSpan(0, 0, 0, 0, 10));

                if (dresult)
                {
                    last_read_time = Helper2.getCurrentTimeSpan();

                    //if (typeof(SUBTYPE) == typeof(RawData))
                    //{
                    //    get_raw_bytes = msg.Data;
                    //}
                    //else
                    //{
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(msg.Data);
                    SUBTYPE result            = Serializer.Deserialize <SUBTYPE>(ms);
                    get = result;
                    //}

                    if (app_exit_sub == false)
                    {
                        state = NetworkState.CONNECTED;
                        updateSetupStatus(true);
                        dataTrigger();
                    }
                }
            }
            catch
            {
            }
        }
    }
Пример #4
0
        public OCForm()
        {
            sc = WindowsFormsSynchronizationContext.Current as WindowsFormsSynchronizationContext;

            InitializeComponent();

            flowLayoutPanelSysmenu.MouseDown   += MoveWindow;
            flowLayoutPanelSysmenu.DoubleClick += ResizeWindow;
            toolStripLeftPanel.MouseDown       += MoveWindow;
            toolStripLeftPanel.DoubleClick     += ResizeWindow;

            RegisterSysCommandBehavior();

            RegisterOwnerDraw();

            LoadLeftPanel();

            //Random randomGen = new Random();
            //KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor));

            lvConversations.Items.AddRange(new ListViewItem[] {
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue136", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue137", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "Message2", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "\ue138", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "Message2", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
                new ListViewItem("1")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "姓名1", LastUpdate = DateTime.Now, PeekMessage = "Message1", IsMute = true
                    }
                },
                new ListViewItem("2")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name2", LastUpdate = DateTime.Now, PeekMessage = "\ue139", IsMute = true
                    }
                },
                new ListViewItem("3")
                {
                    Tag = new ConversationShortcut()
                    {
                        Icon = Guid.NewGuid(), DisplayName = "Name3", LastUpdate = DateTime.Now, PeekMessage = "消息~3", IsMute = true
                    }
                },
            });
            for (int i = 0; i < lvConversations.Items.Count; i++)
            {
                var shortcut = lvConversations.Items[i].Tag as ConversationShortcut;
                var chatUI   = GetChatUI(shortcut.Icon);
                chatrooms.AddOrUpdate(shortcut.Icon.ToString(), chatUI, (key, value) => chatUI);
                //chatUI.BackColor = Color.FromKnownColor(names[randomGen.Next(names.Length)]);
            }

            /*chatUI.AddMessage(Guid.Empty, "你好,祝你生日快乐!");
             * chatUI.AddMessage(Guid.Empty, "你是?", false);
             * chatUI.AddMessage(Guid.Empty, "我是你的小号啊");
             * chatUI.AddMessage(Guid.Empty, ":-( 伐开熏 ...", false);
             */
            Messaging.Message message = null;
            ThreadPool.QueueUserWorkItem(state => {
                //Get Message From 0MQ
                //Handle
                bool working = true;
                while (working)
                {
                    sendEvent.WaitOne();
                    //Validate Message;
                    if (message != null)
                    {
                        Guid guid = message.From; string Guid = guid.ToString();
                        ChatUI ui = null;
                        if (chatrooms.ContainsKey(Guid))
                        {
                            ui = chatrooms[Guid];
                        }
                        else
                        {
                            ui = new ChatUI(guid); chatrooms.TryAdd(Guid, ui);
                        }
                    }
                }
            });

            ThreadPool.QueueUserWorkItem(state => {
                using (SubscriberSocket subscriber = new SubscriberSocket()) {
                    subscriber.Bind($"tcp://localhost:12555");
                    //Handle Subscriber
                    subscriber.SubscribeToAnyTopic();
                    Msg msg = new Msg(); msg.InitEmpty();
                    while (true)
                    {
                        subscriber.TryReceive(ref msg, TimeSpan.MaxValue);
                        using (MemoryStream ms = new MemoryStream(msg.Data)) {
                            BinaryFormatter bf             = new BinaryFormatter();
                            Messaging.Message groupMessage = bf.Deserialize(ms) as Messaging.Message;
                            if (groupMessage == null)
                            {
                                continue;
                            }
                            if (!groupMessage.MessageType.HasFlag(Messaging.MessageType.MT_GROUP_FLAG))
                            {
                                continue;
                            }
                            Guid from = groupMessage.From;
                        }
                    }
                }
            });

            ThreadPool.QueueUserWorkItem(state => {
                new FakeServer().Init();
            });

            cmdSend.Click += (sender, @event) => {
                if (ActiveChatUI == null)
                {
                    return;
                }

                Guid TO = ActiveChatUI.Target; string to = TO.ToString();
                if (!members.ContainsKey(to))
                {
                    return;
                }
                using (var client = new RequestSocket()) {
                    Messaging.Membership membership = members[to];
                    client.Connect($">tcp://0x{membership.LastLoginIP:X}:12553");
                    string            ____ = "-------------------";
                    byte[]            data = Encoding.UTF8.GetBytes(____);
                    Messaging.Message m    = new Messaging.Message(1, from, TO, Guid.Empty,
                                                                   TimeSpan.FromMinutes(1D), false, new Guid(),
                                                                   Messaging.MessageType.MT_PLAINTEXT, data.Length, data);
                    using (MemoryStream ms = new MemoryStream()) {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(ms, m); data = ms.ToArray();
                        msg.Put(data, 0, data.Length);
                    }
                    client.Send(ref msg, false);
                    //Clear Input
                    sendEvent.Set();
                }
            };

            lvConversations.Click += (sender, @event) => {
                if (lvConversations.SelectedIndices.Count == 0)
                {
                    return;
                }
                int selectedIndex = lvConversations.SelectedIndices[0];

                var shortcut = lvConversations.Items[selectedIndex].Tag as ConversationShortcut;
                if (shortcut == null)
                {
                    return;
                }

                ChatUI chatUI = GetChatUI(shortcut.Icon);

                for (int i = 0; i < splitContainerChat.Panel1.Controls.Count; i++)
                {
                    splitContainerChat.Panel1.Controls[i].Visible = (chatUI == splitContainerChat.Panel1.Controls[i]);
                }
                ActiveChatUI = chatUI;
                lblInfo.Text = shortcut.DisplayName;
            };

            lblInfo.Click += (sender, @event) => {
                Msg m = new Msg();// m.InitEmpty();
                Messaging.Message _message = MessageFactory.CreateMemberInfoMessage(new Guid(), new Guid(), new Guid());
                byte[]            b        = SerializerUtil <Messaging.Message> .Serialize(_message);

                m.InitPool(b.Length); m.Put(b, 0, b.Length);
                using (var client = new RequestSocket()) {
                    client.Connect("tcp://localhost:12553");
                    client.Send(ref m, false);
                    Msg mm = new Msg(); mm.InitEmpty();
                    client.Receive(ref mm);
                    var reply = SerializerUtil <Messaging.Message> .Deserialize(mm.Data);

                    var response = SerializerUtil <MemberInfoResponse> .Deserialize(reply.Content);

                    var membership = response.Membership;
                    MessageBox.Show($"{membership.ID}\n{membership.Name}\n{membership.NickName}\n0x{membership.LastLoginIP :X08}");
                }
            };
        }