示例#1
0
        protected override IComondModul <IMyEntity> СommandEnd(IComondModul <IMyEntity> comond)
        {
            if (comond.Answer != null && (comond.Action == TypeComond.Get || comond.Action == TypeComond.Сreate))
            {
                foreach (IMyEntity entity in comond.Answer)
                {
                    IMyEntity найден = cacheEntity.Where(r => r.Id == entity.Id && r.GetType() == entity.GetType()).FirstOrDefault();
                    if (найден == null)
                    {
                        cacheEntity.Add(entity);
                    }
                }
            }
            else if (comond.Answer != null && comond.Action == TypeComond.Remove)
            {
                foreach (IMyEntity entity in comond.Answer)
                {
                    if (cacheEntity.Contains(entity))
                    {
                        cacheEntity.Remove(entity);
                    }
                }
            }

            return(base.СommandEnd(comond));
        }
示例#2
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                IEnumerable <IMyEntity> user = mainContext.GetEntity(comond.TypeModel);

                comond.SetAnswer(user);
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                IMyEntity         ответ = mainContext.CreatEntity(comond.TypeModel);
                IList <IMyEntity> user  = new List <IMyEntity> {
                    ответ
                };
                comond.SetAnswer(user);
            }
            else if (comond.Action == TypeComond.Remove)
            {
                mainContext.RemoveEntity(comond.Data);
                comond.SetAnswer(comond.Data);
            }
            else if (comond.Action == TypeComond.Save)
            {
                mainContext.SaveChangesAsync();
            }
            else if (comond.Action == TypeComond.GetTable)
            {
                comond.Metadata = mainContext.GetTable();
            }
            return(comond);
        }
示例#3
0
        public IEnumerable <ITable> GetTable()
        {
            IComondModul <IMyEntity> comond = comondModul.GetComond(typeof(IMyEntity), TypeComond.GetTable, null);
            IEnumerable <ITable>     врем   = Сommand(comond).Metadata;

            return(врем);
        }
示例#4
0
        protected override IComondModul <IMyEntity> СommandEnd(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                IEnumerable <IMyEntity> врем = (IEnumerable <IMyEntity>)comond.Answer;

                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> Удалить    = observable.ToList().Where(r => врем.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                IEnumerable <IMyEntity> Добавить   = врем.Where(r => observable.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                СhangeObservable(observable, Добавить, Удалить);
                comond.SetAnswer(observable);
                dictionaryobservable[comond.TypeModel] = observable;
            }
            else if (comond.Action == TypeComond.Remove)
            {
                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> врем       = comond.Answer;
                IEnumerable <IMyEntity> Удалить    = observable.ToList().Where(r => врем.Where(r2 => r2.Id == r.Id).Count() != 0).ToList();
                СhangeObservable(observable, null, Удалить);
                comond.SetAnswer(Удалить);
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                ICollection <IMyEntity> observable = (ICollection <IMyEntity>)GetObserCollection(comond.TypeModel);
                IEnumerable <IMyEntity> врем       = comond.Answer;
                IEnumerable <IMyEntity> Добавить   = врем.Where(r => observable.Where(r2 => r2.Id == r.Id).Count() == 0).ToList();
                СhangeObservable(observable, Добавить, null);
                comond.SetAnswer(Добавить);
            }

            return(base.СommandEnd(comond));
        }
示例#5
0
        public IEnumerable <IMyEntity> GetEntity(Type type)
        {
            IComondModul <IMyEntity> comond = comondModul.GetComond(type, TypeComond.Get, null);
            IEnumerable <IMyEntity>  врем   = Сommand(comond).Answer;

            return(врем);
        }
示例#6
0
        public IEnumerable <IMyEntity> CreatNewEntity(Type type)
        {
            IComondModul <IMyEntity> comond = comondModul.GetComond(type, TypeComond.Сreate, null);
            IEnumerable <IMyEntity>  ответ  = Сommand(comond).Answer;

            return(ответ);
        }
示例#7
0
        public IComondModul <IMyEntity> Сommand(IComondModul <IMyEntity> comond)
        {
            IComondModul <IMyEntity> date = СommandStart(comond);

            if (RequestInsideModul is IModul Reposit1)
            {
                date = СommandStartInsideModulRequest(date);
                date = Reposit1.Сommand(date);
                date = СommandEndInsideModulRequest(date);
            }
            if (NextEternalModul is IModul Reposit2)
            {
                if (comond.Visit == TypeVisit.All || (comond.Visit == TypeVisit.FirstAnswer && comond.Answer == null))
                {
                    date = СommandStartEternalModul(date);
                    date = Reposit2.Сommand(date);
                    date = СommandEndEternalModul(date);
                }
            }
            if (AnswerInsideModul is IModul Reposit3)
            {
                date = СommandStartInsideModulAnswer(date);
                date = Reposit3.Сommand(date);
                date = СommandEndInsideModulAnswer(date);
            }
            date = СommandEnd(date);
            return(date);
        }
示例#8
0
        public IEnumerable <IMyEntity> GetAndRefreshEntity(Type type)
        {
            Task <IEnumerable <IMyEntity> > task   = GetEntityAsync(type);
            IComondModul <IMyEntity>        comond = comondModul.GetComond(type, TypeComond.Get, null);

            return(conversionModul.GetObserCollection(comond.TypeModel));
        }
示例#9
0
        public void Creat_ComondMudul()
        {
            IComondModul <IMyEntity> comondcPrototip  = comondModul.GetComond(typeof(IUser), TypeComond.Save, null);
            IComondModul <IMyEntity> comondcPrototip2 = comondModul.GetComond(typeof(User), TypeComond.Save, null);

            Assert.AreEqual(comondcPrototip.TypeModel, typeof(IUser));
            Assert.AreEqual(comondcPrototip2.TypeModel, typeof(IUser));
        }
示例#10
0
 protected override IComondModul <IMyEntity> СommandEndEternalModul(IComondModul <IMyEntity> comond)
 {
     comond = base.СommandEndEternalModul(comond);
     if (comond.Answer != null && kernelТекущая != null)
     {
         comond.Dress(kernelТекущая, GetConstructorArgument);
     }
     return(comond);
 }
示例#11
0
        protected static void SaveComond(IComondModul <IMyEntity> newcomond)
        {
            Type type = newcomond.TypeModel;

            if (comond.Where(r => r.TypeModel == type).Count() == 0)
            {
                SetAllComonds(newcomond);
            }
        }
示例#12
0
        public static IComondModul <IMyEntity> GetComond(Type type, TypeComond action, IEnumerable <IMyEntity> date)
        {
            IComondModul <IMyEntity> como = comond.Where(r => type.GetInterfaces().Contains(r.TypeModel) || (r.TypeModel == type && !r.TypeModel.IsClass)).LastOrDefault();

            if (como != null)
            {
                return(como.Clone(action, date));
            }
            throw new Exception($"Тип {type.Name} не зарегистрирован для команд");
        }
示例#13
0
        static void SetAllComonds(IComondModul <IMyEntity> newcomond)
        {
            IList <IComondModul <IMyEntity> > dubl = comond.ToList();

            dubl.Add(newcomond);

            lock (synccomond)
            {
                comond = dubl;
            }
        }
示例#14
0
        public void CachModul()
        {
            FaceRepository repository = new FaceRepository();
            ÑacheModul     ñacheModul = new ÑacheModul(repository);

            for (int i = 0; i < 5; i++)
            {
                IComondModul <IMyEntity> comondGet = ñacheModul.Ñommand(comondModul.GetComond(typeof(IUser), TypeComond.Get, null));
            }
            Assert.Equal(1, repository.amount(TypeComond.Get));
        }
示例#15
0
        public IEnumerable <IMyEntity> RemoveEntity(IMyEntity Entity)
        {
            IList <IMyEntity> Listuser = new List <IMyEntity>()
            {
                Entity
            };
            IComondModul <IMyEntity> comond = comondModul.GetComond(Entity.GetType(), TypeComond.Remove, Listuser);
            IEnumerable <IMyEntity>  врем   = Сommand(comond).Answer;

            return(врем);
        }
示例#16
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get && cacheEntity != null && cacheEntity.Count > 0)
            {
                IEnumerable <IMyEntity> entity = comond.Sort(cacheEntity);

                if (entity.Count() > 0)
                {
                    comond.SetAnswer(entity);
                }
            }
            return(base.СommandStart(comond));
        }
示例#17
0
        public void CachModul()
        {
            FaceRepository repository = new FaceRepository();
            СacheModul     сacheModul = new СacheModul(repository);

            for (int i = 0; i < 5; i++)
            {
                IComondModul <IMyEntity> comondGet = сacheModul.Сommand(comondModul.GetComond(typeof(IUser), TypeComond.Get, null));
            }
            if (repository.amount(TypeComond.Get) != 1)
            {
                throw new Exception("CachModul отпровляет много запросов get вместо одного");
            }
        }
示例#18
0
        public void CreatСacheModul()
        {
            FaceRepository repository = new FaceRepository();
            СacheModul     сacheModul = new СacheModul(repository);



            for (int i = 0; i < 5; i++)
            {
                IComondModul <IMyEntity> comondGet = сacheModul.Сommand(comondModul.GetComond(typeof(IUser), TypeComond.Get, null));
            }


            Assert.AreEqual(1, repository.amount(TypeComond.Get));
        }
示例#19
0
        protected override IComondModul <IMyEntity> СommandStartEternalModul(IComondModul <IMyEntity> comond)
        {
            comond = base.СommandStartEternalModul(comond);
            if (comond.Data != null && kernelТекущая != null)
            {
                IList <IMyEntity> раскр = new List <IMyEntity> ();

                foreach (IMyEntity iter in comond.Data)
                {
                    раскр.Add(iter.Date);
                }

                comond.SetData(раскр);
            }
            return(comond);
        }
示例#20
0
 protected override IComondModul <IMyEntity> СommandEnd(IComondModul <IMyEntity> comond)
 {
     if (comond.Action == TypeComond.Get || comond.Action == TypeComond.Сreate)
     {
         foreach (IMyEntity Iter in comond.Answer)
         {
             Iter.PropertyChanged += Iter_ChangedEntity;
         }
     }
     else if (comond.Action == TypeComond.Remove)
     {
         foreach (IMyEntity Iter in comond.Answer)
         {
             Iter.PropertyChanged -= Iter_ChangedEntity;
         }
     }
     if (comond.Action == TypeComond.Сreate || comond.Action == TypeComond.Remove)
     {
         Save();
     }
     return(base.СommandEnd(comond));
 }
示例#21
0
        protected override IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            if (comond.Action == TypeComond.Get)
            {
                if (data.ContainsKey(comond.TypeModel))
                {
                    comond.SetAnswer(data[comond.TypeModel].ToList());
                }
            }
            else if (comond.Action == TypeComond.Сreate)
            {
                ConstructorInfo ci      = comond.TypeModel.GetConstructor(new Type[] { });
                object          создали = ci.Invoke(new object[] { });
                if (создали is IMyEntity новый)
                {
                    IList <IMyEntity> myEntities = new List <IMyEntity> {
                        новый
                    };
                    comond.SetAnswer(myEntities);
                    if (data.ContainsKey(comond.TypeModel))
                    {
                        ((IList <IMyEntity>)data[comond.TypeModel]).Add(новый);
                    }
                    else
                    {
                        IDictionary <Type, IEnumerable <IMyEntity> > newData = data.ToDictionary(r => r.Key, r2 => r2.Value);
                        newData.Add(comond.TypeModel, myEntities);
                        data = newData;
                    }
                }


                throw new Exception("Создоваемый объект не неаследует IMyEntity");
            }
            else if (comond.Action == TypeComond.Remove)
            {
                if (data.ContainsKey(comond.TypeModel))
                {
                    foreach (IMyEntity entity in comond.Data)
                    {
                        if (((IList <IMyEntity>)data[comond.TypeModel]).Contains(entity))
                        {
                            ((IList <IMyEntity>)data[comond.TypeModel]).Remove(entity);
                        }
                    }
                }

                comond.SetAnswer(comond.Data.ToList());
            }

            if (dataInt.ContainsKey(comond.Action))
            {
                dataInt[comond.Action] = dataInt[comond.Action] + 1;
            }
            else
            {
                dataInt.Add(comond.Action, 1);
            }

            return(comond);
        }
示例#22
0
        /* public IComondModul<IMyEntity> GetComondModul(Type type, TypeComond action, IEnumerable<IMyEntity> date)
         * {
         *   return  ComondModul<IMyEntity>.GetComond(type, action, date);
         * }*/

        protected virtual IComondModul <IMyEntity> СommandStart(IComondModul <IMyEntity> comond)
        {
            return(comond);
        }
示例#23
0
 protected virtual IComondModul <IMyEntity> СommandStartInsideModulRequest(IComondModul <IMyEntity> comond)
 {
     return(comond);
 }
示例#24
0
 protected virtual IComondModul <IMyEntity> СommandEndEternalModul(IComondModul <IMyEntity> comond)
 {
     return(comond);
 }
示例#25
0
 protected virtual IComondModul <IMyEntity> СommandEndInsideModulAnswer(IComondModul <IMyEntity> comond)
 {
     return(comond);
 }