public async Task SetWalletInfo(WalletId walletId, WalletBlobInfo blob)
        {
            if (walletId == null)
            {
                throw new ArgumentNullException(nameof(walletId));
            }
            using (var ctx = _ContextFactory.CreateContext())
            {
                var walletData = new WalletData()
                {
                    Id = walletId.ToString()
                };
                walletData.SetBlobInfo(blob);
                var entity = await ctx.Wallets.AddAsync(walletData);

                entity.State = EntityState.Modified;
                try
                {
                    await ctx.SaveChangesAsync();
                }
                catch (DbUpdateException) // Does not exists
                {
                    entity.State = EntityState.Added;
                    await ctx.SaveChangesAsync();
                }
            }
        }
示例#2
0
 public IEnumerable <Label> GetLabels(WalletBlobInfo walletBlobInfo, HttpRequest request)
 {
     foreach (var kv in walletBlobInfo.LabelColors)
     {
         yield return(CreateLabel(kv.Key, kv.Value, request));
     }
 }
示例#3
0
        private string ChooseBackgroundColor(
            WalletBlobInfo walletBlobInfo,
            HttpRequest request
            )
        {
            var labels = GetWalletColoredLabels(walletBlobInfo, request);

            List <string> allColors = new List <string>();

            allColors.AddRange(LabelColorScheme);
            allColors.AddRange(labels.Select(l => l.Color));
            var chosenColor =
                allColors
                .GroupBy(k => k)
                .OrderBy(k => k.Count())
                .ThenBy(k =>
            {
                var indexInColorScheme = Array.IndexOf(LabelColorScheme, k.Key);

                // Ensures that any label color which may not be in our label color scheme is given the least priority
                return(indexInColorScheme == -1 ? double.PositiveInfinity : indexInColorScheme);
            })
                .First().Key;

            return(chosenColor);
        }
示例#4
0
 public IEnumerable <ColoredLabel> ColorizeTransactionLabels(WalletBlobInfo walletBlobInfo, WalletTransactionInfo transactionInfo,
                                                             HttpRequest request)
 {
     foreach (var label in transactionInfo.Labels)
     {
         walletBlobInfo.LabelColors.TryGetValue(label.Value.Text, out var color);
         yield return(CreateLabel(label.Value, color, request));
     }
 }
示例#5
0
 public IEnumerable <ColoredLabel> GetWalletColoredLabels(WalletBlobInfo walletBlobInfo, HttpRequest request)
 {
     foreach (var kv in walletBlobInfo.LabelColors)
     {
         yield return(CreateLabel(new RawLabel()
         {
             Text = kv.Key
         }, kv.Value, request));
     }
 }
示例#6
0
 public IEnumerable <Label> GetLabels(WalletBlobInfo walletBlobInfo, WalletTransactionInfo transactionInfo,
                                      HttpRequest request)
 {
     foreach (var label in transactionInfo.Labels)
     {
         if (walletBlobInfo.LabelColors.TryGetValue(label, out var color))
         {
             yield return(CreateLabel(label, color, request));
         }
     }
 }
示例#7
0
        async public Task <RawLabel> BuildLabel(
            WalletBlobInfo walletBlobInfo,
            HttpRequest request,
            WalletTransactionInfo walletTransactionInfo,
            WalletId walletId,
            string transactionId,
            string label
            )
        {
            label = label.Trim().TrimStart('{').ToLowerInvariant().Replace(',', ' ').Truncate(MaxLabelSize);
            var labels = GetWalletColoredLabels(walletBlobInfo, request);

            if (!labels.Any(l => l.Text.Equals(label, StringComparison.OrdinalIgnoreCase)))
            {
                var chosenColor = ChooseBackgroundColor(walletBlobInfo, request);
                walletBlobInfo.LabelColors.Add(label, chosenColor);
                await _walletRepository.SetWalletInfo(walletId, walletBlobInfo);
            }

            return(new RawLabel(label));
        }