public void InitializeForStartup(LogLevel logLevel, Action <IContainer> registrationAction)
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
            ApplicationIcons.DefaultIcon          = ApplicationIcons.PKSim;

            updateGoDiagramKey();
            initializeSynchronizationContext();

            var container = InfrastructureRegister.Initialize();

            container.RegisterImplementationOf(SynchronizationContext.Current);

            container.Register <IApplicationController, ApplicationController>(LifeStyle.Singleton);
            container.Register <PKSimApplication, PKSimApplication>(LifeStyle.Singleton);

            //UI and Presentation mandatory objects for startup
            container.Register <IProgressUpdater, PKSimProgressUpdater>();
            container.RegisterImplementationOf(NumericFormatterOptions.Instance);
            container.Register <IExceptionManager, ExceptionManager>(LifeStyle.Singleton);

            container.AddRegister(x => x.FromType <UIRegister>());
            container.AddRegister(x => x.FromType <PresenterRegister>());

            //must be registered so that the ui thread can start the startup
            container.RegisterImplementationOf(this);

            container.Register <IConfigurableContainerLayoutView, AccordionLayoutView>(ViewLayouts.AccordionView.Id);
            container.Register <IConfigurableContainerLayoutView, TabbedLayoutView>(ViewLayouts.TabbedView.Id);

            configureLogger(container, logLevel);

            registrationAction?.Invoke(container);
        }
Ejemplo n.º 2
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllers();
     services.AddDatabaseInfrastructure(Configuration);
     InfrastructureRegister.Register(services, Configuration);
     services.AddCors(); // cors service
 }
Ejemplo n.º 3
0
        public static void Start()
        {
            UI.BootStrapping.ApplicationStartup.Initialize(LogLevel.Debug);

            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <BatchRegister>());
                container.AddRegister(x => x.FromType <CLIRegister>());

                InfrastructureRegister.LoadSerializers(container);
                InfrastructureRegister.RegisterWorkspace(container);
                UI.BootStrapping.ApplicationStartup.RegisterCommands(container);
                container.RegisterImplementationOf(new DefaultLookAndFeel().LookAndFeel);
            }

            var skinManager  = container.Resolve <ISkinManager>();
            var userSettings = container.Resolve <IPresentationUserSettings>();

            skinManager.ActivateSkin(userSettings, Constants.DEFAULT_SKIN);
        }
        public static void Start()
        {
            BootStrapping.ApplicationStartup.Initialize(LogLevel.Debug);

            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <StarterRegister>());

                registerMinimalImplementations(container);
                registerUIImplementation(container);

                InfrastructureRegister.LoadSerializers(container);
                InfrastructureRegister.RegisterWorkspace(container);
                BootStrapping.ApplicationStartup.RegisterCommands(container);
                container.RegisterImplementationOf(new DefaultLookAndFeel().LookAndFeel);
            }

            container.Register <IToolTipCreator, OSPSuite.UI.Services.IToolTipCreator, ToolTipCreator>(LifeStyle.Transient);
            var skinManager  = container.Resolve <ISkinManager>();
            var userSettings = container.Resolve <IPresentationUserSettings>();
            // skinManager.ActivateSkin(userSettings, Constants.DEFAULT_SKIN);
        }
Ejemplo n.º 5
0
        public void InitializeForStartup()
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");

            updateGoDiagramKey();

            InfrastructureRegister.Initialize();
            var container = IoC.Container;

            container.RegisterImplementationOf(getCurrentContext());
            container.Register <IApplicationController, ApplicationController>(LifeStyle.Singleton);
            container.Register <PKSimApplication, PKSimApplication>(LifeStyle.Singleton);

            //UI and Presentation mandatory ojects for startup
            container.Register <IProgressUpdater, PKSimProgressUpdater>();
            container.RegisterImplementationOf(NumericFormatterOptions.Instance);
            container.Register <IExceptionManager, ExceptionManager>(LifeStyle.Singleton);

            container.AddRegister(x => x.FromType <UIRegister>());
            container.AddRegister(x => x.FromType <PresenterRegister>());

            //must be registered so that the ui thread can start the startup
            container.RegisterImplementationOf(this);

            container.Register <IConfigurableContainerLayoutView, AccordionLayoutView>(ViewLayouts.AccordionView.Id);
            container.Register <IConfigurableContainerLayoutView, TabbedLayoutView>(ViewLayouts.TabbedView.Id);
        }
Ejemplo n.º 6
0
        public override void GlobalContext()
        {
            if (IoC.Container != null)
            {
                return;
            }

            InfrastructureRegister.Initialize();

            //use only in tests
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                var configuration = container.Resolve <IPKSimConfiguration>();
//            configuration.PKSimDb = DomainHelperForSpecs.DbFilePath;
//            configuration.DimensionFilePath = DomainHelperForSpecs.DimensionFilePath;
//            configuration.PKParametersFilePath = DomainHelperForSpecs.PKParametersFilePath;

                //need to register these serives for which the default implementation is in the UI
                container.RegisterImplementationOf(new SynchronizationContext());
                container.Register <IApplicationController, ApplicationController>(LifeStyle.Singleton);
                container.Register <IExceptionManager, ExceptionManagerForSpecs>(LifeStyle.Singleton);
                container.Register <IDisplayUnitRetriever, MatlabDisplayUnitRetriever>();
                container.Register <IOntogenyFactorsRetriever, OntogenyFactorsRetriever>();

                container.RegisterImplementationOf(A.Fake <IProgressUpdater>());
                container.RegisterImplementationOf(A.Fake <IDialogCreator>());
                container.RegisterImplementationOf(A.Fake <IHistoryManager>());
                container.RegisterImplementationOf(A.Fake <IWorkspace>());
                container.RegisterImplementationOf(A.Fake <OSPSuite.Core.IWorkspace>());
                container.RegisterImplementationOf(A.Fake <IHeavyWorkManager>());
                container.RegisterImplementationOf(A.Fake <IChartTemplatingTask>());
                container.RegisterImplementationOf(A.Fake <IPresentationSettingsTask>());
                container.RegisterImplementationOf(A.Fake <IJournalDiagramManagerFactory>());

                container.AddRegister(x =>
                {
                    x.FromInstance(new CoreRegister());
                    x.FromType <InfrastructureRegister>();
                    x.FromType <PresenterRegister>();
                    x.FromType <OSPSuite.Presentation.PresenterRegister>();
                    x.FromType <BatchRegister>();
                });

                var userSettings = container.Resolve <IUserSettings>();
                userSettings.AbsTol = 1e-10;
                userSettings.RelTol = 1e-5;
                //this is use to create reports
                userSettings.NumberOfBins = CoreConstants.DEFAULT_NUMBER_OF_BINS;


                InfrastructureRegister.RegisterSerializationDependencies();
            }
            //Required for usage with nunit 3
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
        }
Ejemplo n.º 7
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // The following line enables Application Insights telemetry collection.
            services.AddApplicationInsightsTelemetry();

            services.AddControllers();

            // Register Api
            services.AddScoped <IAuthService, AuthService>();
            services.AddScoped <IOidcService, OidcService>();
            services.AddScoped <IJwtGenerator, JwtGenerator>();
            services.AddScoped <IJwtValidator, JwtValidator>();
            services.AddScoped <IJwtDecoder, JwtDecoder>();

            // Register Infrastructure
            InfrastructureRegister.RegisterDbContext(services, Configuration.GetConnectionString("DefaultConnection"));
            InfrastructureRegister.RegisterRepository(services);

            // Register Core
            CoreRegister.RegisterServices(services);

            // Register Identity & Authentication
            services.AddIdentity <User, Role>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services
            .AddAuthentication(options =>
            {
                options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultScheme             = JwtBearerDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(cfg =>
            {
                cfg.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = Configuration["Jwt:Issuer"],
                    ValidAudience    = Configuration["Jwt:Issuer"],
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])),
                    ClockSkew        = TimeSpan.Zero // remove delay of token when expire
                };
            });

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "API", Version = "v1"
                });
            });
        }
Ejemplo n.º 8
0
        public static void Initialize()
        {
            Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");

            var container = InfrastructureRegister.Initialize();

            container.RegisterImplementationOf(new SynchronizationContext());
            container.Register <IExceptionManager, CLIExceptionManager>(LifeStyle.Singleton);
        }
Ejemplo n.º 9
0
 private static void registerCLITypes(IContainer container)
 {
     container.Register <IProgressUpdater, CLIProgressUpdater>();
     container.Register <IDialogCreator, CLIDialogCreator>();
     container.Register <IDisplayUnitRetriever, CLIDisplayUnitRetriever>();
     container.Register <IJournalDiagramManagerFactory, CLIJournalDiagramManagerFactory>();
     container.Register <IDiagramModel, CLIDiagramModel>();
     container.Register <IDiagramModelToXmlMapper, CLIDiagramModelToXmlMapper>(LifeStyle.Singleton);
     container.Register <IHistoryManager, HistoryManager <IExecutionContext> >();
     container.Register <ICoreUserSettings, OSPSuite.Core.ICoreUserSettings, IPresentationUserSettings, CLIUserSettings>(LifeStyle.Singleton);
     InfrastructureRegister.RegisterWorkspace <CLIWorkspace>();
 }
Ejemplo n.º 10
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureContainer(ServiceRegistry services)
        {
            services.AddControllers();

            InfrastructureRegister.Register(services, Configuration);
            services.IncludeRegistry <ServiceRegister>();
            services.Scan(s =>
            {
                s.TheCallingAssembly();
                s.WithDefaultConventions();
            });

            services.AddCors();
        }
        /// <summary>
        ///    All specific registration that needs to be performed once all other registrations are done
        /// </summary>
        private void finalizeRegistration(IContainer container)
        {
            InfrastructureRegister.RegisterWorkspace(container);
            //Create one instance of the invokers so that the object is available in the application
            //since the object is not created anywhere and is only used as event listener
            container.Resolve <ICloseSubjectPresenterInvoker>();

            var mainPresenter = container.Resolve <IMainViewPresenter>();

            container.RegisterImplementationOf((IChangePropagator)mainPresenter);

            //This runner is only register when running PKSim as an executable. All other implementation should use the ISimulationRunner
            container.Register <IInteractiveSimulationRunner, InteractiveSimulationRunner>(LifeStyle.Singleton);
        }
Ejemplo n.º 12
0
        public static void Start()
        {
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(NumericFormatterOptions.Instance);

                registerCLITypes(container);

                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <CLIRegister>());

                InfrastructureRegister.LoadSerializers(container);
            }
        }
Ejemplo n.º 13
0
        public static void Start()
        {
            ApplicationStartup.Initialize();
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <BatchRegister>());

                InfrastructureRegister.RegisterSerializationDependencies();
                ApplicationStartup.RegisterCommands(container);

                var workspace = container.Resolve <IWorkspace>();
                container.RegisterImplementationOf((IWithWorkspaceLayout)workspace);
            }
        }
Ejemplo n.º 14
0
        private void initializeForMatlab(string dimensionFilePath, string databaseFilePath, string pkParameterFilePath)
        {
            if (IoC.Container != null)
            {
                return;
            }

            InfrastructureRegister.Initialize();
            var container          = IoC.Container;
            var pksimConfiguration = container.Resolve <IPKSimConfiguration>();

            //path was specified, update the default path
            if (!string.IsNullOrEmpty(dimensionFilePath))
            {
                pksimConfiguration.DimensionFilePath = dimensionFilePath;
            }

            //path was specified, update the default path
            if (!string.IsNullOrEmpty(databaseFilePath))
            {
                pksimConfiguration.PKSimDb = databaseFilePath;
            }

            //path was specified, update the default path
            if (!string.IsNullOrEmpty(pkParameterFilePath))
            {
                pksimConfiguration.PKParametersFilePath = pkParameterFilePath;
            }

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(new SynchronizationContext());
                container.AddRegister(x => x.FromType <MatlabRegister>());
                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <OSPSuite.Presentation.PresenterRegister>());

                //no computation required in matlab interface
                InfrastructureRegister.RegisterSerializationDependencies(registerSimModelSchema: false);
            }
        }
Ejemplo n.º 15
0
        public static void Start()
        {
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(NumericFormatterOptions.Instance);
                container.Register <IApplicationController, ApplicationController>();

                registerCLITypes(container);

                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <OSPSuite.Presentation.PresenterRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <CLIRegister>());

                InfrastructureRegister.RegisterSerializationDependencies();
            }
        }
Ejemplo n.º 16
0
        private void initializeForMatlab()
        {
            if (IoC.Container != null)
            {
                return;
            }

            var container = InfrastructureRegister.Initialize();

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(new SynchronizationContext());
                container.AddRegister(x => x.FromType <MatlabRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());

                InfrastructureRegister.LoadSerializers(container);
                container.Register <ICoreWorkspace, OSPSuite.Core.IWorkspace, CLIWorkspace>(LifeStyle.Singleton);
            }
        }
        private IContainer performInitialization()
        {
            // We do not want to register the IoC container to avoid static pollution that may collide with OSPSuite-R
            var container = InfrastructureRegister.Initialize(registerContainerAsStatic: false);

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(new SynchronizationContext());
                container.AddRegister(x => x.FromType <RRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                InfrastructureRegister.RegisterSerializationDependencies(container);
                registerMinimalImplementations(container);
            }

            var configuration = container.Resolve <IPKSimConfiguration>();
            var currentPath   = new FileInfo(Assembly.GetAssembly(GetType()).Location).DirectoryName;

            if (!File.Exists(configuration.PKSimDbPath))
            {
                configuration.PKSimDbPath = Path.Combine(currentPath, CoreConstants.PK_SIM_DB_FILE);
            }

            if (!File.Exists(configuration.PKParametersFilePath))
            {
                configuration.PKParametersFilePath = Path.Combine(currentPath, Constants.Files.PK_PARAMETERS_FILE_NAME);
            }

            if (!File.Exists(configuration.DimensionFilePath))
            {
                configuration.DimensionFilePath = Path.Combine(currentPath, Constants.Files.DIMENSIONS_FILE_NAME);
            }

            // This will log the version of PKSIm used to R
            Console.WriteLine(PKSimConstants.Information.InitializingPKSim(CoreConstants.PRODUCT_NAME, configuration.FullVersion));

            // Serialization mapping will require access to PKSim DB and as such, it needs to be performed after the DB was set.
            InfrastructureRegister.LoadDefaultEntities(container);
            return(container);
        }
Ejemplo n.º 18
0
        private void initializeForMatlab()
        {
            if (IoC.Container != null)
            {
                return;
            }

            InfrastructureRegister.Initialize();
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(new SynchronizationContext());
                container.AddRegister(x => x.FromType <MatlabRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());

                //no computation required in matlab interface
                InfrastructureRegister.RegisterSerializationDependencies(registerSimModelSchema: false);
                InfrastructureRegister.RegisterWorkspace <CLIWorkspace>();
            }
        }
Ejemplo n.º 19
0
        public static void Start()
        {
            var container = IoC.Container;

            using (container.OptimizeDependencyResolution())
            {
                container.RegisterImplementationOf(NumericFormatterOptions.Instance);
                container.Register <IApplicationController, ApplicationController>();

                registerCLITypes(container);

                container.AddRegister(x => x.FromType <PresenterRegister>());
                container.AddRegister(x => x.FromType <CoreRegister>());
                container.AddRegister(x => x.FromType <EngineRegister>());
                container.AddRegister(x => x.FromType <OSPSuite.Presentation.PresenterRegister>());
                container.AddRegister(x => x.FromType <InfrastructureRegister>());
                container.AddRegister(x => x.FromType <CLIRegister>());

                InfrastructureRegister.RegisterSerializationDependencies();
                var pkSimConfiguration = container.Resolve <IPKSimConfiguration>();
                XMLSchemaCache.InitializeFromFile(pkSimConfiguration.SimModelSchemaFilePath);
            }
        }
Ejemplo n.º 20
0
        public void Start()
        {
            var progressManager = IoC.Resolve <IProgressManager>();
            var container       = IoC.Container;

            using (var progress = progressManager.Create())
            {
                progress.Initialize(8);

                using (container.OptimizeDependencyResolution())
                {
                    showStatusMessage(progress, PKSimConstants.UI.RegisterAssembly(PKSimConstants.UI.Core));
                    container.AddRegister(x => x.FromType <CoreRegister>());

                    showStatusMessage(progress, PKSimConstants.UI.RegisterAssembly(PKSimConstants.UI.Infrastructure));
                    container.AddRegister(x => x.FromType <InfrastructureRegister>());

                    showStatusMessage(progress, message: PKSimConstants.UI.RegisterAssembly(PKSimConstants.UI.Presentation));
                    container.AddRegister(x => x.FromType <Presentation.PresenterRegister>());

                    showStatusMessage(progress, PKSimConstants.UI.RegisterAssembly(PKSimConstants.UI.UserInterface));
                    container.AddRegister(x => x.FromType <UserInterfaceRegister>());

                    showStatusMessage(progress, PKSimConstants.UI.RegisterAssembly(PKSimConstants.UI.Commands));
                    RegisterCommands(container);

                    showStatusMessage(progress, PKSimConstants.UI.RegisterSerializationDependencies);
                    InfrastructureRegister.RegisterSerializationDependencies();

                    finalizeRegistration(container);
                }

                showStatusMessage(progress, PKSimConstants.UI.StartingUserInterface);
                startStartableObject(container);
            }
        }