예제 #1
0
        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);
                    }
                }
            }
        }
예제 #2
0
 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));
 }