示例#1
0
        /// <summary>
        /// Main constructor
        /// </summary>
        /// <param name="message">Message to display</param>
        /// <param name="param">Parameter info</param>
        /// <param name="paramValue">Initial value of parameter</param>
        public ParameterValueDialog(string message, PatchInstructionParameter param, string paramValue)
            : base(Application.ProductName, message, paramValue)
        {
            InitializeComponent();

            _CurrentParameter = param;

            // OK button is activated by Enter key
            OKOnEnterKey = true;

            // If current parameter has no value provider, corresponding link is disabled
            knownValuesLinkLabel.Enabled = (param.ValuesProvider != null);
        }
示例#2
0
文件: PCH.cs 项目: djey47/tdumt
        /// <summary>
        /// Method to create an instruction from a XML node
        /// </summary>
        /// <param name="node">node to process</param>
        /// <param name="order">instruction order</param>
        /// <returns>Correponding instruction</returns>
        private PatchInstruction _ProcessInstruction(XmlNode node, int order)
        {
            PatchInstruction processedPI = null;

            if (node != null && order > 0)
            {
                // Main attributes
                string instructionType = node.Attributes[_TYPE_ATTRIBUTE].Value;
                string isFailOnError   = Xml2.GetAttributeWithDefaultValue(node, _FAIL_ON_ERROR_ATTRIBUTE, true.ToString());
                string isEnabled       = Xml2.GetAttributeWithDefaultValue(node, _ENABLED_ATTRIBUTE, true.ToString());
                string comment         = Xml2.GetAttributeWithDefaultValue(node, _COMMENT_ATTRIBUTE, "");
                string groupName       = Xml2.GetAttributeWithDefaultValue(node, _GROUP_ATTRIBUTE, REQUIRED_GROUP_NAME);

                processedPI = PatchInstruction.MakeInstruction(instructionType);

                if (processedPI != null)
                {
                    processedPI.FailOnError = bool.Parse(isFailOnError);
                    processedPI.Enabled     = bool.Parse(isEnabled);
                    processedPI.Order       = order;
                    processedPI.Comment     = comment;

                    if (string.IsNullOrEmpty(groupName))
                    {
                        groupName = REQUIRED_GROUP_NAME;
                    }

                    processedPI.Group = GetGroupFromName(groupName);

                    // Instruction parameters
                    XmlNodeList allParameterNodes = node.SelectNodes(_PARAMETER_NODE);

                    if (allParameterNodes != null)
                    {
                        foreach (XmlNode anotherParameterNode in allParameterNodes)
                        {
                            PatchInstructionParameter pip = _ProcessParameter(anotherParameterNode);

                            if (pip == null)
                            {
                                throw new Exception("Invalid parameter: " + anotherParameterNode.Value);
                            }

                            processedPI.Parameters.Add(pip.Name, pip);
                        }
                    }
                }
            }

            return(processedPI);
        }
示例#3
0
文件: PCH.cs 项目: djey47/tdumt
        /// <summary>
        /// Handles XML writing of specified parameter
        /// </summary>
        /// <param name="param">Parameter to write</param>
        /// <param name="doc">Main XML document</param>
        /// <param name="instruction">Instruction node</param>
        private static void _SaveParameter(PatchInstructionParameter param, XmlDocument doc, XmlNode instruction)
        {
            if (param == null || doc == null || instruction == null)
            {
                return;
            }

            XmlElement currentParameter = doc.CreateElement(_SINGLE_PARAMETER_NODE);

            instruction.AppendChild(currentParameter);

            // Parameter attributes
            currentParameter.SetAttribute(_NAME_ATTRIBUTE, param.Name);
            currentParameter.SetAttribute(_VALUE_ATTRIBUTE, param.Value);
        }
示例#4
0
        /// <summary>
        /// Creates a value copy of current parameters
        /// </summary>
        /// <returns></returns>
        private Dictionary <string, PatchInstructionParameter> _CloneParameters()
        {
            Dictionary <string, PatchInstructionParameter> returnClone = new Dictionary <string, PatchInstructionParameter>();

            foreach (KeyValuePair <string, PatchInstructionParameter> valuePair in _Parameters)
            {
                string parameterName = valuePair.Key.Clone() as string;
                PatchInstructionParameter parameterValue = valuePair.Value.Clone() as PatchInstructionParameter;

                if (parameterName != null)
                {
                    returnClone.Add(parameterName, parameterValue);
                }
            }

            return(returnClone);
        }
示例#5
0
        /// <summary>
        ///
        /// {</summary>
        /// <param name="parameterName"></param>
        /// <param name="evaluateVariable"></param>
        /// <returns></returns>
        protected string _GetParameter(PatchInstructionParameter.ParameterName parameterName, bool evaluateVariable)
        {
            bool   requiredParameter = false;
            string returnedValue     = null;

            try
            {
                // Parameter information
                ParameterInfo info = SupportedParameterInformation[parameterName];

                requiredParameter = info.Required;

                // Retrieving parameter value...
                PatchInstructionParameter resultPip = _Parameters[parameterName.ToString()];

                if (resultPip != null)
                {
                    if (evaluateVariable)
                    {
                        returnedValue = PatchInstructionParameter.EvaluateParameter(resultPip.Value);
                    }
                    else
                    {
                        returnedValue = resultPip.Value;
                    }
                }
                else if (requiredParameter)
                {
                    throw new MissingParameterException(parameterName);
                }
            }
            catch (Exception ex)
            {
                Exception2.PrintStackTrace(ex);

                if (requiredParameter)
                {
                    throw new MissingParameterException(parameterName, ex);
                }
            }

            return(returnedValue);
        }
示例#6
0
        /// <summary>
        /// Defines a parameter value if it's supported by current instruction. If parameter does not exist, it's created.
        /// </summary>
        /// <param name="paramName">Parameter name</param>
        /// <param name="paramValue">Parameter value</param>
        /// <exception cref="Exception">When specified parameter is not supported</exception>
        public void SetParameter(string paramName, string paramValue)
        {
            if (string.IsNullOrEmpty(paramName))
            {
                return;
            }

            // Existing parameter ?
            if (Parameters.ContainsKey(paramName))
            {
                PatchInstructionParameter currentPip = Parameters[paramName];

                currentPip.Value = paramValue;
            }
            else
            {
                // Compatibility test
                bool isCompatible = false;

                foreach (string s in SupportedParameters)
                {
                    if (s.Equals(paramName))
                    {
                        // OK
                        PatchInstructionParameter newPip = PatchInstructionParameter.MakeParameter(paramName);

                        newPip.Value = paramValue;
                        Parameters.Add(paramName, newPip);

                        isCompatible = true;
                        break;
                    }
                }

                if (!isCompatible)
                {
                    throw new Exception("Error: '" + paramName + "' parameter is not supported by'" + Name +
                                        "' instruction.");
                }
            }
        }
示例#7
0
文件: PCH.cs 项目: djey47/tdumt
        /// <summary>
        /// Method to create a parameter from a XML node
        /// </summary>
        /// <param name="anotherParameterNode">node to process</param>
        /// <returns>Corresponding parameter</returns>
        private static PatchInstructionParameter _ProcessParameter(XmlNode anotherParameterNode)
        {
            PatchInstructionParameter param = null;

            if (anotherParameterNode != null)
            {
                string parameterName  = anotherParameterNode.Attributes[_NAME_ATTRIBUTE].Value;
                string parameterValue = anotherParameterNode.Attributes[_VALUE_ATTRIBUTE].Value;

                param = PatchInstructionParameter.MakeParameter(parameterName);

                if (param == null)
                {
                    throw new Exception("Invalid parameter: " + anotherParameterNode.Value);
                }

                param.Value = parameterValue;
            }

            return(param);
        }