public string ParseSnippet(Snippet snippet, int indent, CALKeyProcessor keyProcessor)
        {
            string content = snippet.Run(keyProcessor);

            if (content == null)
            {
                return(null);
            }

            int pos = content.IndexOf("{{");

            if (pos >= 0)
            {
                StringBuilder builder  = new StringBuilder();
                int           startPos = 0;
                while (pos >= 0)
                {
                    if (content.Substring(pos, 4) == "{{{{")
                    {
                        builder.Append(content.Substring(startPos, pos - startPos + 2));
                        startPos = pos + 4;
                        pos      = startPos;
                    }
                    else
                    {
                        int endPos = content.IndexOf("}}", pos);
                        if (endPos > 0)
                        {
                            string variableName  = content.Substring(pos + 2, endPos - pos - 2).Trim();
                            string variableValue = GetVariableValue(variableName);

                            //check if text has to be indented
                            int prevNewLinePos = content.LastIndexOf('\n', pos);
                            if (prevNewLinePos >= 0)
                            {
                                variableValue = IndentText(variableValue, pos - prevNewLinePos - 1);
                            }

                            //add text to string builder
                            builder.Append(content.Substring(startPos, pos - startPos));
                            builder.Append(variableValue);
                            startPos = endPos + 2;

                            //move pos
                            pos = startPos;
                        }
                    }
                    pos = content.IndexOf("{{", pos);
                }
                if (startPos < content.Length)
                {
                    builder.Append(content.Substring(startPos));
                }
                content = builder.ToString();
            }

            return(IndentText(content, indent));
        }
 public ClosingBracketInputProcessor(CALKeyProcessor keyProcessor) : base(keyProcessor)
 {
     this.ClosingTexts = new Dictionary <string, string>();
     this.ClosingTexts.Add("(", " )");   //we have to add space before closing bracket to make intellisense work
     this.ClosingTexts.Add("[", " ]");   //the same as above
     this.ClosingTexts.Add("{", "}");
     this.ClosingTexts.Add("'", "'");
     this.ClosingTexts.Add("\"", "\"");
 }
        protected void AddRecordTypes(CALKeyProcessor keyProcessor, IList <TypeInfo> destList)
        {
            IList <TypeInfo> types = GetLocalTypes(keyProcessor);

            foreach (TypeInfo typeInfo in types)
            {
                if (typeInfo.DataTypeName == "Record")
                {
                    destList.Add(typeInfo);
                }
            }
        }
        public override string Run(CALKeyProcessor keyProcessor)
        {
            string defaultTemplate = "{{VariableName}}.{{FieldName}} := ;";
            RecordFieldListCodeGeneratorVM     viewModel = new RecordFieldListCodeGeneratorVM(keyProcessor.NavConnector.TypeInfoManager);
            RecordFieldListCodeGeneratorWindow window    = new RecordFieldListCodeGeneratorWindow();

            viewModel.Template = defaultTemplate;
            AddRecordTypes(keyProcessor, viewModel.Variables);
            window.DataContext = viewModel;
            if (window.ShowDialog() == true)
            {
                if ((String.IsNullOrWhiteSpace(viewModel.VariableName)) || (viewModel.Fields.Count == 0))
                {
                    return(null);
                }

                string template = viewModel.Template;
                if (String.IsNullOrWhiteSpace(template))
                {
                    template = defaultTemplate;
                }

                StringBuilder           builder   = new StringBuilder();
                IEnumerable <FieldInfo> fieldList = viewModel.Fields;
                if (viewModel.SelectedFields.Count != 0)
                {
                    fieldList = viewModel.SelectedFields;
                }

                template = template.Replace("{{VariableName}}", viewModel.VariableName);

                foreach (FieldInfo field in fieldList)
                {
                    string fieldName = "\"" + field.Name + "\"";
                    string line      = template.Replace("{{FieldName}}", fieldName);
                    builder.Append(line);
                    builder.Append("\n");
                }

                return(builder.ToString());
            }
            return(null);
        }
Ejemplo n.º 5
0
 public SettingsInputProcessor(CALKeyProcessor keyProcessor) : base(keyProcessor)
 {
 }
 public InputProcessor(CALKeyProcessor keyProcessor)
 {
     this.KeyProcessor = keyProcessor;
 }
        public override string Run(CALKeyProcessor keyProcessor)
        {
            RecordAssignmentCodeGeneratorVM     viewModel = new RecordAssignmentCodeGeneratorVM();
            RecordAssignmentCodeGeneratorWindow window    = new RecordAssignmentCodeGeneratorWindow();

            AddRecordTypes(keyProcessor, viewModel.Variables);

            window.DataContext = viewModel;
            if (window.ShowDialog() == true)
            {
                TypeInfoManager typeInfoManager = keyProcessor.NavConnector.TypeInfoManager;

                IEnumerable <FieldInfo> sourceFieldList = typeInfoManager.GetFields(viewModel.SourceVariableName);
                IEnumerable <FieldInfo> destFieldList   = typeInfoManager.GetFields(viewModel.DestVariableName);

                //collect source fields
                Dictionary <int, FieldInfo>    sourceFieldById   = null;
                Dictionary <string, FieldInfo> sourceFieldByName = null;
                if (viewModel.MatchByName)
                {
                    sourceFieldByName = new Dictionary <string, FieldInfo>();
                    foreach (FieldInfo sourceField in sourceFieldList)
                    {
                        sourceFieldByName.Add(sourceField.Name, sourceField);
                    }
                }
                else
                {
                    sourceFieldById = new Dictionary <int, FieldInfo>();
                    foreach (FieldInfo sourceField in sourceFieldList)
                    {
                        sourceFieldById.Add(sourceField.Id, sourceField);
                    }
                }

                StringBuilder builder = new StringBuilder();

                //process fields
                foreach (FieldInfo destField in destFieldList)
                {
                    FieldInfo sourceField = null;
                    if ((viewModel.MatchByName) && (sourceFieldByName.ContainsKey(destField.Name)))
                    {
                        sourceField = sourceFieldByName[destField.Name];
                    }
                    else if ((!viewModel.MatchByName) && (sourceFieldById.ContainsKey(destField.Id)))
                    {
                        sourceField = sourceFieldById[destField.Id];
                    }

                    string sourceFieldText = "";
                    if (sourceField != null)
                    {
                        sourceFieldText = viewModel.SourceVariableName + ".\"" + sourceField.Name + "\"";
                    }

                    if ((sourceField != null) || (viewModel.AllFields))
                    {
                        builder.Append(viewModel.DestVariableName);
                        if (viewModel.WithValidation)
                        {
                            builder.Append(".VALIDATE(\"");
                            builder.Append(destField.Name);
                            builder.Append("\", ");
                        }
                        else
                        {
                            builder.Append(".\"");
                            builder.Append(destField.Name);
                            builder.Append("\" := ");
                        }
                        builder.Append(sourceFieldText);
                        if (viewModel.WithValidation)
                        {
                            builder.Append(");\n");
                        }
                        else
                        {
                            builder.Append(";\n");
                        }
                    }
                }

                return(builder.ToString());
            }
            return(null);
        }
 protected IList <TypeInfo> GetLocalTypes(CALKeyProcessor keyProcessor)
 {
     return(keyProcessor.NavConnector.Context.LanguageService.Locals.Get(keyProcessor.MethodManager.ActiveMethod));
 }
 public override string Run(CALKeyProcessor keyProcessor)
 {
     return(null);
 }
 public SnippetsInputProcessor(CALKeyProcessor keyProcessor) : base(keyProcessor)
 {
 }
Ejemplo n.º 11
0
 public XmlDocInputProcessor(CALKeyProcessor keyProcessor) : base(keyProcessor)
 {
 }
 public virtual string Run(CALKeyProcessor keyProcessor)
 {
     return(this.Content);
 }