Example #1
0
        /////////////////////////////////////////////////////////////////////////////
        // Overridden Package Implementation
        #region Package Members

        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            packageInstaller     = ComponentModel.GetService <IVsPackageInstaller>();
            pkgInstallerServices = ComponentModel.GetService <IVsPackageInstallerServices>();
            base.Initialize();

            _outputWindow = new OutputWindowWriter(this, GuidList.guidServiceStackVSOutputWindowPane, "ServiceStackVS");

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the menu item.
                CommandID cSharpProjContextAddReferenceCommandId = new CommandID(GuidList.guidVSServiceStackCmdSet, (int)PkgCmdIDList.cmdidServiceStackReference);
                var       cSharpProjectContextOleMenuCommand     = new OleMenuCommand(CSharpAddReferenceCallback, cSharpProjContextAddReferenceCommandId);
                cSharpProjectContextOleMenuCommand.BeforeQueryStatus += CSharpQueryAndAddMenuItem;
                mcs.AddCommand(cSharpProjectContextOleMenuCommand);

                CommandID fSharpProjContextAddReferenceCommandId = new CommandID(GuidList.guidVSServiceStackCmdSet, (int)PkgCmdIDList.cmdidFSharpAddServiceStackReference);
                var       fSharpProjectContextOleMenuCommand     = new OleMenuCommand(FSharpAddReferenceCallback, fSharpProjContextAddReferenceCommandId);
                fSharpProjectContextOleMenuCommand.BeforeQueryStatus += FSharpQueryAndAddMenuItem;
                mcs.AddCommand(fSharpProjectContextOleMenuCommand);

                CommandID fSharpProjContextUpdateReferenceCommandId = new CommandID(GuidList.guidVSServiceStackCmdSet, (int)PkgCmdIDList.cmdidFSharpUpdateServiceStackReference);
                var       fSharpProjectContextUpdateOleMenuCommand  = new OleMenuCommand(FSharpUpdateReferenceCallback, fSharpProjContextUpdateReferenceCommandId);
                fSharpProjectContextUpdateOleMenuCommand.BeforeQueryStatus += FSharpQueryAndAddUpdateMenuItem;
                mcs.AddCommand(fSharpProjectContextUpdateOleMenuCommand);
            }

            solutionEventsListener = new SolutionEventsListener();
            solutionEventsListener.OnAfterOpenSolution += SolutionLoaded;
        }
Example #2
0
        private static void TryBowerInstall(this Document document, OutputWindowWriter windowWriter)
        {
            lock (bowerStartingLock)
            {
                if (!_bowerInstallRunning)
                {
                    windowWriter.Show();
                    windowWriter.WriteLine("--- Bower install started ---");
                    System.Threading.Tasks.Task.Run(() =>
                    {
                        try
                        {
                            NodePackageUtils.RunBowerInstall(document.Path,
                                                             (sender, args) => windowWriter.WriteLine(args.Data),
                                                             (sender, args) => windowWriter.WriteLine(args.Data)
                                                             );
                        }
                        catch (Exception e)
                        {
                            windowWriter.WriteLine(e.Message);
                        }

                        lock (bowerRunningLock)
                        {
                            _bowerInstallRunning = false;
                        }
                        windowWriter.WriteLine("--- Bower install complete ---");
                    });
                    lock (bowerRunningLock)
                    {
                        _bowerInstallRunning = true;
                    }
                }
            }
        }
Example #3
0
        private static void HandleDtoUpdate(Document document, INativeTypesHandler typesHandler,
                                            OutputWindowWriter outputWindowWriter)
        {
            string fullPath = document.ProjectItem.GetFullPath();

            outputWindowWriter.ShowOutputPane(document.DTE);
            outputWindowWriter.Show();
            outputWindowWriter.WriteLine(
                "--- Updating ServiceStack Reference '" +
                fullPath.Substring(fullPath.LastIndexOf("\\", StringComparison.Ordinal) + 1) +
                "' ---");
            var    existingGeneratedCode = File.ReadAllLines(fullPath).Join(Environment.NewLine);
            string baseUrl;

            if (!typesHandler.TryExtractBaseUrl(existingGeneratedCode, out baseUrl))
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unabled to find BaseUrl");
                return;
            }
            try
            {
                var    options     = typesHandler.ParseComments(existingGeneratedCode);
                string updatedCode = typesHandler.GetUpdatedCode(baseUrl, options);

                //Can't work out another way that ensures UI is updated.
                //Overwriting the file inconsistently prompts the user that file has changed.
                //Sometimes old code persists even though file has changed.
                document.Close();
                using (var streamWriter = File.CreateText(fullPath))
                {
                    streamWriter.Write(updatedCode);
                    streamWriter.Flush();
                }
                try
                {
                    bool optOutOfStats = Dte.GetOptOutStatsSetting();
                    if (!optOutOfStats)
                    {
                        var langName = typesHandler.RelativeTypesUrl.Substring(6);
                        Analytics.SubmitAnonymousUpdateReferenceUsage(langName);
                    }
                }
                catch (Exception)
                {
                    // Ignore errors
                }
                //HACK to ensure new file is loaded
                Task.Run(() => { document.DTE.ItemOperations.OpenFile(fullPath); });
            }
            catch (Exception e)
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unhandled error - " + e.Message);
            }

            outputWindowWriter.WriteLine("--- Update ServiceStack Reference Complete ---");
        }
Example #4
0
 public ApiPortVsAnalyzer(
     ApiPortClient client,
     OptionsViewModel optionsViewModel,
     OutputWindowWriter outputWindow,
     IReportViewer viewer,
     IProgressReporter reporter)
 {
     _client           = client;
     _optionsViewModel = optionsViewModel;
     _outputWindow     = outputWindow;
     _viewer           = viewer;
     _reporter         = reporter;
 }
 public ApiPortVsAnalyzer(
     ApiPortClient client,
     OptionsViewModel optionsViewModel,
     OutputWindowWriter outputWindow,
     IReportViewer viewer,
     IProgressReporter reporter)
 {
     _client = client;
     _optionsViewModel = optionsViewModel;
     _outputWindow = outputWindow;
     _viewer = viewer;
     _reporter = reporter;
 }
Example #6
0
        public static void TryRunNpmInstall(this Document document, OutputWindowWriter windowWriter)
        {
            lock (NpmStartingLock)
            {
                if (_npmInstallRunning)
                {
                    return;
                }
                windowWriter.Show();
                windowWriter.WriteLine("--- NPM install started ---");
                Task.Run(() =>
                {
                    try
                    {
                        NodePackageUtils.RunNpmInstall(document.Path,
                                                       (sender, args) =>
                        {
                            if (string.IsNullOrEmpty(args.Data))
                            {
                                return;
                            }
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            windowWriter.WriteLine(s);
                        },
                                                       (sender, args) =>
                        {
                            if (string.IsNullOrEmpty(args.Data))
                            {
                                return;
                            }
                            string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                            windowWriter.WriteLine(s);
                        });
                    }
                    catch (Exception e)
                    {
                        windowWriter.WriteLine(e.Message);
                    }

                    lock (NpmRunningLock)
                    {
                        _npmInstallRunning = false;
                    }
                    windowWriter.WriteLine("--- NPM install complete ---");
                });
                lock (NpmRunningLock)
                {
                    _npmInstallRunning = true;
                }
            }
        }
 public static void HandleDocumentSaved(Document document, OutputWindowWriter windowWriter)
 {
     foreach (var filterWatcher in FilterWatchers)
     {
         var predicate = filterWatcher.Key;
         var fileHandler = filterWatcher.Value;
         if (!predicate(document))
         {
             continue;
         }
         fileHandler(document, windowWriter);
         break;
     }
 }
Example #8
0
 public static void HandleDocumentSaved(Document document, OutputWindowWriter windowWriter)
 {
     foreach (var filterWatcher in FilterWatchers)
     {
         var predicate   = filterWatcher.Key;
         var fileHandler = filterWatcher.Value;
         if (!predicate(document))
         {
             continue;
         }
         fileHandler(document, windowWriter);
         break;
     }
 }
Example #9
0
        private static void BowerDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsBowerUpdateDisabled())
            {
                return;
            }

            _hasBowerInstalled = _hasBowerInstalled ? _hasBowerInstalled : NodePackageUtils.HasBowerOnPath();

            if (!_hasBowerInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine(
                    "Bower Installation not detected. Run npm install bower -g to install if Node.js/NPM already installed.");
                return;
            }
            document.TryBowerInstall(windowWriter);
        }
        private static void BowerDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsBowerUpdateDisabled())
            {
                return;
            }

            _hasBowerInstalled = _hasBowerInstalled ? _hasBowerInstalled : NodePackageUtils.HasBowerOnPath();

            if (!_hasBowerInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine(
                    "Bower Installation not detected. Run npm install bower -g to install if Node.js/NPM already installed.");
                return;
            }
            document.TryBowerInstall(windowWriter);
        }
Example #11
0
        private static void NpmDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsNpmUpdateDisable() || MajorVisualStudioVersion == 14 || (MajorVisualStudioVersion == 12 && ExtensionManager.HasExtension("Package Intellisense")))
            {
                return;
            }

            _hasNpmInstalled = _hasNpmInstalled
                ? _hasNpmInstalled
                : NodePackageUtils.TryRegisterNpmFromDefaultLocation();

            if (!_hasNpmInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine("Node.js Installation not detected. Visit http://nodejs.org/ to download.");
                return;
            }
            document.TryRunNpmInstall(windowWriter);
        }
        private static void NpmDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsNpmUpdateDisable())
            {
                return;
            }

            _hasNpmInstalled = _hasNpmInstalled
                ? _hasNpmInstalled
                : NodePackageUtils.TryRegisterNpmFromDefaultLocation();

            if (!_hasNpmInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine("Node.js Installation not detected. Visit http://nodejs.org/ to download.");
                return;
            }
            document.TryRunNpmInstall(windowWriter);
        }
Example #13
0
        public static void HandleNpmPackageUpdate(this Document document, OutputWindowWriter windowWriter)
        {
            string path = document.GetProjectPath();

            //If package.json and is at the root of the project
            if (document.Name.EqualsIgnoreCase("package.json") && document.Path.EqualsIgnoreCase(path))
            {
                if (document.IsNpmUpdateDisable())
                {
                    return;
                }

                hasNpmInstalled = hasNpmInstalled ? hasNpmInstalled : NodePackageUtils.TryRegisterNpmFromDefaultLocation();

                if (!hasNpmInstalled)
                {
                    windowWriter.Show();
                    windowWriter.WriteLine("Node.js Installation not detected. Visit http://nodejs.org/ to download.");
                    return;
                }
                document.TryRunNpmInstall(windowWriter);
            }
        }
Example #14
0
        public static void HandleBowerPackageUpdate(this Document document, OutputWindowWriter windowWriter)
        {
            string path = document.GetProjectPath();

            //If bower.json and is at the root of the project
            if (document.Name.EqualsIgnoreCase("bower.json") && document.Path.EqualsIgnoreCase(path))
            {
                if (document.IsBowerUpdateDisabled())
                {
                    return;
                }

                hasBowerInstalled = hasBowerInstalled ? hasBowerInstalled : NodePackageUtils.HasBowerOnPath();

                if (!hasBowerInstalled)
                {
                    windowWriter.Show();
                    windowWriter.WriteLine("Bower Installation not detected. Run npm install bower -g to install if Node.js/NPM already installed.");
                    return;
                }
                document.TryBowerInstall(windowWriter);
            }
        }
        private static void HandleDtoUpdate(Document document, INativeTypesHandler typesHandler,
            OutputWindowWriter outputWindowWriter)
        {
            string fullPath = document.ProjectItem.GetFullPath();
            outputWindowWriter.ShowOutputPane(document.DTE);
            outputWindowWriter.Show();
            outputWindowWriter.WriteLine(
                "--- Updating ServiceStack Reference '" +
                fullPath.Substring(fullPath.LastIndexOf("\\", StringComparison.Ordinal) + 1) +
                "' ---");
            var existingGeneratedCode = File.ReadAllLines(fullPath).Join(Environment.NewLine);
            string baseUrl;
            if (!typesHandler.TryExtractBaseUrl(existingGeneratedCode, out baseUrl))
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unabled to find BaseUrl");
                return;
            }
            try
            {
                var options = typesHandler.ParseComments(existingGeneratedCode);
                string updatedCode = typesHandler.GetUpdatedCode(baseUrl, options);

                //Can't work out another way that ensures UI is updated.
                //Overwriting the file inconsistently prompts the user that file has changed.
                //Sometimes old code persists even though file has changed.
                document.Close();
                using (var streamWriter = File.CreateText(fullPath))
                {
                    streamWriter.Write(updatedCode);
                    streamWriter.Flush();
                }
                //HACK to ensure new file is loaded
                Task.Run(() => { document.DTE.ItemOperations.OpenFile(fullPath); });
            }
            catch (Exception e)
            {
                outputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unhandled error - " + e.Message);
            }

            outputWindowWriter.WriteLine("--- Update ServiceStack Reference Complete ---");
        }
 public static void HandleDocumentSaved(this Document document, OutputWindowWriter windowWriter)
 {
     DocumentSavedHandlers.HandleDocumentSaved(document, windowWriter);
 }
        public static void TryRunNpmInstall(this Document document, OutputWindowWriter windowWriter)
        {
            lock (NpmStartingLock)
            {
                if (_npmInstallRunning)
                {
                    return;
                }
                windowWriter.Show();
                windowWriter.WriteLine("--- NPM install started ---");
                Task.Run(() =>
                {
                    try
                    {
                        NodePackageUtils.RunNpmInstall(document.Path,
                            (sender, args) =>
                            {
                                if (string.IsNullOrEmpty(args.Data))
                                {
                                    return;
                                }
                                string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                                windowWriter.WriteLine(s);
                            },
                            (sender, args) =>
                            {
                                if (string.IsNullOrEmpty(args.Data))
                                {
                                    return;
                                }
                                string s = Regex.Replace(args.Data, @"[^\u0000-\u007F]", string.Empty);
                                windowWriter.WriteLine(s);
                            });
                    }
                    catch (Exception e)
                    {
                        windowWriter.WriteLine(e.Message);
                    }

                    lock (NpmRunningLock)
                    {
                        _npmInstallRunning = false;
                    }
                    windowWriter.WriteLine("--- NPM install complete ---");
                });
                lock (NpmRunningLock)
                {
                    _npmInstallRunning = true;
                }
            }
        }
        private void UpdateGeneratedDtos(ProjectItem projectItem, INativeTypesHandler typesHandler)
        {
            OutputWindowWriter.Show();
            OutputWindowWriter.ShowOutputPane(dte);
            OutputWindowWriter.WriteLine("--- Updating ServiceStack Reference '" + projectItem.Name + "' ---");
            string projectItemPath = projectItem.GetFullPath();
            var    selectedFiles   = projectItem.DTE.SelectedItems.Cast <SelectedItem>().ToList();
            bool   isDtoSelected   = false;

            isDtoSelected = selectedFiles
                            .Any(item => item.Name.ToLowerInvariant()
                                 .EndsWith(typesHandler.CodeFileExtension));

            //Handle FSharp file extension name change for DTO files, eg .dto.fs to .dtos.fs
            if (!isDtoSelected && typesHandler is FSharpNativeTypesHandler)
            {
                isDtoSelected = selectedFiles
                                .Any(item => item.Name.ToLowerInvariant()
                                     .EndsWith(".dto.fs"));
            }

            if (isDtoSelected)
            {
                string filePath = projectItemPath;
                var    existingGeneratedCode = File.ReadAllLines(filePath).Join(Environment.NewLine);

                string baseUrl;
                if (!typesHandler.TryExtractBaseUrl(existingGeneratedCode, out baseUrl))
                {
                    OutputWindowWriter.WriteLine("Unable to read URL from DTO file. Please ensure the file was generated correctly from a ServiceStack server.");
                    return;
                }
                try
                {
                    var  options = typesHandler.ParseComments(existingGeneratedCode);
                    bool setSslValidationCallback = false;
                    //Don't set validation callback if one has already been set for VS.
                    if (ServicePointManager.ServerCertificateValidationCallback == null)
                    {
                        //Temp set validation callback to return true to avoid common dev server ssl certificate validation issues.
                        setSslValidationCallback = true;
                        ServicePointManager.ServerCertificateValidationCallback =
                            (sender, certificate, chain, errors) => true;
                    }
                    string updatedCode = typesHandler.GetUpdatedCode(baseUrl, options);
                    if (setSslValidationCallback)
                    {
                        //If callback was set to return true, reset back to null.
                        ServicePointManager.ServerCertificateValidationCallback = null;
                    }
                    using (var streamWriter = File.CreateText(filePath))
                    {
                        streamWriter.Write(updatedCode);
                        streamWriter.Flush();
                    }
                }
                catch (Exception e)
                {
                    OutputWindowWriter.WriteLine("Failed to update ServiceStack Reference: Unhandled error - " + e.Message);
                }

                OutputWindowWriter.WriteLine("--- Update ServiceStack Reference Complete ---");
            }
            else
            {
                OutputWindowWriter.WriteLine("--- Valid file not found ServiceStack Reference '" + projectItem.Name + "' ---");
            }
        }
Example #19
0
 public static void HandleDocumentSaved(this Document document, OutputWindowWriter windowWriter)
 {
     DocumentSavedHandlers.HandleDocumentSaved(document, windowWriter);
 }
        private static void NpmDocumentHandler(Document document, OutputWindowWriter windowWriter)
        {
            if (document.IsNpmUpdateDisable())
            {
                return;
            }

            _hasNpmInstalled = _hasNpmInstalled
                ? _hasNpmInstalled
                : NodePackageUtils.TryRegisterNpmFromDefaultLocation();

            if (!_hasNpmInstalled)
            {
                windowWriter.Show();
                windowWriter.WriteLine("Node.js Installation not detected. Visit http://nodejs.org/ to download.");
                return;
            }
            document.TryRunNpmInstall(windowWriter);
        }