private void PutToHistory(Operation operation, OperationsHistoryItem histItem)
 {
     if (operation.SaveInHistory)
     {
         operationsHistory.Put(histItem);
     }
 }
Beispiel #2
0
 void IOperationsHistory.Put(OperationsHistoryItem item)
 {
     if (item.OperationType == OperationType.Command ||
         item.ExecutionStatus == OperationExecutionStatus.ExecutionCrushErrors ||
         item.ExecutionStatus == OperationExecutionStatus.ExecutionProcessedErrors ||
         item.ExecutionStatus == OperationExecutionStatus.InfrastructureErrors)
     {
         db.GetCollection <OperationsHistoryItem>(operationsHistoryCollectionName).InsertOne(item);
     }
 }
        private object ExecuteOperation(Operation operation, out OperationExecutionReport report)
        {
            log.Info($"Begin execution of {operation.Name} {operation.Id}");
            var          histItem = new OperationsHistoryItem(operation);
            List <Error> errors;

            histItem.InvokedTime = DateTime.Now;
            try
            {
                errors = operation.GetPermissionsValidationErrors();
            }
            catch (UnauthorizedAccessException error)
            {
                log.Error(error);
                throw new OperationExecutionException(new Error(error), OperationExecutionStatus.AuthorizationErrors);
            }
            catch (Exception error)
            {
                log.Error(error);
                errors = new List <Error> {
                    new Error(error)
                };
            }
            histItem.PermissionsValidationVinishedTime = DateTime.Now;

            if (!errors.IsNullOrEmpty())
            {
                histItem.ExecutionStatus = OperationExecutionStatus.PermissionsValidationErrors;
                histItem.Report          = new OperationExecutionReport()
                {
                    Errors = errors
                };
                PutToHistory(operation, histItem);
                throw new OperationExecutionException(errors, OperationExecutionStatus.PermissionsValidationErrors);
            }


            try
            {
                errors = operation.GetDataValidationErrors();
            }
            catch (Exception error)
            {
                log.Error(error);
                errors = new List <Error> {
                    new Error(error)
                };
            }
            histItem.DataValidationVinishedTime = DateTime.Now;

            if (!errors.IsNullOrEmpty())
            {
                histItem.ExecutionStatus = OperationExecutionStatus.DataValidationErrors;
                histItem.Report          = new OperationExecutionReport()
                {
                    Errors = errors
                };
                PutToHistory(operation, histItem);
                throw new OperationExecutionException(errors, OperationExecutionStatus.DataValidationErrors);
            }

            report = null;
            object result = null;

            try
            {
                var executeMethod = operation.GetType().GetTypeInfo().GetMethod("Execute");
                var parameters    = new object[] { null };
                result = executeMethod.Invoke(operation, parameters);
                report = (OperationExecutionReport)parameters[0];
            }
            catch (TargetInvocationException error)
            {
                if (error.InnerException != null)
                {
                    log.Error(error.InnerException);
                    errors = new List <Error> {
                        new Error(error.InnerException)
                    };
                }
            }
            catch (Exception error)
            {
                log.Error(error);
                errors = new List <Error> {
                    new Error(error)
                };
            }
            histItem.ExecutionVinishedTime = DateTime.Now;

            if (report == null)
            {
                histItem.Report = report = new OperationExecutionReport()
                {
                    Errors = errors
                };
            }
            else
            {
                histItem.Report = report;
                if (!errors.IsNullOrEmpty())
                {
                    histItem.Report.Errors.AddRange(errors);
                }
            }


            if (!errors.IsNullOrEmpty())
            {
                histItem.ExecutionStatus = OperationExecutionStatus.ExecutionCrushErrors;
                PutToHistory(operation, histItem);
                throw new OperationExecutionException(errors, OperationExecutionStatus.ExecutionCrushErrors);
            }

            if (!histItem.Report.Errors.IsNullOrEmpty())
            {
                histItem.ExecutionStatus = OperationExecutionStatus.ExecutionProcessedErrors;
            }
            else
            {
                histItem.ExecutionStatus = OperationExecutionStatus.ExecutionWithoutErrors;
            }

            PutToHistory(operation, histItem);
            log.Info($"End execution of {operation.Name} {operation.Id}");
            return(result);
        }
Beispiel #4
0
 public void Put(OperationsHistoryItem item)
 {
     history.Add(item);
 }