Exemple #1
0
        /// <summary>
        /// Adds/Updates the data from in reposiotry and tells all (subscribing) clients about it.
        ///
        /// Override to implement custom logic
        /// </summary>
        /// <param name="model"></param>
        public virtual async Task Update(TM model)
        {
            var command = DataSyncCommand.Update;

            if (model.Id == 0)
            {
                command = DataSyncCommand.Add;
            }

            using (var block = new ActivationBlock(kernel))
            {
                var s = block.Get <TS>();
                //Send back the data in the repo for the type TV
                var result = s.SaveOrUpdate(model);

                if (result.IsValid)
                {
                    //Ok, tell all clients about the update
                    result.SetViewModel();
                    await Sync(command, result.EntityViewModel);
                }
                else
                {
                    //Could not save, send information back to caller
                    await this.Invoke(result, DataSyncCommand.Error);
                }
            }
        }
Exemple #2
0
        public ActivationBlockTests()
        {
            _parentMock  = new Mock <IResolutionRoot>(MockBehavior.Strict);
            _requestMock = new Mock <IRequest>(MockBehavior.Strict);

            _activationBlock = new ActivationBlock(_parentMock.Object);
        }
Exemple #3
0
 /// <summary>
 /// Search the repository, not exposed to clients since accessor is protected
 /// </summary>
 /// <param name="expression"></param>
 /// <returns></returns>
 protected virtual IEnumerable <TM> Find(Func <TM, bool> expression)
 {
     using (var block = new ActivationBlock(kernel))
     {
         var s = block.Get <TS>();
         //Send back the data in the repo for the type TV
         return(s.Find(expression));
     }
 }
Exemple #4
0
 /// <summary>
 /// Will fetch and send all data in the repository for each topic sent in with the connection.
 /// </summary>
 public override async Task OnOpened()
 {
     using (var block = new ActivationBlock(kernel))
     {
         var s = block.Get <TS>();
         //Send back the data in the repo for the type TV
         await this.Invoke(s.GetAll(), string.Format("{0}:{1}", DataSyncCommand.Init, Entity));
     }
 }
Exemple #5
0
 /// <summary>
 /// Deletes the data from the reposiotry and tells all (subscribing) clients about it
 ///
 /// Override to implement custom logic
 /// </summary>
 /// <param name="model"></param>
 public virtual async Task Delete(TVM model)
 {
     using (var block = new ActivationBlock(kernel))
     {
         var s = block.Get <TS>();
         s.Delete(model.Id);
         await Sync(DataSyncCommand.Delete, model);
     }
 }
        /// <summary>
        /// Dispose Repositories
        /// </summary>
        public void Dispose()
        {
            if (Block == null)
            {
                return;
            }

            Block.Dispose();
            Block = null;
        }
        /// <summary>
        /// Creates disposable object for <using> block
        /// </summary>
        /// <returns>disposable object</returns>
        public IDisposable Use()
        {
            if (Block != null && !Block.IsDisposed)
            {
                return(new FakeDisposable());
            }

            Contract.Requires(Kernal != null, "Ninject kernal should not be null");

            Block = new NinjectActivationBlock(Kernal);
            ExtendUsageInitialization();

            return(this);
        }
Exemple #8
0
 public async Task Page(int page, int pageSize)
 {
     using (var block = new ActivationBlock(kernel))
     {
         var s        = block.Get <TS>();
         var entities = new List <TVM>();
         var p        = s.Page(page, pageSize);
         foreach (var entity in p.Entities)
         {
             var vc = entity.GetValidationContainer(default(TVM));
             vc.SetViewModel();
             entities.Add(vc.EntityViewModel);
         }
         await this.Invoke(new Page <TVM>(entities, p.Count, p.PageSize, p.CurrentPage),
                           string.Format("{0}:{1}", DataSyncCommand.Page, Entity));
     }
 }
Exemple #9
0
 public ActivationBlockContext()
 {
     kernel = new StandardKernel();
     block  = new ActivationBlock(kernel);
 }
Exemple #10
0
 public ActivationBlockContext()
 {
     this.parentMock  = new Mock <IResolutionRoot>();
     this.requestMock = new Mock <IRequest>();
     this.block       = new ActivationBlock(this.parentMock.Object);
 }
 public ActivationBlockContext()
 {
     this.kernel = new StandardKernel();
     this.block  = new ActivationBlock(this.kernel);
 }
Exemple #12
0
 public Factory(IResolutionRoot kernel)
 {
     _block = new ActivationBlock(kernel);
 }
 public ActivationBlockContext()
 {
     parentMock  = new Mock <IResolutionRoot>();
     requestMock = new Mock <IRequest>();
     block       = new ActivationBlock(parentMock.Object);
 }