static List <CodeExample> MergeExamples(List <CodeExample> findedExamplesCS, List <CodeExample> findedExamplesVB)
        {
            List <CodeExample> result = new List <CodeExample>();

            int count = findedExamplesCS.Count;

            for (int i = 0; i < count; i++)
            {
                CodeExample itemCS = findedExamplesCS[i];

                CodeExample itemVB = findedExamplesVB[i];
                if (itemCS.HumanReadableGroupName == itemVB.HumanReadableGroupName &&
                    itemCS.RegionName == itemVB.RegionName)
                {
                    CodeExample merged = new CodeExample();
                    merged.RegionName             = itemCS.RegionName;
                    merged.HumanReadableGroupName = itemCS.HumanReadableGroupName;
                    merged.CodeCS = itemCS.CodeCS;
                    merged.CodeVB = itemVB.CodeVB;
                    result.Add(merged);
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            return(result);
        }
        void OnNewExampleSelected(object sender, FocusedNodeChangedEventArgs e)
        {
            CodeExample newExample = (sender as TreeList).GetDataRecordByNode(e.Node) as CodeExample;
            CodeExample oldExample = (sender as TreeList).GetDataRecordByNode(e.OldNode) as CodeExample;

            if (newExample == null)
            {
                return;
            }

            string exampleCode = codeEditor.ShowExample(oldExample, newExample);

            codeExampleNameLbl.Text = CodeExampleDemoUtils.ConvertStringToMoreHumanReadableForm(newExample.RegionName) + " example";
            CodeEvaluationEventArgs args = new CodeEvaluationEventArgs();

            InitializeCodeEvaluationEventArgs(args);
            evaluator.ForceCompile(args);

            if (newExample.HumanReadableGroupName == "Comments")
            {
                this.richEditControl.Options.Comments.Visibility = RichEditCommentVisibility.Visible;
                this.displayResultControl1.DockPanel.Show();
            }
            else
            {
                this.richEditControl.Options.Comments.Visibility = RichEditCommentVisibility.Hidden;
                this.displayResultControl1.DockPanel.Hide();
            }
        }
        // todo: remove example group
        public List <CodeExample> ParseSouceFileAndFindRegionsWithExamples(string groupName, string sourceCode)
        {
            List <CodeExample> result = new List <CodeExample>();
            Dictionary <string, CodeExample> examplesByRegion = new Dictionary <string, CodeExample>();

            var matches = Regex.Matches(sourceCode, RegexRegionPattern, RegexOptions.Singleline);

            foreach (var match in matches)
            {
                string   matchString = match.ToString();
                string   splitter    = matchString.IndexOf("\r\n") >= 0 ? "\r\n" : "\n";
                string[] lines       = match.ToString().Split(new string[] { splitter }, StringSplitOptions.None);

                if (lines.Length <= 2)
                {
                    continue;
                }
                //string endRegion = lines[lines.Length - 1];
                bool isAdditionalModules = lines[0].Contains("AdditionalModules");
                bool isCustomAction      = lines[0].Contains("CustomActionHandler");

                lines = DeleteLeadingWhiteSpacesFromSourceCode(lines, isAdditionalModules || isCustomAction);

                string regionName    = String.Empty;
                bool   regionIsValid = ValidateRegionName(lines[0].Replace("AdditionalModules", "").Replace("CustomActionHandler", ""), ref regionName);
                if (!regionIsValid)
                {
                    continue;
                }

                string exampleCode = string.Join("\r\n", lines, 1, lines.Length - 2);
                if (isAdditionalModules)
                {
                    if (examplesByRegion.ContainsKey(regionName))
                    {
                        SetExampleAdditionalModules(exampleCode, examplesByRegion[regionName]);
                    }
                }
                else
                {
                    if (isCustomAction)
                    {
                        if (examplesByRegion.ContainsKey(regionName))
                        {
                            SetExampleCustomActionHandler(exampleCode, examplesByRegion[regionName]);
                        }
                    }
                    else
                    {
                        CodeExample newCodeExample = CreateRichEditExample(groupName, regionName, exampleCode);
                        result.Add(newCodeExample);
                        examplesByRegion.Add(regionName, newCodeExample);
                    }
                }
            }
            return(result);
        }
        protected CodeExample CreateRichEditExample(string exampleGroup, string regionName, string exampleCode)
        {
            CodeExample result = new CodeExample();

            SetExampleCode(exampleCode, result);
            result.RegionName             = regionName;
            result.HumanReadableGroupName = CodeExampleDemoUtils.ConvertStringToMoreHumanReadableForm(exampleGroup);
            return(result);
        }
 protected override void SetExampleCode(string code, CodeExample newExample)
 {
     if (isHelper)
     {
         newExample.CodeCsHelper = code;
     }
     else
     {
         newExample.CodeCS = code;
     }
 }
        void treeList_VirtualTreeGetCellValue(object sender, VirtualTreeGetCellValueInfo args)
        {
            CodeExampleGroup group = args.Node as CodeExampleGroup;

            if (group != null)
            {
                args.CellData = group.Name;
            }

            CodeExample example = args.Node as CodeExample;

            if (example != null)
            {
                args.CellData = example.RegionName;
            }
        }
Exemplo n.º 7
0
        public string ShowExample(CodeExample oldExample, CodeExample newExample)
        {
            InnerRichEditControl richEditControlCs      = codeEditorCs.InnerControl;
            InnerRichEditControl richEditControlVb      = codeEditorVb.InnerControl;
            InnerRichEditControl richEditControlCsClass = codeEditorCsClass.InnerControl;
            InnerRichEditControl richEditControlVbClass = codeEditorVbClass.InnerControl;

            if (oldExample != null)
            {
                //save edited example
                oldExample.CodeCS       = richEditControlCs.Text;
                oldExample.CodeVB       = richEditControlVb.Text;
                oldExample.CodeCsHelper = richEditControlCsClass.Text;
                oldExample.CodeVbHelper = richEditControlVbClass.Text;
            }
            string exampleCode = String.Empty;

            if (newExample != null)
            {
                try
                {
                    forceTextChangesCounter     = 2;
                    exampleCode                 = (CurrentExampleLanguage == ExampleLanguage.Csharp) ? newExample.CodeCS : newExample.CodeVB;
                    richEditControlCs.Text      = newExample.CodeCS;
                    richEditControlVb.Text      = newExample.CodeVB;
                    richEditControlCsClass.Text = newExample.CodeCsHelper;
                    richEditControlVbClass.Text = newExample.CodeVbHelper;

                    richEditTextChanged = false;
                }
                finally
                {
                    richEditTextChanged = true;
                }
            }
            return(exampleCode);
        }
 protected override void SetExampleCustomActionHandler(string customActionHandler, CodeExample newExample)
 {
     newExample.HasCustomAction       = true;
     newExample.CustomActionHandlerCS = customActionHandler;
 }
 protected override void SetExampleAdditionalModules(string additionalModules, CodeExample newExample)
 {
     newExample.AdditionalModulesCS = additionalModules;
 }
 protected override void SetExampleCode(string code, CodeExample newExample)
 {
     newExample.CodeCS = code;
 }
 protected abstract void SetExampleCustomActionHandler(string customActionHandler, CodeExample newExample);
 protected abstract void SetExampleAdditionalModules(string additionalModules, CodeExample newExample);
 protected abstract void SetExampleCode(string exampleCode, CodeExample newExample);
Exemplo n.º 14
0
        public string ShowExample(CodeExample oldExample, CodeExample newExample)
        {
            InnerRichEditControl richEditControlCs = codeEditorCs.InnerControl;
            InnerRichEditControl richEditControlVb = codeEditorVb.InnerControl;

            if (oldExample != null)
            {
                //save edited example
                //oldExample.CodeCS = richEditControlCs.Text;
                //oldExample.CodeVB = richEditControlVb.Text;
            }
            string exampleCode = String.Empty;

            if (newExample != null)
            {
                try
                {
                    forceTextChangesCounter = 2;
                    exampleCode             = (CurrentExampleLanguage == ExampleLanguage.Csharp) ? newExample.CodeCS : newExample.CodeVB;
                    richEditControlCs.Text  = newExample.CodeCS;
                    if (newExample.AdditionalModulesCS != null)
                    {
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("//---------- Additional modules");
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("\r\n");

                        richEditControlCs.Document.AppendText(newExample.AdditionalModulesCS);
                    }
                    if (newExample.HasCustomAction)
                    {
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("//---------- Custom action handler");
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText("\r\n");
                        richEditControlCs.Document.AppendText(newExample.CustomActionHandlerCS);
                    }
                    richEditControlVb.Text = newExample.CodeVB;
                    if (newExample.AdditionalModulesVB != null)
                    {
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("'---------- Additional modules");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText(newExample.AdditionalModulesVB);
                    }
                    if (newExample.HasCustomAction)
                    {
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("'---------- Custom action handler");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText("\r\n");
                        richEditControlVb.Document.AppendText(newExample.CustomActionHandlerVB);
                    }
                    richEditTextChanged = false;
                }
                finally
                {
                    richEditTextChanged = true;
                }
            }
            return(exampleCode);
        }