Ejemplo n.º 1
0
        public static void CheckAndCreateDialogueTables(IDataLayer forumConnection)
        {
            if (!SQLiteDatabaseHlp.TableExist(forumConnection, "correspondence"))
            {
                CreateTableForCorrespondence(forumConnection);
                Logger.AddMessage("Создана таблица переписки");
            }

            if (!SQLiteDatabaseHlp.TableExist(forumConnection, "dialogue"))
            {
                CreateTableForDialogue(forumConnection);
                Logger.AddMessage("Создана таблица диалогов");
            }
        }
Ejemplo n.º 2
0
        protected void Application_Start(object sender, EventArgs e)
        {
            string appPath   = HttpContext.Current.Server.MapPath("");
            string logFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Logs");

            try
            {
                Logger.EnableLogging(Path.Combine(logFolder, "site.log"), 2);

                GlobalConfiguration.Configure(WebApiConfig.Register);

                string databaseFolder = ApplicationHlp.CheckAndCreateFolderPath(appPath, "Data");

                IDataLayer userConnection = new SQLiteDataLayer(string.Format(
                                                                    connectionStringFormat, Path.Combine(databaseFolder, "user.db3")));

                IDataLayer fabricConnection = new SQLiteDataLayer(string.Format(
                                                                      connectionStringFormat, Path.Combine(databaseFolder, "fabric.db3")));

                IDataLayer messageConnection = new SQLiteDataLayer(string.Format(
                                                                       connectionStringFormat, Path.Combine(databaseFolder, "message.db3")));

                IDataLayer forumConnection = new SQLiteDataLayer(string.Format(
                                                                     connectionStringFormat, Path.Combine(databaseFolder, "forum.db3")));

                Logger.AddMessage("Подключения к базам данных успешно созданы");

                SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(userConnection);
                SQLiteDatabaseHlp.CheckAndCreateDataBoxTables(fabricConnection);
                MessageHlp.CheckAndCreateMessageTables(messageConnection);
                MessageHlp.CheckAndCreateMessageTables(forumConnection);
                DialogueHlp.CheckAndCreateDialogueTables(forumConnection);

                MetaHlp.ReserveDiapasonForMetaProperty(fabricConnection);

                FabricHlp.CheckAndCreateMenu(fabricConnection, "main");

                EditorSelector sectionEditorSelector = new EditorSelector(
                    new SectionTunes("news", "Новости"),
                    new SectionTunes("articles", "Статьи"),
                    new SectionTunes("forum", "Форум"),
                    new SectionTunes("rules", "Правила").Link(),
                    new SectionTunes("forumSection", "Раздел форума")
                    );

                EditorSelector unitEditorSelector = new EditorSelector(
                    new UnitTunes("reclame", "Рекламный блок").Tile().ImageAlt().Link().Annotation()
                    );

                Shop.Engine.Site.Novosti         = "news";
                Shop.Engine.Site.DirectPageLinks = true;
                //Shop.Engine.Site.AddFolderForNews = true;

                try
                {
                    string fabricScriptPath = Path.Combine(appPath, "FabricScript.sql");
                    if (File.Exists(fabricScriptPath))
                    {
                        string script = File.ReadAllText(fabricScriptPath);
                        Logger.AddMessage("Выполняем стартовый скрипт для fabric.db3: {0}", script);
                        fabricConnection.GetScalar("", script);
                    }

                    string userScriptPath = Path.Combine(appPath, "UserScript.sql");
                    if (File.Exists(userScriptPath))
                    {
                        string script = File.ReadAllText(userScriptPath);
                        Logger.AddMessage("Выполняем стартовый скрипт для user.db3: {0}", script);
                        userConnection.GetScalar("", script);
                    }
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex, "Ошибка при выполнении стартового скрипта");
                }

                SiteContext.Default = new BasketballContext(
                    appPath, sectionEditorSelector, unitEditorSelector,
                    userConnection, fabricConnection, messageConnection, forumConnection
                    );

                SiteContext.Default.Pull.StartTask(Labels.Service,
                                                   MemoryChecker((BasketballContext)SiteContext.Default)
                                                   );

                SiteContext.Default.Pull.StartTask(Labels.Service,
                                                   SiteTasks.CleaningSessions(SiteContext.Default,
                                                                              TimeSpan.FromHours(1), TimeSpan.FromMinutes(10), TimeSpan.FromMinutes(1)
                                                                              )
                                                   );
            }
            catch (Exception ex)
            {
                Logger.WriteException(ex, "Ошибка создания подключения к базе данных:");
            }
        }