コード例 #1
0
ファイル: Service.cs プロジェクト: arargame/LetsRoshLibrary
        public virtual bool Delete(Expression <Func <T, bool> > filter)
        {
            var isCommitted = false;

            Guid?entityId = null;

            try
            {
                using (var uow = new Dota2UnitofWork())
                {
                    var repository = Repository.SetContext(uow.Context);

                    var existingEntity = repository.Get(filter, repository.GetAllIncludes());

                    entityId = existingEntity?.Id;

                    if (!repository.Delete(existingEntity))
                    {
                        throw new Exception(string.Format("{0} Delete Exception", repository.GetType().Name));
                    }

                    isCommitted = uow.Commit();
                }
            }
            catch (Exception ex)
            {
                Log.Save(new Log(ex.Message, entityId: entityId?.ToString()));
            }

            return(isCommitted);
        }
コード例 #2
0
ファイル: Log.cs プロジェクト: arargame/LetsRoshLibrary
        public static void Save(Log log)
        {
            Task <bool> t = new Task <bool>(new Func <bool>(() =>
            {
                Thread.Sleep(2000 - DateTime.Now.Millisecond);

                //MsSqlConnection connection = new MsSqlConnection();

                //return SqlManager.ExecuteNonQuery("insert into Log (LogType,Category,Name,Description,EntityId,AddedDate,ModifiedDate,IsActive)"
                //                            + " values(@LogType,@Category,@Name,@Description,@EntityId,@AddedDate,@ModifiedDate,1)",
                //    new Dictionary<string, object>()
                //    {
                //        { "@LogType", log.LogType },
                //        { "@Category",log.Category },
                //        { "@Name", log.Name },
                //        { "@Description", log.Description.Replace("'"," ") },
                //        { "@EntityId", log.EntityId ?? (object)DBNull.Value },
                //        { "@AddedDate", DateTime.Now },
                //        { "@ModifiedDate", DateTime.Now }
                //    }) == 1;

                using (var uow = new Dota2UnitofWork())
                {
                    uow.Load <Log>().Create(log);

                    return(uow.Commit());
                }
            }));

            t.Start();
        }
コード例 #3
0
ファイル: Service.cs プロジェクト: arargame/LetsRoshLibrary
        public bool Create(T entity)
        {
            var isCommitted = false;

            using (var uow = new Dota2UnitofWork())
            {
                Repository.SetContext(uow.Context).Create(entity);

                isCommitted = uow.Commit();
            }

            return(isCommitted);
        }
コード例 #4
0
ファイル: Service.cs プロジェクト: arargame/LetsRoshLibrary
        public T Get(Expression <Func <T, bool> > filter, params string[] includes)
        {
            T entity = null;

            using (var uow = new Dota2UnitofWork())
            {
                entity = uow.Load <T>().Get(filter, includes);

                uow.Load <T>().ShowChangeTrackerEntriesStates();

                uow.Commit();
            }

            return(entity);
        }
コード例 #5
0
ファイル: Service.cs プロジェクト: arargame/LetsRoshLibrary
        public bool Update(T entity)
        {
            var isCommitted = false;

            using (var uow = new Dota2UnitofWork())
            {
                if (!Repository.SetContext(uow.Context).Update(entity))
                {
                    return(false);
                }

                isCommitted = uow.Commit();
            }

            return(isCommitted);
        }
コード例 #6
0
ファイル: Service.cs プロジェクト: arargame/LetsRoshLibrary
        public bool CreateOrUpdate(T entity)
        {
            var isCommitted = false;

            using (var uow = new Dota2UnitofWork())
            {
                var repository = Repository.SetContext(uow.Context);

                if (!(repository.IsItNew(entity) ? repository.Create(entity) : repository.Update(entity)))
                {
                    return(false);
                }

                isCommitted = uow.Commit();
            }

            return(isCommitted);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: arargame/LetsRoshLibrary
        static void Main()
        {
            //var heroes = HeroService.LoadFromDota2Com("tiny", Language.LanguagesFromDota2.Where(l => l.Name == "turkish").FirstOrDefault()).Result;
            var heroes = HeroService.LoadFromDota2Com("omniknight", Language.LanguagesFromDota2.Where(l => l.Name == "turkish").FirstOrDefault()).Result;

            //Func<Hero> populatePersistent = () =>
            //{
            //    using (var uow = new Dota2UnitofWork())
            //    {
            //        var repository = new HeroRepository(uow.Context);

            //        return repository.Select(repository.UniqueFilter(heroes.FirstOrDefault()), repository.GetAllIncludes())
            //        .Select(q => new
            //        {
            //            q.Id,
            //            q.Name,
            //            Image = new
            //            {
            //                Id = (Guid?)q.Image.Id,
            //                q.Image.Name,
            //                q.Image.Path,
            //                q.Image.Data
            //            },
            //            Localizations = q.Localizations.Select(l => new
            //            {
            //                l.Id,
            //                l.BaseObjectId,
            //                l.LanguageId,
            //                l.PropertyName
            //            }),
            //            Skills = q.Skills.Select(s => new
            //            {
            //                s.Id,
            //                s.CharacterId,
            //                s.Name,
            //                Image = new
            //                {
            //                    Id = (Guid?)s.Image.Id,
            //                    s.Image.Name,
            //                    s.Image.Path,
            //                    s.Image.Data
            //                },
            //                Localizations = s.Localizations.Select(l => new
            //                {
            //                    l.Id,
            //                    l.BaseObjectId,
            //                    l.LanguageId,
            //                    l.PropertyName
            //                }),
            //            })

            //        })
            //        .ToList()
            //        .Select(l => new Hero()
            //        {
            //            Id = l.Id,
            //            Name = l.Name,
            //            Image = new ImageService().AnonymousTypeToT(l.Image),
            //            Localizations = l.Localizations.Select(ll=>new LocalizationService().AnonymousTypeToT(ll)).ToList(),
            //            Skills = l.Skills.Select(ls=>new SkillService().AnonymousTypeToT(ls)).ToList()
            //        })
            //        .SingleOrDefault();
            //    }
            //};

            //var x = populatePersistent();


            //using (var uow = new Dota2UnitofWork())
            //{
            //    var rep = new CharacterRepository(uow.Context);

            //    var chars = rep.Select().ToList();
            //}

            //Logda fazlalık var Create Hero da
            // parametreli ve paralel işlemeli Hero.Load
            //Log ta id ler gelebilir
            // Log ta total etkilenen nesneleri toparlıyor 2000 tane nesne insert edildi diye



            foreach (var hero in heroes)
            {
                var heroService = new HeroService();

                heroService.ConvertToPersistent(hero);

                Console.WriteLine("{0} : {1}", hero.Name, heroService.CreateOrUpdate(hero));
            }



            //using (var uow = new Dota2UnitofWork())
            //{
            //    var rep = new HeroRepository(uow.Context);

            //    foreach (var hero in heroes)
            //    {
            //        rep.Create(hero);

            //        var bb = uow.Commit();
            //    }
            //}


            //var imageService = new ImageService();
            //var img = imageService.Get(i=>i.Id.ToString()== "C5C3910A-ECA1-EA11-BA95-C8D3FF210A02");

            //var itemService2 = new ItemService();

            //var abyssal_blade = itemService2.Select(i=>i.LinkParameter== "abyssal_blade",ItemRepository.AllIncludes).FirstOrDefault();

            ////img.Id = Guid.NewGuid();

            ////abyssal_blade.Image = img;

            //itemService2.ConvertToPersistent(abyssal_blade);

            //var ggg = itemService2.CreateOrUpdate(abyssal_blade);



            //var il = new List<Item>()
            //{
            //    new Item(){LinkParameter="X1"},
            //    new Item(){LinkParameter="X2"},
            //};

            //var x = il.Any(new UniqueFilter<Item>().Get(new Item() { LinkParameter = "X2" }).Compile());

            var itemService = new ItemService();



            //var list = itemService.Select(includes: ItemRepository.AllIncludes);
            //language: Language.LanguagesFromDota2.Where(l => l.Name == "bulgarian").FirstOrDefault()

            //var webResults = ItemService.LoadFromDota2Com(language: Language.LanguagesFromDota2.Where(l => l.Name == "bulgarian").FirstOrDefault()).Result;

            var webResults = new ItemService().Select(i => i.Localizations.Any(l => l.Language.Name == "bulgarian"), new ItemRepository().GetAllIncludes());

            //webResults.OrderBy(wr => wr.LinkParameter).FirstOrDefault().Localizations.FirstOrDefault().Language = new Language() { Name = "test", Code = "tst" };

            //var it = webResults.FirstOrDefault();
            //itemService.ConvertToPersistent(it);

            //using (var uow = new Dota2UnitofWork())
            //{
            //    var imageRepository = new ImageRepository(uow.Context);

            //   // var unique = imageRepository.GetUnique(it.Image,true);

            //    var ddgsg = imageRepository.Create(it.Image);

            //    var ddgsg2= uow.Commit();
            //}

            var counter = 0;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            foreach (var result in webResults.OrderBy(wr => wr.LinkParameter))
            {
                itemService.ConvertToPersistent(result);

                result.Localizations.FirstOrDefault().Description = "test";

                var bb102012 = itemService.CreateOrUpdate(result);

                if (!bb102012)
                {
                    throw new Exception();
                }

                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("lp : {0},counter = {1},id= {2}", result.LinkParameter, counter, result.Id);
                Console.ForegroundColor = ConsoleColor.White;
            }

            sw.Stop();

            Console.ReadLine();

            //var persistentItem = itemService.Select(includes:ItemRepository.AllIncludes).FirstOrDefault();

            var persistentItem = new Item()
            {
                LinkParameter = "blink1010"
            };

            itemService.Update(persistentItem);

            //using (var uow =new Dota2UnitofWork())
            //{
            //    var imageRepository = new ImageRepository(uow.Context);

            //    var xcc = imageRepository.Get(persistentItem.ImageId.Value, imageRepository.GetAllIncludes());

            //    var b = imageRepository.Any(imageRepository.UniqueFilter(persistentItem.Image));
            //}

            itemService.ConvertToPersistent(persistentItem);

            //itemService.Update(list.FirstOrDefault());


            var itemSample = new ItemService().Get(i => i.LinkParameter == "blink", new ItemRepository().GetAllIncludes());

            var lclclc = new Localization(itemSample, Language.LanguagesFromDota2.FirstOrDefault(), "className", "propertyName", Guid.NewGuid().ToString());

            lclclc.BaseObjectId = itemSample.Id;
            lclclc.LanguageId   = lclclc.Language.Id;
            lclclc.Name         = DateTime.Now.ToString();

            itemSample.AddLocalization(lclclc);

            itemSample.Image = new Image()
            {
                Id = itemSample.Image.Id, Data = Encoding.UTF8.GetBytes(DateTime.Now.ToString())
            };
            itemSample.Image.Name = DateTime.Now.ToString();

            itemSample.Lore = "Lorem ımpsum : " + Guid.NewGuid();

            //itemSample.Localizations.Clear();



            using (var uow = new Dota2UnitofWork())
            {
                var itemRepository = new ItemRepository(uow.Context);

                itemRepository.Update(itemSample);

                var b1012010 = uow.Commit();
            }



            Console.ReadLine();
        }