Пример #1
0
        protected override IEnumerable<IDataParameter> CoreGetColumnParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema, Table table)
        {
            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)dataSourceTag == null)
                throw new ArgumentNullException("dataSourceTag");

            if ((object)database == null)
                throw new ArgumentNullException("database");

            if ((object)schema == null)
                throw new ArgumentNullException("schema");

            if ((object)table == null)
                throw new ArgumentNullException("table");

            if (dataSourceTag.SafeToString().ToLower() == "net.sqlserver" ||
                dataSourceTag.SafeToString().ToLower() == "net.sqlce")
            {
                return new IDataParameter[]
                       {
                           unitOfWorkContext.CreateParameter(ParameterDirection.Input, DbType.String, 100, 0, 0, true, "@SchemaName", schema.SchemaName),
                           unitOfWorkContext.CreateParameter(ParameterDirection.Input, DbType.String, 100, 0, 0, true, "@TableOrViewName", table.TableName)
                       };
            }

            throw new ArgumentOutOfRangeException(string.Format("dataSourceTag: '{0}'", dataSourceTag));
        }
Пример #2
0
        private static IMessagingAggregateRoot GetReceiver(IUnitOfWorkContext work, IncomingMessage message)
        {                        
            var existingReceiver = (IMessagingAggregateRoot)work.GetById(message.ReceiverType, message.ReceiverId, null);
            CheckProcessingRequirements(message, existingReceiver);

            return existingReceiver ?? CreateNewAggregateInstance(message.ReceiverType, message.ReceiverId);
        }
 public UnitOfWork(IClientOutboxStorageV2 clientOutboxStorage, IMessageSession messageSession, IUnitOfWorkContext unitOfWorkContext, ReadOnlySettings settings)
 {
     _clientOutboxStorage = clientOutboxStorage;
     _messageSession      = messageSession;
     _unitOfWorkContext   = unitOfWorkContext;
     _settings            = settings;
 }
Пример #4
0
        private IDeviceRepository deviceRepository;           // 设备管理

        public BaseSystemConfigService(IUnitOfWorkContext unitContext, IDataDictRepository DataDictRepository, IFieldTypeRepository FieldTypeRepository,
                                       IDeviceRepository DeviceRepository) : base(unitContext)
        {
            this.fieldTypeRepository = FieldTypeRepository;
            this.dataDictRepository  = DataDictRepository;
            this.deviceRepository    = DeviceRepository;
        }
        protected override void ExecuteInContext(IUnitOfWorkContext context, InvalidateUserCommand command)
        {
            var aggregate = context.GetById <User>(command.UserID) as User;

            aggregate.Invalidate(command.UserID);
            context.Accept();
        }
Пример #6
0
        protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceDiscount command)
        {
            Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion);

            invoice.GiveDiscount(command.DiscountInPercent);
            context.Accept();
        }
Пример #7
0
        /// <summary>
        /// Create proxy for unit-of-work.
        /// </summary>
        /// <param name="unitOfWorkContext">Unit-of-work context.</param>
        public UnitOfWorkProvider(IUnitOfWorkContext unitOfWorkContext)
        {
            if (unitOfWorkContext == null)
            {
                throw new UnitOfWorkException($"Cannot get active {nameof(IUnitOfWork)}: {nameof(unitOfWorkContext)} is not assigned");
            }

            if (unitOfWorkContext.CurrentUnitOfWork != null)
            {
                this.unitOfWork = unitOfWorkContext.CurrentUnitOfWork;
                this.isCurrent  = true;
            }
            else
            {
                if (unitOfWorkContext.Factory == null)
                {
                    throw new UnitOfWorkException($"Cannot create new {nameof(IUnitOfWork)}: {nameof(unitOfWorkContext.Factory)} is not assigned");
                }

                this.unitOfWork = unitOfWorkContext.Factory.Create();
                this.isCurrent  = false;

                if (this.unitOfWork == null)
                {
                    throw new UnitOfWorkException($"Cannot use {nameof(UnitOfWorkProvider)}: {nameof(unitOfWorkContext.Factory)} returned null value of {nameof(IUnitOfWork)}");
                }
            }
        }
 public UnitOfWorkManager(IDb db, IMessageSession messageSession, IUnitOfWorkContext unitOfWorkContext, IOutbox outbox, ReadOnlySettings settings)
 {
     _db                = db;
     _messageSession    = messageSession;
     _unitOfWorkContext = unitOfWorkContext;
     _outbox            = outbox;
     _settings          = settings;
 }
Пример #9
0
        protected override void ExecuteInContext(IUnitOfWorkContext context, SetUserPropertyCommand command)
        {
            var aggregate = context.GetById <User>(command.UserID) as User;

            aggregate.SetProperty(command.UserID, command.Name, command.Value);

            context.Accept();
        }
Пример #10
0
        private static IMessagingAggregateRoot GetReceiver(IUnitOfWorkContext work, IncomingMessage message)
        {
            var existingReceiver = (IMessagingAggregateRoot)work.GetById(message.ReceiverType, message.ReceiverId, null);

            CheckProcessingRequirements(message, existingReceiver);

            return(existingReceiver ?? CreateNewAggregateInstance(message.ReceiverType, message.ReceiverId));
        }
        protected override void ExecuteInContext(IUnitOfWorkContext context, DeleteTweetCommand command)
        {
            var aggregate = context.GetById <Tweet>(command.TweetID) as Tweet;

            aggregate.Delete(command.TweetID);

            context.Accept();
        }
        protected override void ExecuteInContext(IUnitOfWorkContext context, AddUserToRoleCommand command)
        {
            var aggregate = context.GetById <User>(command.UserID) as User;

            aggregate.AddToRole(command.UserID, command.Role);

            context.Accept();
        }
        protected override void ExecuteInContext(IUnitOfWorkContext context, SetUserPasswordCommand command)
        {
            var aggregate = context.GetById <User>(command.UserID) as User;

            aggregate.SetPassword(command.UserID, command.Password);

            context.Accept();
        }
Пример #14
0
        protected UnitOfWork(IUnitOfWorkContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Context = context;
        }
Пример #15
0
 /// <summary>
 /// Constructor, initializes a new instance of <see cref="MappedCommandToAggregateRootMethod&lt;TCommand, TAggRoot&gt;"/>.
 /// </summary>
 /// <param name="getidfromcommandfunc">The method responsible for retrieving the id of the aggregateroot from the command.</param>
 /// <remarks>Marked as internal because the construction is only allowed in the framework.</remarks>
 internal MappedCommandToAggregateRootMethod(Func <TCommand, Guid> getidfromcommandfunc)
 {
     _getidfromcommandfunc   = getidfromcommandfunc;
     _aggregaterootfetchfunc = delegate(Guid guid, long?lastKnownVersion)
     {
         IUnitOfWorkContext uow = UnitOfWorkContext.Current;
         return((TAggRoot)uow.GetById(typeof(TAggRoot), guid, lastKnownVersion));
     };
 }
 public DeleteReservationCommandHandler(
     IValidator <DeleteReservationCommand> validator,
     IAccountReservationService reservationService,
     IUnitOfWorkContext context)
 {
     _validator          = validator;
     _reservationService = reservationService;
     _context            = context;
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="workContext"></param>
 public EFRepository(IUnitOfWorkContext workContext = null)
 {
     if (workContext == null)
     {
         workContext = UnitOfWorkContextManage.WorkContext();
     }
     //
     _workContext = workContext;
 }
Пример #18
0
 public BaseAuthorityService(IUnitOfWorkContext unitContext, IUserRepository UserRepository, IRoleRepository RoleRepository,
                             IModuleRepository ModuleRepository, IRoleModuleRepository RoleModuleRepository, ILogRepository LogRepository)
     : base(unitContext)
 {
     this.userRepository       = UserRepository;
     this.roleRepository       = RoleRepository;
     this.moduleRepository     = ModuleRepository;
     this.roleModuleRepository = RoleModuleRepository;
 }
Пример #19
0
        protected override void ExecuteInContext(IUnitOfWorkContext context, AddInvoiceItem command)
        {
            ITaxRepository taxRepo = NcqrsEnvironment.Get <ITaxRepository>();
            Tax            tax     = taxRepo.FindByCode(command.TaxCode, command.OwnerId);

            Invoice invoice = context.GetById <Invoice>(command.InvoiceId, command.KnownVersion);

            invoice.AddInvoiceItem(command.ItemId, command.Description, command.Quantity, command.Price, command.DiscountInPercent, tax, command.OwnerId, command.UserName);
            context.Accept();
        }
Пример #20
0
 public CreateAccountReservationCommandHandler(IAccountReservationService accountReservationService,
                                               IValidator <CreateAccountReservationCommand> validator, IGlobalRulesService globalRulesService,
                                               IUnitOfWorkContext context, IAccountLegalEntitiesService accountLegalEntitiesService)
 {
     _accountReservationService = accountReservationService;
     _validator                   = validator;
     _globalRulesService          = globalRulesService;
     _context                     = context;
     _accountLegalEntitiesService = accountLegalEntitiesService;
 }
Пример #21
0
partial         void OnPreInsertEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog eventLog)
        {
            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)eventLog == null)
                throw new ArgumentNullException("eventLog");

            //eventLog.Mark();
        }
Пример #22
0
partial         void OnPreInsertEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage emailMessage)
        {
            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)emailMessage == null)
                throw new ArgumentNullException("emailMessage");

            //emailMessage.Mark();
        }
Пример #23
0
partial         void OnPreInsertEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment emailAttachment)
        {
            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)emailAttachment == null)
                throw new ArgumentNullException("emailAttachment");

            //emailAttachment.Mark();
        }
Пример #24
0
        }                                                           // 出库管理业务


        /// <summary>
        /// 参数形式初始化仓储类
        /// </summary>
        /// <param name="unitContext">上下文</param>
        /// <param name="arvRepository">档案管理</param>
        /// <param name="arvBoxRepository">档案盒管理</param>
        /// <param name="lendRepository">借阅管理</param>
        /// <param name="returnRepository">归还管理</param>
        /// <param name="outCabRepository">出库管理</param>
        public BaseArvOpService(IUnitOfWorkContext unitContext, IArvRepository arvRepository, IArvBoxRepository arvBoxRepository, ILendRepository lendRepository, IReturnRepository returnRepository, IArvLendReturnRepository arvLendReturnRepository, IOutCabRepository outCabRepository)
            : base(unitContext)
        {
            this.arvRepository           = arvRepository;
            this.arvBoxRepository        = arvBoxRepository;
            this.lendRepository          = lendRepository;
            this.returnRepository        = returnRepository;
            this.outCabRepository        = outCabRepository;
            this.arvLendReturnRepository = arvLendReturnRepository;
        }
Пример #25
0
        /// <summary>
        /// Starts the unit of work.
        /// </summary>
        /// <returns>New unit of work.</returns>
        public static IUnitOfWork StartUnitOfWork(IUnitOfWorkContext innerContext = null)
        {
            var unitOfWork = FactoryResolver.GetUnitOfWork();

            if (innerContext != null)
            {
                unitOfWork.InitUnitOfWorkContext(innerContext);
            }
            return(unitOfWork);
        }
Пример #26
0
        /// <summary>
        /// 参数化构造函数
        /// </summary>
        /// <param name="context">DbContext对象</param>
        public BaseRepository(IUnitOfWorkContext unitContext)
        {
            if (unitContext is IEFUnitOfWorkContext)
            {
                this.EFContext = unitContext as IEFUnitOfWorkContext;
            }

            this.IsDescending     = true;  // 默认降序
            this.SortPropertyName = "ID";  // 排序依据为“ID”
        }
        public void Arrange()
        {
            _employerAccountRepository = new Mock <IEmployerAccountRepository>();
            _transferConnectionInvitationRepository = new Mock <ITransferConnectionInvitationRepository>();
            _userRepository = new Mock <IUserAccountRepository>();

            _receiverUser = new User
            {
                Id        = 123456,
                Ref       = Guid.NewGuid(),
                FirstName = "John",
                LastName  = "Doe"
            };

            _senderAccount = new Account
            {
                Id       = 333333,
                HashedId = "ABC123",
                Name     = "Sender"
            };

            _receiverAccount = new Account
            {
                Id       = 222222,
                HashedId = "XYZ987",
                Name     = "Receiver"
            };

            _unitOfWorkContext = new UnitOfWorkContext();

            _transferConnectionInvitation = new TransferConnectionInvitationBuilder()
                                            .WithId(111111)
                                            .WithSenderAccount(_senderAccount)
                                            .WithReceiverAccount(_receiverAccount)
                                            .WithStatus(TransferConnectionInvitationStatus.Pending)
                                            .Build();

            _userRepository.Setup(r => r.GetUserByRef(_receiverUser.Ref)).ReturnsAsync(_receiverUser);
            _employerAccountRepository.Setup(r => r.GetAccountById(_senderAccount.Id)).ReturnsAsync(_senderAccount);
            _employerAccountRepository.Setup(r => r.GetAccountById(_receiverAccount.Id)).ReturnsAsync(_receiverAccount);
            _transferConnectionInvitationRepository.Setup(r => r.GetTransferConnectionInvitationById(_transferConnectionInvitation.Id)).ReturnsAsync(_transferConnectionInvitation);

            _handler = new ApproveTransferConnectionInvitationCommandHandler(
                _employerAccountRepository.Object,
                _transferConnectionInvitationRepository.Object,
                _userRepository.Object
                );

            _command = new ApproveTransferConnectionInvitationCommand
            {
                AccountId = _receiverAccount.Id,
                UserRef   = _receiverUser.Ref,
                TransferConnectionInvitationId = _transferConnectionInvitation.Id
            };
        }
Пример #28
0
 public Sender(NServiceBusConfiguration nServiceBusConfig,
               IEndpointInstance endpointInstance,
               IEventPublisher publisher,
               IUnitOfWorkContext unitOfWorkContext)
 //, ILog log)
 {
     //_log = log;
     _nServiceBusConfig = nServiceBusConfig;
     Publisher          = publisher;
     EndpointInstance   = endpointInstance;
     _unitOfWorkContext = unitOfWorkContext;
 }
Пример #29
0
        protected override void ExecuteInContext(IUnitOfWorkContext context, ValidateUserCommand command)
        {
            var aggregate = context.GetById <User>(command.UserID) as User;

            bool validated = aggregate.Validate(command.UserID, command.Username, command.Password);

            if (validated)
            {
                aggregate.Validated(command.UserID);
                context.Accept();
            }
        }
Пример #30
0
        /// <summary>
        /// Constructor, initializes a new instance of <see cref="MappedCommandToAggregateRootMethodOrConstructor&lt;TCommand, TAggRoot&gt;"/>.
        /// </summary>
        /// <param name="getidfromcommandfunc">The method responsible for retrieving the id of the aggregateroot from the command.</param>
        /// <param name="creatorfunc">The method that is responsible for the creation of the aggregateroot.</param>
        /// <remarks>Marked as internal because the construction is only allowed in the framework.</remarks>
        internal MappedCommandToAggregateRootMethodOrConstructor(Func <TCommand, Guid> getidfromcommandfunc, Func <TCommand, TAggRoot> creatorfunc)
        {
            Contract.Requires <ArgumentNullException>(creatorfunc != null, "creatorfunc can not be null.");
            _aggregaterootcreatorfunc = creatorfunc;

            _getidfromcommandfunc   = getidfromcommandfunc;
            _aggregaterootfetchfunc = delegate(Guid guid, long?lastKnownVersion)
            {
                IUnitOfWorkContext uow = UnitOfWorkContext.Current;
                return((TAggRoot)uow.GetById(typeof(TAggRoot), guid, lastKnownVersion));
            };
        }
Пример #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfWork" /> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="loader">The loader.</param>
 /// <param name="aggregateEventContext">The aggregate event context.</param>
 /// <param name="workContext">The context.</param>
 /// <param name="queueSender">The queue sender.</param>
 public UnitOfWork(
     IPersistenceProvider provider,
     IAggregateLoader loader,
     IAggregateEventContext aggregateEventContext,
     IUnitOfWorkContext workContext,
     IUnitOfWorkQueueSender queueSender)
 {
     this.provider = Check.NotNull(() => provider);
     this.loader   = Check.NotNull(() => loader);
     this.aggregateEventContext = Check.NotNull(() => aggregateEventContext);
     this.workContext           = Check.NotNull(() => workContext);
     this.queueSender           = Check.NotNull(() => queueSender);
     this.Clean();
 }
Пример #32
0
        public SqlExpressionVisitor(IDataSourceTagSpecific dataSourceTagSpecific, IUnitOfWorkContext unitOfWorkContext, IList<IDataParameter> commandParameters)
        {
            if ((object)dataSourceTagSpecific == null)
                throw new ArgumentNullException("dataSourceTagSpecific");

            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)commandParameters == null)
                throw new ArgumentNullException("commandParameters");

            this.dataSourceTagSpecific = dataSourceTagSpecific;
            this.unitOfWorkContext = unitOfWorkContext;
            this.commandParameters = commandParameters;
        }
Пример #33
0
        public async Task <IActionResult> Test2(IUnitOfWorkContext context, League league)
        {
            // Transaction Scope
            return(await context.Run(async transaction =>
            {
                // Command Scope
                return await transaction.Run(async command =>
                {
                    // Atomic Commands
                    return await command.Post(league);
                });

                // Convert to an IActionResult (handle Exceptions)
            }).Handle <IActionResult, League>(s => new CreatedResult(s.Id.ToString(), s), e => new BadRequestObjectResult(e)));
        }
Пример #34
0
        public AddAccountProviderCommandHandlerTestsFixture()
        {
            Db       = new ProviderRelationshipsDbContext(new DbContextOptionsBuilder <ProviderRelationshipsDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString()).ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)).Options);
            Account  = EntityActivator.CreateInstance <Account>().Set(a => a.Id, 1);
            User     = EntityActivator.CreateInstance <User>().Set(u => u.Ref, Guid.NewGuid());
            Provider = EntityActivator.CreateInstance <Provider>().Set(p => p.Ukprn, 12345678);

            Db.Accounts.Add(Account);
            Db.Users.Add(User);
            Db.Providers.Add(Provider);
            Db.SaveChanges();

            Command           = new AddAccountProviderCommand(Account.Id, Provider.Ukprn, User.Ref);
            Now               = DateTime.UtcNow;
            UnitOfWorkContext = new UnitOfWorkContext();
            Handler           = new AddAccountProviderCommandHandler(new Lazy <ProviderRelationshipsDbContext>(() => Db));
        }
Пример #35
0
        public bool DiscardEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment)
        {
            TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment query;

            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)@emailAttachment == null)
                throw new ArgumentNullException("emailAttachment");

            if (@emailAttachment.IsNew)
                return true;

            using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>())
            {
                this.OnPreDeleteEmailAttachment(unitOfWorkContext, @emailAttachment);

                query = [email protected](lo => lo.@EmailAttachmentId == @emailAttachment.@EmailAttachmentId);

                if((object)query == null)
                    throw new InvalidOperationException("TODO (enhancement): add meaningful message");

                [email protected](query);

                try
                {
                    ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict);
                }
                catch (ChangeConflictException ccex)
                {
                    this.OnDiscardConflictEmailAttachment(unitOfWorkContext, @emailAttachment);

                    return false;
                }

                this.OnPostDeleteEmailAttachment(unitOfWorkContext, @emailAttachment);

                @emailAttachment.IsNew = false;

                return true;
            }
        }
Пример #36
0
        /// <summary>
        /// Create new unit-of-work scope.
        /// </summary>
        /// <param name="dbContextFactory">Factory that creates database context.</param>
        /// <param name="unitOfWorkContext">Unit-of-work context.</param>
        public UnitOfWorkScope(IDbContextFactory dbContextFactory, IUnitOfWorkContext unitOfWorkContext)
        {
            // TODO: Allow wrapping UnitOfWorkScopes
            if (UnitOfWorkScope.Current != null)
            {
                throw new UnitOfWorkException($"Cannot create new {nameof(UnitOfWorkScope)}: outer {nameof(UnitOfWorkScope)} already exists and wrapping {nameof(UnitOfWorkScope)}s is not allowed");
            }

            if (dbContextFactory == null)
            {
                throw new UnitOfWorkException($"Cannot create new {nameof(IDbContext)}: {nameof(dbContextFactory)} is not assigned");
            }

            if (unitOfWorkContext == null)
            {
                throw new UnitOfWorkException($"Cannot create new {nameof(IDbContext)}: {nameof(unitOfWorkContext)} is not assigned");
            }

            this.dbContext                = dbContextFactory.Create();
            this.unitOfWorkContext        = unitOfWorkContext;
            UnitOfWorkScope.current.Value = this;
        }
Пример #37
0
partial         void OnSaveConflictEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
Пример #38
0
partial         void OnSaveConflictEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #39
0
        public bool SaveEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog)
        {
            TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EventLog query;
            bool wasNew;

            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)@eventLog == null)
                throw new ArgumentNullException("eventLog");

            using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>())
            {
                wasNew = @eventLog.IsNew;

                if (wasNew)
                {
                    this.OnPreInsertEventLog(unitOfWorkContext, @eventLog);

                    query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EventLog();

                    ctx.Context.EventLogs.InsertOnSubmit(query);
                }
                else
                {
                    this.OnPreUpdateEventLog(unitOfWorkContext, @eventLog);

                    query = ctx.Context.EventLogs.SingleOrDefault(lo => lo.@EventLogId == @eventLog.@EventLogId);

                    if((object)query == null)
                        throw new InvalidOperationException("TODO (enhancement): add meaningful message");
                }

                // map caller POCO changes to L2S object
                query.@EventLogId = @eventLog.@EventLogId;
                query.@EventText = @eventLog.@EventText;
                query.@CreationTimestamp = @eventLog.@CreationTimestamp;
                query.@ModificationTimestamp = @eventLog.@ModificationTimestamp;
                query.@LogicalDelete = @eventLog.@LogicalDelete;

                try
                {
                    ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict);
                }
                catch (ChangeConflictException ccex)
                {
                    this.OnSaveConflictEventLog(unitOfWorkContext, @eventLog);

                    return false;
                }

                // map server changes back to POCO from L2S object
                @eventLog.@EventLogId = query.@EventLogId;
                @eventLog.@EventText = query.@EventText;
                @eventLog.@CreationTimestamp = query.@CreationTimestamp;
                @eventLog.@ModificationTimestamp = query.@ModificationTimestamp;
                @eventLog.@LogicalDelete = query.@LogicalDelete;

                if (wasNew)
                {
                    this.OnPostInsertEventLog(unitOfWorkContext, @eventLog);
                }
                else
                {
                    this.OnPostUpdateEventLog(unitOfWorkContext, @eventLog);
                }

                return true;
            }
        }
Пример #40
0
        public bool SaveEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment)
        {
            TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment query;
            bool wasNew;

            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)@emailAttachment == null)
                throw new ArgumentNullException("emailAttachment");

            using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>())
            {
                wasNew = @emailAttachment.IsNew;

                if (wasNew)
                {
                    this.OnPreInsertEmailAttachment(unitOfWorkContext, @emailAttachment);

                    query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailAttachment();

                    ctx.Context.EmailAttachments.InsertOnSubmit(query);
                }
                else
                {
                    this.OnPreUpdateEmailAttachment(unitOfWorkContext, @emailAttachment);

                    query = ctx.Context.EmailAttachments.SingleOrDefault(lo => lo.@EmailAttachmentId == @emailAttachment.@EmailAttachmentId);

                    if((object)query == null)
                        throw new InvalidOperationException("TODO (enhancement): add meaningful message");
                }

                // map caller POCO changes to L2S object
                query.@EmailAttachmentId = @emailAttachment.@EmailAttachmentId;
                query.@EmailMessageId = @emailAttachment.@EmailMessageId;
                query.@MimeType = @emailAttachment.@MimeType;
                if ((object)@emailAttachment.@AttachmentBits != null) // prevent implicit conversion of null -> exception
                    query.@AttachmentBits = @emailAttachment.@AttachmentBits;
                query.@CreationTimestamp = @emailAttachment.@CreationTimestamp;
                query.@ModificationTimestamp = @emailAttachment.@ModificationTimestamp;
                query.@LogicalDelete = @emailAttachment.@LogicalDelete;

                try
                {
                    ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict);
                }
                catch (ChangeConflictException ccex)
                {
                    this.OnSaveConflictEmailAttachment(unitOfWorkContext, @emailAttachment);

                    return false;
                }

                // map server changes back to POCO from L2S object
                @emailAttachment.@EmailAttachmentId = query.@EmailAttachmentId;
                @emailAttachment.@EmailMessageId = query.@EmailMessageId;
                @emailAttachment.@MimeType = query.@MimeType;
                @emailAttachment.@AttachmentBits = (object)query.@AttachmentBits != null ? [email protected]() : null;
                @emailAttachment.@CreationTimestamp = query.@CreationTimestamp;
                @emailAttachment.@ModificationTimestamp = query.@ModificationTimestamp;
                @emailAttachment.@LogicalDelete = query.@LogicalDelete;

                if (wasNew)
                {
                    this.OnPostInsertEmailAttachment(unitOfWorkContext, @emailAttachment);
                }
                else
                {
                    this.OnPostUpdateEmailAttachment(unitOfWorkContext, @emailAttachment);
                }

                return true;
            }
        }
Пример #41
0
 protected abstract IEnumerable<IDataParameter> CoreGetColumnParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema, Table table);
Пример #42
0
partial         void OnSelectEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
Пример #43
0
partial         void OnPreInsertEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
Пример #44
0
partial         void OnPostDeleteEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #45
0
partial         void OnPostDeleteEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
Пример #46
0
partial         void OnPostDeleteEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
Пример #47
0
partial         void OnDiscardConflictEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
Пример #48
0
partial         void OnDiscardConflictEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #49
0
partial         void OnSelectEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
Пример #50
0
partial         void OnPreInsertEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
Пример #51
0
partial         void OnSelectEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #52
0
partial         void OnPreUpdateEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
Пример #53
0
 protected abstract IEnumerable<IDataParameter> CoreGetProcedureParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag, Database database, Schema schema);
Пример #54
0
partial         void OnPreUpdateEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #55
0
 protected abstract IEnumerable<IDataParameter> CoreGetDatabaseParameters(IUnitOfWorkContext unitOfWorkContext, string dataSourceTag);
Пример #56
0
partial         void OnPreUpdateEventLog(IUnitOfWorkContext unitOfWorkContext, EventLog @eventLog);
 public GenericRepository(IUnitOfWorkContext unitOfWorkContext)
 {
     this._context = unitOfWorkContext.GetUnitOfWorkContext() as DbContext;
     this._table   = _context.Set <T>();
 }
Пример #58
0
partial         void OnSaveConflictEmailAttachment(IUnitOfWorkContext unitOfWorkContext, EmailAttachment @emailAttachment);
Пример #59
0
partial         void OnPreInsertEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage);
Пример #60
0
        public bool SaveEmailMessage(IUnitOfWorkContext unitOfWorkContext, EmailMessage @emailMessage)
        {
            TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailMessage query;
            bool wasNew;

            if ((object)unitOfWorkContext == null)
                throw new ArgumentNullException("unitOfWorkContext");

            if ((object)@emailMessage == null)
                throw new ArgumentNullException("emailMessage");

            using (ContextWrapper<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext> ctx = unitOfWorkContext.GetContext<TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.TxtMtlPrimaryDataContext>())
            {
                wasNew = @emailMessage.IsNew;

                if (wasNew)
                {
                    this.OnPreInsertEmailMessage(unitOfWorkContext, @emailMessage);

                    query = new TextMetal.HostImpl.AspNetSample.Objects.Model.L2S.EmailMessage();

                    ctx.Context.EmailMessages.InsertOnSubmit(query);
                }
                else
                {
                    this.OnPreUpdateEmailMessage(unitOfWorkContext, @emailMessage);

                    query = ctx.Context.EmailMessages.SingleOrDefault(lo => lo.@EmailMessageId == @emailMessage.@EmailMessageId);

                    if((object)query == null)
                        throw new InvalidOperationException("TODO (enhancement): add meaningful message");
                }

                // map caller POCO changes to L2S object
                query.@EmailMessageId = @emailMessage.@EmailMessageId;
                query.@From = @emailMessage.@From;
                query.@Sender = @emailMessage.@Sender;
                query.@ReplyTo = @emailMessage.@ReplyTo;
                query.@To = @emailMessage.@To;
                query.@Cc = @emailMessage.@Cc;
                query.@Bcc = @emailMessage.@Bcc;
                query.@Subject = @emailMessage.@Subject;
                query.@IsBodyHtml = @emailMessage.@IsBodyHtml;
                query.@Body = @emailMessage.@Body;
                query.@Processed = @emailMessage.@Processed;
                query.@CreationTimestamp = @emailMessage.@CreationTimestamp;
                query.@ModificationTimestamp = @emailMessage.@ModificationTimestamp;
                query.@LogicalDelete = @emailMessage.@LogicalDelete;

                try
                {
                    ctx.Context.SubmitChanges(ConflictMode.FailOnFirstConflict);
                }
                catch (ChangeConflictException ccex)
                {
                    this.OnSaveConflictEmailMessage(unitOfWorkContext, @emailMessage);

                    return false;
                }

                // map server changes back to POCO from L2S object
                @emailMessage.@EmailMessageId = query.@EmailMessageId;
                @emailMessage.@From = query.@From;
                @emailMessage.@Sender = query.@Sender;
                @emailMessage.@ReplyTo = query.@ReplyTo;
                @emailMessage.@To = query.@To;
                @emailMessage.@Cc = query.@Cc;
                @emailMessage.@Bcc = query.@Bcc;
                @emailMessage.@Subject = query.@Subject;
                @emailMessage.@IsBodyHtml = query.@IsBodyHtml;
                @emailMessage.@Body = query.@Body;
                @emailMessage.@Processed = query.@Processed;
                @emailMessage.@CreationTimestamp = query.@CreationTimestamp;
                @emailMessage.@ModificationTimestamp = query.@ModificationTimestamp;
                @emailMessage.@LogicalDelete = query.@LogicalDelete;

                if (wasNew)
                {
                    this.OnPostInsertEmailMessage(unitOfWorkContext, @emailMessage);
                }
                else
                {
                    this.OnPostUpdateEmailMessage(unitOfWorkContext, @emailMessage);
                }

                return true;
            }
        }