Пример #1
0
        /// <summary>
        /// Application_Start()
        /// </summary>
        protected void Application_Start()
        {
//			Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Info, "Application Started, ver " + PortalSettings.CodeVersion);

            if (bool.Parse(ConfigurationSettings.AppSettings["CheckForFilePermission"].ToString()))
            {
                // Verify if ASPN net user has rights on application folder
                FileIOPermission MyPermission = new FileIOPermission(FileIOPermissionAccess.Write, HttpContext.Current.Request.PhysicalApplicationPath);
                try
                {
                    MyPermission.Demand();                     //it doesn't work :( - if anybody make it working please let me know (manu)
                }
                catch (Exception ex)
                {
                    Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Fatal, "ASPNET Account does not have rights to the filesystem", ex);
                    HttpContext.Current.Response.Redirect("~/app_support/ErrorNoFilePermission.html", false);
                    ErrorHandler.HandleException("ASPNET Account does not have rights to the filesystem", ex);
                }

                try
                {
                    string myNewDir = Path.Combine(Rainbow.Settings.Path.ApplicationPhysicalPath, "_createnewdir");


                    if (!System.IO.Directory.Exists(myNewDir))
                    {
                        System.IO.Directory.CreateDirectory(myNewDir);
                    }

                    if (System.IO.Directory.Exists(myNewDir))
                    {
                        System.IO.Directory.Delete(myNewDir);
                    }
                }
                catch (Exception ex)
                {
                    Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Fatal, "ASPNET Account does not have rights to the filesystem", ex);
                    HttpContext.Current.Response.Redirect("~/app_support/ErrorNoFilePermission.html", false);
                    ErrorHandler.HandleException("ASPNET Account does not have rights to the filesystem", ex);
                }
            }

            //Esperantus settings
            //If not found on web.confg defaults are provided here
            try
            {
                // Get Esperantus config
                NameValueCollection mySettings = (NameValueCollection)ConfigurationSettings.GetConfig("Esperantus");

                //Initializes default key and countries store
                if (mySettings != null)                 //Esperantus section must be specified anyway
                {
                    string baseDir = "/";
                    if (Context.Request.ApplicationPath.Length > 0)
                    {
                        baseDir = Context.Request.ApplicationPath;
                    }
                    baseDir = Server.MapPath(baseDir);
                    string binDir = Path.Combine(baseDir, "bin");
                    string resDir = Path.Combine(baseDir, "Resources");

                    // Try to get KeyStore, if not found set defaults
                    if (mySettings["KeysStore"] == null && mySettings["KeysStoreParameters"] == null)
                    {
                        string esperantusConfig = @"AssemblyName=" + Path.Combine(binDir, "Rainbow.dll") + ";KeysSubStore=Rainbow.Resources.Rainbow;Path=" + resDir + ";FilesPrefix=Rainbow";
                        //Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Info, "Running Esperantus from: " + esperantusConfig);
                        Esperantus.Data.DataFactory.SetDefaultKeysStore("Hybrid", esperantusConfig);
                    }

                    // CountryRegionsStore as reinbow default
                    if (mySettings["CountryRegionsStore"] == null && mySettings["CountryRegionsStoreParameters"] == null)
                    {
                        Esperantus.Data.DataFactory.SetDefaultCountryRegionsStore("Resources", @"AssemblyName=" + binDir + @"\Rainbow.dll;CountriesSubStore=Rainbow.Resources.Countries.xml");
                    }

                    // ***********************************************
                    // * Uncomment this code for overwrite Resources/Countries.xml
                    // * with you custom database list, then rebuil reainbow
                    // * and comment it again
                    // ***********************************************
                    //				if (mySettings["CountryRegionsStore"] == null && mySettings["CountryRegionsStoreParameters"] == null)
                    //				{
                    //					// We try to convert a SQLProvider string in a valid OleDb SQL connection string. It is not perfect.
                    //					string toBeTransformedConnectionString = ConfigurationSettings.AppSettings["connectionString"].ToLower();
                    //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("trusted_connection=true", "Integrated Security=SSPI");
                    //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("database=", "Initial Catalog=");
                    //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("server=", "Data Source=");
                    //					//Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Info, "Running Esperantus Countries from: " + toBeTransformedConnectionString);
                    //					Esperantus.Data.DataFactory.SetDefaultCountryRegionsStore("OleDB", "Provider=SQLOLEDB.1;" + toBeTransformedConnectionString);
                    //
                    //					Esperantus.CountryInfo.SaveCountriesAsXML(Esperantus.CountryTypes.AllCountries, Esperantus.CountryFields.Name, Path.Combine(resDir, "Countries.xml"));
                    //				}
                }
            }
            catch (Exception ex)
            {
                Rainbow.Helpers.LogHelper.Logger.Log(Rainbow.Configuration.LogLevel.Fatal, "Error in esperantus section", ex);
                Response.End();
            }

            //Start scheduler
            if (ConfigurationSettings.AppSettings["SchedulerEnable"].ToLower() == "yes")
            {
                int  cacheSize;
                long period;

                try {
                    cacheSize = int.Parse(ConfigurationSettings.AppSettings["SchedulerCacheSize"].ToLower());
                }
                catch {
                    cacheSize = 50;
                }

                try {
                    period = int.Parse(ConfigurationSettings.AppSettings["SchedulerPeriod"].ToLower());
                }
                catch {
                    period = 60000;
                }

                PortalSettings.Scheduler = CachedScheduler.GetScheduler(
                    HttpContext.Current.Server.MapPath(Rainbow.Settings.Path.ApplicationRoot),
                    PortalSettings.SqlConnectionString,
                    period,
                    cacheSize);
                PortalSettings.Scheduler.Start();
            }

            if (ConfigurationSettings.AppSettings.Get("UseProxyServerForServerWebRequests") == "true")
            {
                System.Net.GlobalProxySelection.Select = PortalSettings.GetProxy();
            }
        }
Пример #2
0
        /// <summary>
        /// Runs when the application starts.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        /// <remarks>
        /// </remarks>
        protected void Application_Start(object sender, EventArgs e)
        {
            RouteTable.Routes.MapHubs();
            var context = HttpContext.Current;

            // moved from PortalSettings
            var f = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(Portal)).Location);

            HttpContext.Current.Application.Lock();
            HttpContext.Current.Application["CodeVersion"] = 1908; //f.FilePrivatePart;
            HttpContext.Current.Application["NugetSelfUpdatesToInstall"] = false;
            HttpContext.Current.Application.UnLock();

            ErrorHandler.Publish(
                LogLevel.Info, string.Format("Application Started: code version {0}", Portal.CodeVersion));

            if (Config.CheckForFilePermission)
            {
                try
                {
                    var newDir = Path.Combine(Framework.Settings.Path.ApplicationPhysicalPath, "_createnewdir");

                    if (!Directory.Exists(newDir))
                    {
                        Directory.CreateDirectory(newDir);
                    }

                    if (Directory.Exists(newDir))
                    {
                        Directory.Delete(newDir);
                    }
                }
                catch (Exception ex)
                {
                    throw new AppleseedException(
                              LogLevel.Fatal,
                              HttpStatusCode.ServiceUnavailable,
                              "ASPNET Account does not have rights to the file system",
                              ex); // Jes1111
                }
            }

            // Start scheduler
            if (Config.SchedulerEnable)
            {
                PortalSettings.Scheduler =
                    CachedScheduler.GetScheduler(
                        context.Server.MapPath(Framework.Settings.Path.ApplicationRoot),
                        Config.SqlConnectionString,
                        Config.SchedulerPeriod,
                        Config.SchedulerCacheSize);
                PortalSettings.Scheduler.Start();
            }

            // Start proxy
            if (Config.UseProxyServerForServerWebRequests)
            {
                WebRequest.DefaultWebProxy = PortalSettings.GetProxy();
            }

            try
            {
                UpdateDB();

                //while (CheckForSelfUpdates());

                /* MVCContrib PortableAreas*/

                //Handlers for bus messages
                Bus.AddMessageHandler(typeof(BusMessageHandler));
                Bus.AddMessageHandler(typeof(DBScriptsHandler));

                //Register first core portable area (just in case...)
                Appleseed.Core.PortableAreaUtils.RegisterArea <Appleseed.Core.AppleseedCoreRegistration>(RouteTable.Routes, PortableAreaUtils.RegistrationState.Initializing);

                //Then, register all portable areas
                AreaRegistration.RegisterAllAreas(PortableAreaUtils.RegistrationState.Bootstrapping);
                RegisterRoutes(RouteTable.Routes);

                if (ConfigurationManager.AppSettings["RouteTesting"] != null &&
                    bool.Parse(ConfigurationManager.AppSettings["RouteTesting"]))
                {
                    //RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
                }

                ErrorHandler.Publish(LogLevel.Info, "Registing Routes");


                InputBuilder.BootStrap();
                ValueProviderFactories.Factories.Add(new JsonValueProviderFactory());

                ViewEngines.Engines.Clear();
                ViewEngines.Engines.Add(new AppleseedWebFormViewEngine());
                ViewEngines.Engines.Add(new AppleseedRazorViewEngine());
            }
            catch (Exception exc)
            {
                ErrorHandler.Publish(LogLevel.Error, exc);
            }

            try
            {
                var dbContext = new SelfUpdaterEntities();
                if (dbContext.SelfUpdatingPackages.Any())
                {
                    var selfUpdatesThread = new SelfUpdateThread();
                    var workerThread      = new Thread(selfUpdatesThread.CheckForSelfUpdates);
                    workerThread.Start();
                    HttpContext.Current.Application.Lock();
                    HttpContext.Current.Application["NugetSelfUpdatesToInstall"] = true; //f.FilePrivatePart;
                    HttpContext.Current.Application.UnLock();

                    // Delete Session logger
                    //HttpContext.Current.Session["NugetLogger"] = String.Empty;
                    HttpContext.Current.Application["NugetLogger"] = String.Empty;
                }
            }
            catch (Exception exc)
            {
                ErrorHandler.Publish(LogLevel.Error, exc);
            }
        }
Пример #3
0
        /// <summary>
        /// Application_Start()
        /// </summary>
        protected void Application_Start()
        {
            //HttpContext context = ContextReader.Current;
            HttpContext context = HttpContext.Current;

            // moved from PortalSettings
            FileVersionInfo f = FileVersionInfo.GetVersionInfo(Assembly.GetAssembly(typeof(Rainbow.Framework.Settings.Portal)).Location);

            HttpContext.Current.Application.Lock();
            HttpContext.Current.Application["CodeVersion"] = f.FilePrivatePart;
            HttpContext.Current.Application.UnLock();

            ErrorHandler.Publish(LogLevel.Info, "Application Started: code version " + Portal.CodeVersion.ToString());

            if (Config.CheckForFilePermission)
            {
                try
                {
                    string myNewDir = Path.Combine(Framework.Settings.Path.ApplicationPhysicalPath, "_createnewdir");

                    if (!Directory.Exists(myNewDir))
                    {
                        Directory.CreateDirectory(myNewDir);
                    }

                    if (Directory.Exists(myNewDir))
                    {
                        Directory.Delete(myNewDir);
                    }
                }
                catch (Exception ex)
                {
                    throw new RainbowException(LogLevel.Fatal, HttpStatusCode.ServiceUnavailable,
                                               "ASPNET Account does not have rights to the filesystem", ex); // Jes1111
                }
            }

            // TODO: Need country region store handling....

            /*
             *          //Esperantus settings
             *          //If not found in web.config defaults are provided here
             *          try
             *          {
             *                  // Get Esperantus config
             *                  NameValueCollection mySettings = (NameValueCollection) ConfigurationManager.GetSection("Esperantus");
             *
             *                  //Initializes default key and countries store
             *                  if (mySettings != null) //Esperantus section must be specified anyway
             *                  {
             *                          string baseDir = "/";
             *                          if (context.Request.ApplicationPath.Length > 0)
             *                                  baseDir = context.Request.ApplicationPath;
             *                          baseDir = Server.MapPath(baseDir);
             *                          string binDir = Path.Combine(baseDir, "bin");
             *      string resDir = Path.Combine(baseDir, "App_GlobalResources");
             *      // Try to get KeyStore, if not found set defaults
             *      //string dllName = Assembly.GetExecutingAssembly().Location + Assembly.GetExecutingAssembly().FullName + ".dll";
             *
             *                          // Try to get KeyStore, if not found set defaults
             *                          if (mySettings["KeysStore"] == null && mySettings["KeysStoreParameters"] == null)
             *                          {
             *                                  string esperantusConfig = @"Path=" + resDir + ";FilesPrefix=Rainbow";
             *                                  //string esperantusConfig = @"AssemblyName=" + Path.Combine(binDir, "Rainbow.dll") + ";KeysSubStore=Rainbow.Resources.Rainbow;Path=" + resDir + ";FilesPrefix=Rainbow";
             *                                  DataFactory.SetDefaultKeysStore("StoreXMLResxFiles", esperantusConfig);
             *                                  //DataFactory.SetDefaultKeysStore("Hybrid", esperantusConfig);
             *                          }
             *
             *                          // CountryRegionsStore as rainbow default
             *                          if (mySettings["CountryRegionsStore"] == null && mySettings["CountryRegionsStoreParameters"] == null)
             *                          {
             *                                  // DataFactory.SetDefaultCountryRegionsStore("Resources", @"AssemblyName=" + Path.Combine(binDir, "Rainbow.AppCode.dll") + ";CountriesSubStore=Resources.Rainbow.Countries.xml");
             *          DataFactory.SetDefaultCountryRegionsStore("Resources", @"AssemblyName=" + binDir + @"\App_GlobalResources.dll;CountriesSubStore=App_GlobalResources.Resources.Countries.xml");
             *                          }
             *
             *                          // ***********************************************
             *                          // * Uncomment this code for overwrite Resources/Countries.xml
             *                          // * with you custom database list, then rebuil reainbow
             *                          // * and comment it again
             *                          // ***********************************************
             *                          //				if (mySettings["CountryRegionsStore"] == null && mySettings["CountryRegionsStoreParameters"] == null)
             *                          //				{
             *                          //					// We try to convert a SQLProvider string in a valid OleDb SQL connection string. It is not perfect.
             *                          //					//jes1111 - string toBeTransformedConnectionString = ConfigurationSettings.AppSettings["connectionString"].ToLower();
             *                          //					string toBeTransformedConnectionString = Config.ConnectionString.ToLower();
             *                          //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("trusted_connection=true", "Integrated Security=SSPI");
             *                          //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("database=", "Initial Catalog=");
             *                          //					toBeTransformedConnectionString = toBeTransformedConnectionString.Replace("server=", "Data Source=");
             *                          //					//Rainbow.Framework.Helpers.LogHelper.Logger.Log(Rainbow.Framework.Site.Configuration.LogLevel.Info, "Running Esperantus Countries from: " + toBeTransformedConnectionString);
             *                          //					Esperantus.Data.DataFactory.SetDefaultCountryRegionsStore("OleDB", "Provider=SQLOLEDB.1;" + toBeTransformedConnectionString);
             *                          //
             *                          //					Esperantus.CountryInfo.SaveCountriesAsXML(Esperantus.CountryTypes.AllCountries, Esperantus.CountryFields.Name, Path.Combine(resDir, "Countries.xml"));
             *                          //				}
             *                  }
             *          }
             *          catch (Exception ex)
             *          {
             *                  throw new RainbowException(Rainbow.Framework.LogLevel.Fatal, HttpStatusCode.ServiceUnavailable, "Error loading Esperantus settings in Application_Start", ex); // Jes1111
             *          }
             */

            //Start scheduler
            if (Config.SchedulerEnable)
            {
                PortalSettings.Scheduler = CachedScheduler.GetScheduler(
                    context.Server.MapPath(Framework.Settings.Path.ApplicationRoot),
                    Config.SqlConnectionString,
                    Config.SchedulerPeriod,
                    Config.SchedulerCacheSize);
                PortalSettings.Scheduler.Start();
            }

            // Start proxy
            if (Config.UseProxyServerForServerWebRequests)
            {
                WebRequest.DefaultWebProxy = PortalSettings.GetProxy();
            }
        }