private static void CreateFieldsFromFile(ClientContext context, string filePath) { var fieldPersister = new FilePersistanceProvider <List <ShField> >(filePath); var fieldManager = new FieldManager(context, fieldPersister.Load()); fieldManager.CreateFields(); }
private static void CreateContentTypesFromFile(ClientContext context, string filePath) { var contentTypePersister = new FilePersistanceProvider <List <ShContentType> >(filePath); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.EnsureContentTypes(); }
private static void DeleteContentTypesSpecifiedInFile(ClientContext context, string file) { Log.Info("Deleting all content types with the same group as the ones in the file " + file); var contentTypePersister = new FilePersistanceProvider <List <ShContentType> >(file); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.DeleteAllCustomContentTypes(); }
private static void DeleteFieldsSpecifiedInFile(ClientContext context, string file) { Log.Info("Deleting all fields with the same group as the ones in the file " + file); var siteColumnPersister = new FilePersistanceProvider <List <ShField> >(file); var siteColumnManager = new FieldManager(context, siteColumnPersister.Load()); siteColumnManager.DeleteAllCustomFields(); }
private void InstallTaxonomyFromSingleFile(ClientContext context, string pathToFile) { Log.Info("Starting installation of taxonomy based on " + pathToFile); var taxPersistanceProvider = new FilePersistanceProvider <ShTermGroup>(pathToFile); var taxonomyManager = new TaxonomyManager(taxPersistanceProvider.Load()); taxonomyManager.WriteTaxonomyToTermStore(context); }
private void UploadAllChangedFiles(ClientContext context) { Log.Debug("Starting UploadAllChangedFiles"); foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*sitehierarchy.json", SearchOption.AllDirectories)) { var sitePersister = new FilePersistanceProvider <ShSiteCollection>(file); var siteManager = new SiteSetupManager(context, sitePersister.Load(), _rootPath, _incrementalUpload); siteManager.StartFileWatching(); } }
public void SetupTaxonomy() { Console.WriteLine("Starting installation of term groups, term sets and terms"); using (var context = new ClientContext(_urlToSite)) { context.Credentials = _credentials; foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*taxonomy.json", SearchOption.AllDirectories)) { var taxPersistanceProvider = new FilePersistanceProvider <ShTermGroup>(file); var taxonomyManager = new TaxonomyManager(taxPersistanceProvider.Load()); taxonomyManager.WriteTaxonomyToTermStore(context); } } Console.WriteLine("Done installation of term groups, term sets and terms"); }
private void ImportDataFromFile(ClientContext context, string filePath) { Log.Debug("Starting ImportDataFromFile"); var listDataProvider = new FilePersistanceProvider <ShListData>(filePath); var listData = listDataProvider.Load(); var importDataManager = new ImportDataManager(context); if (listData.Type == "TaskList") { var taskListData = new FilePersistanceProvider <ShTaskListData>(filePath); importDataManager.ImportTaskListData(taskListData.Load()); } else { importDataManager.ImportListData(listData); } }
public void ExportTaxonomyGroup(string groupName) { Console.WriteLine("Starting export of taxonomy group " + groupName); using (var context = new ClientContext(_urlToSite)) { context.Credentials = _credentials; var outputDirectoryPath = Path.Combine(_rootPath, "export"); Directory.CreateDirectory(outputDirectoryPath); var taxPersistanceProvider = new FilePersistanceProvider <ShTermGroup>(Path.Combine(outputDirectoryPath, groupName.ToLower().Replace(" ", "") + "taxonomy.json")); var taxonomyManager = new TaxonomyManager(); var groupConfig = taxonomyManager.ExportTaxonomyGroupToConfig(context, groupName); if (groupConfig != null) { taxPersistanceProvider.Save(groupConfig); Console.WriteLine("Completed exported of taxonomy group " + groupName); } } }
private void ConfigureSitesFromAllSiteHierarchyFiles(ClientContext context, bool onlyContentTypeDependecyFeatures) { Log.Debug("Starting ConfigureSitesFromAllSiteHierarchyFiles, only content type dependencies: " + onlyContentTypeDependecyFeatures); foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*sitehierarchy.json", SearchOption.AllDirectories)) { var sitePersister = new FilePersistanceProvider <ShSiteCollection>(file); var siteManager = new SiteSetupManager(context, sitePersister.Load(), _rootPath, _incrementalUpload); if (onlyContentTypeDependecyFeatures) { Log.Debug("ConfigureSitesFromAllSiteHierarchyFiles: Activating only content type dependecy features"); siteManager.ActivateContentTypeDependencyFeatures(); } else { Log.Debug("ConfigureSitesFromAllSiteHierarchyFiles: Setting up sites in normal mode"); siteManager.SetupSites(); } } }
public void DeleteAllSherpaSiteColumnsAndContentTypes() { Console.WriteLine("Deleting all Glitterind columns and content types"); using (var context = new ClientContext(_urlToSite)) { context.Credentials = _credentials; foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*contenttypes.json", SearchOption.AllDirectories)) { var contentTypePersister = new FilePersistanceProvider <List <GtContentType> >(file); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.DeleteAllCustomContentTypes(); } foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*fields.json", SearchOption.AllDirectories)) { var siteColumnPersister = new FilePersistanceProvider <List <GtField> >(file); var siteColumnManager = new FieldManager(context, siteColumnPersister.Load()); siteColumnManager.DeleteAllCustomFields(); } } Console.WriteLine("Done deleting all Glitterind columns and content types"); }
public void CreateSiteColumnsAndContentTypes() { ConfigureSites(true, "activating content type dependency features"); Console.WriteLine("Starting setup of site columns and content types"); using (var context = new ClientContext(_urlToSite)) { context.Credentials = _credentials; foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*fields.json", SearchOption.AllDirectories)) { var siteColumnPersister = new FilePersistanceProvider <List <GtField> >(file); var siteColumnManager = new FieldManager(context, siteColumnPersister.Load()); siteColumnManager.CreateSiteColumns(); } foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*contenttypes.json", SearchOption.AllDirectories)) { var contentTypePersister = new FilePersistanceProvider <List <GtContentType> >(file); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.CreateContentTypes(); } } Console.WriteLine("Done setup of site columns and content types"); }
public void ConfigureSites(bool onlyContentTypeDependecyFeatures, string operationDescription) { Console.WriteLine("Starting " + operationDescription); using (var clientContext = new ClientContext(_urlToSite) { Credentials = _credentials }) { foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*sitehierarchy.json", SearchOption.AllDirectories)) { var sitePersister = new FilePersistanceProvider <GtWeb>(file); var siteManager = new SiteSetupManager(clientContext, sitePersister.Load()); if (onlyContentTypeDependecyFeatures) { siteManager.ActivateContentTypeDependencyFeatures(); } else { siteManager.SetupSites(); } } } Console.WriteLine("Done " + operationDescription); }
public void InstallOperation(InstallationOperation installationOperation, string siteHierarchyFileName) { Log.Info("Executing operation " + installationOperation); if (installationOperation == InstallationOperation.Invalid) { Log.Warn("Invalid user input - get your act together Ole Martin"); return; } if (installationOperation == InstallationOperation.ExitApplication) { Log.Warn("Installation aborted based on user input"); Environment.Exit(1); } var useConfigurationForInstall = false; var configurationFile = string.Empty; if (string.IsNullOrEmpty(siteHierarchyFileName)) { Log.Info("No configuration file - convention mode enabled"); } else { Log.Debug("Site configuration file: " + siteHierarchyFileName); configurationFile = Path.Combine(ConfigurationDirectoryPath, siteHierarchyFileName); useConfigurationForInstall = true; if (!File.Exists(configurationFile)) { Log.Fatal("Couldn't find the configuration file " + configurationFile); throw new ArgumentException("Couldn't find the configuration file " + configurationFile); } } using (var context = new ClientContext(_urlToSite) {Credentials = _credentials}) { var siteSetupManagerFromConfig = new SiteSetupManager(context, new ShSiteCollection(), _rootPath); if (useConfigurationForInstall) { var filePersistanceProvider = new FilePersistanceProvider<ShSiteCollection>(configurationFile); siteSetupManagerFromConfig = new SiteSetupManager(context, filePersistanceProvider.Load(), _rootPath); } switch (installationOperation) { case InstallationOperation.InstallTaxonomy: { if (useConfigurationForInstall) { foreach (var filename in siteSetupManagerFromConfig.ConfigurationSiteCollection.TaxonomyConfigurations) { InstallTaxonomyFromSingleFile(context, Path.Combine(ConfigurationDirectoryPath, filename)); } } else { InstallAllTaxonomy(context); } break; } case InstallationOperation.UploadAndActivateSolution: { if (useConfigurationForInstall) { var deployManager = new DeployManager(_urlToSite, _credentials, _isSharePointOnline); foreach (var filename in siteSetupManagerFromConfig.ConfigurationSiteCollection.SandboxedSolutions) { UploadAndActivatePackage(context, deployManager, Path.Combine(SolutionsDirectoryPath, filename)); } } else { UploadAndActivateAllSandboxSolutions(context); } break; } case InstallationOperation.InstallFieldsAndContentTypes: { if (useConfigurationForInstall) { siteSetupManagerFromConfig.ActivateContentTypeDependencyFeatures(); foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.FieldConfigurations) { var filePath = Path.Combine(ConfigurationDirectoryPath, fileName); CreateFieldsFromFile(context, filePath); } foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.ContentTypeConfigurations) { var filePath = Path.Combine(ConfigurationDirectoryPath, fileName); CreateContentTypesFromFile(context, filePath); } } else { CreateAllSiteColumnsAndContentTypes(context); } break; } case InstallationOperation.ConfigureSites: { if (useConfigurationForInstall) { siteSetupManagerFromConfig.SetupSites(); } else { ConfigureSitesFromAllSiteHierarchyFiles(context); } break; } case InstallationOperation.ImportSearch: { if (useConfigurationForInstall) { var searchMan = new SearchImportManager(); foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.SearchConfigurations) { try { var pathToSearchSettingsFile = Path.Combine(SearchDirectoryPath, fileName); Log.Info("Importing search configuration in " + fileName); searchMan.ImportSearchConfiguration(context, pathToSearchSettingsFile); } catch (Exception e) { Log.Error("Could not import seach configuration.", e); } } } else { ImportAllSearchSettings(context); } break; } case InstallationOperation.ExecuteCustomTasks: { //TODO: Refactor and allow both convention and configuration var customTasksManager = new CustomTasksManager(_rootPath); customTasksManager.ExecuteTasks(siteSetupManagerFromConfig.ConfigurationSiteCollection.RootWeb, context); break; } case InstallationOperation.DeleteSites: { TeardownSites(); break; } case InstallationOperation.DeleteFieldsAndContentTypes: { if (useConfigurationForInstall) { foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.ContentTypeConfigurations) { var filePath = Path.Combine(ConfigurationDirectoryPath, fileName); DeleteContentTypesSpecifiedInFile(context, filePath); } foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.FieldConfigurations) { var filePath = Path.Combine(ConfigurationDirectoryPath, fileName); DeleteFieldsSpecifiedInFile(context, filePath); } } else { DeleteAllSherpaSiteColumnsAndContentTypes(context); } break; } case InstallationOperation.ExportTaxonomy: { ExportTaxonomyGroup(); break; } case InstallationOperation.ForceRecrawl: { ForceReCrawl(); break; } case InstallationOperation.ExitApplication: { Environment.Exit(1); break; } default: { Log.Warn("Operation not supported in unmanaged mode"); break; } } } Log.Debug("Completed installation operation"); }
private void InstallTaxonomyFromSingleFile(ClientContext context, string pathToFile) { Log.Info("Starting installation of taxonomy based on " + pathToFile); var taxPersistanceProvider = new FilePersistanceProvider<ShTermGroup>(pathToFile); var taxonomyManager = new TaxonomyManager(taxPersistanceProvider.Load()); taxonomyManager.WriteTaxonomyToTermStore(context); }
public void UploadFilesInFolder(ClientContext context, Web web, ShContentFolder contentFolder) { Log.Info("Uploading files from contentfolder " + contentFolder.FolderName); string uploadTargetFolder; Folder rootFolder; web.Lists.EnsureSiteAssetsLibrary(); context.Load(web.Lists); context.ExecuteQuery(); if (!string.IsNullOrEmpty(contentFolder.ListUrl)) { context.Load(web, w => w.ServerRelativeUrl); context.ExecuteQuery(); var rootFolderServerRelativeUrl = Url.Combine(web.ServerRelativeUrl, contentFolder.ListUrl); rootFolder = web.GetFolderByServerRelativeUrl(rootFolderServerRelativeUrl); context.Load(rootFolder); context.ExecuteQuery(); uploadTargetFolder = Url.Combine(rootFolderServerRelativeUrl, contentFolder.FolderUrl); } else if (!string.IsNullOrEmpty(contentFolder.ListName)) { var assetLibrary = web.Lists.GetByTitle(contentFolder.ListName); context.Load(assetLibrary, l => l.Title, l => l.RootFolder); context.ExecuteQuery(); rootFolder = assetLibrary.RootFolder; uploadTargetFolder = Url.Combine(assetLibrary.RootFolder.ServerRelativeUrl, contentFolder.FolderUrl); } else { Log.ErrorFormat("You need to specify either ListName or ListUrl for the Content Folder {0}", contentFolder.FolderName); return; } var configRootFolder = Path.Combine(_contentDirectoryPath, contentFolder.FolderName); if (!web.DoesFolderExists(uploadTargetFolder)) { web.Folders.Add(uploadTargetFolder); } context.ExecuteQuery(); foreach (string folder in Directory.GetDirectories(configRootFolder, "*", SearchOption.AllDirectories)) { var folderName = Url.Combine(uploadTargetFolder, folder.Replace(configRootFolder, "").Replace("\\", "/")); if (!web.DoesFolderExists(folderName)) { web.Folders.Add(folderName); } } context.ExecuteQuery(); List<ShFileProperties> filePropertiesCollection = null; if (!string.IsNullOrEmpty(contentFolder.PropertiesFile)) { var propertiesFilePath = Path.Combine(configRootFolder, contentFolder.PropertiesFile); var filePersistanceProvider = new FilePersistanceProvider<List<ShFileProperties>>(propertiesFilePath); filePropertiesCollection = filePersistanceProvider.Load(); } context.Load(context.Site, site => site.ServerRelativeUrl); context.Load(context.Web, w => w.ServerRelativeUrl, w => w.Language); context.ExecuteQuery(); String[] excludedFileExtensions = { }; if (!string.IsNullOrEmpty(contentFolder.ExcludeExtensions)) { excludedFileExtensions = contentFolder.ExcludeExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } var files = Directory.GetFiles(configRootFolder, "*", SearchOption.AllDirectories) .Where(file => !excludedFileExtensions.Contains(Path.GetExtension(file).ToLower())).ToList(); if (IncrementalUpload) { files = files.Where(f =>!LastUpload.ContainsKey(contentFolder.FolderName) || new FileInfo(f).LastWriteTimeUtc > LastUpload[contentFolder.FolderName]).ToList(); } int filesUploaded = 0; foreach (string filePath in files) { var pathToFileFromRootFolder = filePath.Replace(configRootFolder.TrimEnd(new []{'\\'}) + "\\", ""); var fileName = Path.GetFileName(pathToFileFromRootFolder); if (!string.IsNullOrEmpty(contentFolder.PropertiesFile) && contentFolder.PropertiesFile == fileName) { Log.DebugFormat("Skipping file upload of {0} since it's used as a configuration file", fileName); continue; } Log.DebugFormat("Uploading file {0} to {1}", fileName, contentFolder.ListUrl); var fileUrl = GetFileUrl(uploadTargetFolder, pathToFileFromRootFolder, filePropertiesCollection); web.CheckOutFile(fileUrl); var newFile = new FileCreationInformation { Content = System.IO.File.ReadAllBytes(filePath), Url = fileUrl, Overwrite = true }; File uploadFile = rootFolder.Files.Add(newFile); context.Load(uploadFile); context.Load(uploadFile.ListItemAllFields.ParentList, l => l.ForceCheckout, l => l.EnableMinorVersions, l => l.EnableModeration); context.ExecuteQuery(); ApplyFileProperties(context, filePropertiesCollection, uploadFile); uploadFile.PublishFileToLevel(FileLevel.Published); context.ExecuteQuery(); filesUploaded++; } if (filesUploaded == 0) { Log.Info("No files updated since last upload."); } else { Log.InfoFormat("{0} file(s) uploaded", filesUploaded); } if (LastUpload.ContainsKey(contentFolder.FolderName)) { LastUpload[contentFolder.FolderName] = DateTime.UtcNow; } else { LastUpload.Add(contentFolder.FolderName, DateTime.UtcNow); } }
private void ConfigureSitesFromAllSiteHierarchyFiles(ClientContext context, bool onlyContentTypeDependecyFeatures) { Log.Debug("Starting ConfigureSitesFromAllSiteHierarchyFiles, only content type dependencies: " + onlyContentTypeDependecyFeatures); foreach (var file in Directory.GetFiles(ConfigurationDirectoryPath, "*sitehierarchy.json", SearchOption.AllDirectories)) { var sitePersister = new FilePersistanceProvider<ShSiteCollection>(file); var siteManager = new SiteSetupManager(context, sitePersister.Load(), _rootPath); if (onlyContentTypeDependecyFeatures) { Log.Debug("ConfigureSitesFromAllSiteHierarchyFiles: Activating only content type dependecy features"); siteManager.ActivateContentTypeDependencyFeatures(); } else { Log.Debug("ConfigureSitesFromAllSiteHierarchyFiles: Setting up sites in normal mode"); siteManager.SetupSites(); } } }
private void ExportTaxonomyGroup(string groupName) { Log.Info("Starting export of taxonomy group " + groupName); using (var context = new ClientContext(_urlToSite)) { context.Credentials = _credentials; var outputDirectoryPath = Path.Combine(_rootPath, "export"); Directory.CreateDirectory(outputDirectoryPath); var taxPersistanceProvider = new FilePersistanceProvider<ShTermGroup>(Path.Combine(outputDirectoryPath, groupName.ToLower().Replace(" ", "") + "taxonomy.json")); var taxonomyManager = new TaxonomyManager(); var groupConfig = taxonomyManager.ExportTaxonomyGroupToConfig(context, groupName); if (groupConfig != null) { taxPersistanceProvider.Save(groupConfig); Log.Info("Completed export of taxonomy group " + groupName); } } }
private static void DeleteFieldsSpecifiedInFile(ClientContext context, string file) { Log.Info("Deleting all fields with the same group as the ones in the file " + file); var siteColumnPersister = new FilePersistanceProvider<List<ShField>>(file); var siteColumnManager = new FieldManager(context, siteColumnPersister.Load()); siteColumnManager.DeleteAllCustomFields(); }
private static void DeleteContentTypesSpecifiedInFile(ClientContext context, string file) { Log.Info("Deleting all content types with the same group as the ones in the file " + file); var contentTypePersister = new FilePersistanceProvider<List<ShContentType>>(file); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.DeleteAllCustomContentTypes(); }
private static void CreateFieldsFromFile(ClientContext context, string filePath) { var fieldPersister = new FilePersistanceProvider<List<ShField>>(filePath); var fieldManager = new FieldManager(context, fieldPersister.Load()); fieldManager.CreateFields(); }
public void InstallOperation(InstallationOperation installationOperation, string siteHierarchyFileName) { Log.Info("Executing operation " + installationOperation); if (installationOperation == InstallationOperation.Invalid) { Log.Warn("Invalid user input"); return; } if (installationOperation == InstallationOperation.ExitApplication) { Log.Warn("Installation aborted based on user input"); Environment.Exit(1); } var useConfigurationForInstall = false; var configurationFile = string.Empty; if (string.IsNullOrEmpty(siteHierarchyFileName)) { Log.Info("No configuration file - convention mode enabled"); } else { Log.Debug("Site configuration file: " + siteHierarchyFileName); configurationFile = FindFileInDirectory(ConfigurationDirectoryPath, siteHierarchyFileName); useConfigurationForInstall = true; if (!File.Exists(configurationFile)) { Log.Fatal("Couldn't find the configuration file " + configurationFile); throw new ArgumentException("Couldn't find the configuration file " + configurationFile); } } using (var context = new ClientContext(_urlToSite) { Credentials = _credentials }) { var siteSetupManagerFromConfig = new SiteSetupManager(context, new ShSiteCollection(), _rootPath, _incrementalUpload); if (useConfigurationForInstall) { var filePersistanceProvider = new FilePersistanceProvider <ShSiteCollection>(configurationFile); siteSetupManagerFromConfig = new SiteSetupManager(context, filePersistanceProvider.Load(), _rootPath, _incrementalUpload); } switch (installationOperation) { case InstallationOperation.InstallTaxonomy: { if (useConfigurationForInstall) { foreach (var filename in siteSetupManagerFromConfig.ConfigurationSiteCollection.TaxonomyConfigurations) { InstallTaxonomyFromSingleFile(context, FindFileInDirectory(ConfigurationDirectoryPath, filename)); } } else { InstallAllTaxonomy(context); } break; } case InstallationOperation.UploadAndActivateSolution: { if (useConfigurationForInstall) { var deployManager = new DeployManager(_urlToSite, _credentials, _isSharePointOnline); foreach (var filename in siteSetupManagerFromConfig.ConfigurationSiteCollection.SandboxedSolutions) { UploadAndActivatePackage(context, deployManager, FindFileInDirectory(SolutionsDirectoryPath, filename)); } } else { UploadAndActivateAllSandboxSolutions(context); } break; } case InstallationOperation.AddTemplatesToCts: { if (useConfigurationForInstall) { foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.AddTemplatesToCts) { var filePath = FindFileInDirectory(ConfigurationDirectoryPath, fileName); AddTemplatesToCts(context, filePath); } } else { AddTemplatesToCts(context, null); } break; } case InstallationOperation.InstallFieldsAndContentTypes: { if (useConfigurationForInstall) { siteSetupManagerFromConfig.ActivateContentTypeDependencyFeatures(); foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.FieldConfigurations) { var filePath = FindFileInDirectory(ConfigurationDirectoryPath, fileName); CreateFieldsFromFile(context, filePath); } foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.ContentTypeConfigurations) { var filePath = FindFileInDirectory(ConfigurationDirectoryPath, fileName); CreateContentTypesFromFile(context, filePath); } } else { CreateAllSiteColumnsAndContentTypes(context); } break; } case InstallationOperation.ConfigureSites: { if (useConfigurationForInstall) { siteSetupManagerFromConfig.SetupSites(); } else { ConfigureSitesFromAllSiteHierarchyFiles(context); } break; } case InstallationOperation.ImportSearch: { if (useConfigurationForInstall) { var searchMan = new SearchImportManager(); foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.SearchConfigurations) { try { var pathToSearchSettingsFile = FindFileInDirectory(SearchDirectoryPath, fileName); Log.Info("Importing search configuration in " + fileName); searchMan.ImportSearchConfiguration(context, pathToSearchSettingsFile); } catch (Exception e) { Log.Error("Could not import seach configuration.", e); } } } else { ImportAllSearchSettings(context); } break; } case InstallationOperation.ExecuteCustomTasks: { //TODO: Refactor and allow both convention and configuration var customTasksManager = new CustomTasksManager(_rootPath); customTasksManager.ExecuteTasks(siteSetupManagerFromConfig.ConfigurationSiteCollection.RootWeb, context); break; } case InstallationOperation.DeleteSites: { TeardownSites(); break; } case InstallationOperation.DeleteFieldsAndContentTypes: { if (useConfigurationForInstall) { foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.ContentTypeConfigurations) { var filePath = FindFileInDirectory(ConfigurationDirectoryPath, fileName); DeleteContentTypesSpecifiedInFile(context, filePath); } foreach ( var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.FieldConfigurations) { var filePath = FindFileInDirectory(ConfigurationDirectoryPath, fileName); DeleteFieldsSpecifiedInFile(context, filePath); } } else { DeleteAllSherpaSiteColumnsAndContentTypes(context); } break; } case InstallationOperation.FileWatchUploader: { if (useConfigurationForInstall) { siteSetupManagerFromConfig.StartFileWatching(); } else { UploadAllChangedFiles(context); } break; } case InstallationOperation.ExportTaxonomy: { ExportTaxonomyGroup(); break; } case InstallationOperation.ExportData: { var outputDirectoryPath = Path.Combine(_rootPath, "export"); Directory.CreateDirectory(outputDirectoryPath); siteSetupManagerFromConfig.ExportListData(outputDirectoryPath); break; } case InstallationOperation.ImportData: { foreach (var fileName in siteSetupManagerFromConfig.ConfigurationSiteCollection.ImportDataConfigurations) { var filePath = FindFileInDirectory(ImportDataDirectoryPath, fileName); ImportDataFromFile(context, filePath); } break; } case InstallationOperation.ForceRecrawl: { ForceReCrawl(); break; } case InstallationOperation.ExitApplication: { Environment.Exit(1); break; } default: { Log.Warn("Operation not supported in unmanaged mode"); break; } } } Log.Debug("Completed installation operation"); }
public void UploadFilesInFolder(ClientContext context, Web web, ShContentFolder contentFolder, bool incrementalUpload) { Log.Info("Uploading files from contentfolder " + contentFolder.FolderName); string uploadTargetFolder; Folder rootFolder; web.Lists.EnsureSiteAssetsLibrary(); context.Load(web.Lists); context.ExecuteQuery(); if (!string.IsNullOrEmpty(contentFolder.ListUrl)) { context.Load(web, w => w.ServerRelativeUrl); context.ExecuteQuery(); var listUrl = Url.Combine(web.ServerRelativeUrl, contentFolder.ListUrl); rootFolder = web.GetFolderByServerRelativeUrl(listUrl); context.Load(rootFolder); context.ExecuteQuery(); uploadTargetFolder = Url.Combine(listUrl, contentFolder.FolderUrl); } else if (!string.IsNullOrEmpty(contentFolder.ListName)) { var assetLibrary = web.Lists.GetByTitle(contentFolder.ListName); context.Load(assetLibrary, l => l.Title, l => l.RootFolder); context.ExecuteQuery(); rootFolder = assetLibrary.RootFolder; uploadTargetFolder = Url.Combine(assetLibrary.RootFolder.ServerRelativeUrl, contentFolder.FolderUrl); } else { Log.ErrorFormat("You need to specify either ListName or ListUrl for the Content Folder {0}", contentFolder.FolderName); return; } var configRootFolder = Path.Combine(_contentDirectoryPath, contentFolder.FolderName); EnsureTargetFolder(context, web, rootFolder.ServerRelativeUrl, contentFolder.FolderUrl, uploadTargetFolder); EnsureAllContentFolders(context, web, configRootFolder, uploadTargetFolder); List <ShFileProperties> filePropertiesCollection = null; if (!string.IsNullOrEmpty(contentFolder.PropertiesFile)) { var propertiesFilePath = Path.Combine(configRootFolder, contentFolder.PropertiesFile); var filePersistanceProvider = new FilePersistanceProvider <List <ShFileProperties> >(propertiesFilePath); filePropertiesCollection = filePersistanceProvider.Load(); } context.Load(context.Site, site => site.ServerRelativeUrl); context.Load(context.Web, w => w.ServerRelativeUrl, w => w.Language); context.ExecuteQuery(); String[] excludedFileExtensions = { }; if (!string.IsNullOrEmpty(contentFolder.ExcludeExtensions)) { excludedFileExtensions = contentFolder.ExcludeExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); } var files = Directory.GetFiles(configRootFolder, "*", SearchOption.AllDirectories) .Where(file => !excludedFileExtensions.Contains(Path.GetExtension(file).ToLower())).ToList(); if (incrementalUpload) { files = files.Where(f => !LastUpload.ContainsKey(contentFolder.FolderName) || new FileInfo(f).LastWriteTimeUtc > LastUpload[contentFolder.FolderName]).ToList(); } int filesUploaded = 0; foreach (string filePath in files) { UploadAndPublishSingleFile(context, web, configRootFolder, contentFolder, uploadTargetFolder, rootFolder, filePropertiesCollection, filePath); filesUploaded++; } if (filesUploaded == 0) { Log.Info("No files updated since last upload."); } else { Log.InfoFormat("{0} file(s) uploaded", filesUploaded); } if (LastUpload.ContainsKey(contentFolder.FolderName)) { LastUpload[contentFolder.FolderName] = DateTime.UtcNow; } else { LastUpload.Add(contentFolder.FolderName, DateTime.UtcNow); } }
private static void CreateContentTypesFromFile(ClientContext context, string filePath) { var contentTypePersister = new FilePersistanceProvider<List<ShContentType>>(filePath); var contentTypeManager = new ContentTypeManager(context, contentTypePersister.Load()); contentTypeManager.EnsureContentTypes(); }
public void ExportListData(ClientContext context, Web web, List <ShList> listConfigs, string outputDirectory) { foreach (var listConfig in listConfigs) { if (listConfig.ExportData) { var list = web.Lists.GetByTitle(listConfig.Title); var items = list.GetItems(new CamlQuery()); context.Load(list, l => l.Title, l => l.BaseType); if (listConfig.TemplateType == 171) { context.Load(items, includes => includes.Include(i => i["ID"], i => i["Title"], i => i["ParentID"], i => i["GtProjectPhase"], i => i["Order"])); } else { context.Load(items, includes => includes.Include(i => i["ID"], i => i["Title"], i => i["GtProjectPhase"])); } context.ExecuteQuery(); var listDataRows = new List <ShTaskListDataItem>(); foreach (var item in items) { if (listConfig.TemplateType == 171) { var phaseValue = item["GtProjectPhase"] as TaxonomyFieldValue; var parentIdValue = item["ParentID"] as FieldLookupValue; var parentId = parentIdValue != null ? parentIdValue.LookupId : 0; var order = item["Order"]; var taskItem = new ShTaskListDataItem(int.Parse(item["ID"].ToString()), parentId); taskItem.Order = double.Parse(order.ToString()); taskItem.Fields.Add(new ShFieldValue("Title", item["Title"].ToString())); if (phaseValue != null) { taskItem.Fields.Add(new ShFieldValue("GtProjectPhase", string.Format("{0}|{1}", phaseValue.Label, phaseValue.TermGuid))); } listDataRows.Add(taskItem); } else { var taskItem = new ShTaskListDataItem(int.Parse(item["ID"].ToString())); taskItem.Fields.Add(new ShFieldValue("Title", item["Title"].ToString())); var phaseValue = item["GtProjectPhase"] as TaxonomyFieldValue; if (phaseValue != null) { taskItem.Fields.Add(new ShFieldValue("GtProjectPhase", string.Format("{0}|{1}", phaseValue.Label, phaseValue.TermGuid))); } listDataRows.Add(taskItem); } } listDataRows.Sort((x, y) => x.Order.CompareTo(y.Order)); foreach (var item in listDataRows.Where(i => i.ParentID != 0)) { listDataRows.Single(i => i.ID == item.ParentID).Rows.Add(item); } var itemsToPersist = new List <ShTaskListDataItem>(); foreach (var item in listDataRows) { if (item.ParentID == 0) { itemsToPersist.Add(item); } } var listData = new ShTaskListData(); listData.Data.Rows = itemsToPersist; listData.Name = list.Title; listData.Type = list.BaseType.ToString(); var taxPersistanceProvider = new FilePersistanceProvider <ShListData>(Path.Combine(outputDirectory, String.Format("{0}-export-{1}.json", list.Title.ToLower().Replace(" ", ""), System.DateTime.Now.ToFileTime()))); taxPersistanceProvider.Save(listData); } } }