private int RealizarBusqueda(string query, int offset) { //MSNSearchPortTypeClient s = new MSNSearchPortTypeClient(); MSNSearch.MSNSearchService s = new MSNSearchService(); SearchRequest searchRequest = new SearchRequest(); int arraySize = 1; SourceRequest[] sr = new SourceRequest[arraySize]; sr[0] = new SourceRequest(); sr[0].Source = SourceType.Web; sr[0].Count = resultadosPorPag; sr[0].Offset = offset; searchRequest.Query = query; searchRequest.Requests = sr; // Enter the Application ID, in double quotation marks, supplied by the // Developer Provisioning System, as the value of the AppID on the SearchRequest. searchRequest.AppID = "00E563DCB26A22584ADD1A1F2F182FC8E184B25A"; searchRequest.CultureInfo = "en-US"; SearchResponse searchResponse; searchResponse = s.Search(searchRequest); res = searchResponse.Responses[0].Results; return(searchResponse.Responses[0].Total); }
void when_post_sources() { context["given a sepa source"] = () => { beforeAllAsync = async() => { sourceRequest = new SourceRequest( type: "sepa", billingAddress: new Address() { AddressLine1 = "Checkout GmbH", AddressLine2 = "Rudi-Dutschke-Strasse 26", City = "Berlin", Zip = "10969", State = "Berlin", Country = "DE" }) { Reference = "CKO Demo test", Phone = new Phone() { CountryCode = "+49", Number = "3088789157" }, SourceData = new SourceData() { { "first_name", "Marcus" }, { "last_name", "Barrilius Maximus" }, { "account_iban", "DE25100100101234567893" }, { "bic", "PBNKDEFFXXX" }, { "billing_descriptor", "CKO Demo test" }, { "mandate_type", "single" } } }; result = await controller.RequestSource(sourceRequest); source = (result as ObjectResult).Value as Resource; }; it["should return 201 - Created"] = () => { (result as CreatedAtActionResult).StatusCode.ShouldBe(StatusCodes.Status201Created); }; it["should match request source type with response source type"] = () => { (source as SourceProcessed).Type.ToLower().ShouldBe(sourceRequest.Type.ToLower()); }; it["should return a mandate reference"] = () => { (source as SourceProcessed).ResponseData["mandate_reference"].ShouldNotBeNull(); }; }; }
public override SearchResult[] Search(SearchQuery query) { List <SearchResult> searchResults = new List <SearchResult>(); int startOffset = 0; MSNSearchService msnSearchService = new MSNSearchService(); SearchRequest searchRequest = new SearchRequest(); int arraySize = 1; SourceRequest[] sr = new SourceRequest[arraySize]; sr[0] = new SourceRequest(); sr[0].Source = SourceType.Web; sr[0].Offset = startOffset; String searchPrefix = String.IsNullOrEmpty(_siteDomainName) ? "" : "site:" + _siteDomainName + " "; searchRequest.Query = searchPrefix + query.Query; searchRequest.Requests = sr; searchRequest.AppID = _appID; searchRequest.CultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; SearchResponse searchResponse = msnSearchService.Search(searchRequest); foreach (SourceResponse sourceResponse in searchResponse.Responses) { Result[] sourceResults = sourceResponse.Results; foreach (Result sourceResult in sourceResults) { SearchResult searchResult = new SearchResult(); if (!String.IsNullOrEmpty(sourceResult.Title)) { searchResult.Title = sourceResult.Title; } if (!String.IsNullOrEmpty(sourceResult.Description)) { searchResult.Description = sourceResult.Description; } if (!String.IsNullOrEmpty(sourceResult.Url)) { searchResult.Url = sourceResult.Url; } searchResults.Add(searchResult); } } return(searchResults.ToArray()); }
public SourceRequestTests() { var settings = new ConnectionSettings(UnitTestDefaults.Uri, UnitTestDefaults.DefaultIndex) .SetConnectionStatusHandler(r => this._status = r) .ExposeRawResponse(); var connection = new InMemoryConnection(settings); var client = new ElasticClient(settings, connection); var request = new SourceRequest <ElasticsearchProject>(2) { Preference = "local", Routing = "2", }; var response = client.Source <ElasticsearchProject>(request); }
public static bool IsExistenceSource(SourceRequest sourceRequest, ICompany company, out ISource sourceFromDb) { sourceFromDb = null; if (sourceRequest == null) { return(false); } sourceFromDb = company.ReadSource(sourceRequest.Id); if (sourceFromDb == null) { return(false); } else { return(true); } }
public static bool IsValidatedSource(SourceRequest sourceRequest, ICompany company, out ISource sourceFromDb) { if (IsExistenceSource(sourceRequest, company, out ISource _sourceFromDb)) { sourceFromDb = _sourceFromDb; if (_sourceFromDb.SecretKey == sourceRequest.SecretKey) { return(true); } else { return(false); } } else { sourceFromDb = _sourceFromDb; return(false); } }
public async Task <IActionResult> RequestSource(SourceRequest sourceRequest) { try { var sourceResponse = await api.Sources.RequestAsync(sourceRequest); if (sourceResponse.IsPending) { throw new NotImplementedException("There is no use case for SourceResponse.Pending yet."); } else { return(CreatedAtAction(nameof(RequestSource), new { paymentId = sourceResponse.Source.Id }, sourceResponse.Source)); } } catch (Exception e) { return(UnprocessableEntity(e.Message)); } }
private void ExecuteMSNSearchQuery() { //THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF //ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED //TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //PARTICULAR PURPOSE. // //Copyright (C) 2005 Microsoft Corporation. All rights reserved. // Create a new SearchRequest object that represents the search request. Each SearchRequest can // contain multiple SourceRequest objects; however, each SearchRequest can contain // only one SourceRequest of each type. (More on this later.) SearchRequest searchRequest = new SearchRequest(); int arraySize = 3; // Each SourceRequest can be configured to return one or more result fields: // CacheUrl, Description, DisplayUrl, SearchTags, Title, Url, and All. // Fields can be combined using the bitwise OR operator (|); // All returns all available fields in the enumeration. // Note that some SourceRequest objects cannot return all of the fields // described. For example, a SourceRequest of type Spelling returns one spelling // suggestion in the Title field, so the returned data is the same when the // ResultFields property is set to ResultFieldMask.All or ResultFieldMask.Title. SourceRequest[] sr = new SourceRequest[arraySize]; // The first SourceRequest is a Web source request. This can be a request for Web or // Web-Local results, depending on whether the Location object is set. When the user clicks // Near Me, the sample application applies the Location information to the search and // returns Web-Local results (results that consider Location as a relevance factor) and // PhoneBook results. sr[0] = new SourceRequest(); sr[0].Source = SourceType.Web; // For this SourceRequest, we can return all fields... sr[0].ResultFields = ResultFieldMask.All; // Or just specific fields, such as SearchTags. // sr[0].ResultFields = ResultFieldMask.SearchTags; // To return a subset of all fields, combine the result fields using the bitwise // OR operator (|). The following example returns the Title and URL fields only: // sr[0].ResultFields = ResultFieldMask.Title | ResultFieldMask.Url; // Check for the number of results to return per page. If this value is not set, // the service returns the default number of results, which is ten per page. sr[0].Count = 10; // Check for an offset value. The default offset is zero, meaning that results are // returned from the MSN Search Engine with the highest-ranking result displayed first. // The Offset property is most commonly used in conjunction with the Count // property, above, for paging through long lists of results. sr[0].Offset = 0; //// The second SourceRequest is a spelling source request. Spelling returns only one //// result per call, in the Title field. //sr[1] = new SourceRequest(); //sr[1].Source = SourceType.Spelling; //sr[1].ResultFields = ResultFieldMask.Title; //// Set the Count to 1 and the Offset to 0 for SourceType.Spelling; Spelling returns //// only one result per request (Count = 1) at offset zero (Offset = 0). //sr[1].Count = 1; //sr[1].Offset = 0; //// The third SourceRequest is a PhoneBook source request. PhoneBook results include //// a title, description, URL, phone number, address object, and location object. //// Although the DisplayUrl field can be returned, the URL it contains is not significant. //sr[2] = new SourceRequest(); //sr[2].Source = SourceType.PhoneBook; //// In this sample, we will return the Title, Description, and Url fields, as well as //// the PhoneBook-specific return fields Phone, Address, and Location. //sr[2].ResultFields = ResultFieldMask.Title | ResultFieldMask.Url; //// if (txtNumResults.Text != String.Empty) //sr[2].Count = 10;// Int32.Parse(txtNumResults.Text); //// if (txtOffset.Text != String.Empty) //sr[2].Offset = 0;// Int32.Parse(txtOffset.Text); // The Query field of the SearchRequest object is the text of the query submitted to the // MSN Search Engine. The query can contain any valid query text supported by the // MSN Search Engine, including advanced query syntax. searchRequest.Query = queryText; // The Requests field of the SearchRequest object is the array of SourceRequest objects // for this search. searchRequest.Requests = sr; // Check the user selection for SafeSearchOptions. // If no setting is specified, the default setting of Moderate is applied to this SearchRequest. searchRequest.SafeSearch = SafeSearchOptions.Off; // searchRequest.SafeSearch = SafeSearchOptions.Strict; // searchRequest.SafeSearch = SafeSearchOptions.Moderate; // Enter the Application ID, in double quotation marks, supplied by the // Developer Provisioning System as the value of the AppID on the SearchRequest. searchRequest.AppID = msnAppID; // Determine whether the user chose to enable query word marking. Query word // marking returns specific characters before and after each word or group of words // used in the SearchRequest.Query field. searchRequest.Flags = SearchFlags.None; // Determine the user's CultureInfo selection. // The following code gets the CultureInfo value from the combo box. // The combo box collection contains all values recognized by the MSN Search Engine. // You can also set the CultureInfo to a specific value in the code, as shown in the // following example: searchRequest.CultureInfo = "en-US"; // To return PhoneBook results in addition to Web results, the user must set the Location. // The following code sets the Latitude and Longitude fields of the Location // object and the Radius of the search. // If invalid Location data is specified, the MSN Search Engine will attempt to // return search results based on the information provided. Note that zero results // may return if the Location data does not map to a valid geographic location. // The value of Radius also affects the search results; a small value for Radius may // return fewer results than expected. // The sample application user interface does not validate user input. //if (nearMe) //{ // double latitude = Double.Parse(txtLatitude.Text); // double longitude = Double.Parse(txtLongitude.Text); // double radius = Double.Parse(txtRadius.Text); // searchRequest.Location = new Location(); // searchRequest.Location.Latitude = latitude; // searchRequest.Location.Longitude = longitude; // searchRequest.Location.Radius = radius; //} // Once the SearchRequest has been configured and all of the SourceRequest // objects have been configured and added to the SearchRequest, the // application can process the request. // s.SearchCompleted += new SearchCompletedEventHandler(s_SearchCompleted); // Execute the search request and return the search response by // setting the SearchResponse to MSNSearchService.Search(SearchRequest). SearchResponse searchResponse = s.Search(searchRequest); SearchMSNItemCollection list = new SearchMSNItemCollection(); // Check the SearchResponse to determine whether it contains a spelling suggestion. // The spelling suggestion is returned in the Title field of the Spelling SourceResponse. // If the SearchResponse does not contain a Spelling SourceResponse, there is no // spelling suggestion and the application passes the SearchResponse to the printResults method. // If a Spelling SourceResponse is returned, the application displays a MessageBox that asks // the user to choose whether to ignore the spelling suggestion or accept the spelling // suggestion and re-execute the query with the updated query string. // To test for the presence of the Spelling SourceResponse, check the Total field for // the SearchResponse.Response for the Spelling SourceType. foreach (SourceResponse sourceResponse in searchResponse.Responses) { // The requested result fields for each SourceRequest are returned in the // Results field of the respective SourceResponse. Result[] sourceResults = sourceResponse.Results; // Using foreach, loop through the results returned in each SourceResponse. foreach (Result sourceResult in sourceResults) { SearchMSNItem searchMSNItem = new SearchMSNItem(); searchMSNItem.Name = sourceResult.Title; searchMSNItem.Path = sourceResult.Url; list.Add(searchMSNItem); } } if (uiDispatcher != null) { uiDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(OnMSNSearchCompleteEvent), (object)list); } }
// The encoding algorithm. public string EncodeMessage(string[] IMMessage, out string MacString) { int numSourceRequest = 1; SourceRequest[] sourceRequest = new SourceRequest[numSourceRequest]; string EncodedMessage = ""; string LocalMacString = ""; sourceRequest[0] = new SourceRequest(); sourceRequest[0].Source = SourceType.Web; sourceRequest[0].Count = (int)AlgoParameters.WORD_SEARCH_LENGTH; sourceRequest[0].Offset = resultSelector.Next((int)AlgoParameters.WORD_SEARCH_OFFSET); searchRequest.Query = "Chaffer"; searchRequest.Requests = sourceRequest; searchRequest.AppID = "351A70F9FBE13428EF87F3FEB65F235482371425"; searchRequest.CultureInfo = "en-US"; searchRequest.Requests = sourceRequest; // Get out every single message. foreach (string word in IMMessage) { SearchResponse searchResponse; if (word.Length == 0) { continue; } if (String.Equals(word, "")) { continue; } // Fake Encoding PerformFakeWebSearch((int)fakeSearchInserter.Next((int)AlgoParameters.WORD_FAKE_SEARCH_UPPER_BOUND), EntropyPool, resultSelector, searchService, searchRequest); //--------------Word Encoding Begin ----------------------------------------------------------------------------// // Encode the real word. searchRequest.Query = word; int retry_count = (int)AlgoParameters.WORD_ENCODING_RETRY_COUNT; char[] arraySplit = { ' ' }; Boolean wordEncoded = false; do { searchRequest.Requests[0].Count = (int)AlgoParameters.WORD_SEARCH_OFFSET; searchRequest.Requests[0].Offset = resultSelector.Next((int)AlgoParameters.WORD_SEARCH_LENGTH); searchResponse = searchService.Search(searchRequest); /* Select the appropriate response out of the 10 hits */ foreach (SourceResponse sourceResponse in searchResponse.Responses) { Result[] sourceResults = sourceResponse.Results; int index = 0; foreach (Result sourceResult in sourceResults) { if (sourceResult.Description != null && sourceResult.Description.Contains(word)) { wordEncoded = true; printColored(word, ConsoleColor.Green); string tempstr = PreprocessQueryResult(sourceResult.Description, word); EncodedMessage = EncodedMessage + tempstr + " "; LocalMacString = LocalMacString + GenerateMACString(tempstr.Split(arraySplit), word); // Perform the warm up close to the hit. if (index == sourceResults.GetLength(0) - 1) { EntropyPool.EntropyCacheWarmUp(sourceResults[sourceResults.GetLength(0) - 1].Description); EntropyPool.EntropyCacheWarmUp(sourceResults[sourceResults.GetLength(0) - 2].Description); } else if (index == 0) { EntropyPool.EntropyCacheWarmUp(sourceResults[0].Description); EntropyPool.EntropyCacheWarmUp(sourceResults[1].Description); } else { EntropyPool.EntropyCacheWarmUp(sourceResults[index + 1].Description); EntropyPool.EntropyCacheWarmUp(sourceResults[index - 1].Description); } EntropyPool.EntropyCacheWarmUp(sourceResult.Description); break; } index++; } } } while (!wordEncoded && (retry_count-- > 0)); if (!wordEncoded) { printColored("Oops! Could not encode word->" + word, ConsoleColor.Red); } //--------------Word Encoding Done ----------------------------------------------------------------------------// // Fake Encoding PerformFakeWebSearch(fakeSearchInserter.Next((int)AlgoParameters.WORD_FAKE_SEARCH_UPPER_BOUND), EntropyPool, resultSelector, searchService, searchRequest); } MacString = String.Copy(LocalMacString); return(EncodedMessage); }