예제 #1
0
        private static void SaveDocDataToFileCallBack(object caller, CallbackArgs arguments)
        {
            arguments.ReturnValue = VSConstants.S_OK;

            VSSAVEFLAGS        dwSave         = (VSSAVEFLAGS)arguments.GetParameter(0);
            IPersistFileFormat editorInstance = (IPersistFileFormat)arguments.GetParameter(1);
            string             fileName       = (string)arguments.GetParameter(2);

            //Call Save on the EditorInstance depending on the Save Flags
            switch (dwSave)
            {
            case VSSAVEFLAGS.VSSAVE_Save:
            case VSSAVEFLAGS.VSSAVE_SilentSave:
                editorInstance.Save(fileName, 0, 0);
                arguments.SetParameter(3, fileName);        // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);               // setting pfSaveCanceled
                break;

            case VSSAVEFLAGS.VSSAVE_SaveAs:
                string newFileName = Environment.GetEnvironmentVariable("SystemDrive") +
                                     Path.DirectorySeparatorChar + "NewTempFile.rtf";
                editorInstance.Save(newFileName, 1, 0);         //Call Save with new file and remember=1
                arguments.SetParameter(3, newFileName);         // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);                   // setting pfSaveCanceled
                break;

            case VSSAVEFLAGS.VSSAVE_SaveCopyAs:
                newFileName = Environment.GetEnvironmentVariable("SystemDrive") +
                              Path.DirectorySeparatorChar + "NewTempFile.rtf";
                editorInstance.Save(newFileName, 0, 0);         //Call Save with new file and remember=0
                arguments.SetParameter(3, newFileName);         // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);                   // setting pfSaveCanceled
                break;
            }
        }
예제 #2
0
        private static void GetSelectedItemsCallback(object caller, CallbackArgs arguments)
        {
            // Read the current selection data
            VSITEMSELECTION[] selection = (VSITEMSELECTION[])((BaseMock)caller)["Selection"];

            // Get the arguments
            uint grfGSI          = (uint)arguments.GetParameter(0);
            uint cRequestedItems = (uint)arguments.GetParameter(1);

            VSITEMSELECTION[] rgItemSel = (VSITEMSELECTION[])arguments.GetParameter(2);

            if (selection == null && cRequestedItems > 0 ||
                selection.Length < cRequestedItems)
            {
                arguments.ReturnValue = VSConstants.E_INVALIDARG;
                return;
            }

            for (int i = 0; i < cRequestedItems; i++)
            {
                rgItemSel[i].itemid = selection[i].itemid;
                if ((grfGSI & (uint)__VSGSIFLAGS.GSI_fOmitHierPtrs) == 0)
                {
                    rgItemSel[i].pHier = selection[i].pHier;
                }
            }

            arguments.ReturnValue = VSConstants.S_OK;
        }
예제 #3
0
        private static void SaveDocDataToFileCallBack(object caller, CallbackArgs arguments)
        {
            arguments.ReturnValue = VSConstants.S_OK;

            VSSAVEFLAGS        dwSave         = (VSSAVEFLAGS)arguments.GetParameter(0);
            IPersistFileFormat editorInstance = (IPersistFileFormat)arguments.GetParameter(1);
            string             fileName       = (string)arguments.GetParameter(2);

            //Call Save on the EditorInstance depending on the Save Flags
            switch (dwSave)
            {
            case VSSAVEFLAGS.VSSAVE_Save:
            case VSSAVEFLAGS.VSSAVE_SilentSave:
                editorInstance.Save(fileName, 0, 0);
                arguments.SetParameter(3, fileName);        // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);               // setting pfSaveCanceled
                break;

            case VSSAVEFLAGS.VSSAVE_SaveAs:
                String newFileName = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileName));
                editorInstance.Save(newFileName, 1, 0);         //Call Save with new file and remember=1
                arguments.SetParameter(3, newFileName);         // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);                   // setting pfSaveCanceled
                break;

            case VSSAVEFLAGS.VSSAVE_SaveCopyAs:
                newFileName = Path.Combine(Path.GetTempPath(), Path.GetFileName(fileName));
                editorInstance.Save(newFileName, 0, 0);         //Call Save with new file and remember=0
                arguments.SetParameter(3, newFileName);         // setting pbstrMkDocumentNew
                arguments.SetParameter(4, 0);                   // setting pfSaveCanceled
                break;
            }
        }
예제 #4
0
        private static void StandardMarkerResetSpanCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;
            TextSpan span = new TextSpan();

            span.iStartLine  = (int)args.GetParameter(0);
            span.iStartIndex = (int)args.GetParameter(1);
            span.iEndLine    = (int)args.GetParameter(2);
            span.iEndIndex   = (int)args.GetParameter(3);
            mock["Span"]     = span;
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #5
0
        private static void CreateToolwindowCallback(object sender, CallbackArgs args)
        {
            BaseMock       mock  = (BaseMock)sender;
            IVsWindowFrame frame = mock["Frame"] as IVsWindowFrame;

            Assert.IsInstanceOfType(args.GetParameter(2), CommandWindowHelper.ConsoleType);
            IVsWindowPane pane = args.GetParameter(2) as IVsWindowPane;
            IntPtr        hwnd;

            pane.CreatePaneWindow(IntPtr.Zero, 0, 0, 0, 0, out hwnd);
            args.SetParameter(9, frame);
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #6
0
        private static void ReplaceLinesCallback(object sender, CallbackArgs args)
        {
            IntPtr stringPointer = (IntPtr)args.GetParameter(4);
            int    stringLen     = (int)args.GetParameter(5);

            Assert.IsTrue(IntPtr.Zero != stringPointer);
            Assert.IsTrue(stringLen > 0);
            string   newText = Marshal.PtrToStringAuto(stringPointer, stringLen);
            BaseMock mock    = (BaseMock)sender;

            mock["Text"]     = (string)mock["Text"] + newText;
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #7
0
        private static void TextViewInitializeCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            // Verify that the view is sited and that a text buffer is provided.
            Assert.IsTrue(1 == mock.FunctionCalls(string.Format("{0}.{1}", typeof(IObjectWithSite), "SetSite")));
            IVsTextLines textLines = args.GetParameter(0) as IVsTextLines;

            Assert.IsNotNull(textLines);
            // This text view is not supposed to be initialized using a parent window.
            Assert.IsTrue(IntPtr.Zero == (IntPtr)args.GetParameter(1));
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
        private static void EvaluateNullResultCallback(object sender, CallbackArgs args)
        {
            string param = (string)args.GetParameter(0);

            Assert.IsTrue("dir(dte)" == param);
            args.ReturnValue = null;
        }
예제 #9
0
        private static void CreateMarkerCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            IVsTextLineMarker[] markers    = (IVsTextLineMarker[])args.GetParameter(6);
            BaseMock            markerMock = (BaseMock)mock["LineMarker"];
            TextSpan            span       = new TextSpan();

            span.iStartLine    = (int)args.GetParameter(1);
            span.iStartIndex   = (int)args.GetParameter(2);
            span.iEndLine      = (int)args.GetParameter(3);
            span.iEndIndex     = (int)args.GetParameter(4);
            markerMock["Span"] = span;
            markers[0]         = (IVsTextLineMarker)markerMock;
            args.ReturnValue   = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #10
0
        private static void CreateToolWindowCallBack(object caller, CallbackArgs arguments)
        {
            arguments.ReturnValue = VSConstants.S_OK;

            // Create the output mock object for the frame
            IVsWindowFrame frame = MockWindowFrameProvider.GetBaseFrame();

            arguments.SetParameter(9, frame);

            // The window pane (if one is provided) needs to be sited
            IVsWindowPane pane = arguments.GetParameter(2) as IVsWindowPane;

            if (pane != null)
            {
                // Create a service provider to site the window pane
                OleServiceProvider serviceProvider = OleServiceProvider.CreateOleServiceProviderWithBasicServices();
                // It needs to provide STrackSelection
                GenericMockFactory trackSelectionFactory = MockWindowFrameProvider.TrackSelectionFactory;
                serviceProvider.AddService(typeof(STrackSelection), trackSelectionFactory.GetInstance(), false);
                // Add support for output window
                serviceProvider.AddService(typeof(SVsOutputWindow), new OutputWindowService(), false);
                // Finally we need support for FindToolWindow
                serviceProvider.AddService(typeof(SVsUIShell), GetWindowEnumerator0(), false);

                pane.SetSite(serviceProvider);
            }
        }
예제 #11
0
        private static void AddCommandFilterCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            mock["CommandFilter"] = (IOleCommandTarget)args.GetParameter(0);
            args.SetParameter(1, (IOleCommandTarget)mock["OriginalFilter"]);
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #12
0
        private static void StandardMarkerGetCurrentSpanCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            TextSpan[] spans = (TextSpan[])args.GetParameter(0);
            spans[0]         = (TextSpan)mock["Span"];
            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #13
0
        private static void OutputStringCallback(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            System.Text.StringBuilder builder = (System.Text.StringBuilder)mock["StringBuilder"];
            string text = (string)args.GetParameter(0);

            builder.Append(text);
            args.ReturnValue = 0;
        }
        private void OutputWindowPaneCallback(object sender, CallbackArgs args)
        {
            callbackExecuted = true;
            string expectedText = " ======================================\n" +
                                  "\tGlobalServiceFunction called.\n" +
                                  " ======================================\n";
            string inputText = (string)args.GetParameter(0);

            Assert.AreEqual(expectedText, inputText, "OutputString called with wrong text.");
            args.ReturnValue = 0;
        }
예제 #15
0
        private static void GetPropertyCallBack2(object caller, CallbackArgs arguments)
        {
            if ((int)arguments.GetParameter(0) == (int)__VSSPROPID.VSSPROPID_IsInCommandLineMode)
            {
                arguments.SetParameter(1, false);
                arguments.ReturnValue = VSConstants.S_OK;
                return;
            }

            arguments.ReturnValue = VSConstants.E_NOTIMPL;
        }
        private void EvaluateCallback(object sender, CallbackArgs args)
        {
            string param = (string)args.GetParameter(0);

            Assert.IsTrue("dir(variable)" == param);
            List <string> list = new List <string>();

            list.Add("Method 1");
            list.Add("Method 2");
            args.ReturnValue = list;
        }
예제 #17
0
        private static void GetLineTextCallbackForConsoleTextOfLine(object sender, CallbackArgs args)
        {
            BaseMock mock         = (BaseMock)sender;
            int      expectedLine = (int)mock["ExpectedLine"];

            Assert.IsTrue(expectedLine == (int)args.GetParameter(0));
            Assert.IsTrue(expectedLine == (int)args.GetParameter(2));

            int expectedStart = (int)mock["ExpectedStart"];

            Assert.IsTrue(expectedStart == (int)args.GetParameter(1));

            int expectedEnd = (int)mock["ExpectedEnd"];

            Assert.IsTrue(expectedEnd == (int)args.GetParameter(3));

            args.SetParameter(4, (string)mock["LineText"]);

            args.ReturnValue = Microsoft.VisualStudio.VSConstants.S_OK;
        }
예제 #18
0
        private static void GetPropertiesCallBack(object caller, CallbackArgs arguments)
        {
            arguments.ReturnValue = VSConstants.S_OK;

            // Find the corresponding property
            object propertyID = arguments.GetParameter(0);
            Dictionary <int, object> properties = (Dictionary <int, object>)((BaseMock)caller)[propertiesName];
            object propertyValue = null;

            if (properties != null && propertyID != null)
            {
                propertyValue = properties[(int)propertyID];
            }
            // Set the value we ended up with as the return value
            arguments.SetParameter(1, propertyValue);
        }
예제 #19
0
        private static void GetPropertyCallBack(object caller, CallbackArgs arguments)
        {
            __VSSPROPID propertyID = (__VSSPROPID)arguments.GetParameter(0);

            switch (propertyID)
            {
            case __VSSPROPID.VSSPROPID_IsInCommandLineMode:
                // fake that we are running in command line mode in order to load normally (security)
                arguments.SetParameter(1, true);
                break;

            default:
                break;
            }
            arguments.ReturnValue = VSConstants.S_OK;
        }
예제 #20
0
        private static void GetPropertyCallBack(object caller, CallbackArgs arguments)
        {
            __VSSPROPID propertyID = (__VSSPROPID)arguments.GetParameter(0);

            switch (propertyID)
            {
            case __VSSPROPID.VSSPROPID_IsInCommandLineMode:
                arguments.SetParameter(1, true);
                break;

            default:
                break;
            }

            arguments.ReturnValue = VSConstants.S_OK;
        }
예제 #21
0
        private static void ReadCallback(object caller, CallbackArgs arguments)
        {
            string propertyName = (string)arguments.GetParameter(0);

            if (propertyName == strSolutionControlledProperty)
            {
                arguments.SetParameter(1, true);
                arguments.ReturnValue = VSConstants.S_OK;
                return;
            }
            else if (propertyName == strSolutionBindingsProperty)
            {
                arguments.SetParameter(1, "Solution's location");
                arguments.ReturnValue = VSConstants.S_OK;
                return;
            }

            arguments.ReturnValue = VSConstants.E_NOTIMPL;
        }
        private static void StandardScannerCallback(object sender, CallbackArgs args)
        {
            BaseMock mock      = (BaseMock)sender;
            int      iteration = (int)mock["Iteration"];

            TokenInfo[] tokens = (TokenInfo[])mock["Tokens"];
            if (tokens.Length <= iteration)
            {
                args.ReturnValue = false;
                return;
            }
            TokenInfo token = (TokenInfo)args.GetParameter(0);

            token.StartIndex  = tokens[iteration].StartIndex;
            token.EndIndex    = tokens[iteration].EndIndex;
            token.Trigger     = tokens[iteration].Trigger;
            iteration        += 1;
            mock["Iteration"] = iteration;
            args.ReturnValue  = true;
        }
예제 #23
0
        private static void NextCallBack2(object caller, CallbackArgs arguments)
        {
            if (windowCount >= 2)
            {
                // We already enumerated 2 window frames, we are done (0 left to enumerate)
                NextCallBack0(caller, arguments);
                return;
            }

            arguments.ReturnValue = VSConstants.S_OK;
            // Create the list of properties we expect being asked for
            Dictionary <int, object> properties = new Dictionary <int, object>();

            properties.Add((int)__VSFPROPID.VSFPROPID_Caption, "Tool Window " + windowCount.ToString());
            ++windowCount;
            properties.Add((int)__VSFPROPID.VSFPROPID_GuidPersistenceSlot, Guid.NewGuid());
            // Create the output mock object for the frame
            object o = arguments.GetParameter(1);

            IVsWindowFrame[] frame = (IVsWindowFrame[])o;
            frame[0] = MockWindowFrameProvider.GetFrameWithProperties(properties);
            // fetched 1 frame
            arguments.SetParameter(2, (uint)1);
        }
예제 #24
0
        private static void EventSourceAddTaskFinished(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            mock["TaskFinished"] = args.GetParameter(0);
        }
예제 #25
0
        private static void EventSourceAddBuildStarted(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            mock["BuildStarted"] = args.GetParameter(0);
        }
예제 #26
0
        private static void EventSourceAddMessageRaised(object sender, CallbackArgs args)
        {
            BaseMock mock = (BaseMock)sender;

            mock["MessageRaised"] = args.GetParameter(0);
        }
예제 #27
0
        private static void ReferencedAssembliesCallBack(object caller, CallbackArgs arguments)
        {
            BaseMock compiler = (BaseMock)caller;

            compiler["ReferencedAssemblies"] = arguments.GetParameter(0);
        }
예제 #28
0
        private static void TargetKindCallBack(object caller, CallbackArgs arguments)
        {
            BaseMock compiler = (BaseMock)caller;

            compiler["TargetKind"] = arguments.GetParameter(0);
        }
예제 #29
0
        private static void IncludeDebugInformationCallBack(object caller, CallbackArgs arguments)
        {
            BaseMock compiler = (BaseMock)caller;

            compiler["IncludeDebugInformation"] = arguments.GetParameter(0);
        }
예제 #30
0
        private static void MainFileCallBack(object caller, CallbackArgs arguments)
        {
            BaseMock compiler = (BaseMock)caller;

            compiler["MainFile"] = arguments.GetParameter(0);
        }