Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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
            });
        }
Esempio n. 4
0
        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()
                }
            });
        }
Esempio n. 5
0
        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()
                }
            });
        }
Esempio n. 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);
            }
        }
Esempio n. 7
0
        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));
        }
Esempio n. 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
            });
        }
Esempio n. 9
0
        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
            });
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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}"));
        }
Esempio n. 15
0
 public ActionResult <Site> Get(int id)
 {
     try
     {
         return(Ok(_repo.GetById(id)));
     }
     catch (Exception e)
     {
         return(BadRequest(e));
     }
 }
Esempio n. 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();
        }
Esempio n. 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)));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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
            });
        }
Esempio n. 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);
            }
        }
Esempio n. 22
0
        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);
        }
Esempio n. 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
            });
        }
Esempio n. 24
0
        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;
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
        }
Esempio n. 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
            });
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
        }