Esempio n. 1
0
        private static object CreateDataContext(object arg)
        {
            var provider            = Get(arg);
            var sectionNameProvider = provider.Get <IDataContextConfigSectionNameProvider>();

            var dataContextFactory = DataContextFactoryProvider.GetFactory();
            var dataContext        = dataContextFactory.CreateMultiDc(sectionNameProvider.GetSectionName());

            return(dataContext);
        }
        /// <summary>
        /// Проверяет данные подлючающегося клиента
        /// </summary>
        /// <param name="userName">Логин клиента</param>
        /// <param name="password">Пароль клиента</param>
        public override void Validate(string userName, string password)
        {
            try
            {
                //using (var connection = new EntityConnection("name=cissaEntities"))
                {
                    //using (var dataContext = new DataContext(connection))
                    {
                        BaseServiceFactory.CreateBaseServiceFactories();

                        var dataContextFactory = DataContextFactoryProvider.GetFactory();
                        using (var multiDC = dataContextFactory.CreateMultiDc(BaseServiceFactory.DataContextConfigSectionName))
                        {
                            var providerFactory = AppServiceProviderFactoryProvider.GetFactory();
                            var serviceProvider = providerFactory.Create(multiDC);

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

                            if (userRepo.Validate(userName, password))
                            {
                                return;
                            }
                        }

                        Thread.Sleep(1000); // притормозим выполнение для сложности подбора пароля
                        throw new SecurityTokenException("Unknown Username or Password");
                    }
                }
            }
            catch (Exception e)
            {
                try
                {
                    using (var writer = new StreamWriter(Logger.GetLogFileName("bizServiceValidate"), true))
                    {
                        writer.WriteLine("{0}: Log error for username: \"{1}\"; message: \"{2}\"",
                                         DateTime.Now,
                                         userName, e.Message);
                        if (e.InnerException != null)
                        {
                            writer.WriteLine("  - inner exception: \"{0}\"", e.InnerException.Message);
                        }
                        writer.WriteLine("  -- Stack: {0}", e.StackTrace);
                        writer.WriteLine(Directory.GetCurrentDirectory());
//                        writer.WriteLine(HostingEnvironment.MapPath("."));
                    }
                }
                catch
                {
                    // ignored
                }
                throw;
            }
        }
Esempio n. 3
0
//        private static readonly Logger Log = LogManager.GetCurrentClassLogger();

        public BizService()
        {
            try
            {
                _monitor = new Monitor("BizService session");

                /*Connection = new EntityConnection("name=cissaEntities");
                 * _ownConnection = true;*/
                CurrentUserName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
//              Log.Info(string.Format("Система запущена пользователем {0}", CurrentUserName));

                //var dc = new DataContext(Connection);
                var dataContextFactory = DataContextFactoryProvider.GetFactory();

                _dataContext    = dataContextFactory.CreateMultiDc(BaseServiceFactory.DataContextConfigSectionName); //new MultiDataContext(/*new[] {dc}*/);
                _ownDataContext = true;

                var providerFactory = AppServiceProviderFactoryProvider.GetFactory();
                Provider = providerFactory.Create(DataContext);

                UserRepo = Provider.Get <IUserRepository>(); // new UserRepository(Provider);

                var serviceRegistrator = Provider.Get <IAppServiceProviderRegistrator>();
                serviceRegistrator.AddService(new UserDataProvider(CurrentUserId, CurrentUserName));

                EnumRepo   = Provider.Get <IEnumRepository>();           //new EnumRepository(Provider);
                DocRepo    = Provider.Get <IDocRepository>();            //new DocRepository(DataContext, CurrentUserId);
                DocDefRepo = Provider.Get <IDocDefRepository>();
                FormRepo   = Provider.Get <IFormRepository>();           //new FormRepository(DataContext, CurrentUserId);
                var workflowRepo = Provider.Get <IWorkflowRepository>(); //new WorkflowRepository(DataContext);
                WorkflowRepo   = workflowRepo;
                WorkflowEngine = Provider.Get <IWorkflowEngine>();
                //new WorkflowEngine(DataContext, workflowRepo, CurrentUserId);

                ReportGeneratorProvider = Provider.Get <ITemplateReportGeneratorProvider>();
                //new TemplateReportGeneratorProvider(DataContext, CurrentUserId);
                //PdfTempRepo = new PdfTemplateRepository(DataContext, CurrentUserId);
                //ExcelTempRepo = new ExcelTemplateRepository(DataContext, CurrentUserId);
                LangRepo = Provider.Get <ILanguageRepository>();

                _sqlQueryBuilderFactory = Provider.Get <ISqlQueryBuilderFactory>();
                _sqlQueryReaderFactory  = Provider.Get <ISqlQueryReaderFactory>();
                _comboBoxValueProvider  = Provider.Get <IComboBoxEnumProvider>();

                _id = RegisterProcess(CurrentUserId, CurrentUserName);
            }
            catch (Exception e)
            {
                Logger.OutputLog(e, "BizService construction");
                throw;
            }
        }
Esempio n. 4
0
        static IAppServiceProvider InitProvider(string username, Guid userId)
        {
            var dataContextFactory = DataContextFactoryProvider.GetFactory();

            var dataContext = dataContextFactory.CreateMultiDc("DataContexts");

            BaseServiceFactory.CreateBaseServiceFactories();
            var providerFactory    = AppServiceProviderFactoryProvider.GetFactory();
            var provider           = providerFactory.Create(dataContext);
            var serviceRegistrator = provider.Get <IAppServiceProviderRegistrator>();

            serviceRegistrator.AddService(new UserDataProvider(userId, username));
            return(provider);
        }
Esempio n. 5
0
        public BizService(string userName)
        {
            _monitor = new Monitor("BizService session");

            /*Connection = new EntityConnection("name=cissaEntities");
             * _ownConnection = true;*/
            CurrentUserName = userName;

            //var dc = new DataContext(Connection);
            var dataContextFactory = DataContextFactoryProvider.GetFactory();

            _dataContext    = dataContextFactory.CreateMultiDc(BaseServiceFactory.DataContextConfigSectionName); //new MultiDataContext(/*new[] { dc }*/);
            _ownDataContext = true;

            var providerFactory = AppServiceProviderFactoryProvider.GetFactory();

            Provider = providerFactory.Create(DataContext);

            UserRepo = Provider.Get <IUserRepository>(); // new UserRepository(Provider);

            var serviceRegistrator = Provider.Get <IAppServiceProviderRegistrator>();

            serviceRegistrator.AddService(new UserDataProvider(CurrentUserId, CurrentUserName));

            EnumRepo   = Provider.Get <IEnumRepository>();           //new EnumRepository(Provider);
            DocRepo    = Provider.Get <IDocRepository>();            //new DocRepository(DataContext, CurrentUserId);
            DocDefRepo = Provider.Get <IDocDefRepository>();
            FormRepo   = Provider.Get <IFormRepository>();           //new FormRepository(DataContext, CurrentUserId);
            var workflowRepo = Provider.Get <IWorkflowRepository>(); //new WorkflowRepository(DataContext);

            WorkflowRepo   = workflowRepo;
            WorkflowEngine = Provider.Get <IWorkflowEngine>(); //new WorkflowEngine(DataContext, workflowRepo, CurrentUserId);

            ReportGeneratorProvider = Provider.Get <ITemplateReportGeneratorProvider>();
            //new TemplateReportGeneratorProvider(DataContext, CurrentUserId);
            //PdfTempRepo = new PdfTemplateRepository(DataContext, CurrentUserId);
            //ExcelTempRepo = new ExcelTemplateRepository(DataContext, CurrentUserId);
            LangRepo = Provider.Get <ILanguageRepository>();

            _sqlQueryBuilderFactory = Provider.Get <ISqlQueryBuilderFactory>();
            _sqlQueryReaderFactory  = Provider.Get <ISqlQueryReaderFactory>();
            _comboBoxValueProvider  = Provider.Get <IComboBoxEnumProvider>();

            _id = RegisterProcess(CurrentUserId, CurrentUserName);
        }
        public Service()
        {
            if (dataContextFactory == null)
            {
                dataContextFactory = DataContextFactoryProvider.GetFactory();

                if (dataContext == null)
                {
                    dataContext = dataContextFactory.CreateMultiDc("DataContexts");
                    BaseServiceFactory.CreateBaseServiceFactories();
                    if (providerFactory == null)
                    {
                        providerFactory = AppServiceProviderFactoryProvider.GetFactory();
                        if (provider == null)
                        {
                            provider = providerFactory.Create(dataContext);
                        }
                    }
                }
            }
        }