Пример #1
0
        /// <summary>Validates that the specified package is a 64 bit application.</summary>
        /// <param name="package">The package to examine.</param>
        /// <param name="packageEvent">The event associated with the package.</param>
        /// <returns>Returns <c>true</c> if the packages does not contain a 32-bit application, otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">package</exception>
        /// <remarks>The more correct description is to validate that the package
        /// does not contain a 32-bit application.</remarks>
        public override CommandResult Execute(Package package, PackageEvent packageEvent)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (packageEvent != PackageEvent.Added)
            {
                Logger.LogTrace($"Ignoring {package.Id} due to the event being a delete");
                return(new CommandResult(this));
            }

            if (package.Content == null)
            {
                Logger.LogWarning($"Contents are empty for package {package}.");
                return(new CommandResult(this));
            }

            var result = DoesPackageContain32bitExecutable(package);

            if (result.contains32BitExecutable)
            {
                Logger.LogWarning($"{package} contains a 32-bit application:{result.assemblyName}");
                return(new CommandResult(this, false, $"{package.Id} contains a 32-bit application:{result.assemblyName}"));
            }

            Logger.LogTrace($"{package.Id} does not contain a 32-bit application:{result.assemblyName}");
            return(new CommandResult(this, true, $"{package.Id} does not contain a 32-bit application:{result.assemblyName}"));
        }
Пример #2
0
 /// <summary>
 /// The method in the action that processes the package.
 /// </summary>
 /// <param name="package">The package to process.</param>
 /// <param name="packageEvent">The type of event associated with the package.</param>
 /// <returns><c>true</c> if the process was successful and processing should continue, <c>false</c> otherwise.</returns>
 public override Task <bool> ProcessPackageAsync(Package package, PackageEvent packageEvent)
 {
     if (packageEvent == PackageEvent.Deleted)
     {
         return(ProcessPackageDeleteAsync(package));
     }
     else
     {
         return(ProcessPackageAddedAsync(package, packageEvent));
     }
 }
Пример #3
0
        public void TestApplicationIs64BitCommand(string packageFileName, PackageEvent packageEvent, bool expectedResult)
        {
            var commandResult = CommandTestWrapper.Execute
                                (
                (action, command, loggerFactory) => new ApplicationIs64BitCommand(action, command, loggerFactory),
                LoggerFactory,
                Path.Combine(RootFolder, "local.choco", packageFileName),
                new Library.Settings.Command(),
                packageEvent
                                );

            Assert.Equal(expectedResult, commandResult.ResultValid);
        }
        public IPackageEvent New(PackageEventType type, int id, long oldVersion, long?newVersion = null, decimal price = 0)
        {
            var model = new PackageEvent
            {
                Type       = type,
                PackageId  = id,
                OldVersion = oldVersion,
                NewVersion = newVersion,
                NewPrice   = price
            };

            context.PackageEvents.Add(model);
            return(model);
        }
        public void General_Test(string key, string value, PackageEvent packageEvent, bool expectedResult)
        {
            var commandResult = CommandTestWrapper.Execute
                                (
                (action, command, loggerFactory) => new Log4netReviewCommand(action, command, loggerFactory),
                LoggerFactory,
                Path.Combine(RootFolder, "local.choco", "Test.Package.1.0.0.nupkg"),
                new Library.Settings.Command()
            {
                Settings =
                {
                    { key, value },
                }
            },
                packageEvent
                                );

            Assert.Equal(expectedResult, commandResult.ResultValid);
        }
Пример #6
0
        /// <summary>The method that executes the appropriate command to process the package.</summary>
        /// <param name="package">The package for the command to handle.</param>
        /// <param name="packageEvent">The event associated with the package.</param>
        /// <returns>Returns the CommandResult for the package.</returns>
        public override CommandResult Execute(Package package, PackageEvent packageEvent)
        {
            Debug.Assert(package != null);

            if (new NuGetVersion(package.Version).IsPrerelease)
            {
                Logger.LogWarning($"The {package} skipped because it is a pre-release.");
            }
            else if (packageEvent == PackageEvent.Deleted)
            {
                return(ProcessPackageDeleted(package));
            }
            else if (packageEvent == PackageEvent.Added || packageEvent == PackageEvent.Promoted || packageEvent == PackageEvent.Processed)
            {
                return(ProcessPackageAdded(package));
            }

            return(new CommandResult(this));
        }
Пример #7
0
    // Start is called before the first frame update
    void Start()
    {
        // initialize trigger dictionary
        this.triggers = new Dictionary <string, int>();

        // initialize the individual events
        externalEvents = new List <ExternalEvent>();
        PackageEvent pe = this.transform.Find("PackageEvent").GetComponent <PackageEvent>();

        pe.SetEventHub(this);
        externalEvents.Add(pe);

        VacuumEvent ve = this.transform.Find("VacuumEvent").GetComponent <VacuumEvent>();

        ve.SetEventHub(this);
        externalEvents.Add(ve);

        MakeCoffeeEvent me = this.transform.Find("MakeCoffeeEvent").GetComponent <MakeCoffeeEvent>();

        me.SetEventHub(this);
        externalEvents.Add(me);
    }
Пример #8
0
        /// <summary>The method in the action that processes the package.</summary>
        /// <param name="package">The package to process.</param>
        /// <param name="packageEvent">The type of event associated with the package.</param>
        /// <returns>
        ///   <c>true</c> if the process was successful and processing should continue, <c>false</c> otherwise.</returns>
        public override async Task <bool> ProcessPackageAsync(Package package, PackageEvent packageEvent)
        {
            if (IgnorePackage(package))
            {
                Logger.LogDebug($"Package ({package.Id} is being ignored due to configuration");
                await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageIgnored,
                                                                                $"Package ({package.Id} is being ignored due to configuration", null, package));

                return(true);
            }

            try
            {
                Package packageWithContent = package;
                if (packageEvent != PackageEvent.Deleted)
                {
                    Logger.LogDebug($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}");
                    packageWithContent = await SourceRepository.FetchAsync(package.Id, package.Version);

                    Logger.LogTrace($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}...done");
                    if (packageWithContent == null)
                    {
                        Logger.LogWarning($"Package not found: {package.Id}.{package.Version} from {SourceRepository.Name}. Ignoring but expecting failure.");
                        packageWithContent = package;
                    }
                }

                switch (await ProcessCommandsAsync(packageWithContent, packageEvent))
                {
                case CommandFailureAction.Continue:
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageSuccess,
                                                                                    $"Command successful on {package.Id}.{package.Version}", null, package));

                    return(true);

                case CommandFailureAction.FailPackage:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.", null, package));

                    return(true);

                case CommandFailureAction.FailAction:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.", null, package));

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error processing package {package.Id}.{package.Version}. Exception: {ex.Message}", ex);
                if (ActionSettings.FailOnError)
                {
                    throw;
                }
            }

            return(true);
        }
Пример #9
0
 /// <summary>The method that executes the appropriate command to process the package.</summary>
 /// <param name="package">The package for the command to handle.</param>
 /// <param name="packageEvent">The event associated with the package.</param>
 /// <returns>Returns the CommandResult for the package.</returns>
 public abstract CommandResult Execute(Package package, PackageEvent packageEvent);
        public static CommandResult Execute <TCommand>(Func <IAction, Settings.Command, ILoggerFactory, TCommand> commandFactory, ILoggerFactory loggerFactory, string packageFileName, Settings.Command commandSettings, PackageEvent packageEvent)
            where TCommand : BaseCommand
        {
            var package = Package.CreateFromFile(packageFileName);

            var mockRepository = new Mock <IRepository <Package> >();

            mockRepository
            .Setup(m => m.Name)
            .Returns("MockRepository");
            mockRepository
            .Setup(m => m.FetchAsync(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(package);

            var mockAction = new Mock <IAction>();

            mockAction
            .Setup(a => a.SourceRepository)
            .Returns(mockRepository.Object);

            var commandUnderTest = commandFactory(mockAction.Object, commandSettings, loggerFactory);

            return(commandUnderTest.Execute(package, packageEvent));
        }
Пример #11
0
 public Task <bool> ProcessPackageAsync(Package package, PackageEvent packageEvent)
 {
     return(Task.FromResult(ProcessPackageFunc(package, packageEvent)));
 }
Пример #12
0
        /// <summary>A protected method that processes added packages.</summary>
        /// <param name="package">The package to process.</param>
        /// <param name="packageEvent">The package event that generated the package.</param>
        /// <returns>
        ///   <c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        protected virtual async Task <bool> ProcessPackageAddedAsync(Package package, PackageEvent packageEvent)
        {
            if (IgnorePackage(package))
            {
                Logger.LogDebug($"Package ({package.Id} is being ignored due to configuration");
                await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageIgnored,
                                                                                $"Package ({package.Id} is being ignored due to configuration", null, package));

                return(true);
            }

            try
            {
                Logger.LogDebug($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}");
                var packageWithContent = await SourceRepository.FetchAsync(package.Id, package.Version);

                Logger.LogTrace($"Fetching package {package.Id}.{package.Version} from {SourceRepository.Name}...done");

                switch (await ProcessCommandsAsync(package, packageEvent))
                {
                case CommandFailureAction.Continue:
                    Logger.LogInformation($"Adding package {package.Id}.{package.Version} to {TargetRepository.Name}");
                    await TargetRepository.AddAsync(packageWithContent);

                    Logger.LogTrace($"Adding package {package.Id}.{package.Version} to {TargetRepository.Name}...done");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageSuccess,
                                                                                    $"Package added {package.Id}.{package.Version} to {TargetRepository.Name}",
                                                                                    null, package));

                    break;

                case CommandFailureAction.FailPackage:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionPackageFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailPackage. Ignoring package.",
                                                                                    null, package));

                    return(true);

                case CommandFailureAction.FailAction:
                    Logger.LogDebug($"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.");
                    await this.ObserverManager.NotifyObserversAsync(new ActionEvent(this, ActionEventType.ActionFailed,
                                                                                    $"Failure Action on {package.Id}.{package.Version} is FailAction. Aborting action.",
                                                                                    null,
                                                                                    package));

                    return(false);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError($"Error adding package {package.Id}.{package.Version}. Exception: {ex.Message}", ex);
                if (ActionSettings.FailOnError)
                {
                    throw;
                }
            }

            return(true);
        }
Пример #13
0
        public override void ReadDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("EditorID", false, out subEle))
            {
                if (EditorID == null)
                {
                    EditorID = new SimpleSubrecord <String>();
                }

                EditorID.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Data", false, out subEle))
            {
                if (Data == null)
                {
                    Data = new PackageData();
                }

                Data.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Location1", false, out subEle))
            {
                if (Location1 == null)
                {
                    Location1 = new PackageLocation();
                }

                Location1.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Location2", false, out subEle))
            {
                if (Location2 == null)
                {
                    Location2 = new PackageLocation();
                }

                Location2.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Schedule", false, out subEle))
            {
                if (Schedule == null)
                {
                    Schedule = new PackageScheduleData();
                }

                Schedule.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Target1", false, out subEle))
            {
                if (Target1 == null)
                {
                    Target1 = new PackageTarget();
                }

                Target1.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Conditions", false, out subEle))
            {
                if (Conditions == null)
                {
                    Conditions = new List <Condition>();
                }

                foreach (XElement e in subEle.Elements())
                {
                    Condition tempCTDA = new Condition();
                    tempCTDA.ReadXML(e, master);
                    Conditions.Add(tempCTDA);
                }
            }
            if (ele.TryPathTo("Idle/Flags", false, out subEle))
            {
                if (IdleFlags == null)
                {
                    IdleFlags = new SimpleSubrecord <PackageIdleFlags>();
                }

                IdleFlags.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Idle/Count", false, out subEle))
            {
                if (IdleCount == null)
                {
                    IdleCount = new SimpleSubrecord <Byte>();
                }

                IdleCount.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Idle/TimerSetting", false, out subEle))
            {
                if (IdleTimerSetting == null)
                {
                    IdleTimerSetting = new SimpleSubrecord <Single>();
                }

                IdleTimerSetting.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Idle/Animations", false, out subEle))
            {
                if (IdleAnimations == null)
                {
                    IdleAnimations = new FormArray();
                }

                IdleAnimations.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Unused", false, out subEle))
            {
                if (Unused == null)
                {
                    Unused = new SimpleSubrecord <Byte[]>();
                }

                Unused.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("CombatStyle", false, out subEle))
            {
                if (CombatStyle == null)
                {
                    CombatStyle = new RecordReference();
                }

                CombatStyle.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("EatMarker", false, out subEle))
            {
                if (EatMarker == null)
                {
                    EatMarker = new SubMarker();
                }

                EatMarker.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("EscortDistance", false, out subEle))
            {
                if (EscortDistance == null)
                {
                    EscortDistance = new SimpleSubrecord <UInt32>();
                }

                EscortDistance.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("FollowDistance_StartLocation_TriggerRadius", false, out subEle))
            {
                if (FollowDistance_StartLocation_TriggerRadius == null)
                {
                    FollowDistance_StartLocation_TriggerRadius = new SimpleSubrecord <UInt32>();
                }

                FollowDistance_StartLocation_TriggerRadius.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("PatrolIsRepeatable", false, out subEle))
            {
                if (PatrolIsRepeatable == null)
                {
                    PatrolIsRepeatable = new SimpleSubrecord <NoYesByte>();
                }

                PatrolIsRepeatable.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("UseWeaponData", false, out subEle))
            {
                if (UseWeaponData == null)
                {
                    UseWeaponData = new PackageUseWeaponData();
                }

                UseWeaponData.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("Target2", false, out subEle))
            {
                if (Target2 == null)
                {
                    Target2 = new PackageTarget();
                }

                Target2.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("UseItemMarker", false, out subEle))
            {
                if (UseItemMarker == null)
                {
                    UseItemMarker = new SubMarker();
                }

                UseItemMarker.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("AmbushMarker", false, out subEle))
            {
                if (AmbushMarker == null)
                {
                    AmbushMarker = new SubMarker();
                }

                AmbushMarker.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("DialogData", false, out subEle))
            {
                if (DialogData == null)
                {
                    DialogData = new PackageDialogData();
                }

                DialogData.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("DummyIgnore", false, out subEle))
            {
                if (DummyIgnore == null)
                {
                    DummyIgnore = new PackageLocation();
                }

                DummyIgnore.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("OnBegin", false, out subEle))
            {
                if (OnBegin == null)
                {
                    OnBegin = new PackageEvent();
                }

                OnBegin.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("OnEnd", false, out subEle))
            {
                if (OnEnd == null)
                {
                    OnEnd = new PackageEvent();
                }

                OnEnd.ReadXML(subEle, master);
            }
            if (ele.TryPathTo("OnChange", false, out subEle))
            {
                if (OnChange == null)
                {
                    OnChange = new PackageEvent();
                }

                OnChange.ReadXML(subEle, master);
            }
        }
Пример #14
0
        public override void ReadData(ESPReader reader, long dataEnd)
        {
            while (reader.BaseStream.Position < dataEnd)
            {
                string subTag = reader.PeekTag();

                switch (subTag)
                {
                case "EDID":
                    if (EditorID == null)
                    {
                        EditorID = new SimpleSubrecord <String>();
                    }

                    EditorID.ReadBinary(reader);
                    break;

                case "PKDT":
                    if (Data == null)
                    {
                        Data = new PackageData();
                    }

                    Data.ReadBinary(reader);
                    break;

                case "PLDT":
                    if (Location1 == null)
                    {
                        Location1 = new PackageLocation();
                    }

                    Location1.ReadBinary(reader);
                    break;

                case "PLD2":
                    if (Location2 == null)
                    {
                        Location2 = new PackageLocation();
                    }

                    Location2.ReadBinary(reader);
                    break;

                case "PSDT":
                    if (Schedule == null)
                    {
                        Schedule = new PackageScheduleData();
                    }

                    Schedule.ReadBinary(reader);
                    break;

                case "PTDT":
                    if (Target1 == null)
                    {
                        Target1 = new PackageTarget();
                    }

                    Target1.ReadBinary(reader);
                    break;

                case "CTDA":
                    if (Conditions == null)
                    {
                        Conditions = new List <Condition>();
                    }

                    Condition tempCTDA = new Condition();
                    tempCTDA.ReadBinary(reader);
                    Conditions.Add(tempCTDA);
                    break;

                case "IDLF":
                    if (IdleFlags == null)
                    {
                        IdleFlags = new SimpleSubrecord <PackageIdleFlags>();
                    }

                    IdleFlags.ReadBinary(reader);
                    break;

                case "IDLC":
                    if (IdleCount == null)
                    {
                        IdleCount = new SimpleSubrecord <Byte>();
                    }

                    IdleCount.ReadBinary(reader);
                    break;

                case "IDLT":
                    if (IdleTimerSetting == null)
                    {
                        IdleTimerSetting = new SimpleSubrecord <Single>();
                    }

                    IdleTimerSetting.ReadBinary(reader);
                    break;

                case "IDLA":
                    if (IdleAnimations == null)
                    {
                        IdleAnimations = new FormArray();
                    }

                    IdleAnimations.ReadBinary(reader);
                    break;

                case "IDLB":
                    if (Unused == null)
                    {
                        Unused = new SimpleSubrecord <Byte[]>();
                    }

                    Unused.ReadBinary(reader);
                    break;

                case "CNAM":
                    if (CombatStyle == null)
                    {
                        CombatStyle = new RecordReference();
                    }

                    CombatStyle.ReadBinary(reader);
                    break;

                case "PKED":
                    if (EatMarker == null)
                    {
                        EatMarker = new SubMarker();
                    }

                    EatMarker.ReadBinary(reader);
                    break;

                case "PKE2":
                    if (EscortDistance == null)
                    {
                        EscortDistance = new SimpleSubrecord <UInt32>();
                    }

                    EscortDistance.ReadBinary(reader);
                    break;

                case "PKFD":
                    if (FollowDistance_StartLocation_TriggerRadius == null)
                    {
                        FollowDistance_StartLocation_TriggerRadius = new SimpleSubrecord <UInt32>();
                    }

                    FollowDistance_StartLocation_TriggerRadius.ReadBinary(reader);
                    break;

                case "PKPT":
                    if (PatrolIsRepeatable == null)
                    {
                        PatrolIsRepeatable = new SimpleSubrecord <NoYesByte>();
                    }

                    PatrolIsRepeatable.ReadBinary(reader);
                    break;

                case "PKW3":
                    if (UseWeaponData == null)
                    {
                        UseWeaponData = new PackageUseWeaponData();
                    }

                    UseWeaponData.ReadBinary(reader);
                    break;

                case "PTD2":
                    if (Target2 == null)
                    {
                        Target2 = new PackageTarget();
                    }

                    Target2.ReadBinary(reader);
                    break;

                case "PUID":
                    if (UseItemMarker == null)
                    {
                        UseItemMarker = new SubMarker();
                    }

                    UseItemMarker.ReadBinary(reader);
                    break;

                case "PKAM":
                    if (AmbushMarker == null)
                    {
                        AmbushMarker = new SubMarker();
                    }

                    AmbushMarker.ReadBinary(reader);
                    break;

                case "PKDD":
                    if (DialogData == null)
                    {
                        DialogData = new PackageDialogData();
                    }

                    DialogData.ReadBinary(reader);
                    break;

                case "DUMY":
                    if (DummyIgnore == null)
                    {
                        DummyIgnore = new PackageLocation();
                    }

                    DummyIgnore.ReadBinary(reader);
                    break;

                case "POBA":
                    if (OnBegin == null)
                    {
                        OnBegin = new PackageEvent();
                    }

                    OnBegin.ReadBinary(reader);
                    break;

                case "POEA":
                    if (OnEnd == null)
                    {
                        OnEnd = new PackageEvent();
                    }

                    OnEnd.ReadBinary(reader);
                    break;

                case "POCA":
                    if (OnChange == null)
                    {
                        OnChange = new PackageEvent();
                    }

                    OnChange.ReadBinary(reader);
                    break;

                default:
                    throw new Exception();
                }
            }
        }
Пример #15
0
 public Package(SimpleSubrecord <String> EditorID, PackageData Data, PackageLocation Location1, PackageLocation Location2, PackageScheduleData Schedule, PackageTarget Target1, List <Condition> Conditions, SimpleSubrecord <PackageIdleFlags> IdleFlags, SimpleSubrecord <Byte> IdleCount, SimpleSubrecord <Single> IdleTimerSetting, FormArray IdleAnimations, SimpleSubrecord <Byte[]> Unused, RecordReference CombatStyle, SubMarker EatMarker, SimpleSubrecord <UInt32> EscortDistance, SimpleSubrecord <UInt32> FollowDistance_StartLocation_TriggerRadius, SimpleSubrecord <NoYesByte> PatrolIsRepeatable, PackageUseWeaponData UseWeaponData, PackageTarget Target2, SubMarker UseItemMarker, SubMarker AmbushMarker, PackageDialogData DialogData, PackageLocation DummyIgnore, PackageEvent OnBegin, PackageEvent OnEnd, PackageEvent OnChange)
 {
     this.EditorID = EditorID;
     this.Data     = Data;
     this.Schedule = Schedule;
 }
Пример #16
0
        /// <summary>
        /// Validates that the specified package has consistent versioning with the package.
        /// </summary>
        /// <param name="package">The package to examine.</param>
        /// <param name="packageEvent">The event associated with the package.</param>
        /// <returns>Returns <c>true</c> if the packages is properly versioned, otherwise <c>false</c>.</returns>
        /// <exception cref="ArgumentNullException">package</exception>
        public override CommandResult Execute(Package package, PackageEvent packageEvent)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (packageEvent != PackageEvent.Added)
            {
                Logger.LogTrace($"Ignoring {package.Id} due to the event being a delete");
                return(new CommandResult(this));
            }

            if (package.Content == null)
            {
                Logger.LogWarning($"Contents are empty for package {package}.");
                return(new CommandResult(this));
            }

            if (this.Settings.Settings.TryGetValue(Setting_PackageIdRegex, out var packageIdRegex) && !string.IsNullOrWhiteSpace(packageIdRegex))
            {
                if (!Regex.IsMatch(package.Id, packageIdRegex, RegexOptions.IgnoreCase))
                {
                    Logger.LogTrace($"{package} skipped due to package filtering.");
                    return(new CommandResult(this, true, $"{package} package versioning check skipped."));
                }
            }
            else
            {
                Logger.LogTrace($"Command does not have a '{Setting_PackageIdRegex}' setting, defaulting to all packages.");
            }

            var binariesWithDifferentVersions = GetBinariesWithDifferentVersions(package);

            if (binariesWithDifferentVersions.Count < 1)
            {
                var message = "No version issues detected.";

                Logger.LogTrace(message);

                return(new CommandResult(this, true, message));
            }
            else
            {
                var sb = new StringBuilder();

                sb.AppendLine($"Binaries with versions different from the package detected:");
                sb.AppendLine();

                foreach (var issue in binariesWithDifferentVersions)
                {
                    sb.Append(" * ");
                    sb.AppendLine(issue);
                }

                var message = sb.ToString();

                Logger.LogWarning(message);

                return(new CommandResult(this, false, message));
            }
        }
Пример #17
0
        /// <summary>
        /// Validates that the specified package has additional support files.
        /// </summary>
        /// <param name="package">The package to examine.</param>
        /// <param name="packageEvent">The event associated with the package.</param>
        /// <returns>Returns <c>true</c> if the packages has valid configuration, otherwise <c>false</c>.</returns>
        public override CommandResult Execute(Package package, PackageEvent packageEvent)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (packageEvent != PackageEvent.Added)
            {
                Logger.LogTrace($"Ignoring {package.Id} due to the event being a delete");
                return(new CommandResult(this));
            }

            if (package.Content == null)
            {
                Logger.LogWarning($"Contents are empty for package {package}.");
                return(new CommandResult(this));
            }

            if (this.Settings.Settings.TryGetValue(Setting_PackageIdRegex, out var packageIdRegex) && !string.IsNullOrWhiteSpace(packageIdRegex))
            {
                if (!Regex.IsMatch(package.Id, packageIdRegex, RegexOptions.IgnoreCase))
                {
                    Logger.LogTrace($"{package.Id} (v{package.Version}) skipped due to package filtering.");
                    return(new CommandResult(this, true, $"{package} package check skipped."));
                }
            }
            else
            {
                Logger.LogTrace($"Command does not have a '{Setting_PackageIdRegex}' setting, defaulting to all packages.");
            }

            var issues = new List <string>();

            using var byteStream = new MemoryStream(package.Content);
            using var archive    = ArchiveFactory.Open(byteStream);
            foreach (var archiveEntry in archive.Entries)
            {
                if (archiveEntry.IsDirectory || !archiveEntry.Key.EndsWith(".exe", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                Logger.LogTrace($"Executable found: {archiveEntry.Key}");

                var configFileName     = archiveEntry.Key + ".config";
                var configArchiveEntry = archive.Entries.FirstOrDefault(x => x.Key.Equals(configFileName, StringComparison.InvariantCultureIgnoreCase));

                if (configArchiveEntry == null)
                {
                    Logger.LogDebug($"Skipping, no config file found for : {configFileName}");
                    continue;
                }

                try
                {
                    using var configStream = configArchiveEntry.ExtractToStream();
                    var doc = XDocument.Load(configStream);

                    ValidateConfig(configFileName, doc, issues);
                }
                catch (Exception e)
                {
                    Logger.LogInformation(e, "Unable to parse: {0}", configFileName);
                }
            }

            if (issues.Count < 1)
            {
                var message = "Valid configuration.";

                Logger.LogTrace(message);

                return(new CommandResult(this, true, message));
            }
            else
            {
                var sb = new StringBuilder();

                sb.AppendLine($"Invalid configuration detected:");
                sb.AppendLine();

                foreach (var issue in issues)
                {
                    sb.Append(" * ");
                    sb.AppendLine(issue);
                }

                var message = sb.ToString();

                Logger.LogWarning(message);

                return(new CommandResult(this, false, message));
            }
        }
Пример #18
0
 public static bool ProcessPackageMethod(Package package, PackageEvent packageEvent)
 {
     return(true);
 }