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);
            }
        }
 static void Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     var query      = "";
     var parameters = new KeyValueList();
     IPersistenceManager persist = PersistenceFactory.GetDatabase("MYSQL");
     List <Dictionary <string, string> > result = persist.ExecuteQuery(query, parameters);
 }
Esempio n. 3
0
        protected void Application_End()
        {
            ModuleManager.ShutdownModules();
            IPersistenceManager pManager = PersistenceFactory.GetPersistenceManager();

            pManager.Shutdown(); // release all data access related resources!
            IoCFactory.ShutdownContainer();
        }
Esempio n. 4
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. 5
0
        internal static void Main()
        {
            SetUnhandledExceptions();
            Info.SetApplicationVersion();

            Logging.Info(String.Format("-------------------------------Title: {0} started Version:{1} Date:{2}-------------------------------",
                                       Info.TitleVersion, Info.DLLVersion, Info.BuildDate));
            Logging.Info("Start state 1 Complete: Unhandled exceptions");

            LogGeneralProperties();
            Logging.Info("Start state 2 Complete: Log General properties");

            SetApplicationProperties();
            Logging.Info("Start state 3 Complete: Set application properties");

            var             settings    = Settings.Instance;
            CommandLineArgs commandLine = ParseCommandline(settings);

            Logging.Info("Start state 4 Complete: Parse command line");

            if (!EnsureDataAreWriteAble())
            {
                return;
            }
            Logging.Info("Start state 5 Complete: User account control");

            if (commandLine.SingleInstance && SingleInstanceApplication.Instance.NotifyExisting(commandLine))
            {
                return;
            }

            Logging.Info("Start state 6 Complete: Set Single instance mode");


            var connectionManager  = new ConnectionManager(new PluginsLoader(settings));
            var favoriteIcons      = new FavoriteIcons(connectionManager);
            var persistenceFactory = new PersistenceFactory(settings, connectionManager, favoriteIcons);
            // do it before config update, because it may import favorites from previous version
            IPersistence persistence = persistenceFactory.CreatePersistence();

            Logging.Info("Start state 7 Complete: Initilizing Persistence");

            TryUpdateConfig(settings, persistence, connectionManager);
            Logging.Info("Start state 8 Complete: Configuration upgrade");

            ShowFirstRunWizard(settings, persistence, connectionManager);
            var startupUi = new StartupUi();

            persistence = persistenceFactory.AuthenticateByMasterPassword(persistence, startupUi, commandLine.masterPassword);
            PersistenceErrorForm.RegisterDataEventHandler(persistence.Dispatcher);

            RunMainForm(persistence, connectionManager, favoriteIcons, commandLine);

            Logging.Info(String.Format("-------------------------------{0} Stopped-------------------------------",
                                       Info.TitleVersion));
        }
Esempio n. 6
0
        /// <summary>
        /// Default runtime factory
        /// </summary>
        /// <returns>Runtime</returns>
        public static async Task <TutorialRuntime> UseInMemory()
        {
            var persistence = await PersistenceFactory.CreateInMemoryAsync();

            var snapshots = await PersistenceFactory.CreateInMemoryAsync();

            var runtime = new TutorialRuntime(persistence, snapshots);

            return(runtime);
        }
Esempio n. 7
0
 public void TestInitialize()
 {
     FilePersistedTestLab.SetDefaultFileLocations();
     this.settings = Settings.Instance;
     this.settings.PersistenceType = FilePersistence.TYPE_ID;
     this.passwordRequested        = false;
     this.exitCalled           = false;
     this.fallbackRequested    = false;
     this.authenticationPrompt = new AuthenticationPrompt();
     this.factory = new PersistenceFactory(Settings.Instance, TestConnectionManager.Instance, TestConnectionManager.CreateTestFavoriteIcons());
 }
Esempio n. 8
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. 9
0
        public double SumRegion(PointTO point1, PointTO point2)
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();

            //Point Validations
            ValidatePoint(point1);

            //Point Validations
            ValidatePoint(point2);

            return(persistence.SumRegion(point1, point2));
        }
Esempio n. 10
0
        public int GetDimensions()
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();

            //Check response en return data accordingly
            int dimensions = persistence.GetDimensions();

            if (dimensions == 0)
            {
                dimensions = -1;
            }
            return(dimensions);
        }
Esempio n. 11
0
        public bool Update(PointTO point)
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();

            //Point Validations
            ValidatePoint(point);

            //Check Value
            if (point.Value < Math.Pow(10, 9) * -1 || point.Value > Math.Pow(10, 9))
            {
                throw new Exception("Value is not allowed. -10^9 <= W <= 10^9");
            }

            return(persistence.Update(point));
        }
Esempio n. 12
0
        private void ValidatePoint(PointTO point)
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();
            int dimensions = persistence.GetDimensions();

            //Check Boundaries
            if (point.X <= 0 || point.Y <= 0 || point.Z <= 0)
            {
                throw new Exception("Cube is index 1, lower numbers are not allowed for x, y or z");
            }

            if (point.X > dimensions || point.Y > dimensions || point.Z > dimensions)
            {
                throw new Exception("Cube limits exceeded");
            }
        }
Esempio n. 13
0
        public bool Create(int dimensions)
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();

            if (dimensions <= 0)
            {
                throw new Exception("Dimensions must be greater then Zero");
            }

            if (dimensions > 100)
            {
                throw new Exception("Maximum dimensions is 100");
            }

            return(persistence.Create(dimensions));
        }
Esempio n. 14
0
        public static async Task <TutorialRuntime> UseSqlServer(string connectionString)
        {
            var persistence = await PersistenceFactory.CreateSqlServerAsync
                              (
                connectionString,
                "streams",
                NStoreNullLoggerFactory.Instance
                              );

            var snapshots = await PersistenceFactory.CreateSqlServerAsync
                            (
                connectionString,
                "snapshots",
                NStoreNullLoggerFactory.Instance
                            );

            var runtime = new TutorialRuntime(persistence, snapshots);

            return(runtime);
        }
Esempio n. 15
0
        private static IPersistence AuthenticateByMasterPassword(PersistenceFactory persistenceFactory, IPersistence persistence)
        {
            IPersistence newPersistence = persistence;

            PersistenceErrorForm.RegisterDataEventHandler(persistence.Dispatcher);

            if (!persistence.Security.Authenticate(RequestPassword.KnowsUserPassword))
            {
                if (PersistenceFallback())
                {
                    newPersistence = persistenceFactory.FallBackToPrimaryPersistence(persistence.Security);
                }
                else
                {
                    Environment.Exit(-1);
                }
            }

            return(newPersistence);
        }
        public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var request = context?.Request;
            var cookies = request?.Headers.GetCookies().Where(cookie => cookie.HttpOnly == (cookie.Secure && request.RequestUri.Scheme == Uri.UriSchemeHttps)).SelectMany(cookieBag => cookieBag.Cookies);
            var authenticationCookie = cookies?.FirstOrDefault(cookie => cookie.Name == AUTHENTICATION_COOKIE_NAME);
            var token = authenticationCookie?.Value;

            var cacheKey = BuildCacheKey(token);
            var cache    = HttpContext.Current.Cache;

            var cachedUser = cache.Get(cacheKey) as CustomIdentity;

            if (token != null)
            {
                if (cachedUser == null)
                {
                    var config      = new SiteConfiguration();
                    var accountRepo = PersistenceFactory.GetAccountRepo(config);
                    var user        = accountRepo.GetAccountByRecentToken(token);
                    if (user != null)
                    {
                        var customIdentity = new CustomIdentity(user.Username, user.Email, user.AuthToken);
                        context.Principal = new GenericPrincipal(customIdentity, new string[] { });
                        cache.Insert(cacheKey, customIdentity);
                    }
                    else
                    {
                        context.ErrorResult = new UnauthorizedResult(new AuthenticationHeaderValue[] { }, context.Request);
                    }
                }
            }

            if (!(context.Principal?.Identity is CustomIdentity))
            {
                context.ErrorResult = new UnauthorizedResult(new AuthenticationHeaderValue[] { }, context.Request);
            }

            return(Task.FromResult(0));
        }
Esempio n. 17
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. 18
0
 public AccountController()
 {
     AccountRepo = PersistenceFactory.GetAccountRepo(new SiteConfiguration());
 }
Esempio n. 19
0
 public static void Load()
 {
     PersistenceFactory.getMansioniLoader().Load();
 }
Esempio n. 20
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);
            }
        }
 /// <summary>
 /// Ctor
 /// </summary>
 public ServiceCallOperations()
     : base(PersistenceFactory.Create())
 {
     _serviceCallRepo       = UnitOfWork.CreateRepository <long, ServiceCall>();
     _serviceCallDetailRepo = UnitOfWork.CreateRepository <long, ServiceCallDetail>();
 }
Esempio n. 22
0
 public void Load()
 {
     PersistenceFactory.getImpiantoLoader().Load();
 }
Esempio n. 23
0
        public List <PointTO> GetValues()
        {
            ICubePersistence persistence = PersistenceFactory.GetCubePersistence();

            return(persistence.GetValues());
        }
Esempio n. 24
0
 /// <summary>
 /// Ctor
 /// </summary>
 public CountryOperations()
     : base(PersistenceFactory.Create())
 {
     _countryRepo = UnitOfWork.CreateRepository <Int32, Country>();
 }
Esempio n. 25
0
 internal void Load()
 {
     PersistenceFactory.getPagamentiLoader().Load();
 }
Esempio n. 26
0
 public static void Load()
 {
     PersistenceFactory.getPersonaleFactoryLoader().Load();
 }
Esempio n. 27
0
 /// <summary>
 /// Ctor
 /// </summary>
 public ErrorOperations()
     : base(PersistenceFactory.Create())
 {
     _errorRepo = UnitOfWork.CreateRepository <Guid, Error>();
 }
Esempio n. 28
0
 public void Load()
 {
     PersistenceFactory.getEventiLoarder().Load();
 }