示例#1
0
        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();
                }
            }
        }
示例#2
0
        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");
        }