private void SetRequestParameters(SearchConnection searchConnection, SearchQueryRequest searchQueryRequest) { searchQueryRequest.SharePointSiteUrl = GetSPSite() ?? searchQueryRequest.SharePointSiteUrl; searchConnection.SpSiteUrl = searchQueryRequest.SharePointSiteUrl; searchQueryRequest.QueryText = GetQuery() ?? searchQueryRequest.QueryText; searchQueryRequest.HttpMethodType = MethodType.HasValue ? MethodType.Value : searchQueryRequest.HttpMethodType; searchConnection.HttpMethod = searchQueryRequest.HttpMethodType.ToString(); searchQueryRequest.AcceptType = AcceptType.HasValue ? AcceptType.Value : searchQueryRequest.AcceptType; searchQueryRequest.ClientType = GetClientTypeName(searchQueryRequest); // This cmdlet keeps select properties as a list of strings, and SearchQueryRequest uses a string. // searchQueryRequest.SelectProperties is set very last thing before we execute the query in SetSelectProperties() searchQueryRequest.HitHighlightedProperties = new StringListArgumentParser(HithighlightedProperties).Parse() ?? searchQueryRequest.HitHighlightedProperties; searchQueryRequest.SortList = new SortListArgumentParser(Sort).Parse() ?? searchQueryRequest.SortList; // set based on switches bool?switchValue; switchValue = GetThreeWaySwitchValue(EnableStemming, DisableStemming); if (switchValue.HasValue) { searchQueryRequest.EnableStemming = switchValue; } switchValue = GetThreeWaySwitchValue(EnablePhonetic, DisablePhonetic); if (switchValue.HasValue) { searchQueryRequest.EnablePhonetic = switchValue; } switchValue = GetThreeWaySwitchValue(EnableNickNames, DisableNickNames); if (switchValue.HasValue) { searchQueryRequest.EnableNicknames = switchValue; } switchValue = GetThreeWaySwitchValue(EnableTrimDuplicates, DisableTrimDuplicates); if (switchValue.HasValue) { searchQueryRequest.TrimDuplicates = switchValue; } switchValue = GetThreeWaySwitchValue(EnableFql, DisableFql); if (switchValue.HasValue) { searchQueryRequest.EnableFql = switchValue; } switchValue = GetThreeWaySwitchValue(EnableQueryRules, DisableQueryRules); if (switchValue.HasValue) { searchQueryRequest.EnableQueryRules = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessBestBets, DisableProcessBestBets); if (switchValue.HasValue) { searchQueryRequest.ProcessBestBets = switchValue; } switchValue = GetThreeWaySwitchValue(EnableByPassResultTypes, DisableByPassResultTypes); if (switchValue.HasValue) { searchQueryRequest.ByPassResultTypes = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessPersonalFavorites, DisableProcessPersonalFavorites); if (switchValue.HasValue) { searchQueryRequest.ProcessPersonalFavorites = switchValue; } searchQueryRequest.RankingModelId = RankingModelId ?? searchQueryRequest.RankingModelId; if (RankingModelName.HasValue) { if (!String.IsNullOrWhiteSpace(RankingModelId)) { WriteWarning("RankingModelName overrides RankingModelId. Please use one or the other."); } searchQueryRequest.RankingModelId = RankModel.Select(RankingModelName.Value); } searchQueryRequest.SourceId = ResultSourceId ?? searchQueryRequest.SourceId; if (ResultSourceName.HasValue) { if (!String.IsNullOrWhiteSpace(ResultSourceId)) { WriteWarning("ResultSourceName overrides ResutSourceId. Please use one or the other."); } searchQueryRequest.SourceId = ResultSource.Select(ResultSourceName.Value); } searchQueryRequest.HiddenConstraints = HiddenConstraints ?? searchQueryRequest.HiddenConstraints; searchQueryRequest.QueryTemplate = QueryTemplate ?? searchQueryRequest.QueryTemplate; searchQueryRequest.RowLimit = RowLimit.HasValue ? RowLimit : (searchQueryRequest.RowLimit.HasValue ? searchQueryRequest.RowLimit : rowLimitDefault); searchQueryRequest.StartRow = StartRow.HasValue ? StartRow : (searchQueryRequest.StartRow.HasValue ? searchQueryRequest.StartRow : startRowDefault); searchQueryRequest.Timeout = Timeout.HasValue ? Timeout : (searchQueryRequest.Timeout.HasValue ? searchQueryRequest.Timeout : timeoutDefault); searchQueryRequest.Refiners = new StringListArgumentParser(Refiners).Parse() ?? searchQueryRequest.Refiners; if (Credential != null || searchQueryRequest.AuthenticationType == AuthenticationType.Windows) { if (Credential == null) { var userName = searchQueryRequest.UserName; Credential = this.Host.UI.PromptForCredential("Enter username/password", "", userName, ""); } searchQueryRequest.AuthenticationType = AuthenticationType.Windows; searchQueryRequest.UserName = Credential.UserName; searchQueryRequest.SecurePassword = Credential.Password; } else if (searchQueryRequest.AuthenticationType == AuthenticationType.SPO) { Guid runspaceId = Guid.Empty; using (var ps = PowerShell.Create(RunspaceMode.CurrentRunspace)) { runspaceId = ps.Runspace.InstanceId; CookieCollection cc; bool found = Tokens.TryGetValue(runspaceId, out cc); if (!found) { cc = PSWebAuthentication.GetAuthenticatedCookies(this, searchQueryRequest.SharePointSiteUrl, AuthenticationType.SPO); if (cc == null) { throw new RuntimeException("Authentication cookie returned is null! Authentication failed. Please try again."); // TODO find another exception } else { Tokens.Add(runspaceId, cc); } } searchQueryRequest.AuthenticationType = AuthenticationType.SPO; searchQueryRequest.Cookies = cc; //searchSuggestionsRequest.Cookies = cc; } } else if (AuthenticationMethod == PSAuthenticationMethod.SPOManagement || searchQueryRequest.AuthenticationType == AuthenticationType.SPOManagement) { AdalAuthentication adalAuth = new AdalAuthentication(); var task = adalAuth.Login(searchQueryRequest.SharePointSiteUrl); if (!task.Wait(300000)) { throw new TimeoutException("Prompt for user credentials timed out after 5 minutes."); } var token = task.Result; searchQueryRequest.AuthenticationType = AuthenticationType.SPOManagement; searchQueryRequest.Token = token; //searchSuggestionsRequest.Token = token; } else { searchQueryRequest.AuthenticationType = AuthenticationType.CurrentUser; WindowsIdentity currentWindowsIdentity = WindowsIdentity.GetCurrent(); searchQueryRequest.UserName = currentWindowsIdentity.Name; } }
protected override void SetRequestParameters(SearchQueryRequest searchQueryRequest) { base.SetRequestParameters(searchQueryRequest); searchQueryRequest.ClientType = GetClientTypeName(searchQueryRequest); // This cmdlet keeps select properties as a list of strings, and SearchQueryRequest uses a string. // searchQueryRequest.SelectProperties is set very last thing before we execute the query in SetSelectProperties() searchQueryRequest.HitHighlightedProperties = new StringListArgumentParser(HithighlightedProperties).Parse() ?? searchQueryRequest.HitHighlightedProperties; searchQueryRequest.SortList = new SortListArgumentParser(Sort).Parse() ?? searchQueryRequest.SortList; searchQueryRequest.CollapseSpecification = CollapseSpecification ?? searchQueryRequest.CollapseSpecification; // set based on switches bool?switchValue; switchValue = GetThreeWaySwitchValue(EnableStemming, DisableStemming); if (switchValue.HasValue) { searchQueryRequest.EnableStemming = switchValue; } switchValue = GetThreeWaySwitchValue(EnablePhonetic, DisablePhonetic); if (switchValue.HasValue) { searchQueryRequest.EnablePhonetic = switchValue; } switchValue = GetThreeWaySwitchValue(EnableNickNames, DisableNickNames); if (switchValue.HasValue) { searchQueryRequest.EnableNicknames = switchValue; } if (EnableMultiGeoSearch || MultiGeoSearchConfiguration != null || DisableMultiGeoSearch) { if (EnableMultiGeoSearch || MultiGeoSearchConfiguration != null) { searchQueryRequest.EnableMultiGeoSearch = true; } if (MultiGeoSearchConfiguration != null) { searchQueryRequest.MultiGeoSearchConfiguration = PSSQT.MultiGeoSearchConfiguration.Format(MultiGeoSearchConfiguration, MethodType == HttpMethodType.Post); } if (DisableMultiGeoSearch) { searchQueryRequest.EnableMultiGeoSearch = false; } } switchValue = GetThreeWaySwitchValue(EnableTrimDuplicates, DisableTrimDuplicates); if (switchValue.HasValue) { searchQueryRequest.TrimDuplicates = switchValue; } switchValue = GetThreeWaySwitchValue(EnableFql, DisableFql); if (switchValue.HasValue) { searchQueryRequest.EnableFql = switchValue; } switchValue = GetThreeWaySwitchValue(EnableQueryRules, DisableQueryRules); if (switchValue.HasValue) { searchQueryRequest.EnableQueryRules = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessBestBets, DisableProcessBestBets); if (switchValue.HasValue) { searchQueryRequest.ProcessBestBets = switchValue; } switchValue = GetThreeWaySwitchValue(EnableByPassResultTypes, DisableByPassResultTypes); if (switchValue.HasValue) { searchQueryRequest.ByPassResultTypes = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessPersonalFavorites, DisableProcessPersonalFavorites); if (switchValue.HasValue) { searchQueryRequest.ProcessPersonalFavorites = switchValue; } searchQueryRequest.RankingModelId = RankingModelId ?? searchQueryRequest.RankingModelId; if (RankingModelName.HasValue) { if (!String.IsNullOrWhiteSpace(RankingModelId)) { WriteWarning("RankingModelName overrides RankingModelId. Please use one or the other."); } searchQueryRequest.RankingModelId = RankModel.Select(RankingModelName.Value); } searchQueryRequest.SourceId = ResultSourceId ?? searchQueryRequest.SourceId; if (ResultSourceName.HasValue) { if (!String.IsNullOrWhiteSpace(ResultSourceId)) { WriteWarning("ResultSourceName overrides ResutSourceId. Please use one or the other."); } searchQueryRequest.SourceId = ResultSource.Select(ResultSourceName.Value); } searchQueryRequest.HiddenConstraints = HiddenConstraints ?? searchQueryRequest.HiddenConstraints; searchQueryRequest.QueryTemplate = QueryTemplate ?? searchQueryRequest.QueryTemplate; searchQueryRequest.RowLimit = RowLimit.HasValue ? RowLimit : (searchQueryRequest.RowLimit.HasValue ? searchQueryRequest.RowLimit : rowLimitDefault); searchQueryRequest.StartRow = StartRow.HasValue ? StartRow : (searchQueryRequest.StartRow.HasValue ? searchQueryRequest.StartRow : startRowDefault); searchQueryRequest.Timeout = Timeout.HasValue ? Timeout : (searchQueryRequest.Timeout.HasValue ? searchQueryRequest.Timeout : timeoutDefault); searchQueryRequest.IncludePersonalOneDriveResults = IncludePersonalOneDriveResults.IsPresent ? true : (searchQueryRequest.IncludePersonalOneDriveResults.HasValue ? searchQueryRequest.IncludePersonalOneDriveResults : false); searchQueryRequest.Refiners = new StringListArgumentParser(Refiners).Parse() ?? searchQueryRequest.Refiners; }
private void SetRequestParameters(SearchConnection searchConnection, SearchQueryRequest searchQueryRequest) { searchQueryRequest.SharePointSiteUrl = GetSPSite() ?? searchQueryRequest.SharePointSiteUrl; searchConnection.SpSiteUrl = searchQueryRequest.SharePointSiteUrl; searchQueryRequest.QueryText = GetQuery() ?? searchQueryRequest.QueryText; searchQueryRequest.HttpMethodType = MethodType.HasValue ? MethodType.Value : searchQueryRequest.HttpMethodType; searchConnection.HttpMethod = searchQueryRequest.HttpMethodType.ToString(); searchQueryRequest.AcceptType = AcceptType.HasValue ? AcceptType.Value : searchQueryRequest.AcceptType; searchQueryRequest.ClientType = GetClientTypeName(searchQueryRequest); // This cmdlet keeps select properties as a list of strings, and SearchQueryRequest uses a string. // We always update the list internally, and set the searchQueryRequest string in the Up2Date method which is called last thing before searchQueryRequest is used. if (SelectProperties == null || SelectProperties.Count == 0) { SelectPropertiesAsString = searchQueryRequest.SelectProperties ?? selectPropertiesDefault; } else { NormalizeProperties(); } searchQueryRequest.SortList = GetSortList() ?? searchQueryRequest.SortList; // set based on switches bool?switchValue; switchValue = GetThreeWaySwitchValue(EnableStemming, DisableStemming); if (switchValue.HasValue) { searchQueryRequest.EnableStemming = switchValue; } switchValue = GetThreeWaySwitchValue(EnablePhonetic, DisablePhonetic); if (switchValue.HasValue) { searchQueryRequest.EnablePhonetic = switchValue; } switchValue = GetThreeWaySwitchValue(EnableNickNames, DisableNickNames); if (switchValue.HasValue) { searchQueryRequest.EnableNicknames = switchValue; } switchValue = GetThreeWaySwitchValue(EnableTrimDuplicates, DisableTrimDuplicates); if (switchValue.HasValue) { searchQueryRequest.TrimDuplicates = switchValue; } switchValue = GetThreeWaySwitchValue(EnableFql, DisableFql); if (switchValue.HasValue) { searchQueryRequest.EnableFql = switchValue; } switchValue = GetThreeWaySwitchValue(EnableQueryRules, DisableQueryRules); if (switchValue.HasValue) { searchQueryRequest.EnableQueryRules = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessBestBets, DisableProcessBestBets); if (switchValue.HasValue) { searchQueryRequest.ProcessBestBets = switchValue; } switchValue = GetThreeWaySwitchValue(EnableByPassResultTypes, DisableByPassResultTypes); if (switchValue.HasValue) { searchQueryRequest.ByPassResultTypes = switchValue; } switchValue = GetThreeWaySwitchValue(EnableProcessPersonalFavorites, DisableProcessPersonalFavorites); if (switchValue.HasValue) { searchQueryRequest.ProcessPersonalFavorites = switchValue; } searchQueryRequest.RankingModelId = RankingModelId ?? searchQueryRequest.RankingModelId; if (RankingModelName.HasValue) { if (!String.IsNullOrWhiteSpace(RankingModelId)) { WriteWarning("RankingModelName overrides RankingModelId. Please use one or the other."); } searchQueryRequest.RankingModelId = RankModel.Select(RankingModelName.Value); } searchQueryRequest.SourceId = ResultSourceId ?? searchQueryRequest.SourceId; if (ResultSourceName.HasValue) { if (!String.IsNullOrWhiteSpace(ResultSourceId)) { WriteWarning("ResultSourceName overrides ResutSourceId. Please use one or the other."); } searchQueryRequest.SourceId = ResultSource.Select(ResultSourceName.Value); } searchQueryRequest.HiddenConstraints = HiddenConstraints ?? searchQueryRequest.HiddenConstraints; searchQueryRequest.QueryTemplate = QueryTemplate ?? searchQueryRequest.QueryTemplate; searchQueryRequest.RowLimit = RowLimit.HasValue ? RowLimit : (searchQueryRequest.RowLimit.HasValue ? searchQueryRequest.RowLimit : rowLimitDefault); searchQueryRequest.StartRow = StartRow.HasValue ? StartRow : (searchQueryRequest.StartRow.HasValue ? searchQueryRequest.StartRow : startRowDefault); searchQueryRequest.Timeout = Timeout.HasValue ? Timeout : (searchQueryRequest.Timeout.HasValue ? searchQueryRequest.Timeout : timeoutDefault); searchQueryRequest.Refiners = Refiners ?? searchQueryRequest.Refiners; if (Credential != null || searchQueryRequest.AuthenticationType == AuthenticationType.Windows) { if (Credential == null) { var userName = searchQueryRequest.UserName; Credential = this.Host.UI.PromptForCredential("Enter username/password", "", userName, ""); } searchQueryRequest.AuthenticationType = AuthenticationType.Windows; searchQueryRequest.UserName = Credential.UserName; searchQueryRequest.SecurePassword = Credential.Password; } else if (SPO || searchQueryRequest.AuthenticationType == AuthenticationType.SPO) { Guid runspaceId = Guid.Empty; using (var ps = PowerShell.Create(RunspaceMode.CurrentRunspace)) { runspaceId = ps.Runspace.InstanceId; CookieCollection cc; bool found = Tokens.TryGetValue(runspaceId, out cc); if (!found) { //cc = WebAuthentication.GetAuthenticatedCookies(searchQueryRequest.SharePointSiteUrl, searchQueryRequest.AuthenticationType); cc = SPOClientWebAuth.GetAuthenticatedCookies(searchQueryRequest.SharePointSiteUrl); if (cc == null) { throw new RuntimeException("Authentication cookie returned is null! Authentication failed. Please try again."); // TODO find another exception } else { Tokens.Add(runspaceId, cc); } } searchQueryRequest.AuthenticationType = AuthenticationType.SPO; searchQueryRequest.Cookies = cc; //searchSuggestionsRequest.Cookies = cc; } } else { searchQueryRequest.AuthenticationType = AuthenticationType.CurrentUser; WindowsIdentity currentWindowsIdentity = WindowsIdentity.GetCurrent(); searchQueryRequest.UserName = currentWindowsIdentity.Name; } }