public override void LoadSettingsFromStorage() { var interpreterService = ComponentModel.GetService <IInterpreterOptionsService>(); var seenIds = new HashSet <Guid>(); var placeholders = PyService.InteractiveOptions.Where(kv => kv.Key is InterpreterPlaceholder).ToArray(); PyService.ClearInteractiveOptions(); foreach (var interpreter in interpreterService.Interpreters) { seenIds.Add(interpreter.Id); PyService.GetInteractiveOptions(interpreter); } foreach (var kv in placeholders) { if (!seenIds.Contains(kv.Key.Id)) { PyService.AddInteractiveOptions(kv.Key, kv.Value); } } if (_window != null) { _window.UpdateInterpreters(); } }
public override void SaveSettingsToStorage() { var defaultInterpreter = GetWindow().DefaultInterpreter; if (defaultInterpreter != null) { Version ver; if (defaultInterpreter is InterpreterPlaceholder) { ver = Version.Parse(PyService.GetInterpreterOptions(defaultInterpreter).Version ?? "2.7"); } else { ver = defaultInterpreter.Configuration.Version; } PyService.GlobalInterpreterOptions.DefaultInterpreter = defaultInterpreter.Id; PyService.GlobalInterpreterOptions.DefaultInterpreterVersion = ver; } else { PyService.GlobalInterpreterOptions.DefaultInterpreter = Guid.Empty; PyService.GlobalInterpreterOptions.DefaultInterpreterVersion = new Version(); } PyService.SaveInterpreterOptions(); PyService.GlobalInterpreterOptions.Save(); }
public override void LoadSettingsFromStorage() { var interpreterService = ComponentModel.GetService <IInterpreterRegistryService>(); var seenIds = new HashSet <string>(); var placeholders = PyService.InteractiveOptions.Where(kv => kv.Key.StartsWith(InterpreterPlaceholder.PlaceholderId + ";")).ToArray(); PyService.ClearInteractiveOptions(); foreach (var interpreter in interpreterService.Interpreters) { seenIds.Add(interpreter.Configuration.Id); PyService.GetInteractiveOptions(interpreter.Configuration); } foreach (var kv in placeholders) { if (!seenIds.Contains(kv.Key)) { PyService.AddInteractiveOptions(kv.Key, kv.Value); } } if (_window != null) { _window.UpdateInterpreters(); } }
public override void SaveSettingsToStorage() { var defaultInterpreter = GetWindow().DefaultInterpreter; PyService.GlobalInterpreterOptions.DefaultInterpreter = defaultInterpreter?.Id ?? string.Empty; PyService.SaveInterpreterOptions(); PyService.GlobalInterpreterOptions.Save(); }
public override void LoadSettingsFromStorage() { PyService.GlobalInterpreterOptions.Load(); PyService.LoadInterpreterOptions(); if (_window != null) { _window.UpdateInterpreters(); } }
private void SaveToFile(bool includeAnalysisLogs) { string initialPath = null; try { initialPath = PathUtils.GetAbsoluteFilePath( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Strings.DiagnosticsWindow_DefaultFileName.FormatUI(DateTime.Now) ); } catch (Exception ex) when(!ex.IsCriticalException()) { Debug.Fail(ex.ToUnhandledExceptionMessage(GetType())); } var path = Site.BrowseForFileSave( _window.Handle, Strings.DiagnosticsWindow_TextFileFilter, initialPath ); if (string.IsNullOrEmpty(path)) { return; } Cursor.Current = Cursors.WaitCursor; try { try { TaskDialog.CallWithRetry( _ => { using (var log = new StreamWriter(path, false, new UTF8Encoding(false))) { PyService.GetDiagnosticsLog(log, includeAnalysisLogs); } }, Site, Strings.ProductTitle, Strings.FailedToSaveDiagnosticInfo, Strings.ErrorDetail, Strings.Retry, Strings.Cancel ); if (File.Exists(path)) { Process.Start( Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"), "/select," + ProcessOutput.QuoteSingleArgument(path) )?.Dispose(); } } catch (OperationCanceledException) { } } finally { Cursor.Current = Cursors.Arrow; } }
private void CopyToClipboard(bool includeAnalysisLogs) { Cursor.Current = Cursors.WaitCursor; try { var log = PyService.GetDiagnosticsLog(includeAnalysisLogs); Clipboard.SetText(log, TextDataFormat.Text); } finally { Cursor.Current = Cursors.Arrow; } MessageBox.Show(Strings.DiagnosticsLogCopiedToClipboard, Strings.ProductTitle); }
public override void SaveSettingsToStorage() { EnsureWindow(); foreach (var value in _categories) { foreach (var option in value.Options) { PyService.SetFormattingOption(option.Key, _window.GetSetting(option.Key)); } } base.SaveSettingsToStorage(); }
public override void LoadSettingsFromStorage() { EnsureWindow(); foreach (var value in _categories) { foreach (var option in value.Options) { _window.SetSetting(option.Key, PyService.GetFormattingOption(option.Key)); } } base.LoadSettingsFromStorage(); }
private void SaveToFile(bool includeAnalysisLogs) { var path = PyService.Site.BrowseForFileSave( _window.Handle, Strings.DiagnosticsWindow_TextFileFilter, PathUtils.GetAbsoluteFilePath( Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Strings.DiagnosticsWindow_DefaultFileName.FormatUI(DateTime.Now) ) ); if (string.IsNullOrEmpty(path)) { return; } Cursor.Current = Cursors.WaitCursor; try { try { var log = PyService.GetDiagnosticsLog(includeAnalysisLogs); TaskDialog.CallWithRetry( _ => File.WriteAllText(path, log), PyService.Site, Strings.ProductTitle, Strings.FailedToSaveDiagnosticInfo, Strings.ErrorDetail, Strings.Retry, Strings.Cancel ); Process.Start("explorer.exe", "/select," + ProcessOutput.QuoteSingleArgument(path)).Dispose(); } catch (OperationCanceledException) { } } finally { Cursor.Current = Cursors.Arrow; } }
public PythonInteractiveOptions GetOptions(IPythonInterpreterFactory interpreterFactory) { return(PyService.GetInteractiveOptions(interpreterFactory)); }
private PythonInteractiveOptions ReadOptions(IPythonInterpreterFactory interpreter) { return(PyService.GetInteractiveOptions(interpreter)); }
public MainViewModel() { EnableTableSetupDetectionButtonName = "Enable Tableware Detection"; EnableBareHandDetectionButtonName = "Enable Hand Detection"; EnablePhoneDetectionButtonName = "Enable Phone Detection"; LoadedWindowCommand = new RelayCommand <Window>(p => true, p => { IsLoaded = true; if (p == null) { return; } p.Hide(); LoginWindow loginWindow = new LoginWindow(); loginWindow.ShowDialog(); if (loginWindow.DataContext == null) { return; } var loginVM = loginWindow.DataContext as LoginViewModel; if (loginVM.IsLogin) { p.Show(); } else { p.Close(); } }); DetectTablewareCommand = new RelayCommand <object>(p => true, p => { var pythonService = new PyService(); var cancelSource = new CancellationTokenSource(); if (!IsTablewareDetectionEnabled) { EnableTableSetupDetectionButtonName = "Disable Tableware Detection"; IsTablewareDetectionEnabled = true; new MessageBoxCustom("Tableware Detection started", MessageType.Success, MessageButtons.Ok).ShowDialog(); pythonService.RunScript(DetectionTypeConstant.TableWare, cancelSource.Token); } else { var result = new MessageBoxCustom("Are you sure to stop?", MessageType.Info, MessageButtons.YesNo).ShowDialog(); if (result != null && result.Value == true) { IsTablewareDetectionEnabled = false; EnableTableSetupDetectionButtonName = "Enable Tableware Detection"; new MessageBoxCustom("Tableware Detection stopped", MessageType.Success, MessageButtons.Ok).ShowDialog(); cancelSource.Cancel(); } } }); DetectHandCommand = new RelayCommand <object>(p => true, p => { var pythonService = new PyService(); var cancelSource = new CancellationTokenSource(); if (!IsHandDetectionEnabled) { EnableBareHandDetectionButtonName = "Disable Hand Detection"; IsHandDetectionEnabled = true; new MessageBoxCustom("Hand Detection enabled", MessageType.Success, MessageButtons.Ok).ShowDialog(); pythonService.RunScript(DetectionTypeConstant.Hand, cancelSource.Token); } else { var result = new MessageBoxCustom("Are you sure to stop?", MessageType.Info, MessageButtons.YesNo).ShowDialog(); if (result != null && result.Value == true) { IsHandDetectionEnabled = false; EnableBareHandDetectionButtonName = "Enable Hand Detect"; new MessageBoxCustom("Hand Detection stopped", MessageType.Success, MessageButtons.Ok).ShowDialog(); cancelSource.Cancel(); } } }); DetectPhoneCommand = new RelayCommand <object>(p => true, p => { var pythonService = new PyService(); var cancelSource = new CancellationTokenSource(); if (!IsPhoneDetectionEnabled) { EnablePhoneDetectionButtonName = "Disable Phone Detection"; IsPhoneDetectionEnabled = true; new MessageBoxCustom("Phone Detection enabled", MessageType.Success, MessageButtons.Ok).ShowDialog(); pythonService.RunScript(DetectionTypeConstant.Phone, cancelSource.Token); } else { var result = new MessageBoxCustom("Are you sure to stop?", MessageType.Info, MessageButtons.YesNo).ShowDialog(); if (result != null && result.Value == true) { IsPhoneDetectionEnabled = false; EnablePhoneDetectionButtonName = "Enable Phone Detection"; new MessageBoxCustom("Phone Detection disabled", MessageType.Success, MessageButtons.Ok).ShowDialog(); cancelSource.Cancel(); } } }); LoadConfigCommand = new RelayCommand <object>(p => true, p => { var dialog = new OpenFileDialog(); dialog.DefaultExt = ".zip"; dialog.Filter = "ZIP|*.zip"; var result = dialog.ShowDialog(); if (result == true) { string filename = dialog.FileName; var pythonService = new PyService(); if (pythonService.LoadConfiguration(filename)) { new MessageBoxCustom("Load Configuration Success", MessageType.Success, MessageButtons.Ok).ShowDialog(); } else { new MessageBoxCustom("Invalid configuration file", MessageType.Error, MessageButtons.Ok).ShowDialog(); } } }); }