Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (this.lvModules.Items.Count > 0 && this.lvModules.SelectedItems.Count > 0)
            {
                ListViewItem lvi    = this.lvModules.FocusedItem;
                Module       module = (Module)lvi.Tag;

                // Set the module values
                module.SetModuleName(txtName.Text);
                module.SetModuleType((ModuleType)Enum.Parse(typeof(ModuleType), cmbType.Text, true));
                lvi.Text = txtName.Text;

                // Based on the module type, set its corresponding values
                if (cmbType.Text == "Service")
                {
                    module.SetServiceName(this.txtServiceName.Text);
                }
                else if (cmbType.Text == "Software")
                {
                    module.SetProgramPath(this.txtFilePath.Text);
                }

                module.ClearConfigs();
                module.ClearControls();

                // If there are any controls, create them and add to the module
                if (this.lvControls.Items.Count > 0)
                {
                    foreach (ListViewItem controlLvi in this.lvControls.Items)
                    {
                        ModuleControl control = (ModuleControl)controlLvi.Tag;
                        control.SetControlName(controlLvi.Text);
                        control.SetControlType((ControlType)Enum.Parse(typeof(ControlType), controlLvi.SubItems[1].Text, true));
                        control.SetControlPath(controlLvi.SubItems[2].Text);
                        module.AddControl(control);
                    }
                }

                // If there are any configs, create them and add to the module
                if (this.lvConfigs.Items.Count > 0)
                {
                    foreach (ListViewItem configLvi in this.lvConfigs.Items)
                    {
                        ModuleConfig config = (ModuleConfig)configLvi.Tag;
                        config.SetConfigName(configLvi.Text);
                        config.SetConfigType((ConfigType)Enum.Parse(typeof(ConfigType), configLvi.SubItems[1].Text, true));
                        config.SetConfigPath(configLvi.SubItems[2].Text);
                        module.AddConfig(config);
                    }
                }
            }
        }
Beispiel #2
0
        /**
         * <summary>
         * Load a PandaStack configuration file
         * </summary>
         */
        private void LoadJsonFile(string filePath)
        {
            JsonHandler jsonHandler = new JsonHandler(filePath);

            jsonHandler.FetchJson();

            foreach (JsonModule jsonModule in jsonHandler.GetModules())
            {
                Module module = new Module();
                module.SetModuleName(jsonModule.name);
                module.SetModuleType((ModuleType)Enum.Parse(typeof(ModuleType), jsonModule.type, true));

                if (module.GetModuleType() == ModuleType.Service)
                {
                    module.SetServiceName(jsonModule.service);
                }

                if (jsonModule.control != null && jsonModule.control.Count > 0)
                {
                    foreach (JsonControl jsonControl in jsonModule.control)
                    {
                        ModuleControl control = new ModuleControl();
                        control.SetControlName(jsonControl.name);
                        control.SetControlType((ControlType)Enum.Parse(typeof(ControlType), jsonControl.type, true));
                        control.SetControlPath(jsonControl.path);

                        module.AddControl(control);
                    }
                }

                if (jsonModule.config != null && jsonModule.config.Count > 0)
                {
                    foreach (JsonConfig jsonConfig in jsonModule.config)
                    {
                        ModuleConfig config = new ModuleConfig();
                        config.SetConfigName(jsonConfig.name);
                        config.SetConfigType((ConfigType)Enum.Parse(typeof(ConfigType), jsonConfig.type, true));
                        config.SetConfigPath(jsonConfig.path);

                        module.AddConfig(config);
                    }
                }

                this.Modules.Add(module);

                ListViewItem lvi = new ListViewItem();
                lvi.Text = module.GetModuleName();
                lvi.Tag  = module;
                this.lvModules.Items.Add(lvi);
            }
        }