Esempio n. 1
0
 public static NodePool getInstance(String key = "apps")
 {
     if (!_instance.ContainsKey(key))
     {
         _instance[key] = new NodePool();
     }
     return(_instance[key]);
 }
Esempio n. 2
0
        public void onRemove(object sender, EventArgs e)
        {
            _nodeInstance.kill();
            _nodeInstance.Dispose();
            NodePool.getInstance().removeNodeInstance(_nodeInstance);

            Parent.Items.Remove(this);
        }
Esempio n. 3
0
        public void load()
        {
            if (!_isLoaded)
            {
                //
                // Do we have the profiles directory ?
                //
                if (!Directory.Exists("Profiles"))
                {
                    Directory.CreateDirectory("Profiles");
                }

                //
                // Creating profile if file does not exist
                //
                if (!File.Exists(_profilePath))
                {
                    save();
                }
                //
                // ...Or read it, if it exist, and load everything
                //
                else
                {
                    //
                    String str = File.ReadAllText(_profilePath, Encoding.UTF8);
                    System.Xml.XmlDocument doc = new XmlDocument();
                    doc.LoadXml(str);

                    //
                    foreach (System.Xml.XmlNode i in doc.GetElementsByTagName("NodeInstance"))
                    {
                        if (File.Exists(i.Attributes.GetNamedItem("mainFile").InnerText))
                        {
                            NodeInstance ni = NodePool.getInstance().createNodeInstance(
                                LocalHost.getLatestInstalledNodeVersion(),
                                i.Attributes.GetNamedItem("name").InnerText,
                                i.Attributes.GetNamedItem("mainFile").InnerText
                                );

                            ni.restartOnMainJsFileChange = i.Attributes.GetNamedItem("restartOnFileChange").InnerText == "true" ? true : false;
                            ni.restartOnCrash            = i.Attributes.GetNamedItem("restartOnCrash").InnerText == "true" ? true : false;

                            if (i.FirstChild != null && i.FirstChild.Name == "RestartOnFileChangePatternsString")
                            {
                                ni.restartOnFileChangePatternsString = i.FirstChild.InnerText;
                            }
                        }
                    }
                }

                //
                _isLoaded = true;
            }
        }
Esempio n. 4
0
        public void pool_NodeInstanceCreated(NodePool sender, NodeInstanceCreatedEventArgs e)
        {
            /*
            var nodeinst = new System.Windows.Forms.ToolStripDropDownButton(e.nodeInstance.name, null);
            nodeinst.DropDownItems.Add(new ToolStripButton("start"));
            nodeinst.DropDownItems.Add(new ToolStripButton("kill"));
            nodeinst.DropDownItems.Add(new ToolStripButton("restart"));
            */

            var nodeinst = new NodeInstanceToolStripItem(e.nodeInstance);
            nodeinst.Image = global::nodepool.Resources.icon.stop_16;
            systrayMenuStrip.Items.Insert(0, nodeinst);
        }
Esempio n. 5
0
        public void save()
        {
            FileStream fs = File.Create(_profilePath);

            if (fs.CanWrite)
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;

                XmlWriter w = XmlWriter.Create(fs, settings);

                w.WriteStartDocument();

                // Profile
                w.WriteStartElement("Profile");

                // Profile > NodeInstances
                w.WriteStartElement("NodeInstances");

                foreach (NodeInstance i in NodePool.getInstance().getAllNodeInstances())
                {
                    // Profile > NodeInstances > NodeInstance
                    w.WriteStartElement("NodeInstance");

                    w.WriteAttributeString("mainFile", i.mainJsFilePath);
                    w.WriteAttributeString("name", i.name);
                    w.WriteAttributeString("restartOnCrash", i.restartOnCrash ? "true" : "false");
                    w.WriteAttributeString("restartOnFileChange", i.restartOnMainJsFileChange ? "true" : "false");

                    // Profile > NodeInstances > NodeInstance > RestartOnFileChangePatternsString
                    w.WriteStartElement("RestartOnFileChangePatternsString", i.mainJsFilePath);
                    w.WriteCData(i.restartOnFileChangePatternsString);
                    w.WriteEndElement();

                    w.WriteEndElement();
                }

                w.WriteEndElement();

                w.WriteEndDocument();
                w.Flush();
                w.Close();
            }
            fs.Close();
        }
Esempio n. 6
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            /*Show();
            WindowState = FormWindowState.Minimized;
            Hide();
            this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
            this.SetBounds(3000, 3000, 0, 0);
            */

            //
            pool = NodePool.getInstance();
            pool.NodeInstanceCreated += new Event.NodeInstanceCreatedEventHandler(pool_NodeInstanceCreated);
            pool.NodeInstanceStarted += new Event.NodeInstanceStartedEventHandler(pool_NodeInstanceStarted);
            pool.NodeInstanceStopped += new Event.NodeInstanceStoppedEventHandler(pool_NodeInstanceStopped);

            //
            systrayMenuStrip.ItemClicked += new ToolStripItemClickedEventHandler(systrayMenuStrip_ItemClicked);

            // Load user config (=profile)
            UserProfile.getInstance().load();

            //
            systray.ShowBalloonTip(100, "NodePool", "\nNodePool is now running in background...\n", new ToolTipIcon());
        }
Esempio n. 7
0
 public static NodePool getInstance(String key = "apps")
 {
     if (!_instance.ContainsKey(key))
         _instance[key] = new NodePool();
     return _instance[key];
 }