/// <inheritdoc cref="IBackgroundTask.Run(TParameters)"/>
        public void Run(SchemaDataBindingBackgroundTaskParameters parameters)
        {
            DataBindingControllerResult result =
                DataBindingController.GenerateBindings(parameters.SchemaName, parameters.RecordIds, parameters.SysPackageUId);

            CreateRemindings(parameters.SchemaName, parameters.RecordIds, result);
        }
Ejemplo n.º 2
0
 private void AddResultMessages(Guid recordId, DataBindingControllerResult innerResult, ref DataBindingControllerResult bindingResult)
 {
     if (innerResult.ResultMessages?.Any() == true)
     {
         var resultMessages = innerResult.ResultMessages.First();
         AddResultMessages(recordId, resultMessages.Value, ref bindingResult);
     }
 }
        private void CreateSuccessReminding(string schemaName, Guid[] recordIds, DataBindingControllerResult result)
        {
            string remindSubject     = GetLocalizableString("SchemaDataBindingService", "SuccessCaption");
            string successMessage    = GetSuccessRemindingMessage(recordIds, result);
            Guid?  remindingRecordId = recordIds.Length == 1 ? (Guid?)recordIds[0] : null;

            SaveReminding(schemaName, remindSubject, successMessage, remindingRecordId);
        }
 private void CreateRemindings(string schemaName, Guid[] recordIds, DataBindingControllerResult result)
 {
     if (result == null)
     {
         return;
     }
     CreateErrorRemindings(schemaName, result);
     CreateSuccessReminding(schemaName, recordIds, result);
 }
        private string GetSuccessRemindingMessage(Guid[] recordIds, DataBindingControllerResult result)
        {
            var    countErrorMessages  = GetCountErrorMessages(result);
            int    successfulBindCount = recordIds.Count() - countErrorMessages;
            string bindDataMessage     = successfulBindCount == recordIds.Count() ?
                                         GetLocalizableString("SchemaDataBindingService", "SuccessMessage") :
                                         GetLocalizableString("SchemaDataBindingService", "ErrorCaption");

            return(string.Format(bindDataMessage, successfulBindCount, recordIds.Count(), countErrorMessages));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Bind inner record by structure passed.
        /// </summary>
        /// <param name="innerStructure"><see cref="SchemaDataBindingStructure"/>.</param>
        /// <param name="recordId">Primary record identifier.</param>
        /// <param name="sysPackageUId">Package UId.</param>
        /// <param name="previousResult"><see cref="DataBindingControllerResult"/> from parent binding.</param>
        /// <returns><see cref="DataBindingControllerResult"/> combined parent and inner structure binding result.</returns>
        protected DataBindingControllerResult GenerateInnerStructureBinding(SchemaDataBindingStructure innerStructure, Guid recordId, Guid sysPackageUId,
                                                                            DataBindingControllerResult previousResult = null)
        {
            var innerResult = GenerateHierarchyBinding(innerStructure, recordId, sysPackageUId, previousResult);

            if (innerResult != null)
            {
                previousResult.Success = previousResult.Success && innerResult.Success;
                AddResultMessages(recordId, innerResult, ref previousResult);
            }
            return(previousResult);
        }
Ejemplo n.º 7
0
 protected DataBindingControllerResult GenerateInnerStructureCollectionBinding(
     List <SchemaDataBindingStructure> innerStructureCollection, Guid recordId, Guid sysPackageUId,
     DataBindingControllerResult previousResult = null)
 {
     if (innerStructureCollection != null)
     {
         foreach (var innerStructure in innerStructureCollection)
         {
             previousResult = GenerateInnerStructureBinding(innerStructure, recordId, sysPackageUId, previousResult);
         }
     }
     return(previousResult);
 }
        private Dictionary <Guid, string> GetBindedRecords(string schemaName, DataBindingControllerResult result)
        {
            List <Guid> recordIds = result.ResultMessages?.Keys.ToList();

            if (recordIds == null || recordIds.Count == 0)
            {
                return(null);
            }
            EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(schemaName);

            if (entitySchema.PrimaryDisplayColumn == null)
            {
                return(null);
            }
            EntitySchemaQuery bindedRecordsESQ  = GetBindedRecordsESQ(entitySchema, recordIds);
            EntityCollection  collectionRecords = bindedRecordsESQ.GetEntityCollection(UserConnection);

            return(collectionRecords.ToDictionary(e => e.PrimaryColumnValue, e => e.PrimaryDisplayColumnValue));
        }
        private void CreateErrorRemindings(string schemaName, DataBindingControllerResult result)
        {
            if (!HasErrors(result))
            {
                return;
            }

            string remindSubject = GetLocalizableString("SchemaDataBindingService", "ErrorMessage");
            var    bindedRecords = GetBindedRecords(schemaName, result);

            foreach (var errorMessage in result.ResultMessages)
            {
                var recordId           = errorMessage.Key;
                var displayColumnValue = GetPrimaryDisplayColumnValue(recordId, bindedRecords);
                var errorText          = GetFirstErrorMessage(errorMessage.Value);
                var remindErrorText    = GetRemindErrorMessage(errorText);
                var remindErrorMessage = !string.IsNullOrEmpty(displayColumnValue) ?
                                         $"{displayColumnValue}. {remindErrorText}" :
                                         remindErrorText;
                SaveReminding(schemaName, remindSubject, remindErrorMessage, recordId);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create bindings for all records passed.
        /// </summary>
        /// <param name="bindingStructure"><see cref="SchemaDataBindingStructure"/>.</param>
        /// <param name="recordIds">Primary record identifiers list.</param>
        /// <param name="sysPackageUId">Package UId.</param>
        protected DataBindingControllerResult GenerateHierarchyBindings(SchemaDataBindingStructure bindingStructure, Guid[] recordIds, Guid sysPackageUId)
        {
            var bindingResult = CreateEmptySuccessDataBindingControllerResult();

            foreach (var recordId in recordIds)
            {
                using (var dbExecutor = UserConnection.EnsureDBConnection()) {
                    DataBindingControllerResult result = null;
                    dbExecutor.StartTransaction();
                    try {
                        result = GenerateHierarchyBinding(bindingStructure, recordId, sysPackageUId);
                    } catch (Exception e) {
                        dbExecutor.RollbackTransaction();
                        ClearBindedBundlesList();
                        bindingResult.Success = false;
                        AddExceptionToResultMessages(recordId, e, ref bindingResult);
                    }
                    if (result == null)
                    {
                        continue;
                    }
                    if (result.Success)
                    {
                        dbExecutor.CommitTransaction();
                    }
                    else
                    {
                        dbExecutor.RollbackTransaction();
                        ClearBindedBundlesList();
                    }
                    bindingResult.Success = bindingResult.Success && result.Success;
                    AddResultMessages(recordId, result, ref bindingResult);
                }
            }
            ClearBindedBundlesList();
            return(bindingResult);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Create data bindings for record with its inner structure.
        /// </summary>
        /// <param name="bindingStructure"><see cref="SchemaDataBindingStructure"/>.</param>
        /// <param name="recordId">Primary record identifier.</param>
        /// <param name="sysPackageUId">Package UId.</param>
        /// <param name="previousResult">Data binding controller result</param>
        /// <returns></returns>
        protected DataBindingControllerResult GenerateHierarchyBinding(SchemaDataBindingStructure bindingStructure, Guid recordId,
                                                                       Guid sysPackageUId, DataBindingControllerResult previousResult = null)
        {
            if (previousResult == null)
            {
                previousResult = CreateEmptySuccessDataBindingControllerResult();
            }
            if (IsExistInBindedBundleList(bindingStructure))
            {
                return(previousResult);
            }
            var entities = GetEntities(bindingStructure, recordId);

            if (entities.Count == 0)
            {
                return(previousResult);
            }
            var manufacturerParameters = GetManufacturerParameters(bindingStructure, recordId, sysPackageUId);

            previousResult = GenerateInnerStructureCollectionBinding(bindingStructure.DependsStructures, recordId, sysPackageUId, previousResult);
            var bindingResult = Manufacturer.GenerateBinding(entities, manufacturerParameters);

            previousResult.Success = previousResult.Success && bindingResult.Success;
            if (bindingResult.ResultMessages?.Any() == true)
            {
                AddResultMessages(recordId, bindingResult.ResultMessages, ref previousResult);
            }
            if (previousResult.Success)
            {
                AddBindedBundleToList(bindingStructure);
                previousResult = GenerateInnerStructureCollectionBinding(bindingStructure.InnerStructures, recordId, sysPackageUId, previousResult);
            }
            return(previousResult);
        }
Ejemplo n.º 12
0
        private void AddExceptionToResultMessages(Guid recordId, Exception exception, ref DataBindingControllerResult bindingResult)
        {
            Collection <ItemValidationMessage> errorMessages = new Collection <ItemValidationMessage>();
            Descriptor            descriptor       = new PackageSchemaDataDescriptor();
            string                exceptionMessage = exception.Message + exception.StackTrace;
            ResultMessage         resultMessage    = new ResultMessage(MessageType.Error, exceptionMessage);
            ItemValidationMessage errorMessage     = new ItemValidationMessage(descriptor, resultMessage);

            errorMessages.Add(errorMessage);
            AddResultMessages(recordId, errorMessages, ref bindingResult);
        }
Ejemplo n.º 13
0
 private void AddResultMessages(Guid recordId, Collection <ItemValidationMessage> errorMessages, ref DataBindingControllerResult bindingResult)
 {
     if (bindingResult.ResultMessages.TryGetValue(recordId, out var messagesCollection))
     {
         messagesCollection.AddRangeIfNotExists(errorMessages.ToList());
     }
     else
     {
         bindingResult.ResultMessages.Add(recordId, errorMessages);
     }
 }
 private int GetCountErrorMessages(DataBindingControllerResult bindResult)
 {
     return(!HasErrors(bindResult) ?
            0 :
            bindResult.ResultMessages.Sum(item => GetFirstErrorMessage(item.Value) != null ? 1 : 0));
 }
 private bool HasErrors(DataBindingControllerResult result)
 {
     return(!result.Success && result.ResultMessages?.Any() == true);
 }