public async Task FillSolutionListTreeView(SynchronizationContext synchronizationContext, TreeView treeView)
        {
            _treeView = treeView;
            _synchronizationContext = synchronizationContext;
            var storageIdentifiers = await _applicationStorageService.GetSolutionListStorageIdentifiers();

            if (storageIdentifiers?.Any() == true)
            {
                synchronizationContext.Send(new SendOrPostCallback(o =>
                {
                    _treeView.Nodes.Clear();

                    var data = (List <StorageIdentifier>)o;

                    data
                    .GroupBy(s => s.Name)
                    .ToList()
                    .ForEach(g =>
                    {
                        var rootNode = treeView.Nodes.Add(g.Key);
                        var first    = true;
                        g
                        .OrderByDescending(s => s.Date)
                        .ThenByDescending(s => s.BuildId)
                        .ToList()
                        .ForEach(s =>
                        {
                            var childNode = rootNode.Nodes.Add(s.Name + "-" + s.Date.ToShortDateString() + "-" + s.BuildId);
                            if (first)
                            {
                                childNode.Checked = true;
                                first             = false;
                            }

                            childNode.Tag = s;
                        });

                        rootNode.Expand();
                    });
                }), storageIdentifiers);
            }
        }
Example #2
0
        public async Task Cleanup(int numItemsToKeep = 5)
        {
            var storageIdentifiers = await _storageService.GetSolutionListStorageIdentifiers();

            if (storageIdentifiers.Any() == true)
            {
                var entriesToDelete = storageIdentifiers
                                      .GroupBy(s => s.Name)
                                      .Where(g => g.Count() > numItemsToKeep)
                                      .SelectMany(g => g
                                                  .OrderByDescending(s => s.Date)
                                                  .Skip(numItemsToKeep))
                                      .Select(s => s.BlobName);

                if (entriesToDelete?.Any() == true)
                {
                    var tasks = new List <Task <bool> >();
                    var msg   = $"These blobs will be removed:{Environment.NewLine}";

                    foreach (var blobName in entriesToDelete)
                    {
                        msg += $"{blobName}{Environment.NewLine}";
                        tasks.Add(_storageService.Delete(blobName));
                    }

                    _logger.Information(msg);
                    await Task.WhenAll(tasks);
                }
                else
                {
                    _logger.Information("There are no old entries to remove.");
                }
            }
            else
            {
                _logger.Information("There are no entries to remove.");
            }
        }