Esempio n. 1
0
        private void initPersistence(bool configureModules = true)
        {
            IPersistenceManager pManager = PersistenceFactory.GetPersistenceManager(); // just to prepare data access environment

            pManager.Configure(AppConfiguration.DefaultApplicationConnection.ConnectionString,
                               AppConfiguration.DatabaseDialect, "Default", AppConfiguration.ShowQueries, configureModules);

            if (AppConfiguration.CreateDatabase)
            {
                pManager.ExportSchema();
            }
            pManager.Start();

            // If there is any active module in catalong at the DB creation time, it would be automatically installed.
            // Installation means, the modules' Install method is called, which usually generates the seed data
            if (AppConfiguration.CreateDatabase)
            {
                IModuleSeedDataGenerator shellSeedDataGenerator = IoCFactory.Container.Resolve <IModuleSeedDataGenerator>();
                shellSeedDataGenerator.GenerateSeedData();
                installModuleOnFreshDatabase();
            }
            // if there are pending modules, their schema (if exists) must be applied.
            else if (ModuleManager.HasPendingInstallation())
            {
                insatllPendingModules(pManager);
            }
        }
Esempio n. 2
0
        protected void Application_End()
        {
            ModuleManager.ShutdownModules();
            IPersistenceManager pManager = PersistenceFactory.GetPersistenceManager();

            pManager.Shutdown(); // release all data access related resources!
            IoCFactory.ShutdownContainer();
        }
Esempio n. 3
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            Experiment         exp  = new Experiment(textBox1.Text);
            List <Measurement> list = new List <Measurement>();

            list.Add(recorder.getRecording());
            exp.AddMeasurements(list);
            PersistenceFactory.GetPersistenceManager().AddExperiment(exp);
        }
Esempio n. 4
0
 public void Stop()
 {
     if (runStage == RunStage.Production)
     {
         ModuleManager.ShutdownModules();
         IPersistenceManager pManager = PersistenceFactory.GetPersistenceManager();
         pManager.Shutdown(); // release all data access related resources!
         IoCFactory.ShutdownContainer();
         started = false;
     }
 }
Esempio n. 5
0
        protected void Application_Start()
        {
            IoCFactory.StartContainer(Path.Combine(AppConfiguration.AppRoot, "IoC.config"), "DefaultContainer", HttpContext.Current); // use AppConfig to access the app root folder
            //loadModules();
            IPersistenceManager pManager = PersistenceFactory.GetPersistenceManager();                                                // just to prepare data access environment

            pManager.Configure(AppConfiguration.DefaultApplicationConnection.ConnectionString, AppConfiguration.DatabaseDialect);     //, AppConfiguration.DefaultApplicationConnection.ConnectionString);
            if (AppConfiguration.CreateDatabase)
            {
                pManager.ExportSchema();
            }
            pManager.Start();

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            ITenantResolver     tenantResolver = IoCFactory.Container.Resolve <ITenantResolver>();
            ITenantPathProvider pathProvider   = new DefaultTenantPathProvider(); // should be instantiated by the IoC. client app should provide the Path Ptovider based on its file and tenant structure

            tenantResolver.Load(pathProvider);
            var x = tenantResolver.Manifest;
        }
Esempio n. 6
0
        private void fetchRule(AuthorizationContext filterContext)
        {
            if (!string.IsNullOrWhiteSpace(AccessRule) || FetchAccessRuleFromDB == false)
            {
                return;
            }
            string temp = FullKey;

            try
            {
                AccessRule = filterContext.HttpContext.Application.GetAccessRuleCache().Get(temp) as string;
            }
            catch { AccessRule = string.Empty; }
            if (!string.IsNullOrWhiteSpace(AccessRule))
            {
                return;
            }

            // extract all sub keys to fetch them from db
            List <string> subKeys = new List <string>();

            subKeys.Add(temp);
            do
            {
                if (temp.Contains("."))
                {
                    temp = temp.Substring(0, temp.LastIndexOf("."));
                }
                subKeys.Add(temp);
            }while (temp.Contains("."));
            subKeys.RemoveAll(p => string.IsNullOrWhiteSpace(p));

            //fetch access rules coreponsing to all subkeys
            IPersistenceManager persistenceManager = PersistenceFactory.GetPersistenceManager();

            List <AccessRuleEntity> rules;

            using (IUnitOfWork uow = persistenceManager.UnitOfWorkFactory.CreateUnitOfWork(false, true))
            {
                IReadOnlyRepository <AccessRuleEntity> accessRuleRepo = uow.GetReadOnlyRepository <AccessRuleEntity>();
                rules = accessRuleRepo.Get(p => subKeys.Contains(p.SecurityKey) && p.SecurityObjectType == SecurityObjectType.Feature)
                        .OrderBy(p => p.SecurityKey.Length).ToList();
            }

            // compile the final access rules based on action hierarchy and rule merging policy
            AccessRule = string.Empty;
            AccessRuleMergeOption mergeOption = (AccessRuleMergeOption)Enum.Parse(typeof(AccessRuleMergeOption), ConfigurationManager.AppSettings["AccessRuleMergeOption"]);

            switch (mergeOption)
            {
            case AccessRuleMergeOption.MaximumRight:
                foreach (var rule in rules.Where(p => !string.IsNullOrWhiteSpace(p.RuleBody)))
                {
                    AccessRule = AccessRule + " | (" + rule.RuleBody + ")";
                }
                AccessRule = AccessRule.Trim(" | ".ToCharArray());

                // creates nested parentheses
                //AccessRule = rules.Where(p=> !string.IsNullOrWhiteSpace(p.RuleBody))
                //                .Select(x => x.RuleBody)
                //                .Aggregate((current, next) => '(' + current + ") | (" + next + ')');


                break;

            case AccessRuleMergeOption.MinimumRight:
                foreach (var rule in rules.Where(p => !string.IsNullOrWhiteSpace(p.RuleBody)))
                {
                    AccessRule = AccessRule + " & (" + rule.RuleBody + ")";
                }
                AccessRule = AccessRule.Trim(" & ".ToCharArray());
                break;

            case AccessRuleMergeOption.Normal:
                AccessRule = rules.Last().RuleBody;     // fetches more than required, but is the NH.Linq issue
                break;

            default:
                break;
            }
            if (!string.IsNullOrWhiteSpace(AccessRule))
            {
                int cacheTime = 600;
                int.TryParse(ConfigurationManager.AppSettings["AutorizationRuleCacheTime"], out cacheTime);
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.SlidingExpiration = new TimeSpan(0, 0, cacheTime);
                filterContext.HttpContext.Application.GetAccessRuleCache().Add(FullKey, AccessRule, policy, null);
            }
        }