Beispiel #1
0
        /// <summary>
        /// Runs the bootstrapper process.
        /// </summary>
        public static void Run()
        {
            // Discover routes to Kentico HTTP handlers before the MVC application starts to allow adding them to the route table.
            // It is not possible to completely initialize Kentico yet as it requires access to the current HTTP request that is not available in this phase of application life-cycle.
            SystemContext.IsWebSite = true;
            CMSApplication.PreInit();

            // Register the module that provider Kentico ASP.NET MVC integration.
            HttpApplication.RegisterModule(typeof(ApplicationHttpModule));
        }
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddLogging();
            var _loggerFactory = new LoggerFactory();
            var logger         = _loggerFactory.CreateLogger("Startup");

            try
            {
                // Loads kentico libraries into the app domain
                RegisterCmsAssemblies();

                // Loads custom libraries into the app domain
                RegisterCustomAssemblies();

                // Prinit types
                CMSApplication.PreInit();

                // Declare any Interfaces here, note you do not need to add any interfaces that are automatically implemented through Xperience's IoC attributes such as ProviderInterface
                //builder.Services.AddTransient<ICustomRepository, CustomRepository>();

                // Merge kentico services into the builder services
                Service.MergeDescriptors(builder.Services);

                var    Config          = builder.GetContext().Configuration;
                string EnvironmentName = builder.GetContext().EnvironmentName;

                // Wait for database to be ready since this is a external service
                CMSApplication.WaitForDatabaseAvailable.Value = true;

                string ConnectionString;
                if (EnvironmentName.Equals("Development", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Setup connection string (manually or read frOm key/vault, settings file etc.)  This will read from local.settings.json -> ConnectionStrings.CMSConnectionString
                    ConnectionString = Config.GetSection("ConnectionStrings").GetSection("CMSConnectionString").Value;
                }
                else
                {
                    // In Azure Functions, will be grabbing just the CMSConnectionString from the Azure Functio -> Configuration -> Application Settings
                    ConnectionString = Environment.GetEnvironmentVariable("CMSConnectionString", EnvironmentVariableTarget.Process);
                }

                // Set connection string
                ConnectionHelper.ConnectionString = ConnectionString;

                // Init database
                CMSApplication.Init();
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "An error occurred during startup");
            }
        }
Beispiel #3
0
        public static async Task <int> Main(string[] args)
        {
            CMSApplication.PreInit(true);

            // Connect to external database
            var connString = Environment.GetEnvironmentVariable("CMSConnectionString");

            ConnectionHelper.ConnectionString = connString;

            CMSApplication.Init();
            return(await Bootstrapper
                   .Factory
                   .CreateDefault(args)
                   .AddPipeline <RatingPipeline>()
                   .AddPipeline <BookPipeline>()
                   .AddPipeline <AuthorPipeline>()
                   .AddPipeline <ContactPipeline>()
                   .AddPipeline("Assets", outputModules: new IModule[] { new CopyFiles("assets/**") })
                   .RunAsync());
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            string profileName = string.Empty;

            // Create new instance of AD provider
            ImportProfile.OnDirectoryControllerChanged += () => PrincipalProvider.ClearContext();

            // If there are some arguments specified
            if (args.Length != 0)
            {
                // Try to attach console
                if (!AttachConsole(-1))
                {
                    // Create new console
                    AllocConsole();
                }

                // For each argument
                for (int i = 0; i < args.Length; i++)
                {
                    string arg = args[i];

                    // If argument specifies profile
                    if ((arg == "/profile") || (arg == "-profile"))
                    {
                        // Get profile name
                        if ((i + 1) < args.Length)
                        {
                            if (profileName == string.Empty)
                            {
                                profileName = args[i + 1].Trim();
                            }
                        }
                    }
                    if ((arg == "/h") || (arg == "-h") || (arg == "--help") || (arg == "-?") || (arg == "/?"))
                    {
                        // Write help
                        Console.Write(ResHelper.GetString("Console_Help").Replace("\\n", "\n").Replace("\\r", "\r"));
                        return;
                    }
                }

                // If there was profile specified
                if (profileName != string.Empty)
                {
                    // If there is no such file
                    if (!File.Exists(profileName))
                    {
                        Console.WriteLine(ResHelper.GetString("Error_ProfileDoesNotExist", profileName));
                    }
                    else
                    {
                        // Try to get file info
                        FileInfo fi = FileInfo.New(profileName);

                        Console.WriteLine(ResHelper.GetString("Console_SelectedImportProfile", fi.FullName));

                        // Initialize import profile
                        string validationError = ImportProfile.InitializeImportProfile(profileName);
                        if (!String.IsNullOrEmpty(validationError))
                        {
                            Console.WriteLine(ResHelper.GetString("Error_ProfileIsNotValid"));
                            Console.WriteLine(validationError);
                        }
                        else
                        {
                            // Application is in console mode
                            ImportProfile.UsesConsole = true;

                            // Check permissions
                            string permissionsCheckResult = PrincipalProvider.CheckPermissions();
                            if (!string.IsNullOrEmpty(permissionsCheckResult))
                            {
                                Console.WriteLine(permissionsCheckResult);
                            }
                            else
                            {
                                // Initialize principal provider
                                bool providerInitialized = ValidatePrincipalProvider(PrincipalProvider);
                                bool databaseValid       = ValidateDatabase();

                                if (providerInitialized && databaseValid)
                                {
                                    // Initialize CMS connection
                                    CMSImport.ConfigureApplicationSettings();

                                    // Perform CMS import
                                    CMSImport.Import(PrincipalProvider, MessageLog);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Write message
                    Console.WriteLine(ResHelper.GetString("Console_SpecifyProfile"));
                }
            }
            // Launch windows form application
            else
            {
                // Preinitialize CMS context
                CMSApplication.PreInit();

                // Initialize application
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new ADWizard(PrincipalProvider));
            }
        }