Пример #1
0
        public GherkinPage()
        {
            InitializeComponent();

            folder = WorkSpace.UserProfile.Solution.BusinessFlowsMainFolder;

            GherkinTextEditor.AddToolbarTool(General.GetImage("@Save_16x16.png"), Save_Click, "Save Gherkin Feature");
            GherkinTextEditor.SaveButton.Visibility = Visibility.Collapsed;

            GherkinTextEditor.AddToolbarTool(General.GetImage("@Grid_16x16.png"), AddTable, "Add Examples Table");

            DragDrop2.HookEventHandlers(GherkinTextEditor);

            // Set the grids
            SetScenariosGridView();
            ScenariosGrid.SetTitleLightStyle = true;
            ScenariosGrid.DataSourceList     = mGherkinScenarioDefinition;

            SetStepsGridView();
            StepsGrid.SetTitleLightStyle = true;
            StepsGrid.DataSourceList     = mGherkinSteps;

            TagsGrid.DataSourceList     = mTags;
            TagsGrid.SetTitleLightStyle = true;
            SetTagsGrid();


            SetErrorsGridView();
            ErrorsGrid.SetTitleLightStyle = true;
            ErrorsGrid.DataSourceList     = mErrorsList;

            OptimizedStepsGrid.SetTitleLightStyle = true;
            SetOptimizedGridView();
        }
Пример #2
0
        public bool SavePrompt()
        {
            //set file size to check for changes
            string txt = GherkinTextEditor.GetText();

            if (fileSize != txt.Length && fileSize != 0)
            {
                fileSize = txt.Length; //TODO Reporter.ToUser(eUserMsgKey.AskIfSureWantToClose);
                Amdocs.Ginger.Common.eUserMsgSelection result = Reporter.ToUser(eUserMsgKey.GherkinAskToSaveFeatureFile);
                if (result == Amdocs.Ginger.Common.eUserMsgSelection.Yes)
                {
                    Save();
                    return(true);
                }
                else if (result == Amdocs.Ginger.Common.eUserMsgSelection.No)
                {
                    //Do nothing? this will still create optmized activities and even update BF without saving the feature file... not advised
                    return(true);
                }
                else if (result == Amdocs.Ginger.Common.eUserMsgSelection.Cancel)
                {
                    //stop optimize so user can fix unwanted changes.
                    return(false);
                }
            }
            fileSize = txt.Length;
            return(true);
        }
Пример #3
0
 private void StepsGrid_RowChangedEvent(object sender, EventArgs e)
 {
     if (StepsGrid.CurrentItem != null)
     {
         int line = ((GherkinStep)StepsGrid.CurrentItem).Step.Location.Line;
         GherkinTextEditor.HighlightLine(line);
     }
 }
Пример #4
0
 private void TagsGrid_RowChangedEvent(object sender, EventArgs e)
 {
     if (TagsGrid.CurrentItem != null)
     {
         int line = ((GherkinTag)TagsGrid.CurrentItem).Line;
         GherkinTextEditor.HighlightLine(line);
     }
 }
Пример #5
0
 private void ScenariosGrid_RowChangedEvent(object sender, EventArgs e)
 {
     if (ScenariosGrid.CurrentItem != null)
     {
         int line = ((GherkinScenarioDefinition)ScenariosGrid.CurrentItem).ScenarioDefintion.Location.Line;
         GherkinTextEditor.HighlightLine(line);
     }
 }
Пример #6
0
        public bool Load(string FileName)
        {
            featureFileName = FileName;
            GherkinTextEditor.SetContentEditorTitleLabel(Path.GetFileName(FileName) + " , Target " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + ": N/A", (Style)TryFindResource("@ucGridTitleLightStyle"));
            GherkinDcoumentEditor g = new GherkinDcoumentEditor();

            g.OptimizedSteps = mOptimizedSteps;
            g.OptimizedTags  = mTags;
            GherkinTextEditor.Init(FileName, g, true);
            mSolTags.ClearAll();
            foreach (GherkinTag tag in mTags)
            {
                Guid guid = GetTagInSolution(tag.Name);
                if (guid != Guid.Empty)
                {
                    mSolTags.Add(guid);
                }
            }

            string externalID = FileName.Replace(WorkSpace.Instance.Solution.Folder, "~");

            mBizFlow = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <BusinessFlow>().Where(x => x.Source == BusinessFlow.eSource.Gherkin && (x.ExternalID == externalID || x.ExternalID == FileName)).SingleOrDefault();

            ARP = new ActivitiesRepositoryPage(WorkSpace.Instance.SolutionRepository.GetRepositoryItemRootFolder <Activity>(), new Context()
            {
                BusinessFlow = mBizFlow
            }, mSolTags, ArrowButtonHandler);
            //ARP.xActivitiesRepositoryListView.EnableTagsPanel = false;
            SharedActivitiesFrame.Content = ARP;

            BFName = FileName.Replace(WorkSpace.Instance.Solution.Folder, "");
            //to prevent creating a folder rather than putting them on BF level.
            if (BFName.Contains("Business Flows"))
            {
                BFName = BFName.Replace("Business Flows", "");
            }
            if (BFName.EndsWith(".feature"))
            {
                BFName = Path.GetFileName(FileName).Replace(".feature", "");
            }
            // search if we have the BF defined already, so search in BF will work

            if (mBizFlow != null)
            {
                BFName                 = mBizFlow.FileName;
                isBFexists             = true;
                UpdateBFButton.Content = "Update " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow);
                GherkinTextEditor.SetContentEditorTitleLabel(Path.GetFileName(FileName) + " , Target " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow) + ": " + mBizFlow.ContainingFolder + "\\" + mBizFlow.Name, (Style)TryFindResource("@ucGridTitleLightStyle"));
            }
            else
            {
                isBFexists             = false;
                UpdateBFButton.Content = "Create " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow);
            }
            SavePrompt();

            return(Optimize());
        }
Пример #7
0
        public bool Load(string FileName)
        {
            GherkinTextEditor.ContentEditorTitleLabel.Content = Path.GetFileName(FileName);
            GherkinTextEditor.ContentEditorTitleLabel.Style   = (Style)TryFindResource("@ucGridTitleLightStyle");
            GherkinDcoumentEditor g = new GherkinDcoumentEditor();

            g.OptimizedSteps = mOptimizedSteps;
            g.OptimizedTags  = mTags;
            GherkinTextEditor.Init(FileName, g, true);
            mSolTags.ClearAll();
            foreach (GherkinTag tag in mTags)
            {
                Guid guid = GetTagInSolution(tag.Name);
                if (guid != Guid.Empty)
                {
                    mSolTags.Add(guid);
                }
            }

            ARP = new ActivitiesRepositoryPage(WorkSpace.Instance.SolutionRepository.GetRepositoryItemRootFolder <Activity>(), null, mSolTags, ArrowButtonHandler);
            ARP.xActivitiesRepositoryGrid.EnableTagsPanel = false;
            SharedActivitiesFrame.Content = ARP;

            BFName = FileName.Replace(App.UserProfile.Solution.Folder, "");
            //to prevent creating a folder rather than putting them on BF level.
            if (BFName.Contains("Business Flows"))
            {
                BFName = BFName.Replace("Business Flows", "");
            }
            BFName = BFName.Replace(@"Documents\Features\", "");
            BFName = BFName.Replace(".feature", "");
            BFName = folder + BFName + ".Ginger.BusinessFlow.xml";
            // search if we have the BF defined already, so search in BF will work
            mBizFlow = WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems <BusinessFlow>().Where(x => x.Name == BFName).SingleOrDefault();

            if (File.Exists(BFName))
            {
                isBFexists             = true;
                UpdateBFButton.Content = "Update " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow);
            }
            else
            {
                isBFexists             = false;
                UpdateBFButton.Content = "Create " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow);
            }
            SavePrompt();

            return(Optimize());
        }
Пример #8
0
        private void GeneratBFButton_Click(object sender, RoutedEventArgs e)
        {
            if (!isBFexists)
            {
                BusinessFlowsFolderTreeItem bfsFolder = new BusinessFlowsFolderTreeItem(WorkSpace.Instance.SolutionRepository.GetRepositoryItemRootFolder <BusinessFlow>(), eBusinessFlowsTreeViewMode.ReadOnly);

                bfsFolder.IsGingerDefualtFolder = true;
                SingleItemTreeViewSelectionPage mTargetFolderSelectionPage = new SingleItemTreeViewSelectionPage(GingerDicser.GetTermResValue(eTermResKey.BusinessFlows), eImageType.BusinessFlow, bfsFolder, SingleItemTreeViewSelectionPage.eItemSelectionType.Folder, true);

                List <object> selectedBfs = mTargetFolderSelectionPage.ShowAsWindow();
                if (selectedBfs != null)
                {
                    targetBFFolder = (RepositoryFolder <BusinessFlow>)((ITreeViewItem)selectedBfs[0]).NodeObject();
                }
                CreateNewBF(FeatureName);
                CreateActivities();
                WorkSpace.Instance.SolutionRepository.SaveRepositoryItem(mBizFlow);
                if (genWin != null)
                {
                    genWin.Close();
                }
                UpdateBFButton.Content = "Update " + GingerDicser.GetTermResValue(eTermResKey.BusinessFlow);
                isBFexists             = true;
                Reporter.ToUser(eUserMsgKey.BusinessFlowUpdate, mBizFlow.ContainingFolder + "\\" + mBizFlow.Name, "Created");
            }
            else
            {
                UpdateBFButton_Click();
                Reporter.ToUser(eUserMsgKey.BusinessFlowUpdate, mBizFlow.ContainingFolder + "\\" + mBizFlow.Name, "Updated");
            }

            GherkinTextEditor.SetContentEditorTitleLabel(Path.GetFileName(GherkinTextEditor.FileName) + " , Target Business Flow: " + mBizFlow.ContainingFolder + "\\" + mBizFlow.Name, (Style)TryFindResource("@ucGridTitleLightStyle"));

            if (App.BusinessFlow == mBizFlow)
            {
                App.BusinessFlow = mBizFlow;
                App.BusinessFlow.SaveBackup();
            }
        }
Пример #9
0
 public void Save()
 {
     Optimize();
     GherkinTextEditor.Save();
 }
Пример #10
0
        public bool Optimize()
        {
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            mErrorsList.ClearAll();
            ShowErros(false);

            ColorIndex = 0;

            mGherkinScenarioDefinition.ClearAll();
            mGherkinSteps.ClearAll();
            mTags.ClearAll();

            mOptimizedSteps.ClearAll();
            OptimizedStepsGrid.DataSourceList = mOptimizedSteps;

            var parser = new Parser();

            try
            {
                string     txt             = GherkinTextEditor.GetText();
                TextReader sr              = new StringReader(txt);
                var        gherkinDocument = parser.Parse(sr);

                if (gherkinDocument.Feature == null || gherkinDocument.Feature.Children == null)
                {
                    Mouse.OverrideCursor = null;
                    return(false);
                }


                foreach (ScenarioDefinition SD in gherkinDocument.Feature.Children)
                {
                    mGherkinScenarioDefinition.Add(new GherkinScenarioDefinition(SD));
                }


                FeatureName = System.IO.Path.GetFileName(GherkinTextEditor.FileName).Replace(".feature", "");
                foreach (var c in gherkinDocument.Comments)
                {
                    WriteTXT("Comments:" + c.Text);
                }

                foreach (Tag t in gherkinDocument.Feature.Tags)
                {
                    mTags.Add(new GherkinTag(t));
                }

                mSolTags.ClearAll();
                foreach (GherkinTag tag in mTags)
                {
                    Guid guid = GetTagInSolution(tag.Name.Substring(1));
                    if (guid != Guid.Empty && !mSolTags.Contains(guid))
                    {
                        mSolTags.Add(guid);
                    }
                }
                foreach (var c in gherkinDocument.Feature.Children)
                {
                    if (c.Keyword == "Scenario" || c.Keyword == "Scenario Outline")
                    {
                        WriteTXT("Keyword:" + c.Keyword);
                        WriteTXT("Name:" + c.Name);

                        if (c is Scenario)
                        {
                            foreach (Tag t in ((Gherkin.Ast.Scenario)c).Tags)
                            {
                                mTags.Add(new GherkinTag(t));
                                Guid guid = GetTagInSolution(t.Name.Substring(1));
                                if (guid != Guid.Empty && !mSolTags.Contains(guid))
                                {
                                    mSolTags.Add(guid);
                                }
                            }
                        }

                        if (c is ScenarioOutline)
                        {
                            foreach (Tag t in ((Gherkin.Ast.ScenarioOutline)c).Tags)
                            {
                                mTags.Add(new GherkinTag(t));
                                Guid guid = GetTagInSolution(t.Name.Substring(1));
                                if (guid != Guid.Empty && !mSolTags.Contains(guid))
                                {
                                    mSolTags.Add(guid);
                                }
                            }
                        }
                    }
                }
                foreach (var c in gherkinDocument.Feature.Children)
                {
                    if (c.Keyword == "Scenario" || c.Keyword == "Scenario Outline")
                    {
                        foreach (var step in c.Steps)
                        {
                            WriteTXT("Keyword:" + step.Keyword);
                            WriteTXT("Text:" + step.Text);

                            GherkinStep GS = new GherkinStep();
                            GS.Text = step.Text;
                            GS.Step = step;
                            mGherkinSteps.Add(GS);

                            String GherkingActivityName = GherkinGeneral.GetActivityGherkinName(step.Text);

                            GherkinStep OptimizedStep = SearchStepInOptimizedSteps(GherkingActivityName);
                            if (OptimizedStep == null)
                            {
                                GherkinStep NewOptimizedStep = new GherkinStep();
                                NewOptimizedStep.Text       = GherkingActivityName;
                                NewOptimizedStep.Counter    = 1;
                                NewOptimizedStep.ColorIndex = ColorIndex;
                                ColorIndex++;
                                NewOptimizedStep.AutomationStatus = GetStepAutomationStatus(GherkingActivityName);
                                GS.AutomationStatus = NewOptimizedStep.AutomationStatus;
                                mOptimizedSteps.Add(NewOptimizedStep);
                            }
                            else
                            {
                                OptimizedStep.Counter++;
                                GS.ColorIndex       = OptimizedStep.ColorIndex;
                                GS.AutomationStatus = OptimizedStep.AutomationStatus;
                            }
                        }
                    }
                }

                // Warnings - TODO check other possible warnings
                // Check Dups Scenario names
                var query = mGherkinScenarioDefinition.GroupBy(x => x.Name)
                            .Where(g => g.Count() > 1)
                            .Select(y => y.Key)
                            .ToList();
                foreach (var v in query)
                {
                    IEnumerable <GherkinScenarioDefinition> SCS = from x in mGherkinScenarioDefinition where x.Name == v select x;
                    foreach (GherkinScenarioDefinition sc in SCS)
                    {
                        GherkinParserException PE = new GherkinParserException(sc.ScenarioDefintion.Location.Line, sc.ScenarioDefintion.Location.Column, "Duplicate Scenario Name: " + sc.Name);
                        mErrorsList.Add(PE);
                    }
                }
            }
            catch (CompositeParserException ex)
            {
                // we show the errors in the grid + mark in the textEditor
                GherkinTextEditor.BackgroundRenderer.Segments.Clear();
                foreach (ParserException PE in ex.Errors)
                {
                    mErrorsList.Add(new GherkinParserException(PE));
                    if (PE.Location.Line > GherkinTextEditor.textEditor.Document.LineCount)
                    {
                        continue;
                    }
                    var line = GherkinTextEditor.textEditor.Document.GetLineByNumber(PE.Location.Line);
                    GherkinTextEditor.BackgroundRenderer.Segments.Add(line);
                }
            }

            if (mErrorsList.Count > 0)
            {
                ShowErros(true);
                GherkinTextEditor.Focus();
            }
            else
            {
                GherkinTextEditor.BackgroundRenderer.Segments.Clear();
            }


            ARP.xActivitiesRepositoryGrid.Tags = mSolTags;
            SharedActivitiesFrame.Content      = ARP;

            foreach (GherkinStep gStep in mOptimizedSteps)
            {
            }

            OptimizedStepsGrid.DataSourceList = mOptimizedSteps;
            Mouse.OverrideCursor = null;
            List <GherkinParserException> Errors = mErrorsList.Where(x => x.ErrorType == GherkinParserException.eErrorType.Error).ToList();
            bool result = mOptimizedSteps.Count > 0 && Errors.Count == 0;

            return(result);
        }
Пример #11
0
 private void Save_Click(TextEditorToolRoutedEventArgs Args)
 {
     Optimize();
     GherkinTextEditor.Save();
 }