Ejemplo n.º 1
0
        /// <summary>
        /// Runs inline command on specified files and returns list of found result items.
        /// </summary>
        protected List <CodeReferenceResultItem> BatchInlineLookup(string[] files)
        {
            // select the files in Solution Explorer
            UIHierarchyItem[] selectedItems = new UIHierarchyItem[files.Length];
            int i = 0;

            foreach (var key in files)
            {
                selectedItems[i] = Agent.FindUIHierarchyItem(Agent.GetUIHierarchy().UIHierarchyItems, key);
                Assert.IsNotNull(selectedItems[i]);
                i++;
            }

            // run the command
            Agent.BatchInlineCommand.Results = null;
            Agent.BatchInlineCommand.Process(selectedItems, true);
            VLDocumentViewsManager.ReleaseLocks();

            // copy the results
            List <CodeReferenceResultItem> list = new List <CodeReferenceResultItem>();

            foreach (CodeReferenceResultItem item in Agent.BatchInlineCommand.Results)
            {
                list.Add(item);
            }

            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the move to resources command on specified files and returns list of found result items.
        /// </summary>
        protected List <CodeStringResultItem> BatchMoveLookup(string[] testFiles)
        {
            List <CodeStringResultItem> list = new List <CodeStringResultItem>();

            // select the files in Solution Explorer
            UIHierarchyItem[] selectedItems = new UIHierarchyItem[testFiles.Length];
            for (int i = 0; i < testFiles.Length; i++)
            {
                selectedItems[i] = Agent.FindUIHierarchyItem(Agent.GetUIHierarchy().UIHierarchyItems, testFiles[i]);
                Assert.IsNotNull(selectedItems[i]);
            }

            // run the command
            Agent.BatchMoveCommand.Results = null;
            Agent.BatchMoveCommand.Process(selectedItems, true);

            // copy the results
            foreach (CodeStringResultItem item in Agent.BatchMoveCommand.Results)
            {
                list.Add(item);
            }

            VLDocumentViewsManager.ReleaseLocks();

            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles "Translate resources" command from Solution Explorer's context menu.
        /// </summary>
        private void TranslateSolExpClick(object sender, EventArgs args)
        {
            try {
                if (OperationInProgress)
                {
                    throw new Exception("Cannot start operation 'Global translate', because another operation is in progress.");
                }
                OperationInProgress = true;

                globalTranslateCommand.Process((Array)VisualLocalizerPackage.Instance.UIHierarchy.SelectedItems);
            } catch (Exception ex) {
                if (OperationInProgress)
                {
                    VLDocumentViewsManager.ReleaseLocks();
                }

                Dictionary <string, string> add = null;
                if (ex is CannotParseResponseException)
                {
                    CannotParseResponseException cpex = ex as CannotParseResponseException;
                    add = new Dictionary <string, string>();
                    add.Add("Full response:", cpex.FullResponse);
                }

                VLOutputWindow.VisualLocalizerPane.WriteException(ex, add);
                MessageBox.ShowException(ex, add);
                OperationInProgress = false;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// "Run" button was clicked
        /// </summary>
        private void RunClick(object sender, EventArgs args)
        {
            int checkedRows = panel.ToolGrid.CheckedRowsCount;
            int rowCount    = panel.ToolGrid.Rows.Count;
            int rowErrors   = 0;

            try {
                VLDocumentViewsManager.ReleaseLocks();                                               // unlock the documents
                MenuManager.OperationInProgress = false;                                             // permit other operations

                bool usingFullName = currentNamespacePolicy == NAMESPACE_POLICY_ITEMS[1];            // whether full references will be used
                bool markUncheckedStringsWithComment = currentRememberOption == REMEMBER_OPTIONS[1]; // whether unchecked strings will be marked with "no-localization" comment

                BatchMover mover = new BatchMover(usingFullName, markUncheckedStringsWithComment);

                mover.Move(panel.ToolGrid.GetData(), ref rowErrors); // run the mover
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
            } finally {
                IVsWindowFrame frame = ((IVsWindowFrame)this.Frame);
                if (frame != null)
                {
                    frame.CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave);                // close the toolwindow
                }
                panel.ToolGrid.Clear();

                VLOutputWindow.VisualLocalizerPane.Activate();
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Move to Resources command completed - selected {0} rows of {1}, {2} rows processed successfully", checkedRows, rowCount, checkedRows - rowErrors);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles "Batch move on selection" command from code context menu.
        /// </summary>
        private void BatchMoveSelectionCodeClick(object sender, EventArgs args)
        {
            try {
                if (OperationInProgress)
                {
                    throw new Exception("Cannot start operation 'Batch move to resources', because another operation is in progress.");
                }
                OperationInProgress = true;

                batchMoveCommand.ProcessSelection(true);
                BatchMoveToResourcesToolWindow win = ShowToolWindow <BatchMoveToResourcesToolWindow>();
                if (win != null)
                {
                    win.SetData(batchMoveCommand.Results);
                }
                else
                {
                    throw new Exception("Unable to display tool window.");
                }
                batchMoveCommand.Results.Clear();
            } catch (Exception ex) {
                if (OperationInProgress)
                {
                    VLDocumentViewsManager.ReleaseLocks();
                }
                VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchMoveCommand), false);
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                MessageBox.ShowException(ex);
                OperationInProgress = false;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handles "Batch inline" command from Solution Explorer's context menu.
        /// </summary>
        private void BatchInlineSolExpClick(object sender, EventArgs args)
        {
            try {
                if (OperationInProgress)
                {
                    throw new Exception("Cannot start operation 'Batch inline', because another operation is in progress.");
                }
                OperationInProgress = true;

                batchInlineCommand.Process((Array)VisualLocalizerPackage.Instance.UIHierarchy.SelectedItems, true);
                BatchInlineToolWindow win = ShowToolWindow <BatchInlineToolWindow>();
                if (win != null)
                {
                    win.SetData(batchInlineCommand.Results);
                }
                else
                {
                    throw new Exception("Unable to display tool window.");
                }
                batchInlineCommand.Results.Clear();
            } catch (Exception ex) {
                if (OperationInProgress)
                {
                    VLDocumentViewsManager.ReleaseLocks();
                }
                VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchInlineCommand), false);
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                MessageBox.ShowException(ex);
                OperationInProgress = false;
            }
        }
Ejemplo n.º 7
0
        public void ProcessTest1()
        {
            Agent.EnsureSolutionOpen();

            DTE2             DTE    = Agent.GetDTE();
            BatchMoveCommand target = Agent.BatchMoveCommand;

            for (int i = 0; i < 3; i++)
            {
                var window = DTE.OpenFile(null, Agent.VBStringsTestFile1);
                window.Activate();

                target.Process(true);

                Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1));

                ValidateResults(GetExpectedResultsFor(Agent.VBStringsTestFile1), target.Results);

                window.Detach();
                window.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo);
                Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1));

                VLDocumentViewsManager.ReleaseLocks();
                Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(Agent.VBStringsTestFile1));
            }
        }
 /// <summary>
 /// When window is closed
 /// </summary>        
 protected override void OnWindowHidden(object sender, EventArgs e) {
     if (panel.SetDataFinished) {
         VLDocumentViewsManager.ReleaseLocks(); // unlock all previously locked documents
         MenuManager.OperationInProgress = false; // enable other operations to run
         VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchInlineCommand), false);
     }
     panel.Clear();
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Generic test for classic variant of batch commands
        /// </summary>
        /// <param name="target">Command to test</param>
        /// <param name="itemsToSelect">List of items that should be marked as selected in the Solution Explorer</param>
        /// <param name="expectedFiles">List of files that are expected to be searched</param>
        /// <param name="getExpected">Function that returns list of expected result items for specified file</param>
        protected void GenericTest(AbstractBatchCommand target, string[] itemsToSelect, string[] expectedFiles, Func <string, List <AbstractResultItem> > getExpected)
        {
            Agent.EnsureSolutionOpen();
            try {
                // select the items in Solution Explorer
                UIHierarchyItem[] selectedItems = new UIHierarchyItem[itemsToSelect.Length];
                for (int i = 0; i < itemsToSelect.Length; i++)
                {
                    selectedItems[i] = Agent.FindUIHierarchyItem(Agent.GetUIHierarchy().UIHierarchyItems, itemsToSelect[i]);
                    Assert.IsNotNull(selectedItems[i]);
                }

                // run the command on the selection
                target.Process(selectedItems, true);

                // test if all expected files were processed
                for (int i = 0; i < expectedFiles.Length; i++)
                {
                    Assert.IsTrue(VLDocumentViewsManager.IsFileLocked(expectedFiles[i]));
                }

                // create the list of expected results
                List <AbstractResultItem> list = new List <AbstractResultItem>();
                for (int i = 0; i < expectedFiles.Length; i++)
                {
                    list.AddRange(getExpected(expectedFiles[i]));
                }

                // compare the results
                if (target is BatchMoveCommand)
                {
                    ValidateResults(list, (target as BatchMoveCommand).Results);
                }
                else if (target is BatchInlineCommand)
                {
                    ValidateResults(list, (target as BatchInlineCommand).Results);
                }
                else
                {
                    Assert.Fail("Unkown parent command type");
                }
            } finally {
                VLDocumentViewsManager.ReleaseLocks();
                for (int i = 0; i < expectedFiles.Length; i++)
                {
                    Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(expectedFiles[i]));
                }
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// When the toolwindow is closed
 /// </summary>
 protected override void OnWindowHidden(object sender, EventArgs e)
 {
     try {
         if (panel.ToolGrid.SetDataFinished)
         {
             VLDocumentViewsManager.ReleaseLocks();   // unlocks all locked files
             panel.ToolGrid.UnloadResXItems();        // release all ResX files loaded in the grid
             panel.ToolGrid.ResetConflictResolver();
             MenuManager.OperationInProgress = false; // permits other operations
             VLDocumentViewsManager.CloseInvisibleWindows(typeof(BatchMoveCommand), false);
         }
         panel.ToolGrid.Clear();
     } catch (Exception ex) {
         VLOutputWindow.VisualLocalizerPane.WriteException(ex);
         VisualLocalizer.Library.Components.MessageBox.ShowException(ex);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Handles "Inline" command from code context menu.
        /// </summary>
        private void InlineClick(object sender, EventArgs args)
        {
            bool enteredOk = false;

            try {
                if (OperationInProgress)
                {
                    throw new Exception("Cannot start operation 'Inline', because another operation is in progress.");
                }
                enteredOk = true;

                Document doc = VisualLocalizerPackage.Instance.DTE.ActiveDocument;
                if (doc == null)
                {
                    throw new Exception("No active document.");
                }

                if (doc.ProjectItem.GetFileType() == FILETYPE.ASPX)
                {
                    aspNetInlineCommand.Process();
                }
                else if (doc.ProjectItem.GetFileType() == FILETYPE.CSHARP)
                {
                    csharpInlineCommand.Process();
                }
                else if (doc.ProjectItem.GetFileType() == FILETYPE.VB)
                {
                    vbInlineCommand.Process();
                }
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                MessageBox.ShowException(ex);
            } finally {
                if (enteredOk)
                {
                    VLDocumentViewsManager.ReleaseLocks();
                }
            }
        }
        /// <summary>
        /// "Run" button clicked
        /// </summary>        
        private void RunClick(object sender, EventArgs e) {
            int checkedRows = panel.CheckedRowsCount;
            int rowCount = panel.Rows.Count;
            int rowErrors = 0;

            try {
                VLDocumentViewsManager.ReleaseLocks(); // unlock locked documents
                MenuManager.OperationInProgress = false; // permit other operations
                BatchInliner inliner = new BatchInliner(); 

                inliner.Inline(panel.GetData(), false, ref rowErrors); // run inliner                
            } catch (Exception ex) {
                VLOutputWindow.VisualLocalizerPane.WriteException(ex);
                MessageBox.ShowException(ex);
            } finally {
                if (this.Frame != null)
                    ((IVsWindowFrame)this.Frame).CloseFrame((uint)__FRAMECLOSE.FRAMECLOSE_NoSave); // close the toolwindow

                panel.Clear();

                VLOutputWindow.VisualLocalizerPane.Activate();
                VLOutputWindow.VisualLocalizerPane.WriteLine("Batch Inline command completed - selected {0} rows of {1}, {2} rows processed successfully", checkedRows, rowCount, checkedRows - rowErrors);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Generic test for the "(selection)" commands
        /// </summary>
        /// <param name="target">Command to process</param>
        /// <param name="file">File path</param>
        /// <param name="view"></param>
        /// <param name="lines"></param>
        /// <param name="getExpected">Function that returns list of expected results for specified file path</param>
        protected void GenericSelectionTest(AbstractBatchCommand_Accessor target, string file, IVsTextView view, IVsTextLines lines, Func <string, List <AbstractResultItem> > getExpected)
        {
            Agent.EnsureSolutionOpen();

            int lineCount;

            lines.GetLineCount(out lineCount);
            Random rnd = new Random();

            for (int i = 0; i < 20; i++)
            {
                // initialize selection range
                int beginLine = rnd.Next(lineCount);
                int endLine   = beginLine + rnd.Next(Math.Min(lineCount, beginLine + i) - beginLine);

                int beginLineLength, endLineLength;
                lines.GetLengthOfLine(beginLine, out beginLineLength);
                lines.GetLengthOfLine(endLine, out endLineLength);
                int beginColumn = rnd.Next(beginLineLength);
                int endColumn   = beginLine == endLine ? beginColumn + (rnd.Next(Math.Min(endLineLength, beginColumn + i) - beginColumn)) : rnd.Next(endLineLength);
                if (beginLine == endLine && beginColumn == endColumn)
                {
                    endColumn++;
                }

                // set the selection
                view.SetSelection(beginLine, beginColumn, endLine, endColumn);
                target.InitializeSelection();

                // obtain the list of expected results
                List <AbstractResultItem> expectedList = new List <AbstractResultItem>();
                foreach (AbstractResultItem expected in getExpected(file))
                {
                    if (!target.IsItemOutsideSelection(expected))
                    {
                        expectedList.Add(expected);
                    }
                }

                // run the command
                target.ProcessSelection(true);

                // compare the results
                if (target is BatchMoveCommand_Accessor)
                {
                    ValidateResults(expectedList, (target as BatchMoveCommand_Accessor).Results);
                }
                else if (target is BatchInlineCommand_Accessor)
                {
                    ValidateResults(expectedList, (target as BatchInlineCommand_Accessor).Results);
                }
                else
                {
                    Assert.Fail("Unkown parent command type");
                }

                Assert.IsTrue(expectedList.Count == 0 || VLDocumentViewsManager.IsFileLocked(file));

                VLDocumentViewsManager.ReleaseLocks();
                Assert.IsFalse(VLDocumentViewsManager.IsFileLocked(file));
            }

            // close the window
            Window win = VsShellUtilities.GetWindowObject(VLDocumentViewsManager.GetWindowFrameForFile(file, false));

            win.Detach();
            win.Close(vsSaveChanges.vsSaveChangesNo);
        }