private void btAddPlugin_Click(object sender, RoutedEventArgs e) { var dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Filter = string.Format("Lazurite plugin file (*{0})|*{0}", PluginsManager.PluginFileExtension); dialog.Multiselect = false; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var canAddPluginResult = _manager.CanAddPlugin(dialog.FileName); if (!canAddPluginResult.CanAdd) { _warningHandler.WarnFormat("Невозможно добавить плагин \r\n[{0}];\r\nПричина: {1}", dialog.FileName, canAddPluginResult.Message); } else { try { _manager.AddPlugin(dialog.FileName); MessageView.ShowMessage("Плагин добавлен!", "Добавление плагина", Icons.Icon.Check, Window.GetWindow(this).Content as Panel); Refresh(); } catch (Exception exception) { _warningHandler.ErrorFormat(exception, "Невозможно добавить плагин \r\n[{0}]", dialog.FileName); } } } }
private T Handle <T>(Func <UserBase, T> function, [CallerMemberName] string memberName = "") { try { WarningHandler.DebugFormat("[{0}] execution started", memberName); var currentUser = GetCurrentUser(); var result = function(currentUser); if (result is Array) { WarningHandler.DebugFormat("[{0}] result: [{1}] items", memberName, ((Array)(object)result).Length); } else if (result is IList) { WarningHandler.DebugFormat("[{0}] result: [{1}] items", memberName, ((IList)result).Count); } return(result); } catch (Exception e) { if (SystemUtils.IsFaultExceptionHasCode(e, ServiceFaultCodes.AccessDenied) || SystemUtils.IsFaultExceptionHasCode(e, ServiceFaultCodes.ObjectAccessDenied) || SystemUtils.IsFaultExceptionHasCode(e, ServiceFaultCodes.ObjectNotFound)) { WarningHandler.WarnFormat("[{0}] execution error. {1}", memberName, e.Message); //write only message throw e; } else if (e is DecryptException) { WarningHandler.WarnFormat("[{0}] execution error. {1}", memberName, e.Message); //write only message throw new FaultException(e.Message, new FaultCode(ServiceFaultCodes.DecryptionError)); } else if (e is ScenarioExecutionException executionError) { if (executionError.ErrorType == ScenarioExecutionError.AccessDenied) { ThrowUnauthorizedAccessException(); } } else { WarningHandler.ErrorFormat(e, "[{0}] execution error", memberName); //unrecognized exception; write fully } } finally { WarningHandler.DebugFormat("[{0}] executed", memberName); } return(default(T)); }
public CertificateSelectView(ServerSettings settings) { InitializeComponent(); _settings = settings; Refresh(); btInstallNewCert.Click += (o, e) => { var openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Файл сертификата (*.pfx,*.cer,*.p7b)|*.pfx;*.cer;*.p7b"; if (openFileDialog.ShowDialog() == DialogResult.OK) { EnterPasswordView.Show("Введите пароль сертификата...", (pass) => { try { var certHash = Lazurite.Windows.Server.Utils.AddCertificate(openFileDialog.FileName, pass); Refresh(); certListView.GetItems().Where(x => ((CertificateInfo)((ItemView)x).Tag).Hash.Equals(certHash)).All(x => x.Selected = true); } catch (Exception exception) { _warningHandler.ErrorFormat(exception, "Ошибка при добавлении сертификата [{0}]", openFileDialog.FileName); } }, null, "Если файл сертификата не имеет пароль, то нажмите \"Применить\""); } }; certListView.SelectionChanged += (o, e) => btApply.IsEnabled = true; btApply.Click += (o, e) => { var selectedCert = (CertificateInfo)((ItemView)certListView.SelectedItem).Tag; _settings.CertificateHash = selectedCert.Hash; Selected?.Invoke(settings); }; }