コード例 #1
0
ファイル: SyncProcessWorker.cs プロジェクト: mparsin/Elements
 /// <summary>
 /// Updates the items.
 /// </summary>
 /// <param name="job">The job.</param>
 /// <param name="itemsToSynchronize">The items to synchronize.</param>
 /// <param name="fieldUpdaters">The field updaters.</param>
 /// <param name="dynamicItem">The dynamic item.</param>
 /// <param name="context">The context.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 private bool UpdateItems(
     IProcessSynchronizer job,
     IEnumerable<int> itemsToSynchronize,
     IEnumerable<IFieldUpdater> fieldUpdaters,
     ISyncDynamicItem dynamicItem,
     SynchronizationContext context)
 {
     return itemsToSynchronize.Aggregate(true, (current, id) => current && ExecuteUpdate(job, id, fieldUpdaters, dynamicItem, context));
 }
コード例 #2
0
ファイル: SyncProcessWorker.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Executes the update.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="itemId">The item identifier.</param>
        /// <param name="fieldUpdaters">The field updaters.</param>
        /// <param name="dynamicItem">The dynamic item.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool ExecuteUpdate(
            IProcessSynchronizer job,
            int itemId,
            IEnumerable<IFieldUpdater> fieldUpdaters,
            ISyncDynamicItem dynamicItem,
            SynchronizationContext context)
        {
            try
            {
                var criteria = new DetailCriteria(itemId) { AllowLazyLoading = true };
                var editItem = DynamicTypeManager.GetEditableRoot<IEditableRoot>(job.ProcessName, criteria);

                if (editItem == null || editItem.Id != itemId)
                {
                    context.AddError(string.Format(CultureInfo.InvariantCulture, "Failed to load item with Id = {0}.", itemId));
                    return false;
                }

                foreach (var fieldUpdater in fieldUpdaters)
                {
                    fieldUpdater.Update(dynamicItem, editItem);

                    if (fieldUpdater.IsKey)
                    {
                        editItem.KeyFields.Add(fieldUpdater.FieldName);
                    }
                }

                if (!((ITrackStatus)editItem).IsValid)
                {
                    AddValidationErrors(editItem, context);
                    return false;
                }

                ((ISavable)editItem).Save();

                return true;
            }
            catch (Exception ex)
            {
                context.AddException(ex);
            }

            return false;
        }
コード例 #3
0
ファイル: SyncProcessWorker.cs プロジェクト: mparsin/Elements
        /// <summary>
        /// Executes the insert.
        /// </summary>
        /// <param name="job">The job.</param>
        /// <param name="fieldUpdaters">The field updaters.</param>
        /// <param name="dynamicItem">The dynamic item.</param>
        /// <param name="context">The context.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool ExecuteInsert(
            IProcessSynchronizer job, IEnumerable<IFieldUpdater> fieldUpdaters, ISyncDynamicItem dynamicItem, SynchronizationContext context)
        {
            try
            {
                var editItem = DynamicTypeManager.NewEditableRoot<IEditableRoot>(job.ProcessName);
                editItem.AllowLazyLoading = true;

                foreach (var fieldUpdater in fieldUpdaters)
                {
                    fieldUpdater.Update(dynamicItem, editItem);

                    if (fieldUpdater.IsKey)
                    {
                        editItem.KeyFields.Add(fieldUpdater.FieldName);
                    }
                }

                if (!((ITrackStatus)editItem).IsValid)
                {
                    AddValidationErrors(editItem, context);
                    return false;
                }

                ((ISavable)editItem).Save();

                return true;
            }
            catch (Exception ex)
            {
                context.AddException(ex);
            }

            return false;
        }