Example #1
0
 // Called from the ObjectHandler
 internal void Update(IHasRowVersion target)
 {
     Target = target;
     Handle = string.Format("{0}:{1}", ObjectType, HandleIndex++); ;
     LastUpdate = DateTime.Now;          // Might be used to decide when or how often to refresh
     if (Observer != null)
         Observer.OnNext(Handle);        // Triggers the update sending the new handle to Excel
 }
Example #2
0
        public virtual void Update(T entity, IHasRowVersion dto)
        {
            var entry = ctx.Entry(entity);

            entry.Property(e => e.RowVersion).OriginalValue = dto.RowVersion;

            entry.CurrentValues.SetValues(dto);
        }
Example #3
0
 // Called from the ObjectHandler
 internal void Update(IHasRowVersion target)
 {
     Target     = target;
     Handle     = string.Format("{0}:{1}", ObjectType, HandleIndex++);;
     LastUpdate = DateTime.Now;          // Might be used to decide when or how often to refresh
     if (Observer != null)
     {
         Observer.OnNext(Handle);        // Triggers the update sending the new handle to Excel
     }
 }
Example #4
0
        public HandleInfo(ObjectHandler objectHandler, string objectType, object[] parameters, IHasRowVersion target)
        {
            // TODO: Complete member initialization
            Handler = objectHandler;
            ObjectType = objectType;
            Parameters = parameters;

            Target = target;
            Handle = string.Format("{0}:{1}", objectType, HandleIndex++);
            LastUpdate = DateTime.Now;
        }
Example #5
0
        public HandleInfo(ObjectHandler objectHandler, string objectType, object[] parameters, IHasRowVersion target)
        {
            // TODO: Complete member initialization
            Handler    = objectHandler;
            ObjectType = objectType;
            Parameters = parameters;

            Target     = target;
            Handle     = string.Format("{0}:{1}", objectType, HandleIndex++);
            LastUpdate = DateTime.Now;
        }
Example #6
0
        public virtual async Task <bool> SaveUpdatedWithOptimisticConcurrencyAsync(IHasRowVersion input, IPrincipal principal, Action <string, string> writeError, IDataAccessStrategy <T> savingStrategy = default)
        {
            bool result = false;

            var entity = mapper.Map <T>(input);

            result = await SaveUpdatedWithOptimisticConcurrencyAsync(entity, principal, writeError, savingStrategy);

            if (result)
            {
                mapper.Map(entity, input);
            }

            return(result);
        }
        public virtual bool UpdateWithIncludeOrExcludeProperties(IHasRowVersion source, T destination, bool include, ICollection <string> propertyNames)
        {
            var destinationEntry = ctx.Entry(destination);

            destinationEntry.Property(e => e.RowVersion).OriginalValue = source.RowVersion;

            var sourceProperties = source.GetProperties();

            foreach (var property in sourceProperties)
            {
                string propertyName = property.Name;

                bool contains = propertyNames.Contains(propertyName);

                if ((contains && include) || (!contains && !include))
                {
                    var sourceValue = property.GetPropertyValue(source);

                    destination.SetPropertyValue(propertyName, sourceValue);
                }
            }

            return(true);
        }
        public virtual bool UpdateWithIncludeOrExcludeProperties(IHasRowVersion source, T destination, bool include, params Expression <Func <T, object> >[] properties)
        {
            var propertyNames = properties.ConvertArray(ReflectionUtils.GetNameOf);

            return(UpdateWithIncludeOrExcludeProperties(source, destination, include, propertyNames));
        }
Example #9
0
        public virtual async Task <TOutput> SaveUpdatedWithOptimisticConcurrencyAsync <TOutput>(IHasRowVersion source, T destination, IPrincipal principal, Action <string, string> writeError, IDataAccessStrategy <T> savingStrategy = default)
        {
            savingStrategy = savingStrategy ?? dataAccessStrategy;

            savingStrategy.ThrowIfNull(nameof(savingStrategy));

            TOutput result = default;

            if (savingStrategy.CanUpdate(destination))
            {
                if (savingStrategy.CanUpdateAllProperties(destination))
                {
                    mapper.Map(source, destination);
                }
                else
                {
                    var properties = savingStrategy.GetPropertiesForUpdate(destination);

                    UpdateWithIncludeOrExcludeProperties(source, destination, true, properties);
                }

                bool success = await SaveUpdatedWithOptimisticConcurrencyAsync(destination, writeError, false);

                if (success)
                {
                    result = mapper.Map <TOutput>(destination);
                }
            }
            else
            {
                writeError("", Resources.ErrorMessages.AccessDenied);
            }

            return(result);
        }
Example #10
0
        public virtual async Task <TOutput> SaveUpdatedWithOptimisticConcurrencyAsync <TOutput>(IHasRowVersion input, IPrincipal principal, Action <string, string> writeError, IDataAccessStrategy <T> savingStrategy = default)
        {
            TOutput result = default;

            var entity = mapper.Map <T>(input);

            bool success = await SaveUpdatedWithOptimisticConcurrencyAsync(entity, principal, writeError, savingStrategy);

            if (success)
            {
                result = mapper.Map <TOutput>(entity);
            }

            return(result);
        }
Example #11
0
 public static byte[] EntityVersion(this IUnitOfWork uow, IHasRowVersion versionedEntity)
 {
     return((byte[])uow.PropertyValue(versionedEntity, EFCore.Version));
 }
Example #12
0
 public static void EntityVersion(this IUnitOfWork uow, IHasRowVersion versionedEntity, byte[] version)
 {
     uow.PropertyValue(versionedEntity, EFCore.Version, version);
 }
 public static byte[] EntityVersion(this IDbContext dbContext, IHasRowVersion versionedEntity)
 {
     return((byte[])dbContext.PropertyValue(versionedEntity, EFCoreShadow.Version));
 }
 public static void EntityVersion(this IDbContext dbContext, IHasRowVersion versionedEntity, byte[] version)
 {
     dbContext.PropertyValue(versionedEntity, EFCoreShadow.Version, version);
 }