예제 #1
0
        protected override bool PreVisitNode(Node node)
        {
            var fileSource = Path.GetFileName(node.Span.Location.FileSource);

            if (string.Compare(fileSource, "internal_hlsl_declarations.hlsl", StringComparison.OrdinalIgnoreCase) != 0 && node.Span.Length > 0)
            {
                while (SourceLocations.Count < lineCount)
                {
                    SourceLocations.Add(new SourceLocation(node.Span.Location.FileSource, node.Span.Location.Position, node.Span.Location.Line, 1));
                }
            }

            return(base.PreVisitNode(node));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="settings"></param>
        private void ProcessUpToDate(ZombieSettings settings)
        {
            Locations.Clear();
            SourceLocations.Clear();

            Model.Settings = settings;

            // (Konrad) Populate UI with stored settings
            PopulateSourceFromSettings(settings);
            if (settings.DestinationAssets.Any())
            {
                PopulateDestinationFromSettings(settings);
            }
        }
예제 #3
0
        private void OnLocationRemoved(LocationRemoved obj)
        {
            var assets = obj.Removed.Assets.Where(x => !x.IsPlaceholder);

            foreach (var a in assets)
            {
                if (!SourceLocations.First().Assets.Contains(a))
                {
                    SourceLocations.First().Assets.Add(a);
                }
            }

            // (Konrad) Remove Placeholder asset if other ass
            if (SourceLocations.First()?.Assets.Count > 1 &&
                SourceLocations.FirstOrDefault()?.Assets.FirstOrDefault(x => x.IsPlaceholder) != null)
            {
                SourceLocations.First().RemovePlaceholder();
            }

            Locations.Remove(obj.Removed);
        }
예제 #4
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);
        }
예제 #5
0
        /// <summary>
        /// Validates the provided sources are usable.
        /// </summary>
        /// <param name="sources"></param>
        /// <returns></returns>
        private bool ValidateSources(SourceLocations sources)
        {
            if (sources == null)
            {
                return(false);
            }

            try
            {
                Logger.WriteTraceMessage(string.Format("Validating {0} scan source(s).", sources.Count));
                sources.Validate();
                Logger.WriteTraceMessage("All scan sources validated.");

                return(true);
            }
            catch (SourceLocationException ex)
            {
                var msg = ConvertToFriendlyError(ex);
                Logger.WriteSystemEvent(msg, System.Diagnostics.EventLogEntryType.Error, Constants.EventIDs.FailedToValidateScanSources, true);

                return(false);
            }
        }
예제 #6
0
 public override int GetHashCode()
 {
     return(Rule.GetHashCode() ^ SourceLocations.Aggregate(0, (i, c) => i ^ c.GetHashCode()));
 }
예제 #7
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);
            }
        }
예제 #8
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);
            }
        }