Пример #1
0
        /// <inheritdoc/>
        protected override void ProcessRecord()
        {
            IEnumerable <Instance> instances = Instance;

            if (Product != null && Product.Any())
            {
                // Select instances with no product or the specified product ID.
                var patterns = Product.Select(product => GetPattern(product)).ToArray();
                instances = from instance in instances
                            let instanceProduct = instance?.Product
                                                  where instanceProduct == null || patterns.Any(pattern => pattern.IsMatch(instanceProduct.Id))
                                                  select instance;
            }

            if (Require != null && Require.Any())
            {
                // Select instances that contain the specified package IDs.
                bool Contains(IEnumerable <PackageReference> packages, Func <PackageReference, string> selector)
                {
                    if (RequireAny)
                    {
                        return(packages.ContainsAny(selector, Require, StringComparer.OrdinalIgnoreCase));
                    }

                    return(packages.ContainsAll(selector, Require, StringComparer.OrdinalIgnoreCase));
                }

                instances = from instance in instances
                            let instancePackages = instance?.Packages
                                                   where instancePackages != null && Contains(instancePackages, package => package.Id)
                                                   select instance;
            }

            if (helper != null)
            {
                instances = from instance in instances
                            let instanceVersion = instance?.InstallationVersion?.ToString()
                                                  where !string.IsNullOrEmpty(instanceVersion)
                                                  let version = helper.ParseVersion(instanceVersion)
                                                                where minVersion <= version && version <= maxVersion
                                                                select instance;
            }

            foreach (var instance in instances)
            {
                if (Latest)
                {
                    if (latestInstance == null || InstanceComparer.VersionAndDate.Compare(latestInstance, instance) < 0)
                    {
                        latestInstance = instance;
                    }
                }
                else
                {
                    WriteInstance(instance);
                }
            }
        }
Пример #2
0
        public bool Verify(out string message)
        {
            message = null;
            if (Option == null)
            {
                return(true);                //setting no longer exists, constraints are irrelevant?
            }
            var pItem   = Sys.ActiveProfile.ActiveItems.Find(pi => pi.ModID.Equals(ModID));
            var inst    = Sys.Library.GetItem(pItem.ModID);
            var setting = pItem.Settings.Find(s => s.ID.Equals(Setting, StringComparison.InvariantCultureIgnoreCase));

            if (setting == null)
            {
                setting = new ProfileSetting()
                {
                    ID = Setting, Value = Option.Default
                };
                pItem.Settings.Add(setting);
            }

            string modsList = String.Join("\n", ParticipatingMods.Select(p => $"{p.Value} | ({p.Key})")); // list of mods participating in constraint

            if (Require.Any() && (Require.Min() != Require.Max()))
            {
                message = String.Format("Mod {0}, setting {1} - no compatible option can be found. The following mods all restrict how it can be configured:\n\n{2}", inst.CachedDetails.Name, Option.Name, modsList);
                return(false);
            }

            if (Require.Any() && Forbid.Contains(Require[0]))
            {
                message = String.Format("Mod {0}, setting {1} - no compatible option can be found. The following mods all restrict how it can be configured:\n\n{2}", inst.CachedDetails.Name, Option.Name, modsList);
                return(false);
            }
            if (Option.Values.All(o => Forbid.Contains(o.Value)))
            {
                message = String.Format("Mod {0}, setting {1} - no compatible option can be found. The following mods all restrict how it can be configured:\n\n{2}", inst.CachedDetails.Name, Option.Name, modsList);
                return(false);
            }
            if (Require.Any() && (setting.Value != Require[0]))
            {
                var opt = Option.Values.Find(v => v.Value == Require[0]);
                if (opt == null)
                {
                    message = String.Format("Mod {0}, setting {1} - no compatible option can be found. The following mods all restrict how it can be configured:\n\n{2}", inst.CachedDetails.Name, Option.Name, modsList);
                    return(false);
                }
                setting.Value = Require[0];
                message       = String.Format("Mod {0} - changed setting {1} to {2}", inst.CachedDetails.Name, Option.Name, opt.Name);
            }
            else if (Forbid.Contains(setting.Value))
            {
                setting.Value = Option.Values.First(v => !Forbid.Contains(v.Value)).Value;
                var opt = Option.Values.Find(v => v.Value == setting.Value);
                message = String.Format("Mod {0} - changed setting {1} to {2}", inst.CachedDetails.Name, Option.Name, opt.Name);
            }
            return(true);
        }
        /// <inheritdoc/>
        protected override void ProcessRecord()
        {
            IEnumerable <Instance> instances = Instance;

            if (Product != null && Product.Any())
            {
                // Select instances with no product or the specified product ID.
                instances = from instance in instances
                            let instanceProduct = instance?.Product
                                                  where instanceProduct == null || Product.Contains(instanceProduct.Id, StringComparer.OrdinalIgnoreCase)
                                                  select instance;
            }

            if (Require != null && Require.Any())
            {
                // Select instances that contain all specified package IDs.
                instances = from instance in instances
                            let instancePackages = instance?.Packages
                                                   where instancePackages != null && instancePackages.ContainsAll(package => package.Id, Require, StringComparer.OrdinalIgnoreCase)
                                                   select instance;
            }

            if (helper != null)
            {
                instances = from instance in instances
                            let instanceVersion = instance?.InstallationVersion?.ToString()
                                                  where !string.IsNullOrEmpty(instanceVersion)
                                                  let version = helper.ParseVersion(instanceVersion)
                                                                where minVersion <= version && version <= maxVersion
                                                                select instance;
            }

            foreach (var instance in instances)
            {
                if (Latest)
                {
                    if (latestInstance == null || latestInstance.InstallDate < instance.InstallDate)
                    {
                        latestInstance = instance;
                    }
                }
                else
                {
                    WriteInstance(instance);
                }
            }
        }
Пример #4
0
 public void Any_WhenEmpty_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Require.Any(Enumerable.Empty <int>(), v => v > 1, "message", "name"));
 }
Пример #5
0
 public void Any_WhenContainsElementThatMatchesPredicate_DoesNotThrow()
 {
     Require.Any(new[] { 1, 5 }, v => v > 1, "message", "name");
 }
Пример #6
0
 public void Any_WhenNull_ThrowsArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => Require.Any((int[])null, v => v > 1, "message", "name"));
 }
Пример #7
0
 public void Any_WhenDoesNotContainElementThatMatchesPredicate_ThrowsArgumentException()
 {
     Assert.Throws <ArgumentException>(() => Require.Any(new[] { 1 }, v => v > 1, "message", "name"));
 }