public async Task DeleteAllTaxonomies(CancellationToken?cancellation)
        {
            try
            {
                SyncLog.Log("Deleting all taxonomies");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEALLTAXONOMIES");

                var taxonomyIds = await GetAllTaxonomyIds();

                foreach (var taxonomyId in taxonomyIds)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    await DeleteTaxonomy(taxonomyId);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEALLTAXONOMIES", ex);
                throw;
            }
        }
Exemple #2
0
        public async Task DeleteAllItems(CancellationToken?cancellation, Guid?contentTypeId = null)
        {
            try
            {
                SyncLog.Log("Deleting all content items");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEALLITEMS");

                var itemIds = await GetAllItemIds(contentTypeId);

                var index = 0;

                foreach (var itemId in itemIds)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    await DeleteItem(itemId);

                    index++;

                    if (index % 10 == 0)
                    {
                        SyncLog.Log($"Deleted content items ({index}/{itemIds.Count})");
                    }
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEALLITEMS", ex);
                throw;
            }
        }
Exemple #3
0
        public async Task DeleteMediaFiles(CancellationToken?cancellation, ICollection <MediaFileInfo> mediaFiles, string info)
        {
            try
            {
                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEMEDIAFILES", info);

                var index = 0;

                foreach (var mediaFile in mediaFiles)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    index++;

                    SyncLog.Log($"Deleting media file {mediaFile.FileName} ({index}/{mediaFiles.Count})");

                    await DeleteMediaFile(mediaFile);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEMEDIAFILES", ex);
                throw;
            }
        }
Exemple #4
0
        public async Task SyncRelationships()
        {
            try
            {
                SyncLog.Log($"Synchronizing relationships");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "SYNCRELATIONSHIPS");

                var kontentSnippet = await GetSnippet(RELATED_PAGES_GUID);

                if (kontentSnippet != null)
                {
                    await PatchRelationshipsSnippet(kontentSnippet);
                }
                else
                {
                    await CreateRelationshipsSnippet();
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "SYNCRELATIONSHIPS", ex);
                throw;
            }
        }
Exemple #5
0
        public async Task DeleteAllContentTypes(CancellationToken?cancellation)
        {
            try
            {
                SyncLog.Log("Deleting content types");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEALLCONTENTTYPES");

                var contentTypeIds = await GetAllContentTypeIds();

                foreach (var contentTypeId in contentTypeIds)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    await DeleteContentType(contentTypeId);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEALLCONTENTTYPES", ex);
                throw;
            }
        }
Exemple #6
0
        public async Task DeletePages(CancellationToken?cancellation, ICollection <TreeNode> nodes, string info)
        {
            try
            {
                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEPAGES", info);

                var index = 0;

                foreach (var node in nodes)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    index++;

                    SyncLog.Log($"Deleting page {node.NodeAliasPath} ({index}/{nodes.Count})");

                    await DeletePage(node);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEPAGES", ex);
                throw;
            }
        }
Exemple #7
0
        public async Task DeleteAttachments(CancellationToken?cancellation, ICollection <AttachmentInfo> attachments, string info)
        {
            try
            {
                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEATTACHMENTS", info);

                var index = 0;

                foreach (var attachment in attachments)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    index++;

                    SyncLog.Log($"Deleting attachment {attachment.AttachmentName} ({index}/{attachments.Count})");

                    await DeleteAttachment(attachment);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEATTACHMENTS", ex);
                throw;
            }
        }
Exemple #8
0
        public async Task DeleteAllAssets(CancellationToken?cancellation)
        {
            try
            {
                SyncLog.Log("Deleting all assets");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETEALLASSETS");

                var assetIds = await GetAllAssetIds();

                var index = 0;

                foreach (var assetId in assetIds)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    await DeleteAsset(assetId);

                    index++;

                    if (index % 10 == 0)
                    {
                        SyncLog.Log($"Deleted assets ({index}/{assetIds.Count})");
                    }
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETEALLASSETS", ex);
                throw;
            }
        }
Exemple #9
0
        public async Task UpsertAllMediaFiles(MediaLibraryInfo mediaLibrary)
        {
            try
            {
                SyncLog.Log($"Synchronizing files for media library {mediaLibrary.LibraryDisplayName}");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "UPSERTMEDIAFILES", mediaLibrary.LibraryDisplayName);

                var mediaFiles = MediaFileInfoProvider.GetMediaFiles()
                                 .WhereEquals("FileLibraryID", mediaLibrary.LibraryID)
                                 .BinaryData(false);

                var index = 0;

                foreach (var mediaFile in mediaFiles)
                {
                    index++;

                    SyncLog.Log($"Media file {mediaFile.FilePath} ({index}/{mediaFiles.Count})");

                    await SyncMediaFile(mediaFile);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "UPSERTMEDIAFILES", ex);
                throw;
            }
        }
        private async Task DeleteCategoriesTaxonomy()
        {
            try
            {
                SyncLog.Log("Deleting categories");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "DELETECATEGORIESTAXONOMY");

                var externalId = GetTaxonomyExternalId(CATEGORIES_GUID);
                var endpoint   = $"/taxonomies/external-id/{HttpUtility.UrlEncode(externalId)}";

                await ExecuteWithoutResponse(endpoint, HttpMethod.Delete);
            }
            catch (HttpException ex)
            {
                if (ex.GetHttpCode() == 404)
                {
                    // May not be there yet, 404 is OK
                    return;
                }

                throw;
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "DELETECATEGORIESTAXONOMY", ex);
                throw;
            }
        }
        public async Task SyncCategories()
        {
            try
            {
                SyncLog.Log("Synchronizing categories");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "SYNCCATEGORIES");

                // TODO - consider patch
                await DeleteCategoriesTaxonomy();
                await CreateCategoriesTaxonomy();
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "SYNCCATEGORIES", ex);
                throw;
            }
        }
Exemple #12
0
        public async Task SyncAllPages(CancellationToken?cancellation, DataClassInfo contentType = null, string path = null)
        {
            if (contentType == null)
            {
                throw new ArgumentNullException(nameof(contentType));
            }

            try
            {
                SyncLog.Log($"Synchronizing pages for content type {contentType.ClassDisplayName}");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "SYNCALLPAGES", contentType.ClassDisplayName);

                var documents = GetSourceDocuments(contentType.ClassName)
                                .OnSite(Settings.Sitename)
                                .AllCultures()
                                .PublishedVersion();

                var documentsOnPath = string.IsNullOrEmpty(path) ?
                                      documents :
                                      documents.Path(path, PathTypeEnum.Section);

                var index = 0;

                foreach (var node in documents)
                {
                    if (cancellation?.IsCancellationRequested == true)
                    {
                        return;
                    }

                    index++;

                    SyncLog.Log($"Synchronizing page { node.NodeAliasPath} - { node.DocumentCulture} ({ node.NodeGUID}) - {index}/{documents.Count}");

                    await SyncPage(node);
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "SYNCALLPAGES", ex);
                throw;
            }
        }
Exemple #13
0
        public async Task SyncAllAttachments(CancellationToken?cancellation)
        {
            try
            {
                SyncLog.Log("Synchronizing page attachments");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "SYNCALLATTACHMENTS");

                var attachments = AttachmentInfoProvider.GetAttachments()
                                  .OnSite(Settings.Sitename);

                await SyncAttachments(cancellation, attachments);
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "SYNCALLATTACHMENTS", ex);
                throw;
            }
        }
Exemple #14
0
        public async Task SyncCultures()
        {
            try
            {
                SyncLog.Log("Synchronizing cultures");

                SyncLog.LogEvent(EventType.INFORMATION, "KenticoKontentPublishing", "SYNCCULTURES");

                var existingLanguages = await GetAllLanguages();

                var cultures = CultureSiteInfoProvider.GetSiteCultures(Settings.Sitename).ToList();

                await PatchDefaultLanguage();

                // Deactivate all unknown languages to make sure they don't conflict with the active ones
                foreach (var language in existingLanguages)
                {
                    if (language.IsActive && (language.Id != Guid.Empty) && !cultures.Exists(culture => GetLanguageExternalId(culture.CultureGUID).Equals(language.ExternalId)))
                    {
                        await DeactivateLanguage(language);
                    }
                }

                // Create or update all known languages
                foreach (var culture in cultures)
                {
                    if (existingLanguages.Exists(language => language.ExternalId?.Equals(GetLanguageExternalId(culture.CultureGUID)) == true))
                    {
                        await PatchLanguage(culture);
                    }
                    else
                    {
                        await CreateLanguage(culture);
                    }
                }
            }
            catch (Exception ex)
            {
                SyncLog.LogException("KenticoKontentPublishing", "SYNCCULTURES", ex);
                throw;
            }
        }
Exemple #15
0
        public async Task SyncAllContentTypes(CancellationToken?cancellation)
        {
            SyncLog.Log("Synchronizing content types");

            var contentTypes = GetSynchronizedContentTypes();

            var index = 0;

            foreach (var contentType in contentTypes)
            {
                if (cancellation?.IsCancellationRequested == true)
                {
                    return;
                }

                index++;

                SyncLog.Log($"Synchronizing content type {contentType.ClassDisplayName} ({index}/{contentTypes.Count})");

                await SyncContentType(contentType);
            }
        }
Exemple #16
0
        public async Task SyncAllMediaLibraries(CancellationToken?cancellation)
        {
            SyncLog.Log("Synchronizing media libraries");

            var mediaLibraries = MediaLibraryInfoProvider.GetMediaLibraries().OnSite(Settings.Sitename);

            var index = 0;

            foreach (var mediaLibrary in mediaLibraries)
            {
                if (cancellation?.IsCancellationRequested == true)
                {
                    return;
                }

                index++;

                SyncLog.Log($"Media library {mediaLibrary.LibraryDisplayName} ({index}/{mediaLibraries.Count})");

                await UpsertAllMediaFiles(mediaLibrary);
            }
        }
Exemple #17
0
        private async Task SyncAttachments(CancellationToken?cancellation, ObjectQuery <AttachmentInfo> attachments)
        {
            var processAttachments = attachments
                                     .Clone()
                                     .ExceptVariants()
                                     .BinaryData(false);

            var index = 0;

            foreach (var attachment in processAttachments)
            {
                if (cancellation?.IsCancellationRequested == true)
                {
                    return;
                }

                index++;

                SyncLog.Log($"Synchronizing attachment {attachment.AttachmentName} ({index}/{attachments.Count})");

                await SyncAttachment(attachment);
            }
        }