public async Task <IActionResult> GetTopicList([FromBody] TopicRequest request) { JsonResponse <IEnumerable <TopicList> > objResult = new JsonResponse <IEnumerable <TopicList> >(); try { IEnumerable <TopicList> lists = new List <TopicList>(); lists = await this._superAdminService.GetTopicList(request); if (lists != null && lists.Count() > 0) { objResult.Data = lists; objResult.Status = StaticResource.SuccessStatusCode; objResult.Message = StaticResource.SuccessMessage; return(new OkObjectResult(objResult)); } else { objResult.Data = null; objResult.Status = StaticResource.NotFoundStatusCode; objResult.Message = StaticResource.NotFoundMessage; return(new OkObjectResult(objResult)); } } catch (Exception ex) { HttpContext.RiseError(ex); objResult.Data = null; objResult.Status = StaticResource.FailStatusCode; objResult.Message = StaticResource.FailMessage; } return(new OkObjectResult(objResult)); }
public void TopicGetChannelTopic() { var request = new TopicRequest(ChannelRequests.TopicGetChannelTopic); request.Parse(); Assert.Equal("#GSP!room!test", request.ChannelName); }
public void TestSerializeMetadataRequest() { var meta = new TopicRequest { Topics = new[] { "poulpe", "banana" } }; using (var serialized = meta.Serialize(new ReusableMemoryStream(null), 61, ClientId, null)) { CheckHeader(Basics.ApiKey.MetadataRequest, 0, 61, TheClientId, serialized); Assert.AreEqual(2, BigEndianConverter.ReadInt32(serialized)); Assert.AreEqual("poulpe", Basics.DeserializeString(serialized)); Assert.AreEqual("banana", Basics.DeserializeString(serialized)); } meta = new TopicRequest { Topics = null }; using (var serialized = meta.Serialize(new ReusableMemoryStream(null), 61, ClientId, null)) { CheckHeader(Basics.ApiKey.MetadataRequest, 0, 61, TheClientId, serialized); Assert.AreEqual(0, BigEndianConverter.ReadInt32(serialized)); Assert.AreEqual(serialized.Length, serialized.Position); } }
public void SetUp() { document = new XmlDocument(); document.Load("Topics.xml"); var parser = new TopicParser(); theTop = parser.Parse(theRootDirectory, document); }
public TopicResponse Put(TopicRequest updated) { var entity = db.Topics.SingleOrDefault(t => t.Id == updated.Id); entity.UpdateFieldsFromRequest(updated); db.SaveChanges(); var result = mapper.Map <TopicResponse>(entity); return(result); }
public async Task <IEnumerable <TopicList> > GetTopicList(TopicRequest request) { try { return(await this._superAdminRepo.GetTopicList(request)); } catch (Exception ex) { throw ex; } }
public void GetTopics() { var randomText = new RandomText(); var request = new TopicRequest(); for (int i = 1; i <= 200; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } var client = new TopicClient(apiKey); var opeationUrl = client.StartTopicProcessing(request); TopicResponse response = null; var startTime = DateTime.Now; var timeoutTime = startTime.AddMinutes(30); var doneProcessing = false; while (!doneProcessing) { response = client.GetTopicResponse(opeationUrl); if (response.Status == TopicOperationStatus.Cancelled) { Assert.Fail("Operation Cancelled"); } else if (response.Status == TopicOperationStatus.Failed) { Assert.Fail("Operation Failed"); } else if (response.Status == TopicOperationStatus.Succeeded) { doneProcessing = true; } else { if (DateTime.Now >= timeoutTime) { Assert.Fail("Operation Timeout"); } else { Thread.Sleep(60000); } } } Assert.IsTrue(response.OperationProcessingResult.TopicAssignments.Count > 0); Assert.IsTrue(response.OperationProcessingResult.Topics.Count > 0); }
public TopicResponse Post(TopicRequest created) { var entity = new Topic(); entity.UpdateFieldsFromRequest(created); db.Add(entity); db.SaveChanges(); var result = mapper.Map <TopicResponse>(entity); return(result); }
public override Task <VoidMessage> handleTopic(TopicRequest request, ServerCallContext context) { if (_state.program is ComputerProgram computerProgram) { computerProgram.HandleTopic(request.TopicId, request.Data); } else { throw new Exception("Invalid type."); } return(Task.FromResult(new VoidMessage())); }
public virtual string GetTopics(TopicRequest request) { try { var result = TextAnalyticsRepository.GetTopics(request); return(result); } catch (Exception ex) { Logger.Error("SentimentService.GetTopics failed", this, ex); } return(null); }
public virtual string GetTopics(TopicRequest request) { return(PolicyService.ExecuteRetryAndCapture400Errors( "TextAnalyticsService.GetTopics", ApiKeys.TextAnalyticsRetryInSeconds, () => { var result = TextAnalyticsRepository.GetTopics(request); return result; }, null)); }
public async Task RequestRandomTopic(ChatInfo chat = null) { EnsureChatActive(); chat ??= ActiveChats.First(); var topicRequest = new TopicRequest(chat.Key); var randtopicPacket = new EventPacket("_randtopic", topicRequest, ClientEventID); await SendEventPacket(randtopicPacket); }
public IActionResult CreateTopic([FromBody] TopicRequest topicDataModel) { var token = Request.Headers["Authorization"]; var isCreated = _topicService.CreateTopic(topicDataModel, token); if (isCreated) { return(Ok()); } return(Unauthorized()); }
public async Task <List <TopicExtended> > PostTopic(List <TopicPostRequest> topic, List <PeopleInEpisode> people) { try { HttpResponseMessage response = null; // Send Topic to API using (var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"{_httpClient.BaseAddress}topic")) { requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", (await _userSession.GetToken()).AccessToken); TopicRequest request = new TopicRequest(people, topic); string json = JsonSerializer.Serialize(request); StringContent stringContent = new StringContent(json, Encoding.UTF8, "application/json"); requestMessage.Content = stringContent; response = await _httpClient.SendAsync(requestMessage); } if (response != null) { if (response.IsSuccessStatusCode) { // Get created topic information string json = response.Content.ReadAsStringAsync().Result; List <TopicExtended> topicResponse = JsonSerializer.Deserialize <List <TopicExtended> >(json); // Get the servers current state of the object and return it return(topicResponse); } } if (response.StatusCode == HttpStatusCode.NotFound) { _toastService.ShowError("Error 404: Backend server is offline."); SentrySdk.CaptureMessage("API: Error 404"); } } catch (Exception e) { SentrySdk.CaptureException(e); } return(null); }
public void ValidateTest_DuplicateDocumentId() { var request = new TopicRequest(); for (int i = 1; i <= 101; i++) { request.Documents.Add(new TopicDocument() { Id = "01", Text = "doc1" }); } request.Validate(); }
public void ValidateTest_DocumentIdRequired() { var request = new TopicRequest(); for (int i = 1; i <= 101; i++) { request.Documents.Add(new TopicDocument() { Text = "doc1" }); } request.Validate(); }
public void ValidateTest_MinDocumentSize() { var request = new TopicRequest(); for (int i = 1; i <= 101; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString() }); } request.Validate(); }
public async Task <ActionResult <List <TopicExtended> > > PostTopicList([FromBody] TopicRequest request) { if (request.Topics == null) { return(BadRequest("Topic list is null!")); } try { User user = await _auth.GetUserFromValidToken(Request); Episode claimedEpisode = await _claims.GetUserByClaimedEpisodeAsync(user.Id); // Topics and Subtopics await _database.DeleteTopicAndSubtopicAsync(claimedEpisode.Id); await _database.ResetIdentityForTopicAndSubtopicsAsync(); for (int i = 0; i < request.Topics.Count; i++) { await _database.InsertTopicAsync(new ProcessedTopicPostRequest(request.Topics[i]), claimedEpisode.Id, user.Id); } // People await _database.DeletePeopleFromEpisodeByEpisodeIdAsync(claimedEpisode.Id); await _database.ResetIdentityForPersonInEpisodeTableAsync(); await _database.InsertPeopleInEpisodeAsync(request.People, claimedEpisode.Id); EpisodeExtendedExtra episode = await _database.GetEpisodeAsync(claimedEpisode.Id, true, user.Id); return(Ok(episode)); } catch (TokenDoesNotExistException e) { return(Unauthorized()); } catch (Exception e) { if (e.Message.Contains("Sequence contains no elements")) { return(Unauthorized("User has no claimed episode!")); } SentrySdk.CaptureException(e); _logger.LogError("Error while trying to post a list of topics. Error:\n" + e.Message); return(Problem()); } }
public void ValidateTest_MaxDocumentSize() { int count = 10241 * 3; var text = new string('*', count); var request = new TopicRequest(); for (int i = 1; i <= 101; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = text }); } request.Validate(); }
public void ValidateTest_MaxDocumentCollectionSize() { var count = 1024 * 31; var text = new string('*', 1024); var request = new TopicRequest(); for (int i = 1; i <= count; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = text }); } request.Validate(); }
public void add_the_second_topic_that_is_a_child_to_the_parent() { var root = document.DocumentElement; var top = theStack.AddTopic(root); theStack.PushTopic(top); theStack.PushFolder("HowTo"); var element = document.DocumentElement.FirstChild.FirstChild; var request = theStack.AddTopic((XmlElement)element); top.Children.ShouldContain(request); request.Namespace.ShouldEqual("HowTo"); request.TopicName.ShouldEqual(TopicRequest.GetNameFromTitle(request.Title)); // Screws up in Mono and I do *NOT* have a clue why. Shouldn't even be possible, but of course it is //request.FullTopicClassName.ShouldEqual("WidgetPro.Core.HowTo." + request.TopicName); }
public bool CreateTopic(TopicRequest topicDataModel, string token) { var tokenClient = _tokenService.DecodeToken(token); var client = _clientRepository.GetByID(tokenClient.ID); if (client == null) { return(false); } var newTopic = _mapper.Map <TopicEntity>(topicDataModel); newTopic.Client = client; _topicRepository.Add(newTopic); Console.WriteLine($"Title:{topicDataModel.Title} Subtopic:{topicDataModel.Subtitle}"); return(true); }
internal async Task <MetadataResponse> MetadataRequest(TopicRequest request, BrokerMeta broker = null, bool noTransportErrors = false) { TcpClient tcp; Connection conn; if (broker != null) { conn = broker.Conn; tcp = await conn.GetClientAsync(noTransportErrors); } else { var clientAndConnection = await _cluster.GetAnyClientAsync(); conn = clientAndConnection.Item1; tcp = clientAndConnection.Item2; } //var tcp = await (broker != null ? broker.Conn.GetClientAsync() : _cluster.GetAnyClientAsync()); _log.Debug("Sending MetadataRequest to {0}", tcp.Client.RemoteEndPoint); if (_etw.IsEnabled()) { _etw.ProtocolMetadataRequest(request.ToString()); } var response = await conn.Correlation.SendAndCorrelateAsync( id => Serializer.Serialize(request, id), Serializer.DeserializeMetadataResponse, tcp, CancellationToken.None); if (_etw.IsEnabled()) { _etw.ProtocolMetadataResponse(response.ToString(), broker != null ? broker.Host : "", broker != null ? broker.Port : -1, broker != null ? broker.NodeId : -1); } return(response); }
public async Task <IEnumerable <TopicList> > GetTopicList(TopicRequest request) { try { IEnumerable <TopicList> topicLists = new List <TopicList>(); using (IDbConnection con = new SqlConnection(_connectionString)) { topicLists = await con.QueryAsync <TopicList>("dbo.SSP_getTopicList", new { TopicName = request.TopicName, OffSet = request.OffSet, Limit = request.Limit }, commandType : CommandType.StoredProcedure); } return(topicLists); } catch (Exception ex) { throw ex; } }
public static byte[] Serialize(TopicRequest request, int correlationId) { var stream = new MemoryStream(); WriteRequestHeader(stream, correlationId, ApiKey.MetadataRequest); if (request.Topics == null || request.Topics.Length == 0) { stream.Write(_zero32, 0, 4); } else { BigEndianConverter.Write(stream, request.Topics.Length); foreach (var t in request.Topics) { Write(stream, t); } } stream.Close(); return(WriteMessageLength(stream)); }
private async void Detect_Topics(string text) { try { var source = text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).ToList(); var randomText = new RandomText(source); var request = new TopicRequest(); for (int i = 0; i < 100; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } MainWindow mainWindow = Window.GetWindow(this) as MainWindow; var client = new TopicClient(mainWindow._scenariosControl.SubscriptionKey); var opeationUrl = await client.StartTopicProcessingAsync(request); TopicResponse response = null; var doneProcessing = false; while (!doneProcessing) { response = await client.GetTopicResponseAsync(opeationUrl); switch (response.Status) { case TopicOperationStatus.Cancelled: Log("Operation Status: Cancelled"); doneProcessing = true; break; case TopicOperationStatus.Failed: Log("Operation Status: Failed"); doneProcessing = true; break; case TopicOperationStatus.NotStarted: Log("Operation Status: Not Started"); Thread.Sleep(100); break; case TopicOperationStatus.Running: Log("Operation Status: Running"); Thread.Sleep(100); break; case TopicOperationStatus.Succeeded: Log("Operation Status: Succeeded"); doneProcessing = true; break; } } foreach (var topic in response.OperationProcessingResult.Topics) { var score = topic.Score * 100; Log(string.Format("{0} ({1}%)", topic.KeyPhrase, score)); } } catch (Exception ex) { Log(ex.Message); } }
public virtual string GetTopics(TopicRequest request) { return(RepositoryClient.SendOperationPost(ApiKeys.TextAnalytics, $"{ApiKeys.TextAnalyticsEndpoint}{topicUrl}", JsonConvert.SerializeObject((object)request))); }
/// <summary> /// This takes in at least 100 documents and returns a url to the operation where you check for the status of the result /// </summary> /// <param name="request"></param> /// <returns></returns> public virtual async Task <string> GetTopicsAsync(TopicRequest request) { return(await RepositoryClient.SendOperationPostAsync(ApiKeys.TextAnalytics, $"{ApiKeys.TextAnalyticsEndpoint}{topicUrl}", JsonConvert.SerializeObject((object)request))); }
static async Task MainAsync() { var apiKey = "YOUR-TEXT-ANALYTICS-API-SUBSCRIPTION-KEY"; var randomText = new RandomText(); var request = new TopicRequest(); for (int i = 1; i <= 200; i++) { request.Documents.Add(new TopicDocument() { Id = i.ToString(), Text = randomText.Next() }); } var client = new TopicClient(apiKey); var operationUrl = await client.StartTopicProcessingAsync(request); TopicResponse response = null; var doneProcessing = false; while (!doneProcessing) { response = await client.GetTopicResponseAsync(operationUrl); switch (response.Status) { case TopicOperationStatus.Cancelled: Console.WriteLine("Status: Operation Cancelled"); doneProcessing = true; break; case TopicOperationStatus.Failed: Console.WriteLine("Status: Operation Failed"); doneProcessing = true; break; case TopicOperationStatus.NotStarted: Console.WriteLine("Status: Operation Not Started"); Thread.Sleep(60000); break; case TopicOperationStatus.Running: Console.WriteLine("Status: Operation Running"); Thread.Sleep(60000); break; case TopicOperationStatus.Succeeded: Console.WriteLine("Status: Operation Succeeded"); doneProcessing = true; break; } } foreach (var topic in response.OperationProcessingResult.Topics) { Console.WriteLine("{0} | {1}", topic.KeyPhrase, topic.Score); } Console.WriteLine("Press any key to exit..."); Console.ReadLine(); }
public void ValidateTest_MinDocumentCollectionCount() { var request = new TopicRequest(); request.Validate(); }