private void ImportAllSearchSettings(ClientContext context)
        {
            var searchMan        = new SearchImportManager();
            var pathToSearchXmls = Directory.GetFiles(SearchDirectoryPath);

            foreach (var pathToSearchXml in pathToSearchXmls)
            {
                Log.Info("Importing search setting " + pathToSearchXml);
                searchMan.ImportSearchConfiguration(context, pathToSearchXml);
            }
        }
        private void ImportAllSearchSettings(ClientContext context)
        {
            var searchMan        = new SearchImportManager();
            var pathToSearchXmls = Directory.GetFiles(SearchDirectoryPath);

            foreach (var pathToSearchXml in pathToSearchXmls)
            {
                try {
                    Log.Info("Importing search settings in file " + pathToSearchXml);
                    searchMan.ImportSearchConfiguration(context, pathToSearchXml);
                }
                catch (Exception e)
                {
                    Log.Error("Could not import seach configuration.", e);
                }
            }
        }
예제 #3
0
        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");
        }