Exemplo n.º 1
0
        /// <summary>
        /// 套接字处理
        /// </summary>
        internal void OnSocket()
        {
            ServerSocket serverSocket = null;

            while (isListen != 0)
            {
                socketHandle.Wait();
                SocketLink socket = Interlocked.Exchange(ref socketHead, null);
                do
                {
                    try
                    {
                        while (socket != null)
                        {
                            socket = socket.Start(this, ref serverSocket);
                        }
                        break;
                    }
                    catch (Exception error)
                    {
                        Log.Add(AutoCSer.Log.LogType.Debug, error);
                    }
                    if (serverSocket != null)
                    {
                        serverSocket.Close();
                        serverSocket = null;
                    }
                    socket = socket.Cancel();
                }while (true);
            }
            socketHead = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取客户端请求
        /// </summary>
        private void getSocket()
        {
            Socket     listenSocket = this.Socket;
            SocketLink head, newSocketLink;

            while (isListen != 0)
            {
                try
                {
NEXT:
                    newSocketLink        = new SocketLink();
                    newSocketLink.Socket = listenSocket.Accept();
                    if (isListen == 0)
                    {
                        if (this.Socket != null)
                        {
                            this.Socket = null;
#if DotNetStandard
                            AutoCSer.Net.TcpServer.CommandBase.CloseServer(listenSocket);
#else
                            listenSocket.Dispose();
#endif
                        }
                        return;
                    }
                    do
                    {
                        if ((head = socketHead) == null)
                        {
                            newSocketLink.LinkNext = null;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, null) == null)
                            {
                                socketHandle.Set();
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        else
                        {
                            newSocketLink.LinkNext = head;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, head) == head)
                            {
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        AutoCSer.Threading.ThreadYield.YieldOnly();
                    }while (true);
                }
                catch (Exception error)
                {
                    if (isListen == 0)
                    {
                        return;
                    }
                    Log.Add(AutoCSer.Log.LogType.Error, error);
                    Thread.Sleep(1);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            SocketLink link = new SocketLink
            {
                server   = "localhost",
                account  = "*****@*****.**",
                pwd      = "fupbvxvuce",
                instance = "9ie673ff3bei"
            };


            var c = link.Connect();

            c.Wait();

            Controller ctrl = new Controller();

            var node = new Node("node01", link, ctrl);

            ctrl.node = node;

            node.Inputs  = "led";
            node.Outputs = "switch";
            var r = node.Run();

            r.Wait();
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            SocketLink link = new SocketLink
            {
                server   = "cloud.nodewire.org",
                account  = "*****@*****.**",
                pwd      = "secret",
                instance = "lrsnr49yxurz"
            };


            var c = link.Connect();

            c.Wait();

            Controller ctrl = new Controller();

            var node = new Node("node01", link, ctrl);

            ctrl.node = node;

            node.Inputs  = "led";
            node.Outputs = "switch";
            node.Run().Wait();
            Console.ReadLine();
        }
Exemplo n.º 5
0
        async private void button2_Click(object sender, EventArgs e)
        {
            button2.Text      = "connecting...";
            button2.Enabled   = false;
            comboBox1.Enabled = false;
            link = new SocketLink
            {
                server   = "dashboard.nodewire.org",
                account  = "*****@*****.**",
                pwd      = "aB01@",
                instance = "1jex2k7cbedg"
            };
            try
            {
                await link.Connect();

                node = new Node("c#", link, this)
                {
                    Inputs = "led"
                };
                node.led = 1;
                await node.Run();
            }
            catch
            {
                button2.Text      = "connect";
                button1.Enabled   = false;
                button4.Enabled   = false;
                button2.Enabled   = true;
                button3.Enabled   = false;
                comboBox1.Enabled = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取客户端请求
        /// </summary>
        private void getSocket()
        {
            Socket     listenSocket = this.Socket;
            SocketLink head, newSocketLink;

            while (isListen != 0)
            {
                try
                {
NEXT:
                    newSocketLink        = new SocketLink();
                    newSocketLink.Socket = listenSocket.Accept();
                    if (isListen == 0)
                    {
                        if (this.Socket != null)
                        {
                            this.Socket = null;
                            ShutdownServer(listenSocket);
                        }
                        return;
                    }
                    do
                    {
                        if ((head = socketHead) == null)
                        {
                            newSocketLink.LinkNext = null;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, null) == null)
                            {
                                socketHandle.Set();
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        else
                        {
                            newSocketLink.LinkNext = head;
                            if (Interlocked.CompareExchange(ref socketHead, newSocketLink, head) == head)
                            {
                                newSocketLink = null;
                                goto NEXT;
                            }
                        }
                        AutoCSer.Threading.ThreadYield.Yield();
                    }while (true);
                }
                catch (Exception error)
                {
                    if (isListen == 0)
                    {
                        return;
                    }
                    Log.Exception(error, null, LogLevel.Exception | LogLevel.AutoCSer);
                    Thread.Sleep(1);
                }
            }
        }
        private static void AddSocketByText(this SocketLink socketLink, string color)
        {
            switch (color)
            {
            case "R":
                socketLink.Red++;
                break;

            case "G":
                socketLink.Green++;
                break;

            case "B":
                socketLink.Blue++;
                break;

            case "W":
                socketLink.White++;
                break;
            }
        }
Exemplo n.º 8
0
        private async void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            link            = new SocketLink
            {
                server   = "dashboard.nodewire.org",
                account  = "*****@*****.**",
                pwd      = "secret",
                instance = "lrsnr49yxurz"
            };
            await link.connect();

            controller ctrl = new controller {
                radio = radioButton1
            };

            node = new Node("c#", link, ctrl)
            {
                Inputs = "led"
            };
            await node.Run();
        }
        public static async Task <List <Item> > Parse(string data)
        {
            var document = await new HtmlParser().ParseAsync(data);

            return(document.QuerySelectorAll(".item")
                   .Select(node => {
                var item = new Item();

                item.Id = node.ClassList[1].Substring(10);     // 10 - length of prefix "item-live-"

                var nameBuilder = new StringBuilder();
                if (node.QuerySelector("span.label.success.corrupted") != null)
                {
                    nameBuilder.Append("corrupted ");
                }
                item.Name = nameBuilder.Append(node.Attributes["data-name"].Value)
                            .ToString();

                item.WikiLink = node.QuerySelector("a.wiki-link")?.Attributes["href"]?.Value;

                item.Buyout = node.Attributes["data-buyout"].Value != "" ? ParsePrice(node.Attributes["data-buyout"].Value) : Price.Empty;

                item.SellerId = node.Attributes["data-sellerid"].Value;
                item.SellerAccountName = node.Attributes["data-seller"].Value;
                item.SellerCharacterName = node.Attributes["data-ign"].Value;
                item.StashTab = node.Attributes["data-tab"]?.Value;
                item.StashX = int.Parse(node.Attributes["data-x"].Value) + 1;
                item.StashY = int.Parse(node.Attributes["data-y"].Value) + 1;

                item.GemLevel = node.Attributes["data-level"]?.Value;
                if (item.GemLevel != null)
                {
                    item.GemLevel = new StringBuilder("Gem level: ").Append(item.GemLevel).ToString();
                }

                item.Quality =
                    node.Attributes["data-quality"]?.Value ?? node.QuerySelector("td[data-name='q']")
                    .TextContent;
                if (item.Quality[0] == 160)
                {
                    item.Quality = null;
                }
                if (item.Quality != null)
                {
                    item.Quality = new StringBuilder("Quality: ").Append(item.Quality).ToString();
                }

                var proplistChildren = node.QuerySelector("ul.requirements.proplist").Children;
                item.RequiredLevel = proplistChildren.Length == 0
                        ? "Level: 1"
                        : proplistChildren[0]?.TextContent ?? "Level: 1";

                item.ItemLevel = node.QuerySelector("span.sortable[data-name='ilvl']")?.TextContent;

                item.MaxSockets = node.QuerySelector("span[class='has-tip ']")?.TextContent;

                item.Modifiers = ParseModifiers(node);


                var socketLinksText = node.QuerySelector("span.sockets-raw").TextContent;
                if (socketLinksText != "")
                {
                    item.SocketLinks = socketLinksText.Split(new[] { ' ' })
                                       .Select(socketLinkText => {
                        var socketLink = new SocketLink();

                        foreach (var socketText in socketLinkText.Split(new[] { '-' }))
                        {
                            socketLink.AddSocketByText(socketText);
                        }

                        return socketLink;
                    })
                                       .ToList();
                }
                else
                {
                    item.SocketLinks = new List <SocketLink>();
                }

                return item;
            })
                   .ToList());
        }
Exemplo n.º 10
0
        /// <summary>
        /// 获取客户端请求
        /// </summary>
        private void getSocketVerify()
        {
            Socket     listenSocket = this.Socket;
            SocketLink head, newSocketLink;

            while (isListen != 0)
            {
                try
                {
NEXT:
                    newSocketLink = new SocketLink();
ACCEPT:
                    newSocketLink.Socket = listenSocket.Accept();
                    if (isListen == 0)
                    {
                        if (this.Socket != null)
                        {
                            this.Socket = null;
                            ShutdownServer(listenSocket);
                        }
                        return;
                    }
                    if (verify(newSocketLink.Socket))
                    {
                        do
                        {
                            if ((head = socketHead) == null)
                            {
                                newSocketLink.LinkNext = null;
                                if (Interlocked.CompareExchange(ref socketHead, newSocketLink, null) == null)
                                {
                                    socketHandle.Set();
                                    newSocketLink = null;
                                    goto NEXT;
                                }
                            }
                            else
                            {
                                newSocketLink.LinkNext = head;
                                if (Interlocked.CompareExchange(ref socketHead, newSocketLink, head) == head)
                                {
                                    newSocketLink = null;
                                    goto NEXT;
                                }
                            }
                            AutoCSer.Threading.ThreadYield.YieldOnly();
                        }while (true);
                    }
                    newSocketLink.DisposeSocket();
                    goto ACCEPT;
                }
                catch (Exception error)
                {
                    if (isListen == 0)
                    {
                        return;
                    }
                    Log.Add(AutoCSer.Log.LogType.Error, error);
                    Thread.Sleep(1);
                }
            }
        }