コード例 #1
0
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            UIThreadHelper.VerifyOnUIThread();
            var dte      = _serviceProvider.GetService <DTE2, DTE>();
            var solution = _serviceProvider.GetService <IVsSolution, SVsSolution>();

            try
            {
                Verify.HResult(solution.GetSolutionInfo(out string directory, out string solutionFile, out string optsFile));
                var         globalJsonPath = Path.Combine(directory, "global.json");
                ProjectItem globalJson     = dte.Solution.FindProjectItem(globalJsonPath);
                globalJson?.Delete();
                try
                {
                    _fileSystem.RemoveFile(globalJsonPath);
                }
                catch (FileNotFoundException) { }
                return(VSConstants.S_OK);
            }
            finally
            {
                Verify.HResult(solution.UnadviseSolutionEvents(SolutionCookie));
                // Don't keep a static reference around to an object that won't be used again.
                Assumes.True(ReferenceEquals(this, s_remover));
                s_remover = null;
            }
        }
コード例 #2
0
 /// <summary>
 /// The OnUrlChanged.
 /// </summary>
 /// <param name="d">The d<see cref="DependencyObject"/>.</param>
 /// <param name="e">The e<see cref="DependencyPropertyChangedEventArgs"/>.</param>
 private static void OnUrlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     UIThreadHelper.InvokeAsync(() =>
     {
         CommandManager.InvalidateRequerySuggested();
     });
 }
コード例 #3
0
        public int UpgradeProject(string xprojLocation, uint upgradeFlags, string backupDirectory, out string migratedProjectFileLocation,
                                  IVsUpgradeLogger logger, out int upgradeRequired, out Guid migratedProjectGuid)
        {
            UIThreadHelper.VerifyOnUIThread();
            bool   success     = false;
            string projectName = Path.GetFileNameWithoutExtension(xprojLocation);
            int    hr          = UpgradeProject_CheckOnly(xprojLocation, logger, out upgradeRequired, out migratedProjectGuid, out _);

            // This implementation can only return S_OK. Throw if it returned something else.
            Verify.HResult(hr);

            // First, we back up the project. This function will take care of logging any backup failures.
            if (!BackupProject(backupDirectory, xprojLocation, projectName, logger))
            {
                migratedProjectFileLocation = xprojLocation;
                return(VSConstants.VS_E_PROJECTMIGRATIONFAILED);
            }

#pragma warning disable RS0030 // Do not used banned APIs
            IVsSolution solution = _serviceProvider.GetService <IVsSolution, SVsSolution>();
#pragma warning restore RS0030 // Do not used banned APIs
            Verify.HResult(solution.GetSolutionInfo(out string solutionDirectory, out _, out _));

            HResult backupResult = BackupAndDeleteGlobalJson(solutionDirectory, solution, backupDirectory, projectName, logger);
            if (!backupResult.Succeeded)
            {
                migratedProjectGuid         = GetType().GUID;
                migratedProjectFileLocation = xprojLocation;
                return(backupResult);
            }

            string directory = Path.GetDirectoryName(xprojLocation);
            (string logFile, int processExitCode) = MigrateProject(solutionDirectory, directory, xprojLocation, projectName, logger);

            if (!string.IsNullOrEmpty(logFile))
            {
                (migratedProjectFileLocation, success) = LogReport(logFile, processExitCode, projectName, xprojLocation, logger);
            }
            else
            {
                migratedProjectGuid         = GetType().GUID;
                migratedProjectFileLocation = null;
            }

            if (string.IsNullOrEmpty(migratedProjectFileLocation))
            {
                // If we weren't able to find a new csproj, something went very wrong, and dotnet migrate is doing something that we don't expect.
                migratedProjectGuid = GetType().GUID;
                Assumes.NotNullOrEmpty(migratedProjectFileLocation);
                migratedProjectFileLocation = xprojLocation;
                success = false;
            }

            if (success)
            {
                CleanupXproj(directory, projectName);
            }

            return(success ? VSConstants.S_OK : VSConstants.VS_E_PROJECTMIGRATIONFAILED);
        }
コード例 #4
0
 private void QueueCallerJoinEventHandler(object sender, QueueCallerJoinEvent e)
 {
     if (configuration.PopupOnNewCall)
     {
         UIThreadHelper.ShowForm(this, this);
     }
     LogToConsole($"Caller {e.Attributes.GetValueOrDefault("calleridnum")} joined queue {e.Queue} on position {e.Position}.", ConsoleTextColor.Info);
 }
コード例 #5
0
 /// <summary>
 /// The OnWebBrowser_LoadingStateChanged.
 /// </summary>
 /// <param name="sender">The sender<see cref="object"/>.</param>
 /// <param name="e">The e<see cref="LoadingStateChangedEventArgs"/>.</param>
 private void OnWebBrowser_LoadingStateChanged(object sender, LoadingStateChangedEventArgs e)
 {
     UIThreadHelper.Invoke(() =>
     {
         this.CanBackward = e.CanGoBack;
         this.CanForward  = e.CanGoForward;
         this.CanReload   = e.CanReload;
     });
 }
コード例 #6
0
        public static EnvDTE.Project GetDTEProject(this IVsHierarchy hierarchy)
        {
            UIThreadHelper.VerifyOnUIThread();
            if (ErrorHandler.Succeeded(hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out object extObject)))
            {
                return(extObject as EnvDTE.Project);
            }

            return(null);
        }
コード例 #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TabItem"/> class.
 /// </summary>
 /// <param name="guid">The unique identifier.</param>
 public TabItem(Guid guid)
 {
     this.Guid            = guid;
     this.HeaderViewModel = new WebBrowserTabHeaderViewModel {
         Header = "No Header"
     };
     UIThreadHelper.Invoke(() =>
     {
         this.Header = new WebBrowserTabHeaderView {
             DataContext = this.HeaderViewModel
         };
     });
 }
コード例 #8
0
            /// <summary>
            /// Initializes the <see cref="GlobalJsonRemover"/> if not already initialized. This method assumes that it will be called
            /// from the UI thread, and will throw if this isn't true.
            /// </summary>
            /// <returns>True if the remover was set up for the first time. False otherwise.</returns>
            public virtual bool SetupRemoval(IVsSolution solution, IServiceProvider provider, IFileSystem fileSystem)
            {
                UIThreadHelper.VerifyOnUIThread();
                if (s_remover != null)
                {
                    return(false);
                }

                s_remover = new GlobalJsonRemover(provider, fileSystem);
                Verify.HResult(solution.AdviseSolutionEvents(s_remover, out uint cookie));
                s_remover.SolutionCookie = cookie;
                return(true);
            }
コード例 #9
0
        /// <summary>
        /// The OnTextbox_MouseDoubleClick.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="MouseButtonEventArgs"/>.</param>
        private static void OnTextbox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is TextBox textbox))
            {
                return;
            }

            UIThreadHelper.DelayedInvokeAsync(() =>
            {
                textbox.Focus();
                textbox.SelectAll();
            }, 200);
        }
コード例 #10
0
 /// <summary>
 /// The SaveSettings.
 /// </summary>
 private void SaveSettings()
 {
     this.ChartEditorViewModel.UpdateSettings();
     UIThreadHelper.Invoke(() =>
     {
         var window              = this.GlobalData.MainWindow;
         var settings            = this.GlobalData.SettingsModel;
         settings.WindowPosition = new Point(window.Left, window.Top);
         settings.WindowWidth    = window.ActualWidth;
         settings.WindowHeight   = window.Height;
         settings.WindowState    = window.WindowState;
         SettingsHelper.Save(settings, window);
     });
 }
コード例 #11
0
        /// <summary>
        /// The OnTextbox_PreviewMouseLeftButtonDown.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="MouseButtonEventArgs"/>.</param>
        private static void OnTextbox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is TextBox textbox))
            {
                return;
            }

            if (!textbox.IsFocused)
            {
                UIThreadHelper.DelayedInvokeAsync(() =>
                {
                    textbox.Focus();
                    textbox.SelectAll();
                }, 200);
            }
        }
コード例 #12
0
        public static UnconfiguredProject GetUnconfiguredProject(this IVsHierarchy hierarchy)
        {
            UIThreadHelper.VerifyOnUIThread();

            var context = hierarchy as IVsBrowseObjectContext;

            if (context == null)
            {
                EnvDTE.Project dteProject = hierarchy.GetDTEProject();
                if (dteProject != null)
                {
                    context = dteProject.Object as IVsBrowseObjectContext;
                }
            }

            return(context?.UnconfiguredProject);
        }
コード例 #13
0
        /// <summary>
        /// The OnBeforeDownload.
        /// </summary>
        /// <param name="chromiumWebBrowser">The chromiumWebBrowser<see cref="IWebBrowser"/>.</param>
        /// <param name="browser">The browser<see cref="IBrowser"/>.</param>
        /// <param name="downloadItem">The downloadItem<see cref="DownloadItem"/>.</param>
        /// <param name="callback">The callback<see cref="IBeforeDownloadCallback"/>.</param>
        public void OnBeforeDownload(IWebBrowser chromiumWebBrowser, IBrowser browser, DownloadItem downloadItem, IBeforeDownloadCallback callback)
        {
            lock (this.Lock)
            {
                if (this.DownloadItemDict.ContainsKey(downloadItem.Id) || callback.IsDisposed)
                {
                    return;
                }

                UIThreadHelper.Invoke(() =>
                {
                    using (callback)
                    {
                        var fileName = downloadItem.SuggestedFileName;
                        var filePath = Path.Combine(this.DownloadPath, downloadItem.SuggestedFileName);
                        if (this.IsShowDialog)
                        {
                            var dialog = new VistaSaveFileDialog
                            {
                                FileName         = fileName,
                                CheckPathExists  = true,
                                InitialDirectory = this.DownloadPath,
                                OverwritePrompt  = true,
                                Title            = "Save Link to...",
                            };

                            var element = chromiumWebBrowser as FrameworkElement;

                            var window = Window.GetWindow(element);
                            if (!(bool)dialog.ShowDialog(window))
                            {
                                return;
                            }

                            filePath = dialog.FileName;
                        }

                        this.DownloadPath = Path.GetDirectoryName(filePath);
                        var model         = new DownloadProcessModel(downloadItem);
                        this.DownloadItemDict.Add(downloadItem.Id, model);
                        this.DownloadItemModels.Insert(0, model);
                        callback.Continue(filePath, false);
                    }
                });
            }
        }
コード例 #14
0
        private void TextDocument_FileActionOccurred(object sender, TextDocumentFileActionEventArgs args)
        {
            if (args.FileActionType != FileActionTypes.ContentSavedToDisk)
            {
                return;
            }
            Assumes.Is <ITextDocument>(sender);
            UIThreadHelper.VerifyOnUIThread();
            var textDocument = (ITextDocument)sender;
            var savedText    = textDocument.TextBuffer.CurrentSnapshot.GetText();

            _threadingService.ExecuteSynchronously(() => _msbuildAccessor.RunLockedAsync(true, () =>
            {
                _fileSystem.WriteAllText(_unconfiguredProject.FullPath, savedText);
                return(Task.CompletedTask);
            }));
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebBrowserHeaderedItemViewModel"/> class.
        /// </summary>
        /// <param name="globalBrowserData">The globalBrowserData<see cref="GlobalBrowserData"/>.</param>
        /// <param name="cefWindowData">The cefWindowData<see cref="CefWindowData"/>.</param>
        /// <param name="downloadAction">The downloadAction<see cref="Action{Operation}"/>.</param>
        internal WebBrowserHeaderedItemViewModel(GlobalBrowserData globalBrowserData, CefWindowData cefWindowData, Action <Operation> downloadAction)
        {
            this.VideoBrowserViewModel = new VideoBrowserViewModel(globalBrowserData, cefWindowData)
            {
                DownloadAction = downloadAction
            };

            this.VideoBrowserViewModel.PropertyChanged += this.OnVideoBrowserViewModel_PropertyChanged;
            this.Title = this.VideoBrowserViewModel.Header;
            UIThreadHelper.Invoke(() =>
            {
                this.VideoBrowserView = new VideoBrowserView {
                    DataContext = this.VideoBrowserViewModel
                };
                this.Content = this.VideoBrowserView;
            });
        }
コード例 #16
0
        public int OnAfterOpenSolution(object pUnkReserved, int fNewSolution)
        {
            UIThreadHelper.VerifyOnUIThread();
            var dte      = _serviceProvider.GetService <DTE2, DTE>();
            var solution = _serviceProvider.GetService <IVsSolution, SVsSolution>();

            try
            {
                Verify.HResult(solution.GetSolutionInfo(out string directory, out string solutionFile, out string optsFile));
                ProjectItem globalJson = dte.Solution.FindProjectItem(Path.Combine(directory, "global.json"));
                globalJson?.Remove();
                return(VSConstants.S_OK);
            }
            finally
            {
                Verify.HResult(solution.UnadviseSolutionEvents(SolutionCookie));
            }
        }
コード例 #17
0
        /// <summary>
        /// The Test.
        /// </summary>
        /// <param name="testWindow">The testWindow<see cref="Window"/>.</param>
        protected override void Test(Window testWindow)
        {
            var client = this.GlobalBrowserData.InterTabClient;
            DefaultTabHostWindow window = null;

            UIThreadHelper.Invoke(() =>
            {
                var viewModel       = new DefaultTabHostViewModel(this.GlobalBrowserData);
                var browserTabModel = viewModel.WebBrowserTabControlViewModel;
                var tab             = new WebBrowserHeaderedItemViewModel(this.GlobalBrowserData, browserTabModel.CefWindowData, null);
                //browserTabModel.TabItems.Add(tab);
                window = new DefaultTabHostWindow {
                    DataContext = viewModel
                };
            });

            window.ShowDialog();
        }
コード例 #18
0
ファイル: App.xaml.cs プロジェクト: Artak11111/SSCC
        private void Initialize()
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance(new NavigationManager());

            builder.RegisterType <ApiClient>()
            .SingleInstance();

            builder.RegisterType <UserSession.UserSession>()
            .SingleInstance();

            RegisterViewModels(builder);
            RegisterManagers(builder);
            RegisterServices(builder);

            ServiceLocator.Initialize(builder.Build());

            UIThreadHelper.AccessUIThread(InitializeShell);
        }
コード例 #19
0
        /// <summary>
        /// The Execute.
        /// </summary>
        /// <param name="viewModel">The viewModel<see cref="WebBrowserTabControlViewModel"/>.</param>
        protected override void Execute(WebBrowserTabControlViewModel viewModel)
        {
            if (viewModel.IsTabItemExist(this.Guid))
            {
                viewModel.SetActiveTab(this.Guid);
                return;
            }

            UIThreadHelper.InvokeAsync(() =>
            {
                var view = this.CreateView();
                var tab  = new TabItem(this.Guid)
                {
                    Content = view,
                    Icon    = this.Icon,
                    Title   = this.Title
                };

                viewModel.AddTab(tab);
            });
        }
コード例 #20
0
 private void UpdateConnectionStateIndicator()
 {
     UIThreadHelper.SetToolStripBoxLabelText(this, connectionStateIndicator, managerConnection.IsConnected() ? "Connected" : "Disconnected", null);
 }
コード例 #21
0
 public void ShowError(string message)
 {
     UIThreadHelper.AccessUIThread(() => MessageBox.Show(message));
 }
コード例 #22
0
        public int GetGeneratorInformation(string wszProgId, out int pbGeneratesDesignTimeSource, out int pbGeneratesSharedDesignTimeSource, out int pbUseTempPEFlag, out Guid pguidGenerator)
        {
            pbGeneratesDesignTimeSource       = 0;
            pbGeneratesSharedDesignTimeSource = 0;
            pbUseTempPEFlag = 0;
            pguidGenerator  = Guid.Empty;

            if (wszProgId == null || string.IsNullOrWhiteSpace(wszProgId))
            {
                return(VSConstants.E_INVALIDARG);
            }

            // Get the guid of the project
            UIThreadHelper.VerifyOnUIThread();
            var projectGuid = _projectIntegrationService.ProjectTypeGuid;

            if (projectGuid.Equals(Guid.Empty))
            {
                return(VSConstants.E_FAIL);
            }

            IVsSettingsManager manager = _serviceProvider.GetService <IVsSettingsManager, SVsSettingsManager>();
            HResult            hr      = manager.GetReadOnlySettingsStore((uint)__VsSettingsScope.SettingsScope_Configuration, out IVsSettingsStore store);

            if (!hr.Succeeded)
            {
                return(hr);
            }

            var key = $"Generators\\{projectGuid.ToString("B")}\\{wszProgId}";

            hr = store.CollectionExists(key, out int exists);
            if (!hr.Succeeded)
            {
                return(hr);
            }

            if (exists != 1)
            {
                return(VSConstants.E_FAIL);
            }

            // The clsid value is the only required value. The other 3 are optional
            hr = store.PropertyExists(key, CLSIDKey, out exists);
            if (!hr.Succeeded)
            {
                return(hr);
            }
            if (exists != 1)
            {
                return(VSConstants.E_FAIL);
            }

            hr = store.GetString(key, CLSIDKey, out string clsidString);
            if (hr.Failed)
            {
                return(hr);
            }
            if (string.IsNullOrWhiteSpace(clsidString) || !Guid.TryParse(clsidString, out pguidGenerator))
            {
                return(VSConstants.E_FAIL);
            }

            // Explicitly convert anything that's not 1 to 0. These aren't required keys, so we don't explicitly fail here.
            store.GetIntOrDefault(key, DesignTimeSourceKey, 0, out pbGeneratesDesignTimeSource);
            pbGeneratesDesignTimeSource = pbGeneratesDesignTimeSource == 1 ? 1 : 0;
            store.GetIntOrDefault(key, SharedDesignTimeSourceKey, 0, out pbGeneratesSharedDesignTimeSource);
            pbGeneratesSharedDesignTimeSource = pbGeneratesSharedDesignTimeSource == 1 ? 1 : 0;
            store.GetIntOrDefault(key, DesignTimeCompilationFlagKey, 0, out pbUseTempPEFlag);
            pbUseTempPEFlag = pbUseTempPEFlag == 1 ? 1 : 0;

            return(VSConstants.S_OK);
        }
コード例 #23
0
 private void UpdateQueueStatusRequestStateIndicator(string text)
 {
     UIThreadHelper.SetToolStripBoxLabelText(this, queueStatusRequestStateIndicator, text, null);
 }
コード例 #24
0
 /// <summary>
 /// The OnChromiumWebBrowser_TitleChanged.
 /// </summary>
 /// <param name="sender">The sender<see cref="object"/>.</param>
 /// <param name="e">The e<see cref="DependencyPropertyChangedEventArgs"/>.</param>
 private void OnChromiumWebBrowser_TitleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     UIThreadHelper.InvokeAsync(() => this.Title = (string)e.NewValue);
 }
コード例 #25
0
        private void LogToConsole(string text, Color textColor)
        {
            string newLine = $"{DateTime.Now.ToString(configuration.DateTimeFormat)} > {text}";

            UIThreadHelper.AppendTextBoxText(this, consoleTextBox, newLine, textColor);
        }
コード例 #26
0
 public TestMainThread(UIThreadHelper threadHelper)
 {
     _threadHelper = threadHelper;
 }
コード例 #27
0
 public TestMainThread(UIThreadHelper threadHelper) {
     _threadHelper = threadHelper;
 }