예제 #1
0
        public static void Main(string[] args)
        {
            var deploy = args.Any(x => x == "/deploy");

            if (deploy)
            {
                args = args.Except(new[] { "/deploy" }).ToArray();
            }

            var host = CreateWebHostBuilder(args).Build();

            if (deploy)
            {
                long tenatId = 1;
                var  config  = host.Services.GetRequiredService <IConfiguration>();
                var  shardMapManagerConnString = config.GetConnectionString("ShardMapManager");
                var  shardMapConnString        = config.GetConnectionString("ShardMap");

                var deployUtil = new DeployUtil(shardMapManagerConnString, shardMapConnString);
                deployUtil.DeployShardManagerDbIfNotExist();
                deployUtil.DeployTenantDbIfNotExist(tenatId);

                var userSeeder = new UserSeeder(shardMapConnString);
                userSeeder.SeedDefaultUser(tenatId);

                var productSeeder = new ProductSeeder(shardMapConnString);
                productSeeder.SeedProducts(tenatId);

                return;
            }

            host.Run();
        }
예제 #2
0
        public void SeedProducts(long tenantId)
        {
            var services = new ServiceCollection();

            services.AddScoped <ICurrentUser, SeedDataCurrentUser>();
            services.AddScoped <ITenantProvider, SeedTenantProvider>();

            services.AddDbContext <ApexVoxContext>(options =>
            {
                SqlConnection conn = DeployUtil.GetSqlConnectionWithContextInfoSet(_connectionString, tenantId);

                options.UseSqlServer(conn);
            });


            using (var serviceProvider = services.BuildServiceProvider())
            {
                using (var scope = serviceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
                {
                    var context = scope.ServiceProvider.GetService <ApexVoxContext>();

                    for (var i = 1; i <= 10; i++)
                    {
                        var product = CreateProduct(i, tenantId);

                        if (!context.Products.Any(x => x.Name.Equals(product.Name)))
                        {
                            context.Products.Add(product);
                        }
                    }

                    context.SaveChanges();
                }
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // Attempt to open a restricted resource (see if we're administrator)
            frmSplash splash = new frmSplash();

            splash.Show();
            try
            {
                StringBuilder argString = new StringBuilder();

#if !DEBUG
                WindowsIdentity  identity  = WindowsIdentity.GetCurrent();
                WindowsPrincipal principal = new WindowsPrincipal(identity);
                if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    !principal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    string cmdLine = Environment.CommandLine.Substring(Environment.CommandLine.IndexOf(".exe") + 4);
                    cmdLine = cmdLine.Contains(' ') ? cmdLine.Substring(cmdLine.IndexOf(" ")) : null;
                    ProcessStartInfo psi = new ProcessStartInfo(Assembly.GetEntryAssembly().Location, cmdLine);
                    psi.Verb = "runas";
                    Trace.TraceInformation("Not administrator!");
                    Process proc = Process.Start(psi);
                    Application.Exit();
                    return;
                }
#endif

                // Scan for configuration options
                ConfigurationApplicationContext.Initialize();
                ConfigurationApplicationContext.s_configurationPanels.Add(new OpenIZAboutPanel());
                splash.Close();
#if DEBUG
                ConfigurationApplicationContext.s_configFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "OpenIZ.exe.config.test");
#else
                ConfigurationApplicationContext.s_configFile = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "OpenIZ.exe.config");
#endif
                ParameterParser <ConsoleParameters> parser = new ParameterParser <ConsoleParameters>();

                var consoleParms = parser.Parse(args);

                if (consoleParms.ListDeploy)
                {
                    StringBuilder options = new StringBuilder("Available deployment modules: \r\n");
                    foreach (var pnl in ConfigurationApplicationContext.s_configurationPanels.OfType <IScriptableConfigurableFeature>())
                    {
                        options.AppendFormat("{0}\r\n", pnl.Name);
                    }
                    MessageBox.Show(options.ToString());
                }
                else if (consoleParms.Deploy != null && consoleParms.Deploy.Count > 0)
                {
                    try
                    {
                        DeployUtil.Deploy(consoleParms.Deploy, consoleParms.Options);
                        ConfigurationApplicationContext_ConfigurationApplied(null, EventArgs.Empty);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(String.Format("Could not deploy requested component : {0}", e), "Error Deploying");
                    }
                }
                else
                {
                    ConfigurationApplicationContext.s_configurationPanels.Sort((a, b) => a.Name.CompareTo(b.Name));
                    ConfigurationApplicationContext.ConfigurationApplied += new EventHandler(ConfigurationApplicationContext_ConfigurationApplied);

                    // Allow data services to use the application context
                    MARC.HI.EHRS.SVC.Core.ApplicationContext.Current.AddServiceProvider(typeof(FileConfigurationService));

                    // Configuration File exists?
                    if (!File.Exists(ConfigurationApplicationContext.s_configFile))
                    {
                        frmStartScreen start = new frmStartScreen();
                        if (start.ShowDialog() == DialogResult.Cancel)
                        {
                            return;
                        }
                    }

                    MARC.HI.EHRS.SVC.Core.ApplicationContext.Current.GetService <FileConfigurationService>().Open(ConfigurationApplicationContext.s_configFile);
                    try
                    {
                        MARC.HI.EHRS.SVC.Core.ApplicationContext.Current.Start();
                    }
                    catch { }

                    // Now we need to deploy
                    Application.Run(new frmMain());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Trace.TraceError(e.ToString());
                MessageBox.Show(e.ToString());
            }
            finally
            {
                splash.Dispose();
            }
        }