Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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()
                }
            });
        }
Beispiel #6
0
        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));
        }
Beispiel #8
0
        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
            });
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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);
            }
        }
Beispiel #13
0
        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);
            }
        }
Beispiel #14
0
        private string GetUploadFilePath()
        {
            var currentSite = SiteRepository.GetById(SiteId);

            if (!Directory.Exists(currentSite.UploadDir))
            {
                throw new DirectoryNotFoundException();
            }

            return(HttpUtility.UrlDecode($"{currentSite.UploadDir}\\contents\\{ContentId}\\{FileName}"));
        }
Beispiel #15
0
 public ActionResult <Site> Get(int id)
 {
     try
     {
         return(Ok(_repo.GetById(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Beispiel #16
0
        public static void Cancel(int id)
        {
            var site = SiteRepository.GetById(id);

            if (site == null)
            {
                throw new Exception(string.Format(SiteStrings.SiteNotFound, id));
            }

            site.AutoUnlock();
        }
Beispiel #17
0
        private string GetUploadFilePath()
        {
            var currentSite = SiteRepository.GetById(SiteId);

            if (!Directory.Exists(currentSite.UploadDir))
            {
                throw new DirectoryNotFoundException();
            }

            return(WebUtility.UrlDecode(ImportArticlesParams.GetUploadPath(currentSite, ContentId)));
        }
Beispiel #18
0
        private Site GetSite(int siteId)
        {
            var site = SiteRepository.GetById(siteId);

            if (site == null)
            {
                throw new ApplicationException(string.Format(SiteStrings.SiteNotFound, siteId));
            }

            return(site);
        }
Beispiel #19
0
        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);
        }
Beispiel #20
0
        /// <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
            });
        }
Beispiel #21
0
        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);
        }
Beispiel #23
0
        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;
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        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);
            }
        }
Beispiel #27
0
        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);
        }
Beispiel #28
0
        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
            });
        }
Beispiel #29
0
        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);
            }
        }
Beispiel #30
0
        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);
        }