static void Main(string[] args) { const string topicName = "kafka.SimpleTopic"; TopicClient topicClient = new TopicClient(); TopicView topicView = topicClient.getTopic(topicName); List <Uri> brokers = getBrokerList(topicView); //create an options file that sets up driver preferences var options = new KafkaOptions() { Log = new ConsoleLog() }; options.KafkaServerUri = brokers; //start an out of process thread that runs a consumer that will write all received messages to the console Task.Run(() => { var consumer = new Consumer(new ConsumerOptions(topicName, new BrokerRouter(options)) { Log = new ConsoleLog() }); foreach (var data in consumer.Consume()) { Console.WriteLine("Response: P{0},O{1} : {2}", data.Meta.PartitionId, data.Meta.Offset, data.Value.ToUtf8String()); } }); //create a producer to send messages with var producer = new KafkaNet.Producer(new BrokerRouter(options)) { BatchSize = 100, BatchDelayTime = TimeSpan.FromMilliseconds(2000) }; //take in console read messages Console.WriteLine("Type a message and press enter..."); while (true) { var message = Console.ReadLine(); if (message == "quit") { break; } if (string.IsNullOrEmpty(message)) { //send a random batch of messages SendRandomBatch(producer, topicName, 200); } else { producer.SendMessageAsync(topicName, new[] { new Message(message) }); } } using (producer) { } }
override protected void RenderViews() { CreateViews("BasicTemplates1", "BasicVerticalWithNothingElseThanALinkedTemplate"); TopicView.SetDataSource(ProductsManager.Instance); ETKExcel.TemplateManager.Render(TopicView); }
override protected void RenderViews() { CreateViews("BasicTemplates1", "BasicVerticalMonoHeaderAndFooter"); TopicView.SetDataSource(ShopManager.Shops); ETKExcel.TemplateManager.Render(TopicView); }
/// <summary>Snippet for GetTopicView</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetTopicViewResourceNames() { // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) TopicViewName resourceName = TopicViewName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"); // Make the request TopicView response = topicViewServiceClient.GetTopicView(resourceName); }
/// <summary>Snippet for GetTopicView</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetTopicView() { // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER]/topicViews/[TOPIC_VIEW]"; // Make the request TopicView response = topicViewServiceClient.GetTopicView(resourceName); }
/// <summary>Snippet for GetTopicView</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetTopicView() { // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/topicViews/[AD_GROUP_ID]~[CRITERION_ID]"; // Make the request TopicView response = topicViewServiceClient.GetTopicView(resourceName); }
/// <summary>Snippet for GetTopicView</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void GetTopicViewResourceNames() { // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) TopicViewName resourceName = TopicViewName.FromCustomerTopicView("[CUSTOMER]", "[TOPIC_VIEW]"); // Make the request TopicView response = topicViewServiceClient.GetTopicView(resourceName); }
/// <summary>Snippet for GetTopicViewAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetTopicViewResourceNamesAsync() { // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) TopicViewName resourceName = TopicViewName.FromCustomerTopicView("[CUSTOMER]", "[TOPIC_VIEW]"); // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(resourceName); }
/// <summary>Snippet for GetTopicViewAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetTopicViewAsync() { // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER]/topicViews/[TOPIC_VIEW]"; // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(resourceName); }
public ActionResult TopicView(int topicId, int start = 0) { Topic thisTopic = Topic.Find(topicId); List <Thread> threads = thisTopic.GetThreads(start, start + 20); TopicView topicView = new TopicView(thisTopic, threads); return(View(topicView)); }
// GET: Topics/Create public IActionResult Create() { var tpc = new TopicView(); tpc.Categories = GetCategoryOptions(); if (tpc.Categories == null) { return(NotFound("No Categories found")); } return(View(tpc)); }
/// <summary> /// 向队列中增加统计对象 /// </summary> /// <param name="tv">主题浏览数对象</param> /// <returns>成功返回true</returns> public static bool AddQuedStats(TopicView tv) { if (tv == null) { return(false); } if (queuedAllowCount != GeneralConfigs.GetConfig().TopicQueueStatsCount || queuedStatsList == null) { SetQueueCount(); } //Check for the limit if (queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5) { //aquire the lock lock (queuedStatsList.SyncRoot) { //make sure the pool queue was not cleared during a wait for the lock if (queuedStatsList.ViewCount >= queuedAllowCount || queuedStatsList.Count >= 5) { TopicView[] tva = new TopicView[queuedStatsList.Count]; queuedStatsList.CopyTo(tva, 0); #if NET1 ClearTrackTopicQueue(new TopicViewCollection(tva)); #else ClearTrackTopicQueue(new TopicViewCollection <TopicView>(tva)); #endif queuedStatsList.Clear(); queuedStatsList.ViewCount = 0; } } } bool inArray = false; foreach (TopicView curtv in queuedStatsList) { if (curtv.TopicID == tv.TopicID) { curtv.ViewCount = curtv.ViewCount + tv.ViewCount; inArray = true; break; } } if (!inArray) { queuedStatsList.Add(tv); } queuedStatsList.ViewCount = queuedStatsList.ViewCount + 1; return(true); }
/// <summary> /// 追踪浏览量 /// </summary> /// <param name="tid">主题id</param> /// <param name="viewcount">浏览量</param> /// <returns>成功返回true</returns> public static bool Track(int tid, int viewcount) { if (tid < 1 || viewcount < 1) { return(false); } TopicView tv = new TopicView(); tv.TopicID = tid; tv.ViewCount = viewcount; return(Track(tv)); }
public async Task BlockAfterFollow() { // create a client SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl); // create user1 and user2 var postUserResponse1 = await TestUtilities.PostGenericUser(client); var postUserResponse2 = await TestUtilities.PostGenericUser(client); string auth1 = AuthHelper.CreateSocialPlusAuth(postUserResponse1.SessionToken); string auth2 = AuthHelper.CreateSocialPlusAuth(postUserResponse2.SessionToken); // user1 follows user2 PostFollowingUserRequest postFollowingRequest = new PostFollowingUserRequest(postUserResponse2.UserHandle); await client.MyFollowing.PostFollowingUserAsync(postFollowingRequest, auth1); // user2 posts topic1 var postTopicResponse1 = await TestUtilities.PostGenericTopic(client, auth2); // user1 gets topic1 TopicView topicView1 = await client.Topics.GetTopicAsync(postTopicResponse1.TopicHandle, auth1); // user2 blocks user1 PostBlockedUserRequest postBlockedUserRequest = new PostBlockedUserRequest(postUserResponse1.UserHandle); await client.MyBlockedUsers.PostBlockedUserAsync(postBlockedUserRequest, auth2); // user2 posts topic2 var postTopicResponse2 = await TestUtilities.PostGenericTopic(client, auth2); // user1 gets topic1 TopicView topicView2 = await client.Topics.GetTopicAsync(postTopicResponse1.TopicHandle, auth1); // user1 fetches topic2 TopicView topicView3 = await client.Topics.GetTopicAsync(postTopicResponse2.TopicHandle, auth1); // cleanup: delete both users and both topics await client.Topics.DeleteTopicAsync(postTopicResponse1.TopicHandle, auth2); await client.Topics.DeleteTopicAsync(postTopicResponse2.TopicHandle, auth2); await TestUtilities.DeleteUser(client, auth1); await TestUtilities.DeleteUser(client, auth2); // validate: // check that getting topic1 worked the first time // check that getting topic1 worked the second time // check that getting topic2 did not work Assert.AreEqual(postTopicResponse1.TopicHandle, topicView1.TopicHandle); Assert.AreEqual(postTopicResponse1.TopicHandle, topicView2.TopicHandle); Assert.AreEqual(null, topicView3.TopicHandle); }
/// <summary>Snippet for GetTopicViewAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task GetTopicViewRequestObjectAsync() { // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) GetTopicViewRequest request = new GetTopicViewRequest { ResourceNameAsTopicViewName = TopicViewName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"), }; // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(request); }
/// <summary>Snippet for GetTopicView</summary> public void GetTopicViewRequestObject() { // Snippet: GetTopicView(GetTopicViewRequest, CallSettings) // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) GetTopicViewRequest request = new GetTopicViewRequest { ResourceNameAsTopicViewName = TopicViewName.FromCustomerTopicView("[CUSTOMER]", "[TOPIC_VIEW]"), }; // Make the request TopicView response = topicViewServiceClient.GetTopicView(request); // End snippet }
/// <summary> /// 清除队列,并保存队列中已有数据 /// </summary> /// <param name="save"></param> /// <returns></returns> public static bool ClearQueue(bool save) { lock (queuedStatsList.SyncRoot) { if (save) { TopicView[] eva = new TopicView[queuedStatsList.Count]; queuedStatsList.CopyTo(eva, 0); ClearTrackTopicQueue(new TopicViewCollection <TopicView>(eva)); } queuedStatsList.Clear(); } return(true); }
/// <summary>Snippet for GetTopicViewAsync</summary> public async Task GetTopicViewResourceNamesAsync() { // Snippet: GetTopicViewAsync(TopicViewName, CallSettings) // Additional: GetTopicViewAsync(TopicViewName, CancellationToken) // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) TopicViewName resourceName = TopicViewName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"); // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(resourceName); // End snippet }
/// <summary>Snippet for GetTopicViewAsync</summary> public async Task GetTopicViewAsync() { // Snippet: GetTopicViewAsync(string, CallSettings) // Additional: GetTopicViewAsync(string, CancellationToken) // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) string resourceName = "customers/[CUSTOMER_ID]/topicViews/[AD_GROUP_ID]~[CRITERION_ID]"; // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(resourceName); // End snippet }
/// <summary>Snippet for GetTopicView</summary> public void GetTopicViewRequestObject() { // Snippet: GetTopicView(GetTopicViewRequest, CallSettings) // Create client TopicViewServiceClient topicViewServiceClient = TopicViewServiceClient.Create(); // Initialize request argument(s) GetTopicViewRequest request = new GetTopicViewRequest { ResourceNameAsTopicViewName = TopicViewName.FromCustomerAdGroupCriterion("[CUSTOMER_ID]", "[AD_GROUP_ID]", "[CRITERION_ID]"), }; // Make the request TopicView response = topicViewServiceClient.GetTopicView(request); // End snippet }
/// <summary>Snippet for GetTopicViewAsync</summary> public async Task GetTopicViewResourceNamesAsync() { // Snippet: GetTopicViewAsync(TopicViewName, CallSettings) // Additional: GetTopicViewAsync(TopicViewName, CancellationToken) // Create client TopicViewServiceClient topicViewServiceClient = await TopicViewServiceClient.CreateAsync(); // Initialize request argument(s) TopicViewName resourceName = TopicViewName.FromCustomerTopicView("[CUSTOMER]", "[TOPIC_VIEW]"); // Make the request TopicView response = await topicViewServiceClient.GetTopicViewAsync(resourceName); // End snippet }
public TopicView getTopic(string name) { var RestConfig = new RestConfig(); HttpWebRequest request = WebRequest.Create(RestConfig.topics + name) as HttpWebRequest; request.Method = "GET"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream responseStream = response.GetResponseStream(); string content = new StreamReader(responseStream).ReadToEnd(); responseStream.Close(); TopicView topic = (TopicView)JsonConvert.DeserializeObject(content, typeof(TopicView)); return(topic); }
private void FetchData(int pageIndex) { if (replyFilter.SelectedIndex > -1) { var topics = new List <TopicInfo> { _topic }; TopicView.DataSource = topics; TopicView.DataBind(); } int pageSize = Config.TopicPageSize; var replies = Topics.GetRepliesForTopic(_topic, pageIndex, pageSize); if (replyFilter.SelectedIndex > 0) { switch (replyFilter.SelectedValue) { case "Asc": replies = replies.OrderBy(r => r.Date); break; case "Desc": replies = replies.OrderByDescending(r => r.Date); break; case "Last": replies = replies.Where(r => r.Date >= _topic.LastPostDate); break; case "New": replies = replies.Where(r => r.Date > ((PageBase)Page).LastVisitDateTime); break; } } var page = new PagedDataSource { AllowCustomPaging = true, AllowPaging = true, DataSource = replies, PageSize = pageSize }; TopicReplies.DataSource = page; TopicReplies.DataBind(); }
/// <summary> /// Create topic object from topic view. /// </summary> /// <param name="topicView">Topic view to create topic from</param> /// <returns>Representation of topic</returns> public static Topic Create(TopicView topicView) { #region validation if (topicView == null) { throw new ArgumentNullException(nameof(topicView)); } #endregion return(new Topic() { Id = topicView.Id, Name = topicView.Name, Path = topicView.Path, }); }
static bool Track(TopicView tv) { if (tv == null) { return(false); } if (queuedStatsList == null) { SetQueueCount(); } if (GeneralConfigInfo.Current.TopicQueueStats == 1) { return(AddQuedStats(tv)); } //return TrackTopic(tv); Topic.UpdateViewCount(tv.TopicID, tv.ViewCount); return(true); }
/// <summary> /// 追踪浏览量 /// </summary> /// <param name="tv">主题浏览数对象</param> /// <returns>成功返回true</returns> public static bool Track(TopicView tv) { if (tv == null) { return(false); } if (queuedStatsList == null) { SetQueueCount(); } if (GeneralConfigs.GetConfig().TopicQueueStats == 1) { return(AddQuedStats(tv)); } else { return(TrackTopic(tv)); } }
public async Task GetTopicViewAsync2() { Mock <TopicViewService.TopicViewServiceClient> mockGrpcClient = new Mock <TopicViewService.TopicViewServiceClient>(MockBehavior.Strict); GetTopicViewRequest request = new GetTopicViewRequest { ResourceName = new TopicViewName("[CUSTOMER]", "[TOPIC_VIEW]").ToString(), }; TopicView expectedResponse = new TopicView { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetTopicViewAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <TopicView>(Task.FromResult(expectedResponse), null, null, null, null)); TopicViewServiceClient client = new TopicViewServiceClientImpl(mockGrpcClient.Object, null); TopicView response = await client.GetTopicViewAsync(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void GetTopicView2() { Mock <TopicViewService.TopicViewServiceClient> mockGrpcClient = new Mock <TopicViewService.TopicViewServiceClient>(MockBehavior.Strict); GetTopicViewRequest request = new GetTopicViewRequest { ResourceName = new TopicViewName("[CUSTOMER]", "[TOPIC_VIEW]").ToString(), }; TopicView expectedResponse = new TopicView { ResourceName = "resourceName2625949903", }; mockGrpcClient.Setup(x => x.GetTopicView(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); TopicViewServiceClient client = new TopicViewServiceClientImpl(mockGrpcClient.Object, null); TopicView response = client.GetTopicView(request); Assert.AreEqual(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// Вывод списка тем public ActionResult List(int?id, int?page) { // Получаем запись раздела из БД Rubric rubric = db.Rubrics.FirstOrDefault(p => p.Id == id); // Если такая запись есть if (rubric != null) { // формируем набор данных для формы ViewBag.Rubric = rubric; IEnumerable <Topic> topics = db.Topics.Include("User").Include("Messages.User").Where(p => p.RubricId == id); List <TopicView> topicViewList = new List <TopicView>(); foreach (Topic topic in topics) { TopicView topicView = new TopicView(); topicView.Id = topic.Id; topicView.Name = topic.Name; topicView.Content = topic.Content; topicView.TopicStarter = topic.User.Login; int cntMsg = topic.Messages.Count; if (cntMsg > 0) { topicView.CntMsg = cntMsg.ToString(); Message msg = topic.Messages.OrderByDescending(p => p.Dates).First(); topicView.LastWriter = msg.User.Login; topicView.Dates = msg.Dates.ToString(); } topicViewList.Add(topicView); } ViewBag.TopicCnt = topicViewList.Count; // параметры постраничного вывода int pageSize = 10; int pageNumber = (page ?? 1); // выводим представление return(View(topicViewList.ToPagedList(pageNumber, pageSize))); } else { return(View("Error")); } }
public ActionResult Edit(int id) { var Object = new TopicModel().GetTopicById(id); var Result = new TopicView(); Result.Name = Object.Name; Result.Code = Object.Code; Result.ImageId = Object.ImageId; Result.Descrip = Object.Descrip; Result.OrderDisplay = Object.OrderDisplay; Result.TopicParentID = new TopicModel().GetNameById(Object.TopicParentID); if (Object.LangId == 0) { Result.LangId = "Tiếng Việt"; } else { Result.LangId = "Tiếng Anh"; } return(View(Result)); }