public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var config = resolver.GetService <IConfiguration>(); var cartChannel = new Channel(config["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(config["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(config["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(config["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(config["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); }); }
private void RegisterGrpcServices(IServiceCollection services) { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); }
/// <summary> /// Step 1 - Create a review. An id will be generated, but not pushlished. /// </summary> /// <param name="client">An instance of <see cref="ReviewServiceClient" />.</param> /// <param name="authorName">Author's alias.</param> /// <param name="authorDisplayName">Author's display name.</param> /// <param name="emailAddress">Author's email address.</param> /// <param name="reviewName">The title of review.</param> /// <param name="projectShortName">The name of the project that review belongs to. e.g. "MSODS"</param> /// <returns>Review Id</returns> public static string CreateReview(ReviewServiceClient client, string authorName, string authorDisplayName, string emailAddress, string reviewName, string projectShortName) { Logger.Info("Creating a new code review..."); return(client.CreateReview( new Author { Name = authorName, DisplayName = authorDisplayName, EmailAddress = emailAddress }, reviewName, projectShortName).Key); }
public CoolStoreResolverService( CatalogServiceClient catalogServiceClient, CartServiceClient cartServiceClient, InventoryServiceClient inventoryServiceClient, RatingServiceClient ratingServiceClient, ReviewServiceClient reviewServiceClient) { _catalogServiceClient = catalogServiceClient; _cartServiceClient = cartServiceClient; _inventoryServiceClient = inventoryServiceClient; _ratingServiceClient = ratingServiceClient; _reviewServiceClient = reviewServiceClient; }
public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>(); services.AddSingleton <CoolStoreSchema>(); services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore); services.AddSignalR(options => options.EnableDetailedErrors = true) .AddQueryStreamHubWithTracing(); services.AddCors(options => { options.AddDefaultPolicy(policy => { policy.WithOrigins("*"); policy.AllowAnyHeader(); policy.AllowAnyMethod(); policy.AllowCredentials(); policy.WithHeaders("X-Requested-With", "authorization"); }); }); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }); }
public void ConfigureServices(IServiceCollection services) { services.AddStandardTemplate((svc, resolver) => { var cartChannel = new Channel(Configuration["RpcClients:CartService"], ChannelCredentials.Insecure); var cartClient = new CartServiceClient(cartChannel); var inventoryChannel = new Channel(Configuration["RpcClients:InventoryService"], ChannelCredentials.Insecure); var inventoryClient = new InventoryServiceClient(inventoryChannel); var reviewChannel = new Channel(Configuration["RpcClients:ReviewService"], ChannelCredentials.Insecure); var reviewClient = new ReviewServiceClient(reviewChannel); var pingClient = new PingServiceClient(reviewChannel); var catalogChannel = new Channel(Configuration["RpcClients:CatalogService"], ChannelCredentials.Insecure); var catalogClient = new CatalogServiceClient(catalogChannel); var ratingChannel = new Channel(Configuration["RpcClients:RatingService"], ChannelCredentials.Insecure); var ratingClient = new RatingServiceClient(ratingChannel); services.AddSingleton(typeof(CartServiceClient), cartClient); services.AddSingleton(typeof(InventoryServiceClient), inventoryClient); services.AddSingleton(typeof(ReviewServiceClient), reviewClient); services.AddSingleton(typeof(PingServiceClient), pingClient); services.AddSingleton(typeof(CatalogServiceClient), catalogClient); services.AddSingleton(typeof(RatingServiceClient), ratingClient); services.AddSingleton <ICoolStoreResolverService, CoolStoreResolverService>(); services.AddSingleton <CoolStoreSchema>(); services.AddSingleton(provider => provider.GetRequiredService <CoolStoreSchema>().CoolStore); services.AddCors(options => { options.AddPolicy("CorsPolicy", policy => policy .AllowAnyMethod() .AllowAnyHeader() /* https://github.com/aspnet/AspNetCore/issues/4457 */ .SetIsOriginAllowed(host => true) .AllowCredentials()); }); services.AddSignalR(options => options.EnableDetailedErrors = true) .AddQueryStreamHubWithTracing(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); }); }
public CoolStoreResolverService( IHttpContextAccessor httpContext, CatalogServiceClient catalogServiceClient, CartServiceClient cartServiceClient, InventoryServiceClient inventoryServiceClient, RatingServiceClient ratingServiceClient, ReviewServiceClient reviewServiceClient) { _httpContext = httpContext; _catalogServiceClient = catalogServiceClient; _cartServiceClient = cartServiceClient; _inventoryServiceClient = inventoryServiceClient; _ratingServiceClient = ratingServiceClient; _reviewServiceClient = reviewServiceClient; }
public static void OnTimedEvent(object obj, ElapsedEventArgs args) { //Set run interval as 10 minutes serviceTimer.Interval = 600000; Logger.WriteInfo("OnTime event, start query active reviews"); try { _initMonitorUserList(); bool isNew = false; ReviewServiceClient client = new ReviewServiceClient(); GorillaWebAPI webapi = new GorillaWebAPI("CFMonitor", "User@123"); foreach (string username in _userlist) { if (!_MonitoredReviewDict.Keys.Contains(username)) { _MonitoredReviewDict.Add(username, new Dictionary <string, int>()); isNew = true; } //get all active reviews CodeReviewSummary[] reviews = client.GetActiveReviewsForAuthor(username); if (reviews != null) { //scan each review foreach (var codeReviewSummary in reviews) { _cfTrendStatus.AddReviewCount(codeReviewSummary.Author.Name); CodeReview r = client.GetReview(codeReviewSummary.Key); if (!_MonitoredReviewDict[username].Keys.Contains(r.Key)) { _MonitoredReviewDict[username].Add(r.Key, 0); //A new submit, add to today's total Review count _cfTrendStatus.AddReviewCount(r.Author.Name); isNew = true; } if (_MonitoredReviewDict[username][r.Key] < r.codePackages.Length) { isNew = true; } if (isNew) { for (int i = _MonitoredReviewDict[username][r.Key]; i < r.codePackages.Length; i++) { CodePackage pkg = r.codePackages[i]; #region Generate review string StringBuilder reviewers = new StringBuilder("<table><tr style=\"border: 1px solid; border-top: none; border-left: none;border-right: none;\"><td width=\"40%\"><b>Reviewer</b></td><td width=\"30%\"><b>Type</b></td><td width=\"30%\"><b>Status</b></td></tr>"); StringBuilder reviewerstr = new StringBuilder(); foreach (var reviewer in r.reviewers) { reviewers.Append(string.Format("<tr><td><b>{3}</b>({0})</td><td>{1}</td><td>{2}</td></tr>", reviewer.Name, reviewer.Required ? "<b>Required</b>" : "Optional", reviewer.Status == ReviewerStatus.SignedOff ? "<font color=\"green\">SignedOff</font>" : reviewer.Status.ToString(), reviewer.DisplayName)); reviewerstr.Append(string.Format(" @{0},", reviewer.Name.Substring(reviewer.Name.IndexOf('\\') + 1))); } reviewers.Append("</table>"); #endregion #region Generate changed file StringBuilder changedfiles = new StringBuilder("<table><tr style=\"border: 1px solid; border-top: none; border-left: none;border-right: none;\"><td width=\"50px\"><b>Change</b></td><td width=\"30%\"><b>Type</b></td><td><b>FilePath</b></td></tr>"); foreach (var file in pkg.FileChanges) { changedfiles.Append(string.Format("<tr><td><b>{0}</b></td><td>{1}</td></tr>", file.ChangeType, file.DepotFilePath)); } changedfiles.Append("</table>"); string description = pkg.Description; string newDescription = description; string pat = @"(\d{4,})"; #endregion #region replace tfs number with topic // Instantiate the regular expression object. Regex reg = new Regex(pat, RegexOptions.IgnoreCase); // Match the regular expression pattern against a text string. Match m = reg.Match(description); List <string> replacedValueList = new List <string>(); while (m.Success) { //Console.WriteLine("Match" + (++matchCount)); if (!replacedValueList.Contains(m.Value)) { newDescription = newDescription.Replace(m.Value, string.Format(" #WOSS TFS {0}# ", m.Value)); replacedValueList.Add(m.Value); } m = m.NextMatch(); } #endregion string title = string.Format("Code Review: ({0}){1}", pkg.Author.Substring(pkg.Author.IndexOf('\\') + 1), r.Name); #region Iteration Title string iteration = ""; if (i == 0) { iteration = "New review submitted"; } else if (string.IsNullOrEmpty(r.CompletionMessage)) { iteration = "Author started new iteration"; } else { iteration = "Review completed"; } #endregion string link = "http://codeflow/Client/CodeFlow2010.application?server=http://codeflow/Services/DiscoveryService.svc&review=" + codeReviewSummary.Key; string richMessage = string.Format("<h3>{0}</h3><br/><h4><b>{1}</b></h4><br/><b>Open in: [<a href=\"{2}\">CodeFlow</a>]</b><br/><b>Author: {3}</b><br/>{4}<br/><b>Description:</b><br/>{5}<br/><h4><b>Affected Files</b></h4>{6}", title, iteration, link, pkg.Author, reviewers.ToString(), pkg.Description.Trim(), changedfiles.ToString()); string message = string.Format("#WOSS Codeflow# {0}\nIteration {2} {4}\nAuthor: {1}\nReviewer: {3}\n#WOSS Change {5}#\nReview: {6}", newDescription.Trim(), pkg.Author.Substring(pkg.Author.IndexOf('\\') + 1), pkg.Revision, reviewerstr.ToString().TrimEnd(new char[] { ',' }), pkg.IterationComment, pkg.SourceInfo.SourceName, link); Logger.WriteInfo(message); webapi.PostMessage(message, null, "none", r.Key, new string[] { "WOSS Codeflow" }, new string[] { pkg.Author.Substring(pkg.Author.IndexOf('\\') + 1) }, new string[] { }, richMessage); } _MonitoredReviewDict[username][r.Key] = r.codePackages.Length; } else { Logger.WriteInfo("no new reviews for user " + username); } } } } } catch (Exception e) { Logger.WriteInfo("Exception happened, try get the codeflow info in next run"); Logger.WriteInfo(e.Message); } //Check wether it's time to send trend data if (DateTime.Now.TimeOfDay > new TimeSpan(23, 30, 0)) { if (!_isTrendStatusSend) { GorillaWebAPI webapi = new GorillaWebAPI("CFMonitor", "User@123"); if (DateTime.Now.DayOfWeek == DayOfWeek.Friday) { var winner = _cfTrendStatus.ReviewCountPeople.OrderByDescending(p => p.Value).First(); string winnerThisWeek = string.Format("This Week's CodeFlow winner is @{0}, who submitted {1} CodeReviews!!!", winner.Key, winner.Value); webapi.PostMessage(winnerThisWeek, null, "none", "none", new string[] { "WOSS CodeFlow" }); } StringBuilder dailyTrendValue = new StringBuilder(); foreach (var value in _cfTrendStatus.ReviewCountHistory.OrderBy(t => t.Key).Select(t => t.Value)) { dailyTrendValue.AppendFormat("{0},", value); } string dTrendValue = dailyTrendValue.ToString().TrimEnd(','); StringBuilder dailyTrendDate = new StringBuilder(); foreach (var value in _cfTrendStatus.ReviewCountHistory.OrderBy(t => t.Key).Select(t => t.Key)) { dailyTrendDate.AppendFormat("'{0}',", value.ToShortDateString()); } string dTrendDate = dailyTrendDate.ToString().TrimEnd(','); string dailyTrend = string.Format("{{title:'WOSS Daily New CodeReview Number',legend:['New CodeRview Number'],xAxis:[{0}],yAxis:[{{name:'New CodeRview Number',type:'line',data:[{1}]}}]}}", dTrendDate, dTrendValue); webapi.PostMessage(dailyTrend, null, "chart-axis-singleaxis", "none", new string[] { "WOSS CodeFlow" }); _isTrendStatusSend = true; } } if (DateTime.Now.TimeOfDay < new TimeSpan(23, 00, 0)) { _isTrendStatusSend = false; } _recordMonitorStatus(); }
private void RunRefresh() { try { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Connecting to CodeFlow service" }); var endpointAddressBuilder = new EndpointAddressBuilder(); endpointAddressBuilder.Uri = new Uri("http://codeflow/Services/ReviewService.svc"); endpointAddressBuilder.Identity = new DnsEndpointIdentity("localhost"); // cache needs to be refreshed DateTime lastRefreshed = DateTime.MinValue; string payloadCache = null; while (true) { if (DateTime.Now.Subtract(lastRefreshed).TotalMinutes > this.refreshInterval) { // try up to 3 times for (var retries = 0; retries < 3; retries++) { try { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Loading stats." }); // get a reference to the team project collection using (var reviewServiceClient = new ReviewServiceClient(new WSHttpBinding(), endpointAddressBuilder.ToEndpointAddress())) { reviewServiceClient.Open(); var authorAssignedCount = reviewServiceClient.GetActiveReviewsForReviewer(this.authorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); var authorCreatedCount = reviewServiceClient.GetActiveReviewsForAuthor(this.authorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); var authorAssignedIndirectCount = reviewServiceClient.GetActiveReviewsForReviewer(this.secondAuthorWatch).Where(p => DateTime.Now.Subtract(p.LastUpdatedOn).TotalDays <= 7).Count(); payloadCache = string.Format( "{0} {1,-20}{3,-20}{2,-20}{4,-20}", (char)PacketDataType.Text, "CodeFlow Dashboard", "for " + this.authorWatch + ": " + authorAssignedCount, "by " + this.authorWatch + ": " + authorCreatedCount, "for " + this.secondAuthorWatch + ": " + authorAssignedIndirectCount); } this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Built stats: " + payloadCache }); } catch (Exception ex) { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Failed to refresh: " + ex.Message }); continue; } lastRefreshed = DateTime.Now; this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Cached result." }); break; } } else { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Reloading cached." }); } this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Broadcast result: " + payloadCache }); this.publishEvent.Publish(payloadCache); // sleep i said Thread.Sleep(this.announceInterval); } } catch (Exception ex) { this.traceEvent.Publish(new TraceMessage { Owner = "CodeFlow", Message = "Failure: " + ex.Message }); } }
public ReviewController(ReviewServiceClient reviewServiceClient, PingServiceClient pingServiceClient) { _reviewServiceClient = reviewServiceClient; _pingServiceClient = pingServiceClient; }
/// <summary> /// Step 3.2 - Add a list of reviewers to the review. /// </summary> /// <param name="client">An instance of <see cref="ReviewServiceClient" />.</param> /// <param name="reviewId">Id of the review to be added.</param> /// <param name="reviewers">A list of reviewers.</param> public static void AddReviewers(ReviewServiceClient client, string reviewId, Reviewer[] reviewers) { client.AddReviewers(reviewId, reviewers); }
/// <summary> /// Step 2.2 - Add code package to review. /// </summary> /// <param name="client">An instance of <see cref="ReviewServiceClient" />.</param> /// <param name="reviewId">Id of the review to be added.</param> /// <param name="codePackage">Code package to be added.</param> public static void AddCodePackage(ReviewServiceClient client, string reviewId, CodePackage codePackage) { client.AddCodePackage(reviewId, codePackage); }
/// <summary> /// Step 4 - Final step, publish the review. /// </summary> /// <param name="client">An instance of <see cref="ReviewServiceClient" />.</param> /// <param name="reviewId">Id of the review to be added.</param> /// <param name="messageFromAuthor"></param> public static void PublishReview(ReviewServiceClient client, string reviewId, string messageFromAuthor) { client.PublishReview(reviewId, messageFromAuthor); }
private static void InitializeClients() { Logger.Debug("Initializing CodeFlow Review Clients..."); _rClient = new ReviewServiceClient(); _qClient = new ReviewDashboardServiceClient(); }