public async Task Then_Returns_View_With_Correct_ViewModel( IndexRequest request, IndexViewModel viewModel, string organisationsLink, string schemesLink, [Frozen] Mock <IModelMapper> mockMapper, [Frozen] Mock <ILinkGenerator> mockLinkGenerator, CohortController controller) { mockMapper .Setup(mapper => mapper.Map <IndexViewModel>(request)) .ReturnsAsync(viewModel); mockLinkGenerator .Setup(generator => generator.AccountsLink($"accounts/{request.AccountHashedId}/agreements")) .Returns(organisationsLink); mockLinkGenerator .Setup(generator => generator.AccountsLink($"accounts/{request.AccountHashedId}/schemes")) .Returns(schemesLink); var result = await controller.Index(request) as ViewResult; result.ViewName.Should().BeNull(); var model = result.Model as IndexViewModel; model.Should().BeSameAs(viewModel); }
public async Task Then_Will_Get_Saved_Search_Details_From_Cookies( IndexRequest request, IndexRequest savedRequest, IndexViewModel expectedViewModel, [Frozen] Mock <IModelMapper> apprenticeshipMapper, [Frozen] Mock <ICookieStorageService <IndexRequest> > cookieService, ApprenticeController controller) { //Arrange request.FromSearch = true; apprenticeshipMapper .Setup(mapper => mapper.Map <IndexViewModel>(It.IsAny <IndexRequest>())) .ReturnsAsync(expectedViewModel); cookieService .Setup(x => x.Get(CookieNames.ManageApprentices)) .Returns(savedRequest); //Act await controller.Index(request); //Assert cookieService.Verify(x => x.Get(CookieNames.ManageApprentices)); }
/// <summary> /// Executes the sender reading data from valuesToBeSent. /// </summary> /// <returns>Task</returns> /// <example>To copy data from SQL Server to Elasticsearch following *.json configuration file can be used: /// <code title="SQLServerToElasticsearch.json"> /// <![CDATA[{ /// "$type": "StanskinsImplementation.SimpleJob, StanskinsImplementation", /// "Receivers": { /// "$type": "StankinsInterfaces.OrderedList`1[[StankinsInterfaces.IReceive, StankinsInterfaces]], StankinsInterfaces", /// "0": { /// "$type": "ReiceverDBStmtSqlServer.ReceiverStmtSqlServer, ReiceverDBStmtSqlServer", /// "ConnectionString": "Server=(local)\\SQL2016;Database=IronSQLDBA;Trusted_Connection=True;", /// "CommandType": 4, /// "CommandText": "dbo.active_slow_query_select", /// "FileNameSerializeLastRow": "IronSQLDBA_active_slow_query_select_last_row.json", /// "ParametersMappings": "@original_id=original_id" /// } /// }, /// "FiltersAndTransformers": { /// "$type": "StankinsInterfaces.OrderedList`1[[StankinsInterfaces.IFilterTransformer, StankinsInterfaces]], StankinsInterfaces" /// }, /// "Senders": { /// "$type": "StankinsInterfaces.OrderedList`1[[StankinsInterfaces.ISend, StankinsInterfaces]], StankinsInterfaces", /// "0": { /// "$type": "SenderElasticSearch.SenderToElasticSearch, SenderElasticSearch", /// "Uri": "http://localhost:9200", /// "IndexName": "ironsqldba-index-active-slow-query", /// "TypeName": "active-slow-query", /// "Id": "id" /// } /// } /// }]]> /// </code> /// </example> public async Task Send() { var settings = new ConnectionSettings(new Uri(this.Uri)); var client = new ElasticClient(settings); foreach (IRow item in valuesToBeSent) { IndexRequest <object> request; if (string.IsNullOrWhiteSpace(this.Id)) { request = new IndexRequest <object>(this.IndexName, this.TypeName); } else { string idValue = item.Values[this.Id].ToString(); //TODO: better solution ? (API Nest.Id string/long/Document) request = new IndexRequest <object>(this.IndexName, this.TypeName, idValue); } request.Document = item.Values; IIndexResponse resp = await client.IndexAsync(request); if (!resp.ApiCall.Success) { throw new Exception(resp.ApiCall.DebugInformation); } } }
public async Task IndexAsync() { //var post = new Post //{ // Title = "Hello World" //}; //var request = new IndexRequest<Post>(post); //var response = _client.Index(post, idx => idx.Index("post")); var collection = new string[] { "A", "B", "C", "D" }; foreach (var item in collection) { var user = new User { Id = IDUtils.NewId(), Name = item }; var request = new IndexRequest <User>(user); var response = await _client.IndexAsync(user, idx => idx.Index(nameof(User).ToLower())); Assert.True(response.ApiCall.Success); } }
protected bool Index <T>(string _DefaultIndex, T data, string route, string id, out string id_ret) where T : class { id_ret = ""; IndexRequest <object> req = new IndexRequest <object>(_DefaultIndex, typeof(T)); if (!string.IsNullOrEmpty(route)) { req.Routing = route; } req.Document = data; IndexResponse re = null; if (string.IsNullOrEmpty(id)) { id = id_gen.CreateId().ToString(); } if (!string.IsNullOrEmpty(id)) { re = client.Index <T>(data, i => i.Id(id)); } else { re = client.Index(req); } if (re.Result == Result.Created) { id_ret = re.Id; } return(re.Result == Result.Created); }
public async Task Should_Pass_Params_To_Api_Call( IndexRequest webRequest, long decodedAccountId, [Frozen] Mock <IEncodingService> mockEncodingService, [Frozen] Mock <ICommitmentsApiClient> mockApiClient, IndexViewModelMapper mapper) { mockEncodingService .Setup(service => service.Decode(webRequest.AccountHashedId, EncodingType.AccountId)) .Returns(decodedAccountId); await mapper.Map(webRequest); mockApiClient.Verify(client => client.GetApprenticeships(It.Is <ApiRequests.GetApprenticeshipsRequest>(apiRequest => apiRequest.AccountId == decodedAccountId && apiRequest.PageNumber == webRequest.PageNumber && apiRequest.PageItemCount == Constants.ApprenticesSearch.NumberOfApprenticesPerSearchPage && apiRequest.SearchTerm == webRequest.SearchTerm && apiRequest.ProviderName == webRequest.SelectedProvider && apiRequest.CourseName == webRequest.SelectedCourse && apiRequest.Status == webRequest.SelectedStatus && apiRequest.ApprenticeConfirmationStatus == webRequest.SelectedApprenticeConfirmation && apiRequest.EndDate == webRequest.SelectedEndDate), It.IsAny <CancellationToken>()), Times.Once); }
/** === An example with requests */ [U] public void UsingWithRequests() { /* Given the following CLR type that describes a document */ var project = new Project { Name = "hello-world" }; /** we can see an example of how `DocumentPath` helps your describe your requests more tersely */ var request = new IndexRequest <Project>(2) { Document = project }; request = new IndexRequest <Project>(project) { }; /** when comparing with the full blown constructor and passing document manually, * `DocumentPath<T>`'s benefits become apparent. */ request = new IndexRequest <Project>(IndexName.From <Project>(), TypeName.From <Project>(), 2) { Document = project }; }
public void Can_insert_record() { var indexRequest = new IndexRequest <logEvent>(LogEventBuilder.Default.LogEvent); var indexResponse = elasticClient.Index(indexRequest); indexResponse.Id.Should().NotBeNull(); }
public async Task Then_Gets_Filter_Values_From_Api( IndexRequest webRequest, long decodedAccountId, [Frozen] Mock <IEncodingService> mockEncodingService, GetApprenticeshipsResponse clientResponse, [Frozen] Mock <ICommitmentsApiClient> mockApiClient, IndexViewModelMapper mapper) { clientResponse.TotalApprenticeships = Constants.ApprenticesSearch.NumberOfApprenticesRequiredForSearch + 1; mockApiClient .Setup(client => client.GetApprenticeships( It.IsAny <ApiRequests.GetApprenticeshipsRequest>(), It.IsAny <CancellationToken>())) .ReturnsAsync(clientResponse); mockEncodingService .Setup(service => service.Decode(webRequest.AccountHashedId, EncodingType.AccountId)) .Returns(decodedAccountId); await mapper.Map(webRequest); mockApiClient.Verify(client => client.GetApprenticeshipsFilterValues( It.Is <ApiRequests.GetApprenticeshipFiltersRequest>(request => request.EmployerAccountId == decodedAccountId), It.IsAny <CancellationToken>()), Times.Once); }
public async Task Then_Will_Used_Current_Search_Details_If_Saved_Details_Not_Available( IndexRequest request, IndexViewModel expectedViewModel, [Frozen] Mock <IModelMapper> apprenticeshipMapper, [Frozen] Mock <ICookieStorageService <IndexRequest> > cookieService, ApprenticeController controller) { //Arrange request.FromSearch = true; apprenticeshipMapper .Setup(mapper => mapper.Map <IndexViewModel>(It.IsAny <IndexRequest>())) .ReturnsAsync(expectedViewModel); cookieService .Setup(x => x.Get(CookieNames.ManageApprentices)) .Returns((IndexRequest)null); //Act await controller.Index(request); //Assert apprenticeshipMapper.Verify(mapper => mapper.Map <IndexViewModel>(request)); cookieService.Verify(x => x.Update( CookieNames.ManageApprentices, It.IsAny <IndexRequest>(), It.IsAny <int>()), Times.Once); }
public async Task When_record_status_persited_record_shoud_be_wirtten_to_elasticsearch() { string _someField = Guid.NewGuid().ToString(); string _someValue = Guid.NewGuid().ToString(); nodes.InsertOne( new BsonDocument("_id", _recordId) .Add("Name", "TestName1") .Add("Status", "Processed") .Add(_someField, _someValue) ); var _node = _fixture.MongoDb.GetCollection <dynamic>("Nodes").Find(new BsonDocument("_id", _recordId)).First(); ((IDictionary <string, object>)_node).Remove("_id"); ((IDictionary <string, object>)_node).Add("id", _recordId); ((IDictionary <string, object>)_record).Add("Node", _node); await _harness.InputQueueSendEndpoint.Send <StatusPersisted>(new { id = _record.id, Status = RecordStatus.Processed, Userid = _fixture.UserId, TimeStamp = DateTimeOffset.UtcNow }); _consumer.Consumed.Select <StatusPersisted>().Any().Should().BeTrue(); var request = new IndexRequest <object>(_record, "records", "record", _record.id); _fixture.FakeIndex.Should().HaveCount(1); _fixture.FakeIndex.First().ShouldBeEquivalentTo(request); }
public async Task <IActionResult> GetImages() { var req = new IndexRequest(); var res = await Mediator.Send(req); return(Ok(res.ToDictionary(k => k.Key, v => v.Value as ImageResponse))); }
// public async Task<bool> CreateMappingIfNoExists<T>(string indexName // , Func<PutMappingDescriptor<T>, IPutMappingRequest> selector) where T : class // { // var log = _loggerFac.CreateLogger<ElasticsearchService>(); // var types = Types.Parse(typeName); // var exists = await _elasticClient.TypeExistsAsync(Indices.Index(indexName), typeName); // if (exists.Exists) // { // log.LogWarning("index:{0},type:{1}已经存在", indexName, typeName); // return await Task.FromResult(true); // } // PutMappingRequest indexMappings = new PutMappingRequest(indexName,typeName); // var putMapping = await _elasticClient.MapAsync<T>((des) => // { // return selector(des); // }); // log.LogInformation(putMapping.DebugInformation); // if (putMapping.Acknowledged) // { // log.LogInformation("index:{0},type:{1},创建成功", indexName, typeName); // return await Task.FromResult(false); // } // else // { // log.LogError(putMapping.ServerError.ToString()); // log.LogError(putMapping.OriginalException.ToString()); // return await Task.FromResult(false); // } // } public async Task <ICreateResponse> CreateDocument <T>(string indexName, T t) where T : class { var log = _loggerFac.CreateLogger <ElasticsearchService>(); if (t == null) { log.LogError("bulk 参数不能为空。"); return(null); } IndexRequest <T> request = new IndexRequest <T>(indexName, TypeName.From <T>()) { Document = t }; var createResponse = await _elasticClient.CreateDocumentAsync <T>(t); log.LogInformation(createResponse.DebugInformation); if (createResponse.ApiCall.Success) { log.LogInformation("index:{0},type:{1},创建成功", createResponse.Index, createResponse.Type); return(createResponse); } else { log.LogError(createResponse.ServerError.ToString()); log.LogError(createResponse.OriginalException.ToString()); return(null); } }
public async Task <IActionResult> Index(IndexRequest request) { IndexRequest savedRequest = null; if (request.FromSearch) { savedRequest = _cookieStorage.Get(CookieNames.ManageApprentices); if (savedRequest != null) { request = savedRequest; } } if (savedRequest == null) { _cookieStorage.Update(CookieNames.ManageApprentices, request); } var viewModel = await _modelMapper.Map <IndexViewModel>(request); viewModel.SortedByHeader(); return(View(viewModel)); }
public void Index(int limit = -1, string since = null, bool returnData = false) { if (indexRequest != null) { Exception e = new Exception("Index already in process"); OnIndexCompleted(new DataEventArgs <IndexResult>(e)); return; } string uri = getBucketUriString() + "/index"; // set up the base url for each index request Dictionary <string, string> parameters = new Dictionary <string, string>(); if (limit >= 0) { parameters.Add("limit", "" + limit); } if (since != null) { parameters.Add("since", since); } if (returnData) { parameters.Add("data", "1"); } uri += appendQueryParameters(parameters); indexRequest = new IndexRequest(uri, (parameters.Count > 0), getWebClient()); indexRequest.webClient.DownloadStringCompleted += FinishedRemoteIndexRequest; StartRemoteIndexRequest(null); }
public async Task When_persited_folder_it_shoud_wirtten_to_elasticsearch() { string _someField = Guid.NewGuid().ToString(); string _someValue = Guid.NewGuid().ToString(); var nodes = _fixture.MongoDb.GetCollection <BsonDocument>("Nodes"); nodes.InsertOneAsync( new BsonDocument("_id", _folder.id) .Add("Name", "TestName1") .Add("Status", "Processed") .Add(_someField, _someValue)) .Wait(); await _fixture.Harness.Bus.Publish <FolderPersisted>(new { Id = _folder.id }); await _fixture.Harness.Consumed.Any <FolderPersisted>(); ((IDictionary <string, object>)_folder).Add("Node", new Dictionary <string, object> { { "id", _folder.id }, { "Name", "TestName1" }, { "Status", "Processed" }, { _someField, _someValue } }); var request = new IndexRequest <object>(_folder, "folders", "folder", _folder.id); _fixture.FakeIndex.Should().HaveCount(1); _fixture.FakeIndex.First().ShouldBeEquivalentTo(request); }
public IActionResult Index([FromQuery] IndexRequest model) { var viewModel = new IndexResponse(); if (!model.ContainsValidColors()) { throw new Exception("Invalid colors."); } viewModel.Color1 = model.Color1; viewModel.Color2 = model.Color2; viewModel.Color3 = model.Color3; viewModel.Color4 = model.Color4; viewModel.Color5 = model.Color5; byte[] rawPixelBoard; if (session.TryGetValue("pixelBoard", out rawPixelBoard)) { var pixelBoard = JsonConvert.DeserializeObject <CreateRequest>(Encoding.UTF8.GetString(rawPixelBoard)); viewModel.Pixels = pixelBoard.Pixels; } return(View(viewModel)); }
public void Log(IAuditInfo info) { try { if (info is IPagePreRenderCompleteEvent) { return; } if (info == null) { return; } var request = new IndexRequest <IDictionary <string, object> >(this.IndexName, new Id(Guid.NewGuid().ToString())); request.Document = info.Fields; this.client.Index(request); } catch (Exception e) { var exceptionMessage = new StringBuilder() .AppendLine("Error sending the audit information to Elasticsearch.") .AppendLine("Error details:") .Append(e.ToString()) .ToString(); Telerik.Sitefinity.Abstractions.Log.Write(exceptionMessage); } }
public async Task <bool> HandleAsync(TracerEvent @event, CancellationToken cancellationToken = default(CancellationToken)) { var info = @event.TraceSpan; if (info != null) { var StartTime = DateTime.Now; var index = new IndexName() { Name = $"tracer" }; var indexRequest = new IndexRequest <TraceSpan>(info, index); var response = await _elasticClientManager._elasticClient.IndexAsync(indexRequest); if (!response.IsValid) { // throw new ElasticsearchClientException("Add auditlog disaster!"); Console.WriteLine("Add auditlog disaster!" + response.OriginalException); } var TimeLength = Math.Round((DateTime.Now - StartTime).TotalMilliseconds, 4); Console.WriteLine("es数据创建耗时" + TimeLength + "毫秒"); } return(true); }
public async Task Then_Maps_ReservationId( IndexRequest request, IndexViewModelMapper mapper) { var viewModel = await mapper.Map(request); viewModel.ReservationId.Should().Be(request.ReservationId); }
public async Task Then_Maps_EmployerAccountLegalEntityPublicHashedId( IndexRequest request, IndexViewModelMapper mapper) { var viewModel = await mapper.Map(request); viewModel.AccountLegalEntityHashedId.Should().Be(request.AccountLegalEntityHashedId); }
public async Task Then_Maps_StartMonthYear( IndexRequest request, IndexViewModelMapper mapper) { var viewModel = await mapper.Map(request); viewModel.StartMonthYear.Should().Be(request.StartMonthYear); }
public async Task Then_Maps_CourseCode( IndexRequest request, IndexViewModelMapper mapper) { var viewModel = await mapper.Map(request); viewModel.CourseCode.Should().Be(request.CourseCode); }
public async Task UpdateAsync(IndexRequest indexRequest) { var dto = indexRequest.ToDbo(); await _client.IndexAsync(dto, x => x .Id(dto.Url.ToString()) .Index(_options.RequestsIndexName) ); }
public void Index(ElasticClient client) { var indexRequest = new IndexRequest <Product>("esdemo", "product"); var response = client.Index(indexRequest); Console.WriteLine($"{response.Index}-{response.Type}"); }
public async Task Then_Maps_AccountHashedId( IndexRequest request, IndexViewModelMapper mapper) { var viewModel = await mapper.Map(request); viewModel.AccountHashedId.Should().Be(request.AccountHashedId); }
public IndexResponse AddDocument(IndexRequest query) { GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Entering MI4TIndexManager.AddDocument for TCM URI: " + query.ItemURI); IndexResponse response = new IndexResponse(); OperationResult result = OperationResult.Failure; try { XmlDocument doc = new XmlDocument(); string ID = string.Empty; doc.LoadXml(Utility.UpdateContentTypeXML(Regex.Replace(query.DCP.ToString(), @"\b'\b", ""))); var bln = Deserialize <MongoDBModel>(doc); var conString = propConfiguration.GetString(GenericStorageExtensionServicesConstants.Search_URL); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "conString: " + conString); /// creating MongoClient var client = new MongoClient(conString); ///Get the database var DB = client.GetDatabase(propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName)); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "dbName: " + propConfiguration.GetString(GenericStorageExtensionServicesConstants.dbName)); ///Get the collcetion from the DB in which you want to insert the data var collection = DB.GetCollection <MongoDBModel>(propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName)); GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "tableName: " + propConfiguration.GetString(GenericStorageExtensionServicesConstants.tableName)); //var filter = Builders<MongoDBModel>.Filter.Eq("ItemURI", bln.ItemURI); //var result11 = collection.Find(filter).ToListAsync(); ///Insert data in to MongoDB collection.InsertOne(bln); result = OperationResult.Success; } catch (Exception ex) { string logString = GenericStorageExtensionServiceConstants.LOG_MESSAGE + Environment.NewLine; logString = string.Concat(logString, Environment.NewLine, string.Format("{0}{1}", ex.Message, ex.StackTrace)); GenericStorageExtensionLogger.WriteLog(ELogLevel.ERROR, logString); result = OperationResult.Failure; } response.Result = (int)result; GenericStorageExtensionLogger.WriteLog(ELogLevel.INFO, "Exiting MI4TIndexManager.AddDocument, Result: " + result.ToString()); return(response); }
/// <summary> /// 单一添加一行数据(没有就创建,有就修改覆盖) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="model"></param> /// <param name="indexName"></param> /// <param name="typeName"></param> /// <param name="id"></param> /// <returns></returns> public bool Set(T model, string indexName, string typeName, string id) { var res = new IndexRequest <T>(indexName, typeName, id); res.Document = model; IndexResponse result = (IndexResponse)_es.Index <T>(res); return(result.IsValid); }
public void Update(IndexRequest indexRequest) { var dto = indexRequest.ToDbo(); _client.Index(dto, x => x .Id(dto.Url.ToString()) .Index(_options.RequestsIndexName) ); }
private async Task <Result <string> > IndexPage( Uri currentUrl, IndexRequest request, string siteHost, string siteHostWithDotBefore, ConcurrentDictionary <Uri, byte> urlsToIndex, ConcurrentDictionary <Uri, byte> indexedUrls) { var htmlResult = await GetHtml(currentUrl); if (htmlResult.IsFailure) { if (currentUrl == request.Url) { return(Result <string> .Fail($"Не удалось загрузить страницу {request.Url}\n" + htmlResult.Error)); } return(Result <string> .Success()); } var html = htmlResult.Value; var parsedHtmlResult = Parser.HtmlToText.ParseHtml(html, request.Url); if (parsedHtmlResult.IsFailure) { if (currentUrl == request.Url) { return(Result <string> .Fail($"Не удалось проиндексировать страницу {request.Url}\n" + parsedHtmlResult.Error)); } return(Result <string> .Success()); } var parsedHtml = parsedHtmlResult.Value; parsedHtml.Links .Where(uri => (uri.Host == siteHost || uri.Host.EndsWith(siteHostWithDotBefore)) && !indexedUrls.ContainsKey(uri)) .ForEach(uri => urlsToIndex.TryAdd(uri, default)); var document = new Document { Url = currentUrl, IndexedTime = DateTime.UtcNow, Title = parsedHtml.Title, Text = parsedHtml.Text }; #pragma warning disable 4014 _client.IndexAsync(document, desc => desc #pragma warning restore 4014 .Id(document.Url.ToString()) .Index(_options.DocumentsIndexName) ); return(Result <string> .Success()); }
public IndexResponse Welcome(IndexRequest request) { return new IndexResponse { AvailableDemos = new[] { new AvailableDemo { Href = this.HrefForRouteNamed("GreetIndex"), Title = "Simple Greeting Request / Response" }, new AvailableDemo { Href = this.HrefForRouteNamed("AsyncIndex"), Title = "Async Functionality" } } }; }
public IndexRequestTests() { var newProject = new ElasticsearchProject { Id = 15, Name = "Some awesome new elasticsearch project" }; var request = new IndexRequest<ElasticsearchProject>(newProject) { Replication = Replication.Async }; //TODO Index(request) does not work as expected var response = this._client.Index<ElasticsearchProject>(request); this._status = response.ConnectionStatus; }
[U] public void UsingWithRequests() { var project = new Project { Name = "hello-world" }; /** Here we can see and example how DocumentPath helps your describe your requests more tersely */ var request = new IndexRequest<Project>(2) { Document = project }; request = new IndexRequest<Project>(project) { }; /** when comparing with the full blown constructor and passing document manually * DocumentPath<T>'s benefits become apparent. */ request = new IndexRequest<Project>(IndexName.From<Project>(), TypeName.From<Project>(), 2) { Document = project }; }
/** === An example with requests */ [U] public void UsingWithRequests() { /* Given the following CLR type that describes a document */ var project = new Project { Name = "hello-world" }; /** we can see an example of how `DocumentPath` helps your describe your requests more tersely */ var request = new IndexRequest<Project>(2) { Document = project }; request = new IndexRequest<Project>(project) { }; /** when comparing with the full blown constructor and passing document manually, * `DocumentPath<T>`'s benefits become apparent. */ request = new IndexRequest<Project>(IndexName.From<Project>(), TypeName.From<Project>(), 2) { Document = project }; }
public void Index(int limit = -1, string since = null, bool returnData = false) { if (indexRequest != null) { Exception e = new Exception("Index already in process"); OnIndexCompleted(new DataEventArgs<IndexResult>(e)); return; } string uri = getBucketUriString() + "/index"; // set up the base url for each index request Dictionary<string, string> parameters = new Dictionary<string, string>(); if (limit >= 0) parameters.Add("limit", "" + limit); if (since != null) parameters.Add("since", since); if (returnData) parameters.Add("data", "1"); uri += appendQueryParameters(parameters); indexRequest = new IndexRequest(uri, (parameters.Count > 0), getWebClient()); indexRequest.webClient.DownloadStringCompleted += FinishedRemoteIndexRequest; StartRemoteIndexRequest(null); }
private void FinishedRemoteIndexRequest(object sender, DownloadStringCompletedEventArgs e) { if (e.Error == null) { IndexResultInternal nextIndexResultInternal = indexInternalConverter.ConvertJsonToObject(e.Result); if (nextIndexResultInternal == null) OnIndexCompleted(new DataEventArgs<IndexResult>(new Exception("Error deserializing index response from server:" + e.Result))); else { List<JsonObjectResult> jsonIndex = new List<JsonObjectResult>(); foreach (string json in nextIndexResultInternal.index) { // note that null objects will be added if they fail to deserialize JsonObjectResult jsonObject = jsonObjectConverter.ConvertJsonToObject(json); jsonIndex.Add(jsonObject); } IndexResult nextIndexResult = new IndexResult(nextIndexResultInternal.current, jsonIndex); OnIndexPartialCompleted(new DataEventArgs<IndexResult>(nextIndexResult)); if (indexRequest.result == null) indexRequest.result = nextIndexResult; // accummulate changes in index, which is our deserialization of the first response if (indexRequest.result != nextIndexResult) indexRequest.result.index.AddRange(nextIndexResult.index); // more to come? if (nextIndexResultInternal.mark != null) { StartRemoteIndexRequest(nextIndexResultInternal.mark); return; } // upcall that we are all done OnIndexCompleted(new DataEventArgs<IndexResult>(indexRequest.result)); } } else { OnIndexCompleted(new DataEventArgs<IndexResult>(e.Error)); } // note that the pointer to the indexResult will remain valid as long as the user holds on to it indexRequest = null; }
private bool Index(ISearchableItem item, bool overwrite, params SearchField[] customFields) { Initialise(); int isPublic = 1; if (item is IPermissibleItem) { IPermissibleItem pitem = (IPermissibleItem)item; isPublic = pitem.Access.IsPublic() ? 1 : 0; if (isPublic == 0) { isPublic = pitem.Access.IsPrivateFriendsOrMembers() ? 2 : 0; } } if (item is IPermissibleSubItem) { IPermissibleItem pitem = ((IPermissibleSubItem)item).PermissiveParent; isPublic = pitem.Access.IsPublic() ? 1 : 0; if (isPublic == 0) { isPublic = pitem.Access.IsPrivateFriendsOrMembers() ? 2 : 0; } } ItemIndexDocument writer = new ItemIndexDocument(); IndexRequest<ItemIndexDocument> request = new IndexRequest<ItemIndexDocument>(writer); writer.Id = item.ItemKey.TypeId.ToString() + "," + item.Id.ToString(); writer.ItemId = item.Id; writer.ItemTypeId = item.ItemKey.TypeId; writer.OwnerId = item.Owner.Id; writer.OwnerTypeId = item.Owner.ItemKey.TypeId; writer.ApplicationId = item.ItemKey.GetType(core).ApplicationId; writer.ItemPublic = isPublic; /*foreach (SearchField field in customFields) { writer.WritePropertyName(field.Key); writer.WriteValue(field.Value); }*/ writer.ItemTitle = item.IndexingTitle; writer.ItemString = item.IndexingString; writer.ItemTitle = item.IndexingTags; client.Index<ItemIndexDocument>("", "", item.ItemKey.TypeId.ToString() + "," + item.Id.ToString(), request); return true; }
public IndexResponse Index(IndexRequest request) { return new IndexResponse { GetAllAccountsUri = this.links.Relative(RouteNames.GetAllAccounts) }; }