public void ReGeneratePages() { var session = SessionFactory.Create(); var repos = new PageTreeRepository(session); var pageRepos = new PageRepository(session); var locator = new Mock<IServiceLocator>(); locator.Setup(x => x.ResolveAll<IPostLoadProcessor>()).Returns(new IPostLoadProcessor[] { new ChildPageSection(pageRepos) }); locator.Setup(x => x.ResolveAll<ITextProcessor>()).Returns(new ITextProcessor[] { new MarkdownParser(), new WikiLinkProcessor(repos) }); locator.Setup(x => x.ResolveAll<IHtmlProcessor>()).Returns(new IHtmlProcessor[] { new HeadingProcessor() }); var pre = new PreProcessorService(locator.Object); var user = new UserRepository(session).GetOrCreate("BA84194", "Jonas Gauffin"); var myIdentity = new WikiIdentity(user); Thread.CurrentPrincipal = new WikiPrinicpal(myIdentity); using (var transaction = session.BeginTransaction()) { foreach (var page in pageRepos.FindAll()) { var ctx = new PreProcessorContext(page, page.RawBody); pre.Invoke(ctx); page.SetBody(ctx, "Changed to relative links", pageRepos); } transaction.Commit(); } }
public ActionResult Pages() { try { IList<PageViewModel> postList = null; using (UnitOfWork uow = new UnitOfWork()) { PageRepository pr = new PageRepository(uow.Current); IList<Page> tmpList = pr.FindAll().ToList(); if (tmpList != null) { postList = new List<PageViewModel>(); foreach (var p in tmpList) { PageViewModel pvm = new PageViewModel(); pvm.Id = p.Id; pvm.Data = p.Date.Value; pvm.Titolo = p.Title; pvm.Autore = p.Author.NameAndSurname; pvm.Categoria = p.Category.Name; postList.Add(pvm); } } } return View(postList); } catch (Exception ex) { return Error(ex); } }
private static void export() { System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); TextureRepository texturesRepository = new TextureRepository(); texturesRepository.FromJSON(File.ReadAllText( URLManager.CombinePath( Application.streamingAssetsPath, AssetPath.DEFAULT_REPOSITORY_IN_SA, URLManager.DEFAULT_TEXTURE_REPOSITORY_FILENAME) )); PageRepository pagesRepository = new PageRepository(); pagesRepository.FromJSON(File.ReadAllText( URLManager.CombinePath( Application.streamingAssetsPath, AssetPath.DEFAULT_REPOSITORY_IN_SA, URLManager.DEFAULT_PAGE_REPOSITORY_FILENAME) )); lastUsedAssetPath = AssetPath.CreateAssetPath(AssetPath.DEFAULT_RESOURCES_PATH, wizard.Folder) + "/" + PAGE_PREFIX + wizard.Name + ".asset"; ImageData data = exportMeshData(); AssetDatabase.CreateAsset(data, lastUsedAssetPath); AssetImporter asset = AssetImporter.GetAtPath(lastUsedAssetPath); string bundleName = wizard.Folder + ".unity3d"; asset.SetAssetBundleNameAndVariant(bundleName, ""); AssetDatabase.SaveAssets(); // Модификация реестра страниц string previewPath = AssetDatabase.GetAssetPath(wizard.PreviewTexture); uint textureID = texturesRepository.Find(t => t.Location.ResourceName == previewPath).ID; List <uint> allPagesIDs = pagesRepository.FindAll(p => true).Select(p => p.ID).ToList(); uint maxPageID = 0; allPagesIDs.ForEach(id => maxPageID = (id > maxPageID) ? id : maxPageID); Page oldPage = pagesRepository.Find(p => p.Location.ResourceName == lastUsedAssetPath); if (oldPage == null) { pagesRepository.Add(new Page( maxPageID + 1, lastUsedAssetPath, bundleName, textureID )); } else { pagesRepository.Storage[oldPage.ID].TextureID = textureID; // = new Page( // oldPage.ID, // oldPage.Location.ResourceName, // bundleName, // textureID // ); } File.WriteAllText(URLManager.CombinePath( Application.streamingAssetsPath, AssetPath.DEFAULT_REPOSITORY_IN_SA, URLManager.DEFAULT_PAGE_REPOSITORY_FILENAME), pagesRepository.ToJSON()); sw.Stop(); Debug.Log(string.Format("Import completed. Time elapsed: {0}ms", sw.ElapsedMilliseconds)); }