Exemple #1
0
        public void LogServiceTest()
        {
            //LocatorCreator.Execute();



            var container = new WindsorContainer();

            container.Register(Component.For <ILoggerService>().ImplementedBy <DbLoggerService>().LifeStyle.BoundTo <IService>());
            //container.Register(Component.For<ILogRepository>().ImplementedBy<LogRepository>().LifeStyle.Transient);

            container.Register(Component.For <IConnectionProvider>()
                               .UsingFactoryMethod(c => new ConnectionProvider(() =>
            {
                var s = System.Configuration.ConfigurationManager.
                        ConnectionStrings["PMSDBConnection"].ConnectionString;
                var res = new SqlConnection(s);
                res.Open();
                return(res);
            })).LifestyleBoundTo <IService>());

            DataAccessConfigHelper.ConfigureContainer <UserRepository>(container,
                                                                       () =>
            {
                var session = PMSSecuritySession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "PMSSecurity");

            var locator = new WindsorServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);

            //var userRep = ServiceLocator.Current.GetInstance<UserRepository>();


            var uows = new MITD.Domain.Repository.UnitOfWorkScope(
                new Data.NH.NHUnitOfWorkFactory(() => PMSSecurity.Persistence.NH.PMSSecuritySession.GetSession()));



            using (var uow = new NHUnitOfWork(PMSSession.GetSession()))
                using (var uow2 = uows.CurrentUnitOfWork)
                {
                    var logFactory = new LoggerServiceFactory();
                    var logManager = new LogManagerService(logFactory);
                    var logService = new LogService(logManager);

                    var gid = Guid.NewGuid();
                    Log log = new EventLog(new LogId(gid), "diddd", LogLevel.Information, null, "clll", "mett", "ttttt", "mmmmmmm");

                    logService.AddEventLog(log.Code, log.LogLevel, null, log.ClassName, log.MethodName, log.Title, log.Messages);
                }
        }
Exemple #2
0
        public void LogTest()
        {
            using (var session = PMSSecuritySession.GetSession())
                using (session.BeginTransaction())
                {
                    LogRepository logRep = new LogRepository(new NHUnitOfWork(session));

                    var user = session.Get <User>(1);
                    var gid  = Guid.NewGuid();
                    Log log  = new EventLog(new LogId(gid), "diddd", LogLevel.Information, user, "clll", "mett", "ttttt", "mmmmmmm");

                    logRep.Add(log);
                    //session.Save(log);

                    var l = session.Get <Log>(22);
                    session.Transaction.Commit();
                }
        }
Exemple #3
0
        public void UserRepTest()
        {
            long uid   = 0;
            var  uname = Guid.NewGuid().ToString();

            using (var session = PMSSecuritySession.GetSession())
                using (session.BeginTransaction())
                {
                    //var gname = Guid.NewGuid().ToString();
                    //Group g = new Group(new PartyId(gname), "manahers and admiddjdb");
                    //Dictionary<ActionType, bool> gCustActs = new Dictionary<ActionType, bool>();
                    //gCustActs.Add(ActionType.AddClaim, true);
                    //gCustActs.Add(ActionType.ReplyClaim, false);
                    //g.UpdateCustomActions(gCustActs);


                    User u = new User(new PartyId(uname), "dssd", "sdfsd", "*****@*****.**");
                    Dictionary <ActionType, bool> custActs = new Dictionary <ActionType, bool>();
                    custActs.Add(ActionType.ManageCalculations, true);
                    custActs.Add(ActionType.ManageEmployees, false);

                    Group g = session.Get <Group>(26);

                    u.UpdateCustomActions(custActs);
                    u.AssignGroup(g);

                    session.Save(g);
                    session.Save(u);

                    session.Transaction.Commit();
                }

            using (var session = PMSSecuritySession.GetSession())
                using (session.BeginTransaction())
                {
                    //User u = new User(new UserId(uname), "dssd", "sdfsd", "*****@*****.**");
                    //rep.AddUser(u);
                    //var u = session.Get<User>(uname);
                    var u2 = session.Get <User>(50);
                    session.Transaction.Commit();
                }
        }
Exemple #4
0
        private static void RegisterDataAccess(WindsorContainer container)
        {
            container.Register(Component.For <IConnectionProvider>()
                               .UsingFactoryMethod(c => new ConnectionProvider(() =>
            {
                var s = System.Configuration.ConfigurationManager.
                        ConnectionStrings["PMSDBConnection"].ConnectionString;
                var res = new SqlConnection(s);
                res.Open();
                return(res);
            })).LifestyleBoundTo <IService>());

            DataAccessConfigHelper.ConfigureContainer <CustomFieldRepository>(container,
                                                                              () =>
            {
                var session = PMSAdminSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "PMSAdmin");

            DataAccessConfigHelper.ConfigureContainer <PeriodRepository>(container,
                                                                         () =>
            {
                var session = PMSSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "PMS");

            DataAccessConfigHelper.ConfigureContainer <RuleRepository>(container,
                                                                       () =>
            {
                var session = RuleEngineSession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "RuleEngine");

            DataAccessConfigHelper.ConfigureContainer <UserRepository>(container,
                                                                       () =>
            {
                var session = PMSSecuritySession.GetSession(container.Resolve <IConnectionProvider>().GetConnection());
                return(session);
            }, "PMSSecurity");

            registerExceptionConvertors();
        }
Exemple #5
0
        public static void ConfigeLocator()
        {
            var container = new WindsorContainer();

            container.Kernel.ComponentModelBuilder.RemoveContributor(
                container.Kernel.ComponentModelBuilder.Contributors.OfType <PropertiesDependenciesModelInspector>().Single());
            container.Register(
                Component.For <IFacadeService>().Interceptors(InterceptorReference.ForType <Interception>()).Last,
                Component.For <Interception>());

            RegisterDataAccess(container);



            container.Register(
                Classes.FromAssemblyContaining <CalculationMapper>()
                .BasedOn <IMapper>()
                .WithService.FromInterface()
                .LifestyleBoundToNearest <IService>(),
                Classes.FromAssemblyContaining <CalculationServiceFacade>()
                .BasedOn <IFacadeService>()
                .WithService.FromInterface()
                .LifestyleBoundTo <ApiController>(),
                Classes.FromThisAssembly().BasedOn <ApiController>().LifestyleTransient(),
                Classes.FromThisAssembly().BasedOn <Controller>().LifestyleTransient()
                );

            //container.Register(Component.For<IFacadeService>()
            //    .Interceptors(InterceptorReference.ForType<Interception>()).Anywhere,
            //    Component.For<Interception>()
            //    );



            container.Register(
                Component.For <ILoggerService>().ImplementedBy <DbLoggerService>().Named("DB").LifeStyle.BoundTo <IService>(),
                Component.For <ILoggerService>().ImplementedBy <FileLoggerService>().Named("File").LifeStyle.BoundTo <IService>(),
                Component.For <ILoggerService>().ImplementedBy <WindowsEventsLoggerService>().Named("WindowsEvent").LifeStyle.BoundTo <IService>()
                );


            container.Register
            (
                Classes.FromAssemblyContaining <MITD.PMS.Application.JobService>()
                .BasedOn <IService>().If(c => c.Namespace == typeof(MITD.PMS.Application.JobService).Namespace &&
                                         c.Name != typeof(MITD.PMS.Application.CalculatorEngine).Name
                                         &&
                                         c.Name != typeof(MITD.PMS.Application.JobIndexPointCalculator).Name
                                         &&
                                         c.Name != typeof(MITD.PMS.Application.CalculationDataProvider).Name
                                         )
                .WithService.FromInterface()
                .LifestyleBoundToNearest <IService>(),
                Classes.FromAssemblyContaining <FunctionService>()
                .BasedOn <IService>().If(c => c.Namespace == typeof(FunctionService).Namespace)
                .WithService.FromInterface()
                .LifestyleBoundToNearest <IService>(),
                Classes.FromAssemblyContaining <MITD.PMS.Domain.Service.RuleBasedPolicyEngineService>()
                .BasedOn <IService>().OrBasedOn(typeof(IConfigurator))
                .WithService.FromInterface()
                .LifestyleBoundToNearest <IService>(),


                Component.For <IRuleService>().ImplementedBy <RuleEngineService>()
                .LifestyleBoundToNearest <IService>(),
                Component.For <IServiceLocatorProvider>().ImplementedBy <LocatorProvider>()
                .DependsOn(new Hashtable {
                { "connectionName", "PMSDBConnection" }
            })
                .LifeStyle.BoundTo <IService>(),
                Component.For <IEventPublisher>().ImplementedBy <EventPublisher>()
                .LifestyleBoundTo <IService>(),
                Component.For <ISecurityService>().ImplementedBy <SecurityService>()
                .LifestyleBoundToNearest <IService>(),
                Component.For <ISecurityCheckerService>().ImplementedBy <SecurityCheckerService>()
                .LifestyleBoundToNearest <IService>(),
                Component.For <ILogService>().ImplementedBy <LogService>()
                .LifestyleBoundToNearest <IService>(),
                Component.For <ILogManagerService>().ImplementedBy <LogManagerService>()
                .LifestyleBoundToNearest <IService>(),
                Component.For <ILoggerServiceFactory>().ImplementedBy <LoggerServiceFactory>()
                .LifestyleBoundToNearest <IService>()

            );

            container.Register(
                Component.For <IInquiryJobIndexPointCreatorService>()
                .ImplementedBy <InquiryJobIndexPointCreatorService>()
                .LifeStyle.Transient);
            container.Register(
                Component.For <IPMSAdminService>().ImplementedBy <PMSAdminService>().LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IPMSSecurityService>().ImplementedBy <PMSSecurityService>().LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IJobPositionInquiryConfiguratorService>()
                .ImplementedBy <JobPositionInquiryConfiguratorService>()
                .LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IUnitInquiryConfiguratorService>()
                .ImplementedBy <UnitInquiryConfiguratorService>()
                .LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IJobIndexPointCalculatorProvider>()
                .ImplementedBy <JobIndexPointCalculatorProvider>()
                .LifeStyle.Singleton.IsDefault());

            container.Register(
                Component.For <IInquiryConfiguratorService>()
                .ImplementedBy <InquiryConfiguratorService>()
                .LifeStyle.Singleton.IsDefault());


            container.Register(
                Component.For <IPeriodBasicDataCopierService>()
                .ImplementedBy <PeriodBasicDataCopierService>()
                .LifeStyle.Singleton.IsDefault());

            //container.Register(
            //    Component.For<IEmployeePointCopierService>()
            //        .ImplementedBy<EmployeePointCopierService>()
            //        .LifestyleBoundToNearest<IService>());

            container.Register(
                Component.For <ICalculatorEngine>().ImplementedBy <CalculatorEngine>()
                .LifeStyle.Transient);

            container.Register(
                Component.For <ISecurityServiceFacade>().ImplementedBy <SecurityServiceFacade>()
                .LifeStyle.Transient);

            container.Register(
                Component.For(typeof(IServiceLifeCycleManager <>)).ImplementedBy(typeof(ServiceLifeCycleManager <>))
                .LifeStyle.Transient);

            //container.Register(
            //    Component.For<IPeriodServiceFactory>().ImplementedBy<PeriodServiceFactory>()
            //        .LifeStyle.Transient);

            container.Register(
                Component.For <ICalculationDataProvider>().ImplementedBy <CalculationDataProvider>()
                .LifeStyle.Transient);

            container.Register(
                Component.For <IJobIndexPointCalculator>().ImplementedBy <JobIndexPointCalculator>().LifeStyle.Transient);

            //container.Register(
            //    Component.For<Castle.DynamicProxy.IInterceptor>().ImplementedBy<Interception>().LifestyleBoundTo<IService>());

            container.Register(
                Component.For <IUserManagementService>().ImplementedBy <UserManagementService>().LifeStyle.Singleton);

            container.Register(
                Component.For <ICalculationEngineService>().ImplementedBy <CalculationEngineService>().LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IPeriodEngineService>().ImplementedBy <PeriodEngineService>().LifestyleBoundTo <IService>());

            container.Register(
                Component.For <IFaultExceptionAdapter>().ImplementedBy <CalculationFaultExceptionAdapter>().LifeStyle.Singleton);

            container.Register(
                Component.For <AccessPermission>().LifeStyle.Singleton);

            container.Register(
                Component.For <IEmailManager>().ImplementedBy <EmailManager>().LifeStyle.Singleton);


            var locator = new WindsorServiceLocator(container);

            ServiceLocator.SetLocatorProvider(() => locator);


            //var accessPermissionSetup=new AccessPermissionSetup();
            //accessPermissionSetup.Execute(ServiceLocator.Current.GetInstance<AccessPermission>(),
            //    container.Kernel.GetAssignableHandlers(typeof (IFacadeService)).Count());



            NHibernateInnerJoinSupport.Enable();
            PMSAdminSession.GetSession();
            PMSSession.GetSession();
            PMSSecuritySession.GetSession();
            RuleEngineSession.GetSession();
        }