Example #1
0
 public IEnumerable <match> GetAllMatches()
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.matches.ToList());
     }
 }
Example #2
0
 public user GetUserByName(string userName)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.users.FirstOrDefault(l => l.Name == userName));
     }
 }
Example #3
0
 public IEnumerable <user> SearchUser(string name)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.users.Where(l => l.Name.Contains(name) || l.Info.Contains(name)).ToList());
     }
 }
Example #4
0
        public IEnumerable <MatchAttach> GetAttachsByIDAndType(int id, string type)
        {
            var context = ContextHelper.CreateContext <MatchEntities>();
            var result  = new List <MatchAttach>();

            context.attaches.Where(l => l.Type == type && l.TypeID == id).ToList().ForEach(l =>
            {
                var attach = l.CopyTo <MatchAttach>();
                try
                {
                    attach.URL  = new Uri(HttpContext.Current.Request.Url, l.Path).AbsoluteUri;
                    var path    = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~"), l.Path);
                    attach.Size = new System.IO.FileInfo(path).Length;
                    var file    = ShellFile.FromFilePath(path);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    file.Thumbnail.MediumBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    attach.Thumbnail = ms.ToArray();
                }
                catch (Exception e) { }
                finally
                {
                    result.Add(attach);
                }
            });
            return(result);
        }
Example #5
0
 public IEnumerable <user> GetAllUsers()
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.users.ToList());
     }
 }
Example #6
0
        public void TestRebindSingletonToSingleton()
        {
            IDIContext context = ContextHelper.CreateContext();

            context.s().Bind <IMyClass>(() => new MyClass());

            IDIContext childContext = ContextHelper.CreateContext(context);

            childContext.s().Rebind <IMyClass>();

            IMyClass a1 = context.Resolve <IMyClass>();
            IMyClass a2 = context.Resolve <IMyClass>();

            Assert.AreSame(a1, a2);

            IMyClass b1 = childContext.Resolve <IMyClass>();
            IMyClass b2 = childContext.Resolve <IMyClass>();

            Assert.AreSame(b1, b2);
            Assert.AreNotSame(b1, a1);
            Assert.AreNotSame(b2, a2);


            IBinding d1 = context.Introspect <IMyClass>();

            Assert.AreEqual(InstantiationType.Concrete, d1.instantiationType);
            Assert.AreEqual(context, d1.context);

            IBinding d2 = childContext.Introspect <IMyClass>();

            Assert.AreEqual(InstantiationType.Concrete, d2.instantiationType);
            Assert.AreEqual(childContext, d2.context);
        }
Example #7
0
        public virtual T Create <T>(string sceneName, bool destroyableObjects, string bindingName = null,
                                    Action <IDIContext> customContextInitializer = null, Func <IConstruction> construction = null)
            where T : class, ISceneObject
        {
            if (environment != ContextEnvironment.RemoteObjects)
            {
                throw new MindiException("SceneFactory can only work in the Remote objects environment");
            }

            IDIContext newContext = ContextHelper.CreateContext(this.context);

            if (destroyableObjects)
            {
                newContext.s().BindInstance <MBLifeTime>(MBLifeTime.DestroyWithScene);
            }

            IList <ISceneContextInitializer> initializers = ContextBuilder.Initialize <ISceneContextInitializer>(newContext, new SceneContextAttribute(sceneName));

            BindObjectsRecord(newContext);

            if (customContextInitializer != null)
            {
                customContextInitializer(newContext);
            }

            return(CreateScene <T>(newContext, initializers, sceneName, bindingName, construction));
        }
Example #8
0
        public static void Main(string[] args)
        {
            IDIContext context = ContextHelper.CreateContext <IGlobalContextInitializer>().Reproduce <IApplicationContextInitializer>();
            var        world   = context.Resolve <IWorld>();

            world.Run();
        }
Example #9
0
        public void TestGenericRebinding()
        {
            IDIContext context = ContextHelper.CreateContext();

            context.s().BindInstance <ContextEnvironment>(ContextEnvironment.Normal);
            context.m().BindGeneric(typeof(IDIFactory <>), typeof(ContextFactory <>));
            context.m().BindGeneric(typeof(IDIRFactory <,>), typeof(ReproduceContextFactory <,>));

            IDIContext childContext = ContextHelper.CreateContext(context);

            childContext.m().Bind <IMyClass>(() => new MyClass());
            childContext.s().Rebind <IDIFactory <IOtherClass> >();

            MyClass obj1 = childContext.Resolve <IMyClass>() as MyClass;

            Assert.That(obj1.factory is ContextFactory <IOtherClass>);
            Assert.That(obj1.chainFactory is ReproduceContextFactory <IOtherClass, IGlobalContextInitializer>);

            MyClass obj2 = childContext.Resolve <IMyClass>() as MyClass;

            Assert.That(obj2.factory is ContextFactory <IOtherClass>);
            Assert.That(obj2.chainFactory is ReproduceContextFactory <IOtherClass, IGlobalContextInitializer>);

            Assert.AreSame(obj1.factory, obj2.factory);
            Assert.AreNotSame(obj1.chainFactory, obj2.chainFactory);
        }
Example #10
0
        public void TestNamedParentIntrospection()
        {
            IDIContext parentContext = ContextHelper.CreateContext();

            parentContext.m().Bind <IApple>(() => new Apple(), BindingName.ForType <Apple>());

            IDIContext context = parentContext.Reproduce();

            context.m().Bind <IApple>(() => new BigApple(), BindingName.ForType <BigApple>());

            IBinding desc = context.Introspect <IApple>(BindingName.ForType <BigApple>());

            Assert.IsNotNull(desc);
            Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType);
            Assert.That(desc.context == context);
            object apple = desc.factory();

            Assert.That(apple is BigApple);

            desc = context.Introspect <IApple>();
            Assert.IsNotNull(desc);
            Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType);
            Assert.That(desc.context == context);
            apple = desc.factory();
            Assert.That(apple is BigApple);

            desc = context.Introspect <IApple>(BindingName.ForType <Apple>());
            Assert.IsNotNull(desc);
            Assert.AreEqual(InstantiationType.Abstract, desc.instantiationType);
            Assert.That(desc.context == parentContext);
            apple = desc.factory();
            Assert.That(apple is Apple);
        }
Example #11
0
 public IEnumerable <team> GetAllTeams()
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.teams.ToList());
     }
 }
Example #12
0
 public IEnumerable <faq_question> SearchFaqs(string keyWord)
 {
     if (string.IsNullOrEmpty(keyWord))
     {
         return(null);
     }
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         var result = context.faq_question.Where(l => l.Question.Contains(keyWord) || l.KeyWord.Contains(keyWord)).OrderByDescending(l => l.SearchCount).ToList();
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
             using (var context1 = ContextHelper.CreateContext <TestEntities>())
             {
                 result.ToList().ForEach(l =>
                 {
                     var q = context1.faq_question.FirstOrDefault(p => p.ID == l.ID);
                     if (q != null)
                     {
                         q.SearchCount = q.SearchCount.HasValue ? ++q.SearchCount : 1;
                     }
                 });
                 context1.SaveChanges();
             }
         });
         return(result);
     }
 }
        public async Task GetPageSortTest(string fieldName, SortType sortType, int[] ids)
        {
            //Arrange
            var teamProjects = Builder <ProjectTeam> .CreateListOfSize(10)
                               .All().WithFactory(i => new ProjectTeam(_testData.Projects[i].Id, 1))
                               .Build();

            var context = ContextHelper.CreateContext(_dbConnection, false);

            context.RemoveRange(_testData.ProjectTeams);
            await context.AddRangeAsync(teamProjects);

            await context.SaveChangesAsync();

            var field       = new FieldSort(fieldName, sortType);
            var pageOptions = new PageOptions
            {
                PageNumber = 0,
                PageSize   = 10,
                SortFields = new[] { field }
            };


            //Act
            var projects = (await _service.GetPage(_currentUser, 1, pageOptions)).ToArray();

            //Assert
            for (int i = 0; i < ids.Length; i++)
            {
                Assert.AreEqual(ids[i], projects[i].Id);
            }
        }
Example #14
0
 public int GetCountOfCategory(int categoryID)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_question.Where(l => l.CategoryID == categoryID).Count());
     }
 }
Example #15
0
 public IEnumerable <faq_question> GetAllQuestion()
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_question.ToList());
     }
 }
Example #16
0
 public IEnumerable <faq_user> GetAllUsers()
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_user.ToList());
     }
 }
Example #17
0
 public bool DeleteFaqByID(IEnumerable <int> faqID)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         context.faq_question.ToList().ForEach(l =>
         {
             if (faqID.Contains(l.ID))
             {
                 context.faq_question.Remove(l);
             }
         });
         context.SaveChanges();
         var root = System.Web.HttpContext.Current.Server.MapPath("~");
         System.Threading.Tasks.Task.Factory.StartNew(() =>
         {
             faqID.ToList().ForEach(l =>
             {
                 var dir = root + @"\ClientBin\Attach\" + l;
                 if (System.IO.Directory.Exists(dir))
                 {
                     System.IO.Directory.Delete(dir, true);
                 }
             });
         });
         return(true);
     }
 }
Example #18
0
 public IEnumerable <faq_category> GetAllCategorys()
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_category.ToList());
     }
 }
Example #19
0
        public IEnumerable <Attach> GetAttachsByQID(int id)
        {
            TestEntities context = ContextHelper.CreateContext <TestEntities>();
            var          result  = new List <Attach>();

            context.faq_attach.Where(l => l.QuestionID == id).ToList().ForEach(l =>
            {
                var attach = l.CopyTo <Attach>();
                try
                {
                    attach.URL  = new Uri(HttpContext.Current.Request.Url, string.Format("ClientBin/Attach/{0}/{1}", l.QuestionID, l.Path)).AbsoluteUri;
                    var path    = System.IO.Path.Combine(HttpContext.Current.Server.MapPath("~"), string.Format(@"ClientBin\Attach\{0}\{1}", l.QuestionID, l.Path));
                    attach.Size = new System.IO.FileInfo(path).Length;
                    var file    = ShellFile.FromFilePath(path);
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    file.Thumbnail.MediumBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    attach.Thumbnail = ms.ToArray();
                }
                catch (Exception e) { }
                finally
                {
                    result.Add(attach);
                }
            });
            return(result);
        }
Example #20
0
 public IEnumerable <team> SearchTeam(string name)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.teams.Where(l => l.Name.Contains(name)).ToList());
     }
 }
Example #21
0
 public faq_question GetQuestionByID(int id)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_question.FirstOrDefault(l => l.ID == id));
     }
 }
Example #22
0
 public IEnumerable <faq_answer> GetAnswersByID(int id)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_answer.Where(l => l.QuestionID == id).OrderBy(l => l.Order).ToList());
     }
 }
Example #23
0
 public match GetMatchByID(int id)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.matches.FirstOrDefault(l => l.ID == id));
     }
 }
Example #24
0
 public user GetUserByID(int id)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         return(context.users.FirstOrDefault(l => l.ID == id));
     }
 }
        public async Task GetPageFilterTest(int teamId, string filter, int expectedCount)
        {
            //Arrange
            var teamProjects = Builder <ProjectTeam> .CreateListOfSize(10)
                               .All().WithFactory(i => new ProjectTeam(_testData.Projects[i].Id, teamId))
                               .Build();

            var context = ContextHelper.CreateContext(_dbConnection, false);

            context.RemoveRange(_testData.ProjectTeams);
            await context.AddRangeAsync(teamProjects);

            await context.SaveChangesAsync();

            var pageOptions = new PageOptions
            {
                PageNumber = 0,
                PageSize   = 10,
                Filter     = filter,
            };

            //Act
            var projects = (await _service.GetPage(_currentUser, teamId, pageOptions)).ToArray();

            //Assert
            Assert.AreEqual(expectedCount, projects.Length);
        }
Example #26
0
 public IEnumerable <faq_question> GetPagedQuestions(int pageSize, int currentPage, int categoryID)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         return(context.faq_question.Where(l => l.CategoryID == categoryID).OrderByDescending(l => l.SearchCount).Skip(pageSize * currentPage).Take(pageSize).ToList());
     }
 }
Example #27
0
 public IEnumerable <string> GetImagesByQuestionID(int id)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         var baseuri = System.Web.HttpContext.Current.Request.Url;
         return(context.faq_attach.Where(l => l.QuestionID == id && l.Type == "Image").ToList().Select(l => new Uri(baseuri, "ClientBin/Attach/" + id + "/" + l.Path).AbsoluteUri));
     }
 }
Example #28
0
 public void AddAttaches(IEnumerable <attach> attaches)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         context.attaches.AddRange(attaches);
         context.SaveChanges();
     }
 }
Example #29
0
 public int AddOrUpdateTeam(team team)
 {
     using (var context = ContextHelper.CreateContext <MatchEntities>())
     {
         context.teams.AddOrUpdate(team);
         context.SaveChanges();
         return(team.ID);
     }
 }
Example #30
0
 public int AddAnswer(faq_answer answer)
 {
     using (var context = ContextHelper.CreateContext <TestEntities>())
     {
         context.faq_answer.Add(answer);
         context.SaveChanges();
         return(answer.ID);
     }
 }