private void GetSetting(WSNode node)
        {
            var obj = new
            {
                Port  = ConfigSystem.GetSettingPort(),
                Size  = ConfigSystem.GetWIndowSize(),
                Start = ConfigSystem.GetWindowStart()
            };

            String json = JsonConvert.SerializeObject(obj);

            node.Data = json;
        }
Esempio n. 2
0
        public MainContext()
        {
            ORMFactory.Initialize();
            this.components         = new Container();
            this.notify             = new NotifyIcon(this.components);
            this.notify.Icon        = new Icon(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "favicon.ico"));
            this.notify.Visible     = true;
            this.notify.ContextMenu = new ContextMenu();
            this.notify.ContextMenu.MenuItems.AddRange(SetMenuItem());

            this.notify.Text = "Private Task Management";
            ThreadPool.QueueUserWorkItem(c =>
            {
                int port = 9999;
                try
                {
                    port = Convert.ToInt32(ConfigSystem.GetSettingPort());
                }
                catch { }
                string path = Path.GetDirectoryName(Application.ExecutablePath);
                var server  = ServerFactory.NewInstance(port);
                var flow    = new Flow();
                var message = new Message(this);
                server.SetDefaultFile("index.html");
                server.SetZip(path + "\\html.data");
                //server.SetRootPath(webpath);

                /*server.Set("/", (res, req) =>
                 * {
                 *  //req.SetCookie("test", "aaa", DateTime.Now.AddMinutes(5));
                 *  //req.SetSession("aaaaa", "asdfasfd");
                 *  req.ReadFile(webpath + @"\index.html");
                 * });*/
                server.Set("/js/define.js", (res, req) =>
                {
                    req.ContextType = "text / javascript; charset = UTF - 8";
                    req.Body        = "var wsurl = \"ws://localhost:" + Convert.ToInt32(ConfigSystem.GetSettingPort()) + "/menu\";";
                });
                server.Set("/Start", (res, req) =>
                {
                    ShowForm();
                    req.StateOK();
                });
                server.SetWebSocket(mes =>
                {
                    Console.WriteLine(mes);
                    WSNode node = WSNode.ToNode(mes.ToString());
                    if (node.Type == 1)
                    {
                        flow.Execute(node.Key, node);
                    }
                    else if (node.Type == 2)
                    {
                        message.Execute(node.Key, node);
                    }
                    return(new WebSocketNode()
                    {
                        OPCode = Opcode.BINARY, Message = node.ToString2()
                    });
                });
            });
            if (String.Equals(ConfigSystem.GetWindowStart(), "on"))
            {
                ShowForm();
            }
        }