private IReadOnlyCollection <NavBarItem> CreateNavBarItems() { var rt = WebPipeline.CurrentRequest; var siteId = rt.Route.SiteId; var adminSite = _siteRepository.GetById(siteId); var sitemap = SitemapBuilder.BuildSitemap(adminSite, ContentEnvironment.Live, SitemapBuilderFilters.DisplayInNavigation); List <NavBarItem> navBarItems = new List <NavBarItem>(); foreach (var node in sitemap.ChildNodes) { var item = CreateNavBarItem(node); navBarItems.Add(item); } return(navBarItems); }
public static MessageResult AssembleContentsPreAction(int id) { var site = SiteRepository.GetById(id); var message = !site.IsLive ? null : string.Format(SiteStrings.SiteInLiveWarning, site.ModifiedToDisplay, site.LastModifiedByUserToDisplay); return(string.IsNullOrEmpty(message) ? null : MessageResult.Confirm(message)); }
public static ContentInitListResult InitList(int siteId, bool isVirtual = false) { var isActionAccessable = !isVirtual && SecurityRepository.IsActionAccessible(ActionCode.AddNewContent); if (siteId > 0) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, siteId)); } var isSiteAccessable = !isVirtual && SecurityRepository.IsEntityAccessible(EntityTypeCode.Site, siteId, ActionTypeCode.Update); return(new ContentInitListResult { ParentName = site.Name, IsVirtual = isVirtual, IsAddNewAccessable = isActionAccessable && isSiteAccessable }); } return(new ContentInitListResult { IsVirtual = isVirtual, IsAddNewAccessable = isActionAccessable }); }
protected override MultistepActionSettings CreateActionSettings(int siteId, int templateId) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId)); } if (site.IsDotNet) { return(new MultistepActionSettings { Stages = new[] { templateCommand.GetStageSettings(), pagesCommand.GetStageSettings(), notificationsCommand.GetStageSettings() } }); } return(new MultistepActionSettings { Stages = new[] { pagesCommand.GetStageSettings() } }); }
protected override MultistepActionServiceContext CreateContext(int siteId, int templateId, bool?boundToExternal) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId)); } if (site.IsDotNet) { return(new MultistepActionServiceContext { CommandStates = new[] { templateCommand.GetState(), pagesCommand.GetState(), notificationsCommand.GetState() } }); } return(new MultistepActionServiceContext { CommandStates = new[] { pagesCommand.GetState() } }); }
protected override IMultistepActionStageCommand CreateCommand(MultistepActionStageCommandState state) { var site = SiteRepository.GetById(state.Id); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, state.Id)); } switch (state.Type) { case BuildSiteStageCommandTypes.CreateFolders: return(new CreateFoldersCommand(state)); case BuildSiteStageCommandTypes.BuildTemplates: return(new AssembleTemplatesCommand(state)); case BuildSiteStageCommandTypes.BuildPages: return(new AssemblePagesCommand(state, true, site.IsDotNet)); case BuildSiteStageCommandTypes.BuildNotifications: return(new AssembleNotificationsCommand(state, true)); default: throw new ApplicationException("Undefined Site Building Stage Command Type: " + state.Type); } }
public override MultistepActionSettings Setup(int parentId, int templateId, bool?boundToExternal) { var site = SiteRepository.GetById(parentId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, parentId)); } var template = PageTemplateRepository.GetPageTemplatePropertiesById(templateId); if (site.IsDotNet) { templateCommand = new AssembleTemplateCommand(templateId, template.Name); pagesCommand = new AssemblePagesCommand(templateId, template.Name, false, true); pagesCommand.Setup(); notificationsCommand = new AssembleNotificationsCommand(templateId, template.Name, false); } else { pagesCommand = new AssemblePagesCommand(templateId, template.Name, false, false); pagesCommand.Setup(); } return(base.Setup(parentId, templateId, boundToExternal)); }
public MultistepActionStepResult Step(int step) { var site = SiteRepository.GetById(SiteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, SiteId)); } if (!site.IsDotNet) { throw new ApplicationException(string.Format(SiteStrings.ShouldBeDotNet)); } if (site.IsLive) { site.CreateLiveSiteFolders(); } else { site.CreateStageSiteFolders(); } return(new MultistepActionStepResult { ProcessedItemsCount = 1 }); }
public MultistepActionStepResult Step(int step) { var site = SiteRepository.GetById(SiteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, SiteId)); } var deletedContentsIds = ContentRepository.BatchRemoveContents(SiteId, ITEMS_PER_STEP); var deletedContentsStrIds = new HashSet <string>(deletedContentsIds.Select(id => id.ToString()), StringComparer.InvariantCultureIgnoreCase); var sitePath = site.BasePathInfo.GetSubPathInfo("contents").Path; if (Directory.Exists(sitePath)) { foreach (var sd in new DirectoryInfo(sitePath).EnumerateDirectories().Where(i => deletedContentsStrIds.Contains(i.Name))) { sd.Delete(true); } } return(new MultistepActionStepResult { ProcessedItemsCount = ITEMS_PER_STEP }); }
public static MessageResult AssembleContents(int id) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } if (!site.IsDotNet) { return(MessageResult.Error(string.Format(SiteStrings.ShouldBeDotNet))); } var sqlMetalPath = QPConfiguration.ConfigVariable(Config.SqlMetalKey); if (site.ExternalDevelopment) { var liveTempDirectory = $@"{site.TempDirectoryForClasses}\live"; var stageTempDirectory = $@"{site.TempDirectoryForClasses}\stage"; if (Directory.Exists(liveTempDirectory)) { Directory.Delete(liveTempDirectory, true); } Directory.CreateDirectory(liveTempDirectory); if (Directory.Exists(stageTempDirectory)) { Directory.Delete(stageTempDirectory, true); } Directory.CreateDirectory(stageTempDirectory); if (File.Exists(site.TempArchiveForClasses)) { File.Delete(site.TempArchiveForClasses); } new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString) { SiteRoot = liveTempDirectory, IsLive = true, DisableClassGeneration = site.DownloadEfSource }.Assemble(); new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString) { SiteRoot = stageTempDirectory, IsLive = false, DisableClassGeneration = site.DownloadEfSource }.Assemble(); ZipFile.CreateFromDirectory(site.TempDirectoryForClasses, site.TempArchiveForClasses); return(MessageResult.Download($"/Backend/Site/GetClassesZip/{id}")); } new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString).Assemble(); return(null); }
public static MessageResult AssembleContents(int id) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } if (!site.IsDotNet) { return(MessageResult.Error(string.Format(SiteStrings.ShouldBeDotNet))); } var sqlMetalPath = QPConfiguration.ConfigVariable(Config.SqlMetalKey); var extDbType = (QP.ConfigurationService.Models.DatabaseType)QPContext.DatabaseType; if (site.ExternalDevelopment) { var liveTempDirectory = $@"{site.TempDirectoryForClasses}{Path.DirectorySeparatorChar}live"; var stageTempDirectory = $@"{site.TempDirectoryForClasses}{Path.DirectorySeparatorChar}stage"; if (Directory.Exists(liveTempDirectory)) { Directory.Delete(liveTempDirectory, true); } Directory.CreateDirectory(liveTempDirectory); if (Directory.Exists(stageTempDirectory)) { Directory.Delete(stageTempDirectory, true); } Directory.CreateDirectory(stageTempDirectory); if (File.Exists(site.TempArchiveForClasses)) { File.Delete(site.TempArchiveForClasses); } new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType) { SiteRoot = liveTempDirectory, IsLive = true, DisableClassGeneration = site.DownloadEfSource }.Assemble(); new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType) { SiteRoot = stageTempDirectory, IsLive = false, DisableClassGeneration = site.DownloadEfSource }.Assemble(); var urlHelper = HttpContext.RequestServices.GetRequiredService <IUrlHelper>(); ZipFile.CreateFromDirectory(site.TempDirectoryForClasses, site.TempArchiveForClasses); return(MessageResult.Download(urlHelper.Content($"~/Site/GetClassesZip/{id}"))); } new AssembleContentsController(id, sqlMetalPath, QPContext.CurrentDbConnectionString, extDbType).Assemble(); return(null); }
public void Should_return_site_by_id() { using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var site = repository.GetById(_siteId1); Assert.NotNull(site); } }
public void Should_return_null_if_site_is_deleted() { using (var context = new WeapsyDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var site = repository.GetById(_deletedSiteId); Assert.Null(site); } }
private string GetUploadFilePath() { var currentSite = SiteRepository.GetById(SiteId); if (!Directory.Exists(currentSite.UploadDir)) { throw new DirectoryNotFoundException(); } return(HttpUtility.UrlDecode($"{currentSite.UploadDir}\\contents\\{ContentId}\\{FileName}")); }
public ActionResult <Site> Get(int id) { try { return(Ok(_repo.GetById(id))); } catch (Exception e) { return(BadRequest(e)); } }
public static void Cancel(int id) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } site.AutoUnlock(); }
private string GetUploadFilePath() { var currentSite = SiteRepository.GetById(SiteId); if (!Directory.Exists(currentSite.UploadDir)) { throw new DirectoryNotFoundException(); } return(WebUtility.UrlDecode(ImportArticlesParams.GetUploadPath(currentSite, ContentId))); }
private Site GetSite(int siteId) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId)); } return(site); }
public MultistepActionStepResult Step(int step) { var result = new MultistepActionStepResult(); var sourceSite = SiteRepository.GetById(SiteId); var destinationSite = SiteRepository.GetById(NewSiteId.Value); var helper = new CopySiteFilesHelper(sourceSite, destinationSite); helper.CopyDirectories(); result.ProcessedItemsCount = helper.CopyFiles(step); return(result); }
/// <summary> /// Инициализация списка контентов /// </summary> public static ContentInitListResult InitUnionSourceList(int siteId) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, siteId)); } return(new ContentInitListResult { ParentName = site.Name }); }
public static void CaptureLock(int id) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } if (site.CanBeUnlocked) { EntityObjectRepository.CaptureLock(site); } }
public override MessageResult PreAction(int parentId, int templateId) { var site = SiteRepository.GetById(parentId); if (site == null) { return(MessageResult.Error(string.Format(SiteStrings.SiteNotFound, parentId), new[] { parentId })); } if (site.IsLive) { return(MessageResult.Confirm(TemplateStrings.AssembleLiveSiteTemplateConfirmation, new[] { parentId })); } return(null); }
public PageInitListResult InitPageListForSite(int siteId) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, siteId)); } return(new PageInitListResult { ParentName = site.Name, IsAddNewAccessable = false }); }
public CopySiteSettingsCommand(int siteId, string siteName) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId)); } SiteId = siteId; SiteName = siteName; var prms = HttpContext.Session.GetValue <CopySiteSettings>(HttpContextSession.CopySiteServiceSettings); NewSiteId = prms.DestinationSiteId; }
public static MessageResult SimpleRemove(int id) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } if (site.LockedByAnyoneElse) { return(MessageResult.Error(string.Format(SiteStrings.LockedByAnyoneElse, site.LockedByDisplayName))); } SiteRepository.Delete(id); return(null); }
public void Should_save_new_site() { var newSite = SiteFactory.CreateNew(Guid.NewGuid(), "Name 3"); using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); repository.Create(newSite); } using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var language = repository.GetById(newSite.Id); Assert.NotNull(language); } }
internal static Content InternalNew(int siteId, int?groupId) { var site = SiteRepository.GetById(siteId); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, siteId)); } var content = Content.Create(site); if (groupId.HasValue) { content.GroupId = groupId.Value; } return(content); }
public MultistepActionStepResult Step(int step) { var site = SiteRepository.GetById(SiteId); if (site == null) { throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, SiteId)); } if (site.LockedByAnyoneElse) { throw new ApplicationException(string.Format(SiteStrings.LockedByAnyoneElse, site.LockedByDisplayName)); } SiteRepository.Delete(SiteId); return(new MultistepActionStepResult { ProcessedItemsCount = 1 }); }
public void Should_update_site() { const string newSiteName = "New Title 1"; var siteToUpdate = SiteFactory.CreateNew(_siteId1, newSiteName); using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); repository.Update(siteToUpdate); } using (var context = new MSSQLDbContext(_contextOptions)) { var repository = new SiteRepository(DbContextShared.CreateNewContextFactory(context), Shared.CreateNewMapper()); var updatedSite = repository.GetById(_siteId1); Assert.AreEqual(newSiteName, updatedSite.Name); } }
private static Site Read(int id, bool withAutoLock) { var site = SiteRepository.GetById(id); if (site == null) { throw new Exception(string.Format(SiteStrings.SiteNotFound, id)); } if (site.LockedByAnyoneElse || !site.IsUpdatable) { site.IsReadOnly = true; } else if (withAutoLock) { site.AutoLock(); } site.LoadLockedByUser(); return(site); }