Пример #1
0
        public async Task RunAsync(bool clone)
        {
            if (clone)
            {
                bool enableDiagnostics;
                bool.TryParse(ConfigurationManager.AppSettings["EnableDiagnostics"], out enableDiagnostics);
                WriteLog("Cloning source...");
                await _cloneProvider.CloneAsync(_sourceProvider, enableDiagnostics?(Action <String>)WriteLog : (s) => { }, this.ExclusionRules);
            }

            // Where all source resources are based
            _baseSourceUri = FixRelativeTo((await _sourceProvider.GetAsync("", WriteLog)).OfType <ITemplateFile>().First().DownloadUri);
            _baseCloneUri  = FixRelativeTo((await _cloneProvider.GetAsync("", WriteLog)).OfType <ITemplateFile>().First().DownloadUri);

            WriteLog("Synchonizing first release tenants...");
            await SyncFirstReleaseTenants();

            WriteLog("Synchonizing pages...");
            await SyncContentPages();

            WriteLog("Synchonizing page templates...");
            await SyncPageTemplates();

            WriteLog("Synchonizing categories...");
            await SyncCategories();

            WriteLog("Synchonizing platforms...");
            await SyncPlatforms();

            WriteLog("Synchonizing templates...");
            await SyncTemplatesAsync(SITE_PATH, PackageType.SiteCollection);
            await SyncTemplatesAsync(TENANT_PATH, PackageType.Tenant);

            WriteLog("Done");
        }
        public async Task CloneAsync(ITemplatesProvider sourceProvider, Action <string> log, string exclusionRules = null)
        {
            Regex exclusionRegex = new Regex(exclusionRules, RegexOptions.Compiled);
            IEnumerable <ITemplateItem> items = await sourceProvider.GetAsync("", log);

            await CloneAsync(sourceProvider, "", items, log, exclusionRegex);
        }
        private async Task CloneAsync(ITemplatesProvider sourceProvider, string path, IEnumerable <ITemplateItem> items, Action <string> log, Regex exclusionRegex)
        {
            HashSet <ITemplateItem> existingItems = new HashSet <ITemplateItem>(await GetAsync(path, log));

            // Add or update the items
            foreach (ITemplateItem item in items)
            {
                log?.Invoke($"Cloning: {item.Path}");

                // Mark as done
                if (!existingItems.Remove(item))
                {
                    existingItems.RemoveWhere(i => i.Path == System.Uri.EscapeUriString(item.Path));
                }

                if (item is ITemplateFolder folder)
                {
                    // If the target folder is not excluded
                    if (!exclusionRegex.IsMatch(folder.Path))
                    {
                        // Get the children and clone the entire folder
                        IEnumerable <ITemplateItem> folderItems = await sourceProvider.GetAsync(folder.Path, log);
                        await CloneAsync(sourceProvider, folder.Path, folderItems, log, exclusionRegex);
                    }
                    else
                    {
                        log?.Invoke($"Skipped: {folder.Path}");
                    }
                }
                else if (item is ITemplateFile file)
                {
                    using (Stream sourceStream = await file.DownloadAsync())
                    {
                        CloudBlockBlob blob = _container.GetBlockBlobReference(item.Path);
                        await blob.UploadFromStreamAsync(sourceStream);
                    }
                }
            }

            // Remove any additional item
            foreach (ITemplateItem item in existingItems)
            {
                log?.Invoke($"Removing: {item.Path}");

                if (item is ITemplateFolder folder)
                {
                    // To remove a directory we need to iterate through children
                    await DeleteDirectoryAsync(item.Path, log);
                }
                else if (item is ITemplateFile file)
                {
                    CloudBlockBlob blob = _container.GetBlockBlobReference(System.Uri.UnescapeDataString(item.Path));
                    await blob.DeleteAsync();
                }
            }
        }
Пример #4
0
        public async Task CloneAsync(ITemplatesProvider sourceProvider, Action <string> log)
        {
            IEnumerable <ITemplateItem> items = await sourceProvider.GetAsync("", log);

            await CloneAsync(sourceProvider, "", items, log);
        }