コード例 #1
0
        protected override void ExecuteCmdlet()
        {
            string configOutput = string.Empty;

            switch (Scope)
            {
            case SearchConfigurationScope.Web:
            {
                configOutput = CurrentWeb.GetSearchConfiguration();
                break;
            }

            case SearchConfigurationScope.Site:
            {
                configOutput = ClientContext.Site.GetSearchConfiguration();
                break;
            }

            case SearchConfigurationScope.Subscription:
            {
                if (!ClientContext.Url.ToLower().Contains("-admin"))
                {
                    throw new InvalidOperationException(Resources.CurrentSiteIsNoTenantAdminSite);
                }

                SearchObjectOwner owningScope = new SearchObjectOwner(ClientContext, SearchObjectLevel.SPSiteSubscription);
                var config = new SearchConfigurationPortability(ClientContext);
                ClientResult <string> configuration = config.ExportSearchConfiguration(owningScope);
                ClientContext.ExecuteQueryRetry();

                configOutput = configuration.Value;
            }
            break;
            }

            if (Path != null)
            {
                if (!System.IO.Path.IsPathRooted(Path))
                {
                    Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
                }
                System.IO.File.WriteAllText(Path, configOutput);
            }
            else
            {
                if (OutputFormat == OutputFormat.CompleteXml)
                {
                    WriteObject(configOutput);
                }
                else if (OutputFormat == OutputFormat.ManagedPropertyMappings)
                {
                    StringReader sr  = new StringReader(configOutput);
                    var          doc = XDocument.Load(sr);
                    var          mps = GetCustomManagedProperties(doc);

                    foreach (var mp in mps)
                    {
                        mp.Aliases  = new List <string>();
                        mp.Mappings = new List <string>();

                        var mappings = GetCpMappingsFromPid(doc, mp.Pid);
                        mp.Mappings = mappings;
                        var aliases = GetAliasesFromPid(doc, mp.Pid);
                        mp.Aliases = aliases;
                    }
                    WriteObject(mps);
                }
            }
        }