public override void DoCommand(object sender, EventArgs args)
        {
            var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar));

            statusBar.SetText("Importing project...");

            var dlg = new Microsoft.NodejsTools.Project.ImportWizard.ImportWizard();
            int commandIdToRaise = (int)VSConstants.VSStd97CmdID.OpenProject;

            Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs oleArgs = args as Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs;
            if (oleArgs != null)
            {
                string projectArgs = oleArgs.InValue as string;
                if (projectArgs != null)
                {
                    var argItems = projectArgs.Split('|');
                    if (argItems.Length == 3)
                    {
                        dlg.ImportSettings.ProjectPath = CommonUtils.GetAvailableFilename(
                            argItems[1],
                            argItems[0],
                            ".njsproj"
                            );
                        dlg.ImportSettings.SourcePath = argItems[1];
                        commandIdToRaise = int.Parse(argItems[2]);
                    }
                }
            }

            if (dlg.ShowModal() ?? false)
            {
                var settings = dlg.ImportSettings;

                settings.CreateRequestedProjectAsync()
                .ContinueWith(t => {
                    string path;
                    try {
                        path = t.Result;
                    } catch (AggregateException ex) {
                        if (ex.InnerException is UnauthorizedAccessException)
                        {
                            MessageBox.Show(
                                "Some file paths could not be accessed." + Environment.NewLine +
                                "Try moving your source code to a location where you " +
                                "can read and write files.",
                                SR.ProductName
                                );
                        }
                        else
                        {
                            string exName = String.Empty;
                            if (ex.InnerException != null)
                            {
                                exName = "(" + ex.InnerException.GetType().Name + ") ";
                            }

                            MessageBox.Show(
                                "An unexpected error " + exName +
                                "occurred while creating your project.",
                                SR.ProductName
                                );
                        }
                        return;
                    }
                    if (File.Exists(path))
                    {
                        object outRef = null, pathRef = "\"" + path + "\"";
                        NodejsPackage.Instance.DTE.Commands.Raise(VSConstants.GUID_VSStandardCommandSet97.ToString("B"), commandIdToRaise, ref pathRef, ref outRef);
                        statusBar.SetText(String.Empty);
                    }
                    else
                    {
                        statusBar.SetText("An error occurred and your project was not created.");
                    }
                }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                statusBar.SetText("");
            }
        }
        public override void DoCommand(object sender, EventArgs args) {
            var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar));
            statusBar.SetText("Importing project...");

            var dlg = new Microsoft.NodejsTools.Project.ImportWizard.ImportWizard();
            int commandIdToRaise = (int)VSConstants.VSStd97CmdID.OpenProject;
            
            Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs oleArgs = args as Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs;
            if (oleArgs != null) {
                string projectArgs = oleArgs.InValue as string;
                if (projectArgs != null) {
                    var argItems = projectArgs.Split('|');
                    if (argItems.Length == 3) {
                        dlg.ImportSettings.ProjectPath = CommonUtils.GetAvailableFilename(
                            argItems[1], 
                            argItems[0], 
                            ".njsproj"
                        );
                        dlg.ImportSettings.SourcePath = argItems[1];
                        commandIdToRaise = int.Parse(argItems[2]);
                    }
                }
            }
            
            if (dlg.ShowModal() ?? false) {
                var settings = dlg.ImportSettings;

                settings.CreateRequestedProjectAsync()
                    .ContinueWith(t => {
                        string path;
                        try {
                            path = t.Result;
                        } catch (AggregateException ex) {
                            if (ex.InnerException is UnauthorizedAccessException) {
                                MessageBox.Show(
                                    "Some file paths could not be accessed." + Environment.NewLine +
                                    "Try moving your source code to a location where you " +
                                    "can read and write files.",
                                    SR.ProductName
                                );
                            } else {
                                string exName = String.Empty;
                                if (ex.InnerException != null) {
                                    exName = "(" + ex.InnerException.GetType().Name + ") ";
                                }

                                MessageBox.Show(
                                    "An unexpected error " + exName +
                                    "occurred while creating your project.",
                                    SR.ProductName
                                );
                            }
                            return;
                        }
                        if (File.Exists(path)) {
                            object outRef = null, pathRef = "\"" + path + "\"";
                            NodejsPackage.Instance.DTE.Commands.Raise(VSConstants.GUID_VSStandardCommandSet97.ToString("B"), commandIdToRaise, ref pathRef, ref outRef);
                            statusBar.SetText(String.Empty);
                        } else {
                            statusBar.SetText("An error occurred and your project was not created.");
                        }
                    },
                    CancellationToken.None,
                    TaskContinuationOptions.HideScheduler,
                    System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            } else {
                statusBar.SetText("");
            }
        }
Beispiel #3
0
        public override void DoCommand(object sender, EventArgs args)
        {
            var statusBar = (IVsStatusbar)CommonPackage.GetGlobalService(typeof(SVsStatusbar));

            statusBar.SetText(Resources.ImportingProjectStatusText);

            var dlg = new Microsoft.NodejsTools.Project.ImportWizard.ImportWizard();
            int commandIdToRaise = (int)VSConstants.VSStd97CmdID.OpenProject;

            Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs oleArgs = args as Microsoft.VisualStudio.Shell.OleMenuCmdEventArgs;
            if (oleArgs != null)
            {
                string projectArgs = oleArgs.InValue as string;
                if (projectArgs != null)
                {
                    var argItems = projectArgs.Split('|');
                    if (argItems.Length == 3)
                    {
                        dlg.ImportSettings.ProjectPath = CommonUtils.GetAvailableFilename(
                            argItems[1],
                            argItems[0],
                            ".njsproj"
                            );
                        dlg.ImportSettings.SourcePath = argItems[1];
                        commandIdToRaise = int.Parse(argItems[2], CultureInfo.InvariantCulture);
                    }
                }
            }

            if (dlg.ShowModal() ?? false)
            {
                var settings = dlg.ImportSettings;

                settings.CreateRequestedProjectAsync()
                .ContinueWith(t => {
                    string path;
                    try {
                        path = t.Result;
                    } catch (AggregateException ex) {
                        if (ex.InnerException is UnauthorizedAccessException)
                        {
                            MessageBox.Show(
                                string.Format(CultureInfo.CurrentCulture, Resources.ImportingProjectAccessErrorStatusText, Environment.NewLine),
                                SR.ProductName);
                        }
                        else
                        {
                            string exName = String.Empty;
                            if (ex.InnerException != null)
                            {
                                exName = "(" + ex.InnerException.GetType().Name + ")";
                            }

                            MessageBox.Show(
                                string.Format(CultureInfo.CurrentCulture, Resources.ImportingProjectUnexpectedErrorMessage, exName),
                                SR.ProductName);
                        }
                        return;
                    }
                    if (File.Exists(path))
                    {
                        object outRef = null, pathRef = "\"" + path + "\"";
                        NodejsPackage.Instance.DTE.Commands.Raise(VSConstants.GUID_VSStandardCommandSet97.ToString("B"), commandIdToRaise, ref pathRef, ref outRef);
                        statusBar.SetText(String.Empty);
                    }
                    else
                    {
                        statusBar.SetText(Resources.ImportingProjectErrorStatusText);
                    }
                },
                              CancellationToken.None,
                              TaskContinuationOptions.HideScheduler,
                              System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
            }
            else
            {
                statusBar.SetText("");
            }
        }