Esempio n. 1
0
        private void OnReleaseDownloaded(ReleaseDownloaded obj)
        {
            // TODO: I am also shipping here a new settings object since these could also be updated.
            // TODO: We need to use that new Settings to set them on other objects.
            if (obj.Result != ConnectionResult.Success)
            {
                return;
            }

            // (Konrad) Get all allocated assets. They would be allocated if they were
            // previously deserialized from Settings, or set on previous cycle.
            var allocated = new HashSet <AssetObject>();

            foreach (var l in SourceLocations)
            {
                foreach (var a in l.Assets)
                {
                    allocated.Add(a.Asset);
                }
            }
            foreach (var l in Locations)
            {
                foreach (var a in l.Assets)
                {
                    allocated.Add(a.Asset);
                }
            }

            // (Konrad) Find out if there are any new assets downloaded that were not accounted for.
            // These would be added to the SourceLocations collection.
            var added = new HashSet <AssetObject>();

            foreach (var a in obj.Release.Assets)
            {
                if (allocated.Contains(a))
                {
                    allocated.Remove(a);
                    continue;
                }

                added.Add(a);
            }

            // (Konrad) Whatever is left in allocated needs to be deleted.
            foreach (var l in Locations)
            {
                l.Assets = l.Assets.Where(x => !allocated.Contains(x.Asset)).ToObservableCollection();
            }

            // (Konrad) If any location is now empty let's remove it.
            Locations = Locations.Where(x => x.Assets.Any()).ToObservableCollection();

            // (Konrad) Add all new assets to source locations.
            // Since we are calling this from another thread (Timer runs on a thread pool)
            // we need to make sure that the collection is locked.
            lock (_lock)
            {
                SourceLocations.Clear();

                var loc = new LocationsViewModel(new Location
                {
                    IsSourceLocation = true,
                    MaxHeight        = 557
                }, !added.Any());

                foreach (var asset in added)
                {
                    var vm = new AssetViewModel(asset)
                    {
                        Parent = loc
                    };
                    if (!loc.Assets.Contains(vm))
                    {
                        loc.Assets.Add(vm);
                    }
                }

                SourceLocations.Add(loc);
            }
        }
Esempio n. 2
0
 private void OnReleaseDownloaded(ReleaseDownloaded obj)
 {
     Settings.LatestRelease = obj.Result == ConnectionResult.Failure
         ? null
         : obj.Release;
 }