private void Awake() { selector = GetComponent <EditorSelector>(); LevelInitializer.StartAddObjEvent.AddListener(() => { if (routine != null) { routine.Dispose(); } }); }
private void OnEnable() { _exportSettings = new EditorScriptableSingleton <ExportSettings>(); _editorSelector = new EditorSelector(_exportSettings.Instance.SelectedEditor); _editorSelector.Add(new PrefabEditor(this)); _editorSelector.Add(new SceneEditor(this)); _editorSelector.Add(new ArtifactEditor(this)); _editorSelector.Add(new PreloadAssemblyEditor(this)); _editorSelector.Add(new RuntimeAssemblyEditor(this)); _editorSelector.Add(new DependencyEditor(this)); _editorSelector.Add(new ExportEditor(this)); }
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, "Ошибка создания подключения к базе данных:"); } }
protected virtual void OnCloseFileClick(EventArgs e) { CloseFileClick?.Invoke(this, e); EditorSelector?.RemoveCurrentEditor(); }
public BasketballContext(string rootPath, EditorSelector sectionEditorSelector, EditorSelector unitEditorSelector, IDataLayer userConnection, IDataLayer fabricConnection, IDataLayer messageConnection, IDataLayer forumConnection) { this.rootPath = rootPath; this.imagesPath = Path.Combine(RootPath, "Images"); this.userConnection = userConnection; this.fabricConnection = fabricConnection; this.messageConnection = messageConnection; this.forumConnection = forumConnection; this.sectionEditorSelector = sectionEditorSelector; this.unitEditorSelector = unitEditorSelector; this.userStorage = new UserStorage(userConnection); this.NewsStorages = new TopicStorageCache(fabricConnection, messageConnection, NewsType.News); this.ArticleStorages = new TopicStorageCache(fabricConnection, messageConnection, ArticleType.Article); this.Forum = new ForumStorageCache(fabricConnection, forumConnection); string settingsPath = Path.Combine(rootPath, "SiteSettings.config"); if (!File.Exists(settingsPath)) { this.siteSettings = new SiteSettings(); } else { this.siteSettings = XmlSerialization.Load <SiteSettings>(settingsPath); } this.pull = new TaskPull( new ThreadLabel[] { Labels.Service }, TimeSpan.FromMinutes(15) ); this.newsCache = new Cache <Tuple <ObjectHeadBox, LightHead[]>, long>( delegate { ObjectHeadBox newsBox = new ObjectHeadBox(fabricConnection, string.Format("{0} order by act_from desc", DataCondition.ForTypes(NewsType.News)) ); int[] allNewsIds = newsBox.AllObjectIds; List <LightHead> actualNews = new List <LightHead>(); for (int i = 0; i < Math.Min(22, allNewsIds.Length); ++i) { int newsId = allNewsIds[i]; actualNews.Add(new LightHead(newsBox, newsId)); } return(_.Tuple(newsBox, actualNews.ToArray())); }, delegate { return(newsChangeTick); } ); this.articlesCache = new Cache <Tuple <ObjectBox, LightObject[]>, long>( delegate { ObjectBox articleBox = new ObjectBox(fabricConnection, string.Format("{0} order by act_from desc", DataCondition.ForTypes(ArticleType.Article)) ); int[] allArticleIds = articleBox.AllObjectIds; ObjectBox actualBox = new ObjectBox(FabricConnection, string.Format("{0} order by act_from desc limit 5", DataCondition.ForTypes(ArticleType.Article)) ); List <LightObject> actualArticles = new List <LightObject>(); foreach (int articleId in actualBox.AllObjectIds) { actualArticles.Add(new LightObject(actualBox, articleId)); } return(_.Tuple(articleBox, actualArticles.ToArray())); }, delegate { return(articleChangeTick); } ); this.lightStoreCache = new Cache <IStore, long>( delegate { LightObject contacts = DataBox.LoadOrCreateObject(fabricConnection, ContactsType.Contacts, ContactsType.Kind.CreateXmlIds, "main"); LightObject seo = DataBox.LoadOrCreateObject(fabricConnection, SEOType.SEO, SEOType.Kind.CreateXmlIds, "main"); SectionStorage sections = SectionStorage.Load(fabricConnection); WidgetStorage widgets = WidgetStorage.Load(fabricConnection, siteSettings.DisableScripts); RedirectStorage redirects = RedirectStorage.Load(fabricConnection); SiteStore store = new SiteStore(sections, null, widgets, redirects, contacts, seo); store.Links.AddLink("register", null); store.Links.AddLink("passwordreset", null); return(store); }, delegate { return(dataChangeTick); } ); this.lastPublicationCommentsCache = new Cache <RowLink[], long>( delegate { DataTable table = messageConnection.GetTable("", "Select Distinct article_id From message order by create_time desc limit 10" ); List <RowLink> lastComments = new List <RowLink>(10); foreach (DataRow row in table.Rows) { int topicId = ConvertHlp.ToInt(row[0]) ?? -1; if (News.ObjectById.Exist(topicId)) { TopicStorage topic = NewsStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } else if (Articles.ObjectById.Exist(topicId)) { TopicStorage topic = ArticleStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } } return(lastComments.ToArray()); }, delegate { return(publicationCommentChangeTick); } ); this.lastForumCommentsCache = new Cache <RowLink[], long>( delegate { DataTable table = forumConnection.GetTable("", "Select Distinct article_id From message order by create_time desc limit 7" ); List <RowLink> lastComments = new List <RowLink>(7); foreach (DataRow row in table.Rows) { int topicId = ConvertHlp.ToInt(row[0]) ?? -1; TopicStorage topic = Forum.TopicsStorages.ForTopic(topicId); RowLink lastMessage = _.Last(topic.MessageLink.AllRows); if (lastMessage != null) { lastComments.Add(lastMessage); } } return(lastComments.ToArray()); }, delegate { return(forumCommentChangeTick); } ); this.tagsCache = new Cache <TagStore, long>( delegate { ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc"); return(new TagStore(tagBox)); }, delegate { return(tagChangeTick); } ); //this.tagsCache = new Cache<Tuple<ObjectHeadBox, Dictionary<string, int>>, long>( // delegate // { // ObjectHeadBox tagBox = new ObjectHeadBox(fabricConnection, DataCondition.ForTypes(TagType.Tag) + " order by xml_ids asc"); // Dictionary<string, int> tagIdByKey = new Dictionary<string, int>(); // foreach (int tagId in tagBox.AllObjectIds) // { // string tagName = TagType.DisplayName.Get(tagBox, tagId); // if (StringHlp.IsEmpty(tagName)) // continue; // string tagKey = tagName.ToLower(); // tagIdByKey[tagKey] = tagId; // } // return _.Tuple(tagBox, tagIdByKey); // }, // delegate { return tagChangeTick; } //); this.unreadDialogCache = new Cache <TableLink, long>( delegate { return(DialogueHlp.LoadUnreadLink(forumConnection)); }, delegate { return(unreadChangeTick); } ); Pull.StartTask(Labels.Service, SiteTasks.SitemapXmlChecker(this, rootPath, delegate(LinkInfo[] sectionlinks) { List <LightLink> allLinks = new List <LightLink>(); allLinks.AddRange( ArrayHlp.Convert(sectionlinks, delegate(LinkInfo link) { return(new LightLink(link.Directory, null)); }) ); foreach (int articleId in Articles.AllObjectIds) { LightHead article = new LightHead(Articles, articleId); allLinks.Add( new LightLink(UrlHlp.ShopUrl("article", articleId), article.Get(ObjectType.ActTill) ?? article.Get(ObjectType.ActFrom) ) ); } foreach (int newsId in News.AllObjectIds) { LightHead news = new LightHead(News, newsId); allLinks.Add( new LightLink(UrlHlp.ShopUrl("news", newsId), news.Get(ObjectType.ActTill) ?? news.Get(ObjectType.ActFrom) ) ); } //foreach (int tagId in Tags.AllObjectIds) //{ // LightHead tag = new LightHead(Tags, tagId); // allLinks.Add( // new LightLink(string.Format("/tags?tag={0}", tagId) // ) // ); //} return(allLinks.ToArray()); } ) ); }