Ejemplo n.º 1
0
 private void ShowForm()
 {
     if (this.MainForm == null)
     {
         this.MainForm = new MainForm(ConfigSystem.GetSettingPort());
         (this.MainForm as MainForm).SetSize(ConfigSystem.GetWIndowSize());
     }
     (this.MainForm as MainForm).Booting();
 }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        private void SetSetting(WSNode node)
        {
            var data = JsonConvert.DeserializeObject <Dictionary <String, String> >(node.Data);

            foreach (var n in data)
            {
                ConfigSystem.WriteConfig("Config", "Setting", n.Key, n.Value);
            }
            if (this.context.MainForm != null)
            {
                (this.context.MainForm as MainForm).SetSize(ConfigSystem.GetWIndowSize());
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string mtxName = "PrivateTaskManager";
            Mutex  mtx     = new Mutex(true, mtxName);

            TimeSpan tsWait  = new TimeSpan(0, 0, 1);
            bool     success = mtx.WaitOne(tsWait);

            if (!success)
            {
                String         port    = ConfigSystem.GetSettingPort();
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:" + port + "/Start");
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                {
                    Console.WriteLine(response.StatusCode);
                }
                return;
            }
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MainContext());
        }
Ejemplo n.º 5
0
        public static string GetWindowStart()
        {
            string start = ConfigSystem.ReadConfig("Config", "Setting", "Start");

            return(String.IsNullOrEmpty(start) ? "on" : start);
        }
Ejemplo n.º 6
0
        public static string GetWIndowSize()
        {
            String size = ConfigSystem.ReadConfig("Config", "Setting", "Size");

            return(String.IsNullOrEmpty(size) ? "full" : size);
        }
Ejemplo n.º 7
0
        public static string GetSettingPort()
        {
            string port = ConfigSystem.ReadConfig("Config", "Setting", "Port");

            return(String.IsNullOrEmpty(port) ? "9999" : port);
        }
Ejemplo n.º 8
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();
            }
        }