コード例 #1
0
        /// <summary>
        /// Sets DestinationAssets from a Zombie Settings.
        /// </summary>
        /// <param name="settings">Zombie Settings.</param>
        private void PopulateDestinationFromSettings(ZombieSettings settings)
        {
            foreach (var loc in settings.DestinationAssets)
            {
                var newLocation = new LocationsViewModel(loc);
                var assets      =
                    new ObservableCollection <AssetViewModel>(loc.Assets.Select(x =>
                                                                                new AssetViewModel(x)
                {
                    Parent = newLocation
                }));
                newLocation.Assets = assets;

                Locations.Add(newLocation);
            }
        }
コード例 #2
0
        /// <summary>
        /// Sets Source Assets from a Zombie Settings.
        /// </summary>
        /// <param name="settings">Zombie Settings.</param>
        private void PopulateSourceFromSettings(ZombieSettings settings)
        {
            var loc = new LocationsViewModel(new Location
            {
                LocationType = LocationType.Source
            }, !settings.SourceAssets.Any());

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

            SourceLocations.Add(loc);
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="settings"></param>
        private void ProcessSucceeded(ZombieSettings settings)
        {
            Model.Settings = settings;

            // (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);
                }
            }

            Locations = Locations.Where(x => x.LocationObject.LocationType != LocationType.Trash).ToObservableCollection();
            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 settings.LatestRelease.Assets)
            {
                if (allocated.Contains(a))
                {
                    allocated.Remove(a);
                    continue;
                }

                added.Add(a);
            }

            // (Konrad) Whatever is left in allocated needs to be deleted.
            var trashLocations = new ObservableCollection <LocationsViewModel>();

            foreach (var l in Locations)
            {
                var remain   = new ObservableCollection <AssetViewModel>();
                var trashLoc = new LocationsViewModel(new Location
                {
                    LocationType  = LocationType.Trash,
                    DirectoryPath = l.LocationObject.DirectoryPath
                }, false);

                foreach (var avm in l.Assets)
                {
                    if (!allocated.Contains(avm.Asset))
                    {
                        remain.Add(avm);
                    }
                    else
                    {
                        if (trashLoc.Assets.Contains(avm))
                        {
                            continue;
                        }

                        avm.IsPlaceholder = true;
                        trashLoc.Assets.Add(avm);
                    }
                }

                l.Assets = remain;
                trashLocations.Add(trashLoc);
            }

            // (Konrad) Let's put these deleted assets into new deleted locations
            foreach (var lvm in trashLocations)
            {
                Locations.Add(lvm);
            }

            // (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 (_sourceLock)
            {
                SourceLocations.Clear();

                var loc = new LocationsViewModel(new Location
                {
                    LocationType = LocationType.Source
                }, !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);
            }
        }