private static void GroupSubBranchesIntoOneMainBranch( IGrouping <CommitId, KeyValuePair <string, MSubBranch> > groupByBranch) { // All sub branches in the groupByBranch have same name and parent commit id, lets take // the first sub branch and base the branch corresponding to the group on that sub branch MSubBranch subBranch = groupByBranch.First().Value; string branchId = subBranch.Name + "-" + subBranch.ParentCommitId; MBranch branch = GetBranch(branchId, subBranch); // Get active sub branches in group (1 if either local or remote, 2 if both) var activeSubBranches = groupByBranch .Where(b => b.Value.IsActive).Select(g => g.Value) .ToList(); branch.IsActive = activeSubBranches.Any(); MSubBranch localSubBranch = activeSubBranches.FirstOrDefault(b => b.IsLocal); MSubBranch remoteSubBranch = activeSubBranches.FirstOrDefault(b => b.IsRemote); branch.IsLocal = localSubBranch != null; branch.LocalTipCommitId = localSubBranch?.TipCommitId ?? CommitId.None; branch.IsRemote = remoteSubBranch != null; branch.RemoteTipCommitId = remoteSubBranch?.TipCommitId ?? CommitId.None; branch.IsCurrent = activeSubBranches.Any(b => b.IsCurrent); branch.IsDetached = activeSubBranches.Any(b => b.IsDetached); branch.LocalAheadCount = 0; branch.RemoteAheadCount = 0; // Set branch if of each sub branch groupByBranch.ForEach(b => b.Value.BranchId = branch.Id); }
private static DayExportReportEntry CreateFromReportEntries(IGrouping <string, ReportEntry> entries) { var reportedTimeSpans = default(TimeSpan); entries.ForEach(f => reportedTimeSpans += f.CalculateReportedMinutes()); var timeDescription = new TimeDescription(reportedTimeSpans); return(new DayExportReportEntry(timeDescription, entries.Key)); }
private async Task GetGeoLocationFromCacheAsync(IGrouping <string, EventContext> geoGroup) { var location = await _cacheClient.GetAsync <Location>(geoGroup.Key, null).AnyContext(); if (location == null) { return; } await _cacheClient.SetExpirationAsync(geoGroup.Key, TimeSpan.FromDays(3)).AnyContext(); geoGroup.ForEach(c => c.Event.Data[Event.KnownDataKeys.Location] = location); }
private Item[] CreateTaskItem(IGrouping <string, Item> grouping) { var isGroup = grouping.Count() > 1; var firstItem = grouping.First(); var firstItemHref = $"{grouping.Key}/{grouping.First().Uid}.yml"; if (isGroup && grouping.Key == _commonNamespace) { grouping.ForEach(x => x.Href = $"{grouping.Key}/{x.Uid}.yml"); return(grouping.ToArray()); } return(new[] { new Item { Uid = isGroup ? grouping.Key : firstItem.Uid, Href = isGroup ? $"{grouping.Key}/toc.yml" : firstItemHref, TopicUid = isGroup ? firstItem.Uid : null, Icon = GetIconClassText(firstItem.Uid), Name = grouping.Key.Split('.').Last() } }); }
protected virtual async Task PopulateRowDetails(EntityView view, PriceCard card, string itemId, bool isAddAction, bool isEditAction, CommercePipelineExecutionContext context) { if (view == null || card == null || string.IsNullOrEmpty(itemId)) { return; } if (isAddAction) { CurrencySet currencySet = null; string entityTarget = (await _findEntityCommand.Process(context.CommerceContext, typeof(PriceBook), card.Book.EntityTarget, false).ConfigureAwait(false) as PriceBook)?.CurrencySet.EntityTarget; if (!string.IsNullOrEmpty(entityTarget)) { currencySet = await _getCurrencySetCommand.Process(context.CommerceContext, entityTarget).ConfigureAwait(false); } List <Policy> commercePolicies = new List <Policy>() { new AvailableSelectionsPolicy(currencySet == null || !currencySet.HasComponent <CurrenciesComponent>() ? new List <Selection>() : currencySet.GetComponent <CurrenciesComponent>().Currencies.Select(c => { return(new Selection() { DisplayName = c.Code, Name = c.Code }); }).ToList(), false) }; ViewProperty item = new ViewProperty() { Name = "Currency", RawValue = string.Empty, Policies = commercePolicies }; view.Properties.Add(item); } else { string[] strArray = itemId.Split('|'); if (strArray.Length != 2 || string.IsNullOrEmpty(strArray[0]) || string.IsNullOrEmpty(strArray[1])) { context.Logger.LogError("Expecting a SnapshotId and Currency in the ItemId: " + itemId + ". Correct format is 'snapshotId|currency'", Array.Empty <object>()); } else { string snapshotId = strArray[0]; string currency = strArray[1]; PriceSnapshotComponent snapshotComponent = card.Snapshots.FirstOrDefault(s => s.Id.Equals(snapshotId, StringComparison.OrdinalIgnoreCase)); if (snapshotComponent == null) { context.Logger.LogError("Price snapshot " + snapshotId + " on price card " + card.FriendlyId + " was not found.", Array.Empty <object>()); } else { var list = snapshotComponent.GetComponent <MembershipTiersComponent>().Tiers; IGrouping <string, CustomPriceTier> currencyGroup = list.GroupBy(t => t.Currency) .ToList() .FirstOrDefault(g => g.Key.Equals(currency, StringComparison.OrdinalIgnoreCase)); if (currencyGroup == null) { context.Logger.LogError("Price row " + currency + " was not found in snapshot " + snapshotId + " for card " + card.FriendlyId + ".", Array.Empty <object>()); } else { view.Properties.Add(new ViewProperty { Name = "Currency", RawValue = currencyGroup.Key, IsReadOnly = true }); if (isEditAction) { view.UiHint = "Grid"; currencyGroup.ForEach(tier => { EntityView entityView = new EntityView() { Name = context.GetPolicy <KnownCustomPricingViewsPolicy>().PriceCustomCell, EntityId = card.Id, ItemId = itemId }; var membershipLevels = context.GetPolicy <MembershipLevelPolicy>().MembershipLevels; ViewProperty item1 = new ViewProperty() { Name = "MembershipLevel", RawValue = tier.MembershipLevel, OriginalType = typeof(string).FullName, IsReadOnly = true, Policies = new List <Policy>() { new AvailableSelectionsPolicy(membershipLevels.Select(c => { return(new Selection() { DisplayName = c.MemerbshipLevelName, Name = c.MemerbshipLevelName }); }).ToList(), false) } }; entityView.Properties.Add(item1); entityView.Properties.Add(new ViewProperty() { Name = "Quantity", RawValue = tier.Quantity, IsReadOnly = true }); entityView.Properties.Add(new ViewProperty() { Name = "Price", RawValue = tier.Price, IsRequired = false }); view.ChildViews.Add(entityView); }); } else { view.Properties.Add(new ViewProperty { Name = "ItemId", RawValue = itemId, IsReadOnly = true, IsHidden = true }); list.Select(t => t.MembershipLevel).Distinct().OrderBy(q => q).ToList().ForEach(availableMembershipLevel => { CustomPriceTier priceTier = currencyGroup.FirstOrDefault(ct => ct.MembershipLevel == availableMembershipLevel); List <ViewProperty> properties = view.Properties; properties.Add(new ViewProperty() { Name = availableMembershipLevel.ToString(CultureInfo.InvariantCulture), RawValue = priceTier?.Price, IsReadOnly = true }); }); } } } } } }