コード例 #1
0
ファイル: DataObjects.cs プロジェクト: mrkurt/mubble-old
        public void SetupDB()
        {
            Console.WriteLine("Setting up database");
            #region Create newest DB
            Server s = new Server(".\\sqlexpress");

            Database db = s.Databases["mubble_test"];

            if (db != null)
            {

                db.ExecuteNonQuery(@"ALTER DATABASE mubble_test
                                    SET SINGLE_USER
                                    WITH ROLLBACK IMMEDIATE");
                db.Drop();
                Console.WriteLine("Database dropped");

            }
            db = new Database(s, "mubble_test");
            db.Create();

            Console.WriteLine("Database created");

            ProcessStartInfo proc = new ProcessStartInfo("creator.exe");
            proc.Arguments = "migrate /mode test";

            proc.WorkingDirectory = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\");
            proc.UseShellExecute = false;
            proc.RedirectStandardError = true;

            Process process = Process.Start(proc);
            process.WaitForExit();

            string errors = process.StandardError.ReadToEnd();

            Assert.IsEmpty(errors, string.Format("The errors returned were {0}", errors));

            Console.WriteLine();

            Console.WriteLine("DB Structure updated");

            #endregion

            ConnectionStringsSection section = (ConnectionStringsSection)
                    ConfigurationManager.GetSection("connectionStrings");
            Assert.IsNotNull(section.ConnectionStrings["mubbleTestDB"], "No mubbleTestDB connection string defined in config.");
            string cnString = section.ConnectionStrings["mubbleTestDB"].ConnectionString;

            Console.WriteLine(cnString);
            SqlConnection cn = new SqlConnection(cnString);
            cn.Open();
            Console.WriteLine("Connected successfully: {0}", cn.Database);
            cn.Close();

            ActiveObjects.SqlServer.SqlDataUtility.ReadDB = ActiveObjects.SqlServer.SqlDataUtility.WriteDB = cn.ConnectionString;

            Mubble.Config.Module.LoadDbFromFileSystem(System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\web\Modules"), "~/Modules/");

            try
            {
                db.ExecuteNonQuery(System.IO.File.ReadAllText("db_inserts.sql"));
            }
            catch (Exception ex)
            {
                Exception x = ex;
                while (x.InnerException != null && x.InnerException.Message != null)
                {
                    Console.WriteLine(" -- " + x.InnerException.Message);
                    x = x.InnerException;
                }
                throw ex;
            }

            Console.WriteLine("DB crapola inserted");

            if (System.IO.Directory.Exists("Store"))
            {
                System.IO.Directory.Delete("Store", true);
            }
            System.IO.Directory.CreateDirectory("Store\\");
            Mubble.Models.Settings.Lucene lucene = new Mubble.Models.Settings.Lucene();
            lucene.IndexLocation = "Store\\Lucene";
            Mubble.Models.Settings.Application.Lucene = lucene;
        }
コード例 #2
0
ファイル: Global.asax.cs プロジェクト: mrkurt/mubble-old
        void Application_Start(Object sender, EventArgs e)
        {
            Benchmark b = new Benchmark(true);
            System.IO.FileInfo logFile = new System.IO.FileInfo(Server.MapPath("Mubble.log4net"));
            SqlServerMetrics.Init();
            log4net.Config.XmlConfigurator.ConfigureAndWatch(logFile);
            Configuration configuration = WebConfigurationManager.OpenWebConfiguration("~/");
            HttpHandlersSection handlers = (HttpHandlersSection)configuration.GetSection("system.web/httpHandlers");

            foreach (HttpHandlerAction handler in handlers.Handlers)
            {
                Type t = Type.GetType(handler.Type);
                if (t != null &&
                    t.IsSubclassOf(typeof(Handlers.HttpHandler)) &&
                    handler.Path.IndexOf('*') == 0 &&
                    !Mubble.Handlers.Settings.Extensions.ContainsKey(t.FullName))
                {
                   Mubble.Handlers.Settings.Extensions.Add(t.FullName, handler.Path.Substring(1));
               }
               else if (t != null && t == typeof(Mubble.Handlers.StaticFileHelper) && handler.Path.StartsWith("*"))
               {
                   Config.Caching.StaticFileHelperExtension = handler.Path.Substring(1);
               }
            }

            // Set various middle tier object configuration settings
            ConnectionStringsSection section = (ConnectionStringsSection)
                    WebConfigurationManager.GetSection("connectionStrings");
            ActiveObjects.SqlServer.SqlDataUtility.ReadDB = section.ConnectionStrings["mubbleDBRead"].ConnectionString;
            ActiveObjects.SqlServer.SqlDataUtility.WriteDB = section.ConnectionStrings["mubbleDBRead"].ConnectionString;

            Controller.RootContentPath = WebConfigurationManager.AppSettings["DefaultContent"];
            Controller.RootContent = DataBroker.GetController(Controller.RootContentPath);

            File.FileStoreBase = Server.MapPath(WebConfigurationManager.AppSettings["StoreBase"]);

            MubbleUrl.ApplicationPath = this.Context.Request.ApplicationPath;

            // Loads new modules
            Mubble.Config.Module.LoadDbFromFileSystem(Server.MapPath("~/Modules"), "~/Modules/");

            Mubble.Models.Settings.Lucene lucene = new Mubble.Models.Settings.Lucene();
            lucene.IndexLocation = Server.MapPath(WebConfigurationManager.AppSettings["LuceneIndexLocation"]);
            Mubble.Models.Settings.Application.Lucene = lucene;

            Mubble.Models.Settings.Web web = new Mubble.Models.Settings.Web();
            web.ApplicationPath = this.Context.Request.ApplicationPath;;
            Mubble.Models.Settings.Application.Web = web;

            Mubble.Models.QueryEngine.Engine.CurrentEngine =
                            Mubble.Models.QueryEngine.Engines.Lucene.Init(lucene.IndexLocation, Config.Index.Current.UseRamSearcher);
            //Mubble.Models.QueryEngine.Engines.Lucene.Init(lucene.IndexLocation, Config.Index.Current.UseRamSearcher);

            //Mubble.Caching.CacheLocation = System.IO.Path.Combine(File.FileStoreBase, "CacheKeys");

            //DataBroker.Warmup();

            CacheBroker.Init();

            Mubble.Models.ScheduledCommand.StartTimer();

            b.End();

            log.InfoFormat("Application startup too {0}", b.ElapsedTime);
        }