Exemple #1
0
        private void DeleteModule()
        {
            if (selectedModule == null)
            {
                return;
            }
            Module module = selectedModule;

            selectedModule            = null;
            dgvModuleCommands.Enabled = false;
            ClearModule();
            if (modules.ContainsKey(module.Name))
            {
                modules.Remove(module.Name);
            }
            if (ConfigurationHelper.Blackboard.Modules.Contains(module))
            {
                ConfigurationHelper.Blackboard.Modules.Remove(module);
            }
            if (lstBBModules.Items.Contains(module))
            {
                lstBBModules.Items.Remove(module);
            }
            foreach (IPrototype proto in module.Prototypes)
            {
                if (prototypes.ContainsKey(proto.Command))
                {
                    prototypes.Remove(proto.Command);
                }
            }
        }
Exemple #2
0
        private Prototype AddPrototype(Module module, string commandName, bool responseRequired, bool paramsRequired, bool hasPriority, int timeout)
        {
            if (module == null)
            {
                return(null);
            }
            Prototype proto = new Prototype(commandName, paramsRequired, responseRequired, timeout, hasPriority);

            module.Prototypes.Add(proto);
            return(proto);
        }
Exemple #3
0
        private bool IsValidInput(Module source, string s)
        {
            Command  cmd;
            Response rsp;

            if ((Response.IsResponse(s) && Response.TryParse(s, source, out rsp)) ||
                Command.IsCommand(s) && Command.TryParse(s, source, out cmd))
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
 private void ReplacePrototype(Module module, Prototype oldPrototype, Prototype newPrototype)
 {
     if ((module == null) || (newPrototype == null))
     {
         return;
     }
     if (oldPrototype != null)
     {
         prototypes.Remove(oldPrototype.Command);
         for (int i = 0; i < ConfigurationHelper.Blackboard.Modules.Count; ++i)
         {
             ConfigurationHelper.Blackboard.Modules[i].Prototypes.Remove(oldPrototype);
         }
     }
     //prototypes.Add(newPrototype.CommandName, newPrototype);
 }
Exemple #5
0
        private void SelectModule(Module selectedModule)
        {
            if (selectedModule == null)
            {
                dgvModuleCommands.Enabled  = false;
                pgModuleProperties.Enabled = false;
                //ClearModule();
                return;
            }

            if (this.selectedModule == selectedModule)
            {
                return;
            }
            this.selectedModule        = selectedModule;
            pgModuleProperties.Enabled = true;
            ClearModule();
            FillModuleData();
            pgModuleProperties.Focus();
            dgvModuleCommands.Sort(dgvModuleCommands.Columns["colCommandName"], ListSortDirection.Ascending);
        }
		private Button CreateModuleButton(ModuleClient mc)
		{
			Button b = new Button();
			b.Name = "btn" + mc.Name;
			b.Text = mc.Name;
			b.Width = flpModuleList.Width - 25;
			b.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;
			b.ImageAlign = ContentAlignment.MiddleLeft;
			b.TextImageRelation = TextImageRelation.ImageBeforeText;
			b.Image = mc.Enabled ? Properties.Resources.ExitGreen_16 : Properties.Resources.ExitRed_16;

			return b;
		}
        /// <summary>
        /// Converts the string representation of a command to a Command object.
        /// A return value indicates whether the conversion succeded or not.
        /// </summary>
        /// <param name="s">A string containing the command to convert</param>
        /// <param name="source">The module which sent the command</param>
        /// <param name="destination">The destination module for the command</param>
        /// <param name="cmd">When this method returns, contains the Command equivalent to the command
        /// contained in s, if the conversion succeeded, or null if the conversion failed.
        /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <param name="ex">When this method returns, contains the Exception generated during the parse operation,
        /// if the conversion failed, or null if the conversion succeeded. The conversion fails if the s parameter
        /// is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <returns>true if conversion was successfull, false otherwise</returns>
        protected static bool TryParse(string s, ModuleClient source, ModuleClient destination, out Command cmd, out Exception ex)
        {
            IPrototype proto;
            string sCommand;
            string sParams;
            int result;
            int id;

            cmd = null;
            ex = null;

            // Module Validation
            if (source.Parent != destination.Parent)
            {
                ex = new Exception("Source and destination modules does not belong to the same blackboard");
                return false;
            }

            // Extract Data
            CommandBase.XtractCommandElements(s, out sCommand, out sParams, out result, out id);
            if ((sCommand == null) || (result != -1))
            {
                ex = new ArgumentException("Invalid String", "s");
                return false;
            }

            // Browse for an adequate prototype
            proto = null;
            if (destination.Prototypes.Contains(sCommand))
                proto = destination.Prototypes[sCommand];
            // Check if command matchs a prototype. If no prototype found, asume redirection
            if ((proto != null) && proto.ParamsRequired && ((sParams == null) || (sParams.Length < 1)))
            {
                ex = new Exception("Invalid string. The Command requires parameters");
                return false;
            }
            // Create the Command
            cmd = new Command(source, destination, sCommand, sParams, id);
            cmd.prototype = proto;
            cmd.sentTime = DateTime.Now;
            return true;
        }
 private void module_Disconnected(ModuleClient m)
 {
     if (Disconnected != null) Disconnected(m);
     Log.WriteLine(4, "Disconnected from " + m.Name);
 }
 private void module_ActionExecuted(ModuleClient m, IAction action, bool success)
 {
     Log.WriteLine(5, m.Name + ": " + action.ToString() + (success ? " Success!!!" : " failed."));
 }
        private static void ExtractPrototypes(ModuleClient mod, XmlDocument tmpDoc, ILogWriter log)
        {
            XmlNodeList commands;
            Prototype proto;
            List<Prototype> protoList;
            string cmdName;
            bool cmdParams;
            bool cmdAnswer;
            int cmdPriority = 1;
            bool cmdPriorityB;
            int cmdTimeOut;

            #region Module Commands Extraction

            // Leo lista de comandos.
            log.WriteLine(2, "\tLoading module commands...");
            if (tmpDoc.GetElementsByTagName("commands").Count < 1)
            {
                log.WriteLine(3, "\tNo commands to load");
                log.WriteLine(2, "\tModule skipped");
                return;
            }
            commands = tmpDoc.GetElementsByTagName("commands")[0].ChildNodes;
            protoList = new List<Prototype>(commands.Count);

            #region Extraccion de Comandos de modulo

            for (int j = 0; j < commands.Count; ++j)
            {
                // Verifico que sea un comando
                cmdTimeOut = 0;
                if ((commands[j].Name == "command") &&
                (commands[j].Attributes.Count >= 3) &&
                (commands[j].Attributes["name"].Value.Length > 1) &&
                Boolean.TryParse(commands[j].Attributes["answer"].Value, out cmdAnswer) &&
                (
                    (cmdAnswer && Int32.TryParse(commands[j].Attributes["timeout"].Value, out cmdTimeOut) && (cmdTimeOut >= 0)) || !cmdAnswer
                ))
                {
                    // Leo nombre de comando
                    cmdName = commands[j].Attributes["name"].Value;
                    log.WriteLine(2, "\t\tAdded command " + cmdName);
                    // Verifico si requiere parametros
                    if ((commands[j].Attributes["parameters"] == null) || !Boolean.TryParse(commands[j].Attributes["parameters"].Value, out cmdParams))
                        cmdParams = true;
                    // Verifico si tiene prioridad
                    if (commands[j].Attributes["priority"] != null)
                    {
                        if(Boolean.TryParse(commands[j].Attributes["priority"].Value, out cmdPriorityB))
                            cmdPriority = cmdPriorityB ? 0 : 1;
                        else if (!Int32.TryParse(commands[j].Attributes["priority"].Value, out cmdPriority))
                            cmdPriority = 1;
                    }
                    // Creo el prototipo
                    proto = new Prototype(cmdName, cmdParams, cmdAnswer, cmdTimeOut, cmdPriority);
                    // Agrego el prototipo al modulo
                    mod.Prototypes.Add(proto);
                    protoList.Add(proto);
                }
                else log.WriteLine(4, "\t\tInvalid Command ");
            }
            #endregion
            // Si no hay comandos soportados por el modulo, salto el modulo
            if (protoList.Count < 1)
            {
                log.WriteLine(3, "\tAll commands rejected.");
                //log.WriteLine(2, "Module skipped");
                return;
            }

            #endregion
        }
        /// <summary>
        /// Converts the string representation of a response to a Response object.
        /// A return value indicates whether the conversion succeded or not.
        /// <param name="s">A string containing the response to convert</param>
        /// <param name="source">The module which sent the response</param>
        /// <param name="destination">The destination module for the response</param>
        /// <param name="result">When this method returns, contains the Response equivalent to the response
        /// contained in s, if the conversion succeeded, or null if the conversion failed.
        /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// </summary>
        /// <returns>true if conversion was successfull, false otherwise</returns>
        public static bool TryParse(string s, ModuleClient source, ModuleClient destination, out Response result)
        {
            Exception ex;

            return TryParse(s, source, destination, out result, out ex);
        }
        /// <summary>
        /// Converts the string representation of a response to a Response object.
        /// A return value indicates whether the conversion succeded or not.
        /// <param name="s">A string containing the response to convert</param>
        /// <param name="source">The module which sent the response</param>
        /// <param name="destination">The destination module for the response</param>
        /// <param name="response">When this method returns, contains the Response equivalent to the response
        /// contained in s, if the conversion succeeded, or null if the conversion failed.
        /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <param name="ex">When this method returns, contains the Exception generated during the parse operation,
        /// if the conversion failed, or null if the conversion succeeded. The conversion fails if the s parameter
        /// is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// </summary>
        /// <returns>true if conversion was successfull, false otherwise</returns>
        protected static bool TryParse(string s, ModuleClient source, ModuleClient destination, out Response response, out Exception ex)
        {
            IPrototype proto;
            string sCommand;
            string sParams;
            bool result;
            int iResult;
            int id;

            ex = null;
            response = null;

            // Module Validation
            if (source.Parent != destination.Parent)
            {
                ex = new Exception("Source and destination modules does not belong to the same blackboard");
                return false;
            }
            // Extract Data
            CommandBase.XtractCommandElements(s, out sCommand, out sParams, out iResult, out id);
            if ((sCommand == null) || (iResult == -1))
            {
                ex = new ArgumentException("Invalid String", "s");
                return false;
            }
            result = iResult == 1;

            // Browse for an adequate prototype
            proto = null;
            if (destination.Prototypes.Contains(sCommand))
                proto = destination.Prototypes[sCommand];
            // Check if response matchs a prototype. If no prototype found, asume redirection
            if ((proto != null) && proto.ParamsRequired && ((sParams == null) || (sParams.Length < 1)))
            {
                ex = new Exception("Invalid string. The Response requires parameters");
                return false;
            }
            // Create the Response
            response = new Response(source, destination, sCommand, sParams, result, id);
            response.prototype = proto;
            if (!response.success) response.failReason = ResponseFailReason.ExecutedButNotSucceded;
            return true;
        }
Exemple #13
0
        private void SelectModule(ModuleClient selectedModule)
        {
            //if (selectedModule == null)
            //{
            //    gbModule.Enabled = false;
            //    ClearModule();
            //    return;
            //}

            //if (this.selectedModule == selectedModule)
            //    return;
            //this.selectedModule = selectedModule;
            //ClearModule();
            //FillModuleData();
            //txtModuleName.Focus();
            throw new NotImplementedException();
        }
Exemple #14
0
 private void ReplacePrototype(ModuleClient module, Prototype oldPrototype, Prototype newPrototype)
 {
     if ((module == null) || (newPrototype == null))
         return;
     if (oldPrototype != null)
     {
         prototypes.Remove(oldPrototype.Command);
         for (int i = 0; i < ConfigurationHelper.Blackboard.Modules.Count; ++i)
             ConfigurationHelper.Blackboard.Modules[i].Prototypes.Remove(oldPrototype);
     }
     prototypes.Add(newPrototype.Command, newPrototype);
     module.Prototypes.Add(newPrototype);
 }
		private void ModuleStop(ModuleClient module)
		{
			module.BeginStop();
			btnModuleStartStopModule.Enabled = false;
			btnModuleStartStopModule.Text = "Stopping Module";
			while (module.IsRunning)
				Application.DoEvents();
			btnModuleStartStopModule.Text = "Start Module";
			btnModuleStartStopModule.Image = Properties.Resources.run16;
			btnModuleStartStopModule.Enabled = true;
		}
		private void ModuleStartStop(ModuleClient module)
		{
			if ((blackboard == null) || !blackboard.IsRunning || (module == null) || !module.Enabled) return;
			if (module.IsRunning)
				ModuleStop(module);
			else
				ModuleStart(module);
		}
		private void ModuleRestart(ModuleClient module)
		{
			if ((blackboard == null) || !blackboard.IsRunning || (module == null) || !module.Enabled)
				return;
			module.Restart();
		}
		private void ModuleProcessZombieCheck(ModuleClient module)
		{
			if ((processManager == null) || (module == null))
				return;
		}
		private void PopulateModuleMenu_Start(ToolStripMenuItem mnu, ModuleClient mc)
		{
			ToolStripMenuItem mni;

			mni = (ToolStripMenuItem)mnu.DropDownItems.Add(mc.IsRunning ? "Running (click to stop)" : "Stopped (click to start)");
			mni.Image = mc.IsRunning ? Properties.Resources.Stop_16 : Properties.Resources.run16;
			mni.Enabled = mc.Enabled && blackboard.IsRunning;
			mni.Tag = mc;
			mni.Click += new EventHandler(mnuiModule_Module_Start_Click);
		}
 public ModuleWrapper(ModuleClient module)
 {
     this.module = module;
 }
Exemple #21
0
 private void DeleteModule()
 {
     if (selectedModule == null)
         return;
     ModuleClient module = selectedModule;
     selectedModule = null;
     //gbModule.Enabled = false;
     ClearModule();
     if (modules.ContainsKey(module.Name))
         modules.Remove(module.Name);
     if (ConfigurationHelper.Blackboard.Modules.Contains(module))
         ConfigurationHelper.Blackboard.Modules.Remove(module);
     if (lstBBModules.Items.Contains(module))
         lstBBModules.Items.Remove(module);
     foreach (Prototype proto in module.Prototypes)
     {
         if (prototypes.ContainsKey(proto.Command))
             prototypes.Remove(proto.Command);
     }
 }
        /// <summary>
        /// Converts the string representation of a response to a Response object.
        /// <param name="s">A string containing the response to convert</param>
        /// <param name="source">The module which sent the response</param>
        /// <param name="destination">The destination module for the response</param>
        /// </summary>
        /// <returns>A response object that represents the response contained in s</returns>
        public static Response Parse(string s, ModuleClient source, ModuleClient destination)
        {
            Exception ex;
            Response response;

            if (!TryParse(s, source, destination, out response, out ex))
                throw ex;
            else return response;
        }
		private void PopulateModuleMenu_ZombieCheck(ToolStripMenuItem mnu, ModuleClient mc)
		{
			ToolStripMenuItem mni = (ToolStripMenuItem)mnu.DropDownItems.Add("&Check for zombie processes");
			mni.Image = Properties.Resources.ProcessInfo16;
			mni.Enabled = mc.Enabled && mc.IsRunning;
			mni.Tag = mc;
			mni.Click += new EventHandler(mnuiModule_Module_ZombieCheck_Click);
		}
        /// <summary>
        /// Converts the string representation of a response to a Response object.
        /// A return value indicates whether the conversion succeded or not.
        /// <param name="s">A string containing the response to convert</param>
        /// <param name="source">The module which sent the response</param>
        /// <param name="response">When this method returns, contains the Response equivalent to the response
        /// contained in s, if the conversion succeeded, or null if the conversion failed.
        /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <param name="ex">When this method returns, contains the Exception generated during the parse operation,
        /// if the conversion failed, or null if the conversion succeeded. The conversion fails if the s parameter
        /// is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// </summary>
        /// <returns>true if conversion was successfull, false otherwise</returns>
        protected static bool TryParse(string s, ModuleClient source, out Response response, out Exception ex)
        {
            IPrototype proto;
            //Module destination;
            IModuleClient destination;
            //Module eSource;
            IModuleClient eSource;
            string sCommand;
            string sParams;
            string sDest;
            bool result;
            int iResult;
            int id;

            ex = null;
            response = null;

            // Extract Data
            CommandBase.XtractCommandElements(s, out sDest, out sCommand, out sParams, out iResult, out id);
            if ((sCommand == null) || (iResult == -1))
            {
                ex = new ArgumentException("Invalid String", "s");
                return false;
            }
            result = iResult == 1;

            // Browse for prototype and validating command
            if (!source.Parent.FindDestinationModule(sCommand, out eSource, out proto) || (eSource != source))
            //Since the response arrived from a module which can't generate it a exception is rised
            {
                ex = new Exception("Sender module and generator module does not match");
                return false;
            }

            // if destination module is specified, then it mus be set
            if ((sDest != null) && (sDest.Length > 0) && source.Parent.Modules.Contains(sDest))
                destination = source.Parent.Modules[sDest];
            // Else, since there is no way at this point to determine which is destination module for response
            // and this is no specified, it is set to null, to allow blackboard to find an apropiate one
            else
                destination = null;
            // Check if response matchs a prototype
            if ((proto != null) && proto.ParamsRequired && ((sParams == null) || (sParams.Length < 1)))
            {
                ex = new Exception("Invalid string. The Response requires parameters");
                return false;
            }
            // Create the Response
            response = new Response(source, destination, sCommand, sParams, result, id);
            response.prototype = proto;
            if (!response.success) response.failReason = ResponseFailReason.ExecutedButNotSucceded;
            return true;
        }
 private bool InjectUserMessage(ModuleClient mc, string message)
 {
     return blackboard.Inject(mc.Name + " " + message);
 }
        /// <summary>
        /// Extracts the module information from the provided xml document
        /// </summary>
        /// <param name="module">The module to load the commands in</param>
        /// <param name="doc">The document from where the commands will be loaded</param>
        /// <param name="log">The log writer</param>
        /// <returns>Returns a list of prototypes which contains the command information.</returns>
        private static Prototype[] XtractModuleCommands(ModuleClient module, XmlDocument doc, LogWriter log)
        {
            XmlNodeList commands;
            List<Prototype> protoList;
            Prototype proto;
            string cmdName;
            bool cmdParams;
            bool cmdAnswer;
            bool cmdPriority;
            int cmdTimeOut;

            // Get the list of commands. If none, return
            log.WriteLine(2, "\tLoading module commands...");
            if (doc.GetElementsByTagName("commands").Count < 1)
            {
                log.WriteLine(3, "\tNo commands to load");
                return null;
            }

            commands = doc.GetElementsByTagName("commands")[0].ChildNodes;
            protoList = new List<Prototype>(commands.Count);

            #region Module command extraction

            for (int j = 0; j < commands.Count; ++j)
            {
                // Verify that the node is a command
                cmdTimeOut = 0;
                if ((commands[j].Name == "command") &&
                (commands[j].Attributes.Count >= 3) &&
                (commands[j].Attributes["name"].Value.Length > 1) &&
                Boolean.TryParse(commands[j].Attributes["answer"].Value, out cmdAnswer) &&
                (
                    (cmdAnswer && Int32.TryParse(commands[j].Attributes["timeout"].Value, out cmdTimeOut) && (cmdTimeOut >= 0)) || !cmdAnswer
                ))
                {
                    // Read command name
                    cmdName = commands[j].Attributes["name"].Value;
                    log.WriteLine(2, "\t\tAdded command " + cmdName);
                    // Check if command require parameters
                    if ((commands[j].Attributes["parameters"] == null) || !Boolean.TryParse(commands[j].Attributes["parameters"].Value, out cmdParams))
                        cmdParams = true;
                    // Check if command has preiority
                    if ((commands[j].Attributes["priority"] == null) || !Boolean.TryParse(commands[j].Attributes["priority"].Value, out cmdPriority))
                        cmdPriority = false;
                    // Create the prototype
                    proto = new Prototype(cmdName, cmdParams, cmdAnswer, cmdTimeOut, cmdPriority);
                    // Add the prototype to the module
                    module.Prototypes.Add(proto);
                    protoList.Add(proto);
                }
                else log.WriteLine(4, "\t\tInvalid Command ");
            }
            #endregion
            // If there are no commands supported by the module, skip it.
            if (protoList.Count < 1)
                log.WriteLine(3, "\tAll commands rejected.");

            return protoList.ToArray();
        }
        private bool SendUserMessage(ModuleClient mc, string message)
        {
            Command c;
            Response r;
            bool success;
            if (Command.TryParse(message, mc, out c))
            {
                success = mc.Send(c);
                Log("# Send user command [" + message + "] " + (success ? "success!" : "failed"));
                lblLastSendToModuleResult.Text = "Send user command: " + (success ? "success!" : "failed");
                return true;
            }

            if (Response.TryParse(message, mc, out r))
            {
                success = mc.Send(r);
                Log("# Send user response [" + message + "] " + (success ? "success!" : "failed"));
                lblLastSendToModuleResult.Text = "Send user response: " + (success ? "success!" : "failed");
                return true;
            }
            return false;
        }
 private void module_Connected(ModuleClient m)
 {
     if (Connected != null) Connected(m);
     Log.WriteLine(4, "Connected to " + m.Name);
 }
Exemple #29
0
 /// <summary>
 /// Converts the string representation of a command to a Command object.
 /// A return value indicates whether the conversion succeded or not.
 /// </summary>
 /// <param name="s">A string containing the command to convert</param>
 /// <param name="source">The module which sent the command</param>
 /// <param name="destination">The destination module for the command</param>
 /// <param name="command">When this method returns, contains the Command equivalent to the command
 /// contained in s, if the conversion succeeded, or null if the conversion failed.
 /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
 /// This parameter is passed uninitialized</param>
 /// <returns>true if conversion was successfull, false otherwise</returns>
 public static bool TryParse(string s, ModuleClient source, ModuleClient destination, out Command command)
 {
     Exception ex;
     return TryParse(s, source, destination, out command, out ex);
 }
 /// <summary>
 /// Adds a module to the blackboard
 /// </summary>
 private static void AddModuleToBlackboard(Blackboard blackboard, ILogWriter log, ModuleClient mod, SortedList<string, ModuleClient> disabledModules)
 {
     if (mod.Enabled)
     {
         blackboard.modules.Add(mod);
         log.WriteLine(2, "Loading module complete!");
     }
     else
     {
         disabledModules.Add(mod.Name, mod);
         log.WriteLine(2, "Disabled module enqueued!");
     }
 }
		private void PopulateModuleMenu_Simulation(ToolStripMenuItem mnu, ModuleClient mc)
		{
			ToolStripMenuItem mni = (ToolStripMenuItem)mnu.DropDownItems.Add(mc.Simulation.SimulationEnabled ?
						 "&Simulation enabled" : "&Simulation disabled");
			mni.Image = mc.Simulation.SimulationEnabled ?
				Properties.Resources.CircleGreen_16 :
				Properties.Resources.CircleGray_16;
			mni.Enabled = mc.Enabled;
			mni.Tag = mc;
			mni.Click += new EventHandler(mnuiModule_Module_Simulation_Click);
		}
Exemple #32
0
        /// <summary>
        /// Converts the string representation of a command to a Command object.
        /// <param name="s">A string containing the command to convert</param>
        /// <param name="source">The module which sent the command</param>
        /// <param name="destination">The destination module for the command</param>
        /// </summary>
        /// <returns>A command object that represents the command contained in s</returns>
        public static Command Parse(string s, ModuleClient source, ModuleClient destination)
        {
            Exception ex;
            Command command;

            if (!TryParse(s, source, destination, out command, out ex))
                throw ex;
            else return command;
        }
		private void AddSecondaryModuleButton(ModuleClient mc)
		{
			Button b2 = CreateModuleButton(mc);
			frmBbss.FlpModuleList.Controls.Add(b2);
			moduleButtonsClone.Add(mc.Name, b2);
		}
Exemple #34
0
        /// <summary>
        /// Converts the string representation of a command to a Command object.
        /// A return value indicates whether the conversion succeded or not.
        /// </summary>
        /// <param name="s">A string containing the command to convert</param>
        /// <param name="source">The module which sent the command</param>
        /// <param name="cmd">When this method returns, contains the Command equivalent to the command
        /// contained in s, if the conversion succeeded, or null if the conversion failed.
        /// The conversion fails if the s parameter is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <param name="ex">When this method returns, contains the Exception generated during the parse operation,
        /// if the conversion failed, or null if the conversion succeeded. The conversion fails if the s parameter
        /// is a null reference (Nothing in Visual Basic) or is not of the correct format.
        /// This parameter is passed uninitialized</param>
        /// <returns>true if conversion was successfull, false otherwise</returns>
        protected static bool TryParse(string s, ModuleClient source, out Command cmd, out Exception ex)
        {
            IPrototype proto;
            //Module destination;
            IModuleClient destination;
            string sCommand;
            string sParams;
            string sDest;
            int result;
            int id;

            cmd = null;
            ex = null;

            // Extract Data
            CommandBase.XtractCommandElements(s, out sDest, out sCommand, out sParams, out result, out id);
            if ((sCommand == null) || (result != -1))
            {
                ex = new ArgumentException("Invalid String", "s");
                return false;
            }

            // Browse for destination module and prototype
            if (source.SupportCommand(sCommand, out proto))
                destination = source;
            else if(!source.Parent.FindDestinationModule(sCommand, out destination, out proto))
            {
                // No destination module found. Must check if destination is availiable
                if ((sDest == null) || (sDest.Length < 1) || !source.Parent.Modules.Contains(sDest))
                {
                    ex = new Exception("No destination module found for command provided");
                    return false;
                }
                destination = source.Parent.Modules[sDest];
                proto = null;
            }
            // Check if command matchs a prototype
            if (proto == null)
            {
                ex = new Exception("No prototype for provided command was found");
                return false;
            }
            if ((proto != null) && proto.ParamsRequired && ((sParams == null) || (sParams.Length < 1)))
            {
                ex = new Exception("Invalid string. The Command requires parameters");
                return false;
            }
            // Create the Command
            cmd = new Command(source, destination, sCommand, sParams, id);
            cmd.prototype = proto;
            cmd.sentTime = DateTime.Now;
            return true;
        }
		private void PopulateModuleMenu_Run(ToolStripMenuItem mnu, ModuleClient mc)
		{
			ToolStripMenuItem mni = (ToolStripMenuItem)mnu.DropDownItems.Add("Run (&unconditionally)");
			mni.Image = Properties.Resources.ProcessWarning16;
			mni.Enabled = mc.Enabled;
			mni.Tag = mc;
			mni.Click += new EventHandler(mnuiModule_Module_Run_Click);
		}