예제 #1
0
        public void AppServiceProviderTest()
        {
            using (var connection = new SqlConnection(ConnectionString))
            {
                using (var dataContext = new DataContext(connection))
                {
                    //AppServiceProvider.SetServiceFactoryFunc(typeof (IUserRepository), CreateFakeUserRepository);
                    using (var multiDc = new MultiDataContext(new[] { dataContext }))
                    {
                        var service = new BizService.BizService(multiDc, "D");
                        try
                        {
                            Console.WriteLine(@"Count of AppServiceProvider Factory functions: {0}",
                                              AppServiceProvider.TypeFactoryFuncs.Count);
                            Console.WriteLine(@"Count of Services in AppServiceProvider: {0}",
                                              service.Provider.GetServiceCount());

                            Assert.IsNotNull(service);
                            service.TryConnect();
                        }
                        finally
                        {
                            service.Dispose();
                        }
                        service = new BizService.BizService(service.Provider, "D");
                        try
                        {
                            Console.WriteLine(@"Count of AppServiceProvider Factory functions: {0}",
                                              AppServiceProvider.TypeFactoryFuncs.Count);
                            Console.WriteLine(@"Count of Services in AppServiceProvider: {0}",
                                              service.Provider.GetServiceCount());

                            Assert.IsNotNull(service);

                            var userInfo = service.GetUserInfo();
                            Assert.IsNotNull(userInfo);
                            Console.WriteLine(userInfo.OrganizationName);
                            foreach (var l in service.GetLanguages())
                            {
                                Console.Write(l.Name, " ");
                            }
                        }
                        finally
                        {
                            service.Dispose();
                        }
                    }
                }
            }
        }
예제 #2
0
        public void ValidateSecurityUserName()
        {
            //using (var connection = new SqlConnection(ConnectionString))
            {
                //using (var dataContext = new DataContext(connection))
                {
                    BaseServiceFactory.CreateBaseServiceFactories();

                    using (var multiDc = new MultiDataContext(BaseServiceFactory.DataContextConfigSectionName /*new[] {dataContext}*/))
                    {
                        var providerFactory = AppServiceProviderFactoryProvider.GetFactory();
                        var serviceProvider = providerFactory.Create(multiDc);

                        var userRepo = serviceProvider.Get <IUserRepository>(); //new UserRepository(dataContext);

                        Console.WriteLine(userRepo.GetType().Name);
                        Assert.IsTrue(userRepo.Validate("R", "803"));
                    }
                }
            }
        }
예제 #3
0
        public void TestMethod2()
        {
            using (var connection = new SqlConnection(ChatkalConnectionString))
            {
                using (var dataContext = new DataContext(connection))
                {
                    using (var mdc = new MultiDataContext(new[] { dataContext }))
                    {
                        var factory = AppServiceProviderFactoryProvider.GetFactory();
                        using (var provider = factory.Create())
                        {
                            var defRepo = provider.Get <IDocDefRepository>(); // new DocDefRepository(dataContext);
                            var docDef  = defRepo.DocDefByName("Person-Sheet");

                            using (var def = new XlsDef())
                            {
                                // Header
                                def.Style.FontName = "Arial Narrow";
                                def.AddArea().AddRow().AddEmptyCell();
                                def.AddArea().AddRow().AddText("Список граждан");
                                def.AddArea().AddRow().AddEmptyCell();

                                // Grid Header
                                var h1 = def.AddArea().AddRow();
                                foreach (var attr in docDef.Attributes)
                                {
                                    h1.AddNode(attr.Name).ShowAllBorders(true);
                                }

                                var qb = new QueryBuilder(docDef.Id);
                                qb.Where("LastName").Contains("ИВАН");

                                var sqlQueryBuilder = provider.Get <ISqlQueryBuilder>();
                                var query           = sqlQueryBuilder.Build(qb.Def);
                                query.AddAttribute("&Id");
                                var list = new List <Guid>();
                                using (var r = new SqlQueryReader(dataContext, query))
                                    while (r.Read())
                                    {
                                        list.Add(r.GetGuid(0));
                                    }
                                using (var docDataSet = new DocDataSet(provider, dataContext, list, Guid.Empty))
                                {
                                    var gridRow = def.AddGrid(docDataSet).AddRow();
                                    foreach (var attr in docDef.Attributes)
                                    {
                                        gridRow.ShowAllBorders(true);
                                        gridRow.Style.AutoWidth  = true;
                                        gridRow.Style.AutoHeight = true;
                                        gridRow.AddDataField(new DocDataSetField(docDataSet, attr));
                                    }

                                    var builder  = new XlsBuilder(def);
                                    var workbook = builder.Build();
                                    using (
                                        var stream = new FileStream(@"c:\distr\cissa\testXlsDefPersons.xls", FileMode.Create))
                                    {
                                        workbook.Write(stream);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }