コード例 #1
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// Set entity as modified.
 /// </summary>
 /// <typeparam name="TEntity">Entity type.</typeparam>
 /// <param name="item">Entity to establish.</param>
 public virtual void SetModified <TEntity>(TEntity item) where TEntity : Entity
 {
     //this operation also attach item in object state manager
     DDDExceptionProcessor.ProcessDataAccess(
         () => base.Entry <TEntity>(item).State = System.Data.Entity.EntityState.Modified
         );
 }
コード例 #2
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// Commits object.
 /// </summary>
 public virtual void Commit()
 {
     DDDExceptionProcessor.ProcessDataAccess(() =>
     {
         base.SaveChanges();
     });
 }
コード例 #3
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
 /// </summary>
 /// <param name="persisted">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 /// <param name="current">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 public virtual void Merge(TEntity persisted, TEntity current)
 {
     DDDExceptionProcessor.ProcessDataAccess(() =>
     {
         QueryableUnitOfWork.ApplyCurrentValues(persisted, current);
     });
 }
コード例 #4
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// Commits object and refresh changes.
        /// </summary>
        public virtual void CommitAndRefreshChanges()
        {
            bool saveFailed = false;

            do
            {
                try
                {
                    DDDExceptionProcessor.ProcessDataAccess(() =>
                    {
                        base.SaveChanges();

                        saveFailed = false;
                    });
                }
                catch (SemanticException sex)
                {
                    DbUpdateConcurrencyException ex = sex.InnerException as DbUpdateConcurrencyException;

                    saveFailed = true;

                    ex.Entries.ToList()
                    .ForEach(entry =>
                    {
                        entry.OriginalValues.SetValues(entry.GetDatabaseValues());
                    });
                }
            } while (saveFailed);
        }
コード例 #5
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
 /// </summary>
 /// <param name="filter">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
 public virtual IEnumerable <TEntity> GetFiltered(System.Linq.Expressions.Expression <Func <TEntity, bool> > filter)
 {
     return(DDDExceptionProcessor.ProcessDomain <IEnumerable <TEntity> >(() =>
     {
         return GetSet().Where(filter);
     }));
 }
コード例 #6
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
 /// </summary>
 /// <param name="specification">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
 public virtual IEnumerable <TEntity> AllMatching(ISpecification <TEntity> specification)
 {
     return(DDDExceptionProcessor.ProcessDomain <IEnumerable <TEntity> >(() =>
     {
         return GetSet().Where(specification.SatisfiedBy());
     }));
 }
コード例 #7
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// Apply values to entity.
 /// </summary>
 /// <typeparam name="TEntity">Entity type.</typeparam>
 /// <param name="original">Original values.</param>
 /// <param name="current">Current values.</param>
 public virtual void ApplyCurrentValues <TEntity>(TEntity original, TEntity current) where TEntity : Entity
 {
     //if it is not attached, attach original and set current values
     DDDExceptionProcessor.ProcessDataAccess(
         () => base.Entry <TEntity>(original).CurrentValues.SetValues(current)
         );
 }
コード例 #8
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// Crate set.
        /// </summary>
        /// <typeparam name="TEntity">Entoty type set to create.</typeparam>
        /// <returns>A DbSet.</returns>
        public virtual DbSet <TEntity> CreateSet <TEntity>() where TEntity : Entity
        {
            DbSet <TEntity> set = default(DbSet <TEntity>);

            DDDExceptionProcessor.ProcessDataAccess(
                () => set = base.Set <TEntity>()
                );
            return(set);
        }
コード例 #9
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// Execute command.
        /// </summary>
        /// <param name="sqlCommand">Sql command.</param>
        /// <param name="parameters">Aql parameters.</param>
        /// <returns>Sql value returned.</returns>
        public virtual int ExecuteCommand(string sqlCommand, params object[] parameters)
        {
            int res = default(int);

            DDDExceptionProcessor.ProcessDataAccess(
                () => res = base.Database.ExecuteSqlCommand(sqlCommand, parameters)
                );
            return(res);
        }
コード例 #10
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// Execute query.
        /// </summary>
        /// <typeparam name="TEntity">Entity returned.</typeparam>
        /// <param name="sqlQuery">Query to execute.</param>
        /// <param name="parameters">Query parameters.</param>
        /// <returns>A collection of entity objects.</returns>
        public virtual IEnumerable <TEntity> ExecuteQuery <TEntity>(string sqlQuery, params object[] parameters)
        {
            IEnumerable <TEntity> entities = default(IEnumerable <TEntity>);

            DDDExceptionProcessor.ProcessDataAccess(
                () => entities = base.Database.SqlQuery <TEntity>(sqlQuery, parameters)
                );
            return(entities);
        }
コード例 #11
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
        /// </summary>
        /// <param name="id">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
        public virtual TEntity GetById(int id)
        {
            TEntity entity = default(TEntity);

            DDDExceptionProcessor.ProcessDataAccess(() =>
            {
                entity = GetSet().Find(id);
            });
            return(entity);
        }
コード例 #12
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
        /// </summary>
        /// <param name="id">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
        public virtual TEntity GetById(Guid id)
        {
            TEntity entity = default(TEntity);

            DDDExceptionProcessor.ProcessDataAccess(() =>
            {
                entity = id != Guid.Empty ? GetSet().Find(id) : null;
            });
            return(entity);
        }
コード例 #13
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// Attachs an entity to DbSet.
 /// </summary>
 /// <typeparam name="TEntity">Entity type to attach.</typeparam>
 /// <param name="item">Entity to attach.</param>
 public virtual void Attach <TEntity>(TEntity item) where TEntity : Entity
 {
     //attach and set as unchanged
     DDDExceptionProcessor.ProcessDataAccess(
         () =>
     {
         base.Entry <TEntity>(item).State = System.Data.Entity.EntityState.Unchanged;
     }
         );
 }
コード例 #14
0
ファイル: UnitOfWork.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// Roll back changes.
 /// </summary>
 public virtual void RollbackChanges()
 {
     // set all entities in change tracker
     // as 'unchanged state'
     DDDExceptionProcessor.ProcessDataAccess(
         () =>
         base.ChangeTracker.Entries()
         .ToList()
         .ForEach(entry => entry.State = System.Data.Entity.EntityState.Unchanged)
         );
 }
コード例 #15
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
        /// </summary>
        /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
        public virtual IEnumerable <TEntity> All()
        {
            IEnumerable <TEntity> entities = default(IEnumerable <TEntity>);

            DDDExceptionProcessor.ProcessDataAccess(() =>
            {
                entities = GetSet();
            }
                                                    );
            return(entities);
        }
コード例 #16
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
 /// </summary>
 /// <param name="item">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 public virtual void Add(TEntity item)
 {
     DDDExceptionProcessor.ProcessDataAccess(() =>
     {
         if (item == (TEntity)null)
         {
             throw new ArgumentNullException(String.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.InfoCannotAddNullEntity, typeof(TEntity).ToString()));
         }
         else
         {
             GetSet().Add(item);     // add new item in this set
         }
     });
 }
コード例 #17
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
 /// <summary>
 /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
 /// </summary>
 /// <param name="item">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
 public virtual void Modify(TEntity item)
 {
     DDDExceptionProcessor.ProcessDataAccess(() =>
     {
         if (item == (TEntity)null)
         {
             throw new ArgumentNullException(String.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.InfoCannotTrackNullEntity, typeof(TEntity).ToString()));
         }
         else
         {
             QueryableUnitOfWork.SetModified(item);
         }
     });
 }
コード例 #18
0
        public void DDDInfrastructureExceptionCheckExceptionsStructReturnValue()
        {
            int result = DDDExceptionProcessor.ProcessDataAccess <int>(() =>
            {
                try
                {
                    throw new Exception();
                }
                catch (Exception)
                {
                    return(1);
                }
            });

            Assert.AreEqual(1, result);
        }
コード例 #19
0
        public void DDDInfrastructureExceptionCheckExceptionsObjectReturnValue()
        {
            object result = DDDExceptionProcessor.ProcessDataAccess <object>(() =>
            {
                try
                {
                    throw new Exception();
                }
                catch (Exception)
                {
                    return(null);
                }
            });

            Assert.AreEqual(null, result);
        }
コード例 #20
0
 public void DDDApplicationExceptionCheckExceptions()
 {
     DDDExceptionProcessor.ProcessApplication(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionApplication(ex, out outEx);
             Assert.AreNotEqual(ex, outEx);
         }
     });
 }
コード例 #21
0
        public void DDDApplicationExceptionCheckExceptionsObjectReturnValue()
        {
            object result = DDDExceptionProcessor.ProcessApplication <object>(() =>
            {
                try
                {
                    throw new Exception();
                }
                catch (Exception)
                {
                    return(null);
                }
            });

            Assert.AreEqual(null, result);
        }
コード例 #22
0
 public void DDDWebServerExceptionCheckExceptions()
 {
     DDDExceptionProcessor.ProcessWebserver(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionWebserver(ex);
             Assert.AreNotEqual(ex, outEx);
         }
     });
 }
コード例 #23
0
 public void DDDInfrastructureExceptionCheckExceptions()
 {
     DDDExceptionProcessor.ProcessDataAccess(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionDataAccess(ex, out outEx);
             Assert.AreNotEqual(ex, outEx);
         }
     });
 }
コード例 #24
0
 public void DDDWebServerExceptionCheckExceptionsObjectReturnValueDefaultValue()
 {
     DDDExceptionProcessor.ProcessWebserver <object>(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionWebserver(ex);
             Assert.AreNotEqual(ex, outEx);
         }
         return(null);
     }, null);
 }
コード例 #25
0
 public void DDDDomainExceptionCheckExceptionsStructReturnValueDefaultValue()
 {
     DDDExceptionProcessor.ProcessDomain <int>(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionDomain(ex, out outEx);
             DDDExceptionProcessor.HandleExceptionDomain(ex);
             Assert.AreNotEqual(ex, outEx);
         }
         return(0);
     }, 0);
 }
コード例 #26
0
 public void DDDDomainExceptionCheckExceptionsObjectReturnValue()
 {
     DDDExceptionProcessor.ProcessDomain <object>(() =>
     {
         try
         {
             throw new Exception();
         }
         catch (Exception ex)
         {
             Exception outEx = null;
             DDDExceptionProcessor.HandleExceptionDomain(ex, out outEx);
             DDDExceptionProcessor.HandleExceptionDomain(ex);
             Assert.AreNotEqual(ex, outEx);
         }
         return(null);
     });
 }
コード例 #27
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
        /// </summary>
        /// <param name="item">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        public virtual void Remove(TEntity item)
        {
            DDDExceptionProcessor.ProcessDataAccess(() =>
            {
                if (item == (TEntity)null)
                {
                    throw new ArgumentNullException(String.Format(System.Globalization.CultureInfo.InvariantCulture, Resources.InfoCannotRemoveNullEntity, typeof(TEntity).ToString()));
                }
                else
                {
                    //attach item if not exist
                    QueryableUnitOfWork.Attach(item);

                    //set as "removed"
                    GetSet().Remove(item);
                }
            });
        }
コード例 #28
0
ファイル: EntityRepository.cs プロジェクト: crazyants/nCubed
        /// <summary>
        /// <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>
        /// </summary>
        /// <typeparam name="T">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</typeparam>
        /// <param name="pageIndex">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <param name="pageCount">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <param name="orderByExpression">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <param name="ascending">A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</param>
        /// <returns>A <see cref="T:RaraAvis.nCubed.DDD.Core.IEntityRepository`1"/>.</returns>
        public virtual IEnumerable <TEntity> GetPaged <T>(int pageIndex, int pageCount, System.Linq.Expressions.Expression <Func <TEntity, T> > orderByExpression, bool ascending)
        {
            var set = GetSet();

            return(DDDExceptionProcessor.ProcessDomain <IEnumerable <TEntity> >(() =>
            {
                if (ascending)
                {
                    return set.OrderBy(orderByExpression)
                    .Skip(pageCount * pageIndex)
                    .Take(pageCount);
                }
                else
                {
                    return set.OrderByDescending(orderByExpression)
                    .Skip(pageCount * pageIndex)
                    .Take(pageCount);
                }
            }));
        }