public static List <ParameterMappingInfo> GetMappingsFromRule(iLogicRule rule)
        {
            List <ParameterMappingInfo> result = new List <ParameterMappingInfo>();

            string[] lines = rule.Text.Split('\n');

            bool bIsLinkParametersSection = false;

            foreach (string line in lines)
            {
                //Not in a section, look for section start
                if (!bIsLinkParametersSection)
                {
                    if (line.Contains("<LinkParameters:Section:Start>"))
                    {
                        bIsLinkParametersSection = true;
                    }

                    continue;
                }

                //we are in a section, look for section end
                if (line.Contains("<LinkParameters:Section:End>"))
                {
                    bIsLinkParametersSection = false;
                    continue;
                }

                //Now process section...

                int pos = line.IndexOf('=');

                if (pos < 0)
                {
                    continue;
                }

                string leftSide  = line.Substring(0, pos).Trim();
                string rightSide = line.Substring(pos + 1).Trim();

                string targetComponent, targetParameter,
                       sourceComponent, sourceParameter;

                ParseParameterExpression(leftSide, out targetComponent, out targetParameter);
                ParseParameterExpression(rightSide, out sourceComponent, out sourceParameter);

                ParameterMappingInfo mapping = new ParameterMappingInfo()
                {
                    SourceComponentName = sourceComponent,
                    SourceParameterName = sourceParameter,
                    TargetComponentName = targetComponent,
                    TargetParameterName = targetParameter,
                };

                result.Add(mapping);
            }
            return(result);
        }
        public static List <ParameterMappingInfo> GetMappings(Document document, string ruleName)
        {
            IiLogicAutomation ruleApi = iLogicUtilities.GetiLogicAutomation();

            System.Collections.IEnumerable rules =
                iLogicUtilities.GetiLogicAutomation().get_Rules(document);

            iLogicRule rule = ruleApi.GetRule(document, ruleName);

            if (rule != null)
            {
                return(ParameterMappingInfo.GetMappingsFromRule(rule));
            }

            return(new List <ParameterMappingInfo>());
        }
        private static string CreateMappingString(ParameterMappingInfo mapping)
        {
            StringBuilder newMapping = new StringBuilder();

            string format = (mapping.SourceComponentName == string.Empty ?
                             "Parameter(\"{0}\", \"{1}\") = Parameter(\"{3}\")" :
                             "Parameter(\"{0}\", \"{1}\") = Parameter(\"{2}\", \"{3}\")");

            newMapping.AppendFormat(format,
                                    mapping.TargetComponentName,
                                    mapping.TargetParameterName,
                                    mapping.SourceComponentName,
                                    mapping.SourceParameterName);

            return(newMapping.ToString());
        }