コード例 #1
0
        /// <summary>
        /// Compares two instances of type <see cref="RuntimeInfo"/> and returns a value indicating whether one is less than,
        ///     equal to, or greater than the other.
        /// </summary>
        /// <param name="x">The first <see cref="RuntimeInfo"/> to compare.</param>
        /// <param name="y">The second <see cref="RuntimeInfo"/> to compare.</param>
        /// <returns>A signed integer that indicates the relative values of x and y, as shown in the following table.
        ///     Value Meaning Less than zero x is less than y.
        ///     Zero x equals y.
        ///     Greater than zero x is greater than y.</returns>
        public Int32 Compare(RuntimeInfo x, RuntimeInfo y)
        {
            if (x == null)
            {
                return(y == null ? 0 : -Compare(y, x));
            }

            if (y == null)
            {
                return(1);
            }

            Int32 tfResult = new FrameworkIdentifiersComparer().Compare(x.Framework, y.Framework);

            if (tfResult != 0)
            {
                if (x.Framework == FrameworkIdentifiers.Unsupported || y.Framework == FrameworkIdentifiers.Unsupported)
                {
                    return(tfResult);
                }

                if (x.Framework == FrameworkIdentifiers.NETStandard)
                {
                    return(-Compare(y, x));
                }

                if (y.Framework == FrameworkIdentifiers.NETStandard)
                {
                    return(RuntimesHelper.TryGetStandardVersion(x, out Version x_netStandardVersion) && x_netStandardVersion.IsGreaterThanOrEqual(y.Version) ? 1 : -1);
                }
            }

            return(x.Version.CompareTo(y.Version));
        }
コード例 #2
0
        internal IExecutorConfiguration Dump()
        {
            Factory.Instance.Create(out IWorkerClientConfiguration workerClientConfig);
            workerClientConfig.AutoShutdown           = Worker.AutoShutdown;
            workerClientConfig.TestAssembly           = null;
            workerClientConfig.TestMethodModeOverride = Execution.TestMethodModeOverride;
            workerClientConfig.WriteReport            = Worker.WriteReport;

            Factory.Instance.Create(out IWorkerRemoteConfiguration workerRemoteConfig);
            workerRemoteConfig.ClientConfiguration = workerClientConfig;
            workerRemoteConfig.Executable          = null;
            workerRemoteConfig.StartClientVisible  = Worker.StartClientVisible;

            Factory.Instance.Create(out IProxyClientConfiguration proxyClientConfiguration);
            proxyClientConfiguration.WorkerRemoteConfiguration = workerRemoteConfig;
            proxyClientConfiguration.AssemblyModeOverride      = Execution.AssemblyModeOverride;

            RuntimesHelper.TryGetMatchingRuntimes(new RuntimeInfo(FrameworkIdentifiers.NETStandard, new Version(2, 0)), out IEnumerable <RuntimeInfo> runtimes);
            IEnumerable <RuntimeInfo> filterRuntimes = Execution.RuntimesFilter.Values.SelectMany(ri => ri.Convert());

            proxyClientConfiguration.AvailableRuntimes = runtimes
                                                         .Where(r => Execution.RuntimesFilter.Mode switch {
                FilterModes.Blacklist => !filterRuntimes.Contains(r),
                FilterModes.WhiteList => filterRuntimes.Contains(r),
                _ => false,
            });
コード例 #3
0
        private Boolean TryGetTargetFramework(out DirectoryInfo runtimeDir)
        {
            runtimeDir = File.Directory;

            if (RuntimesHelper.TryParseTFM(File.Directory.Name, out RuntimeInfo runtime))
            {
                PackageTargetFramework = runtime;
            }

            return(PackageTargetFramework != null && runtimeDir != null);
        }
コード例 #4
0
        internal static IDictionary <RuntimeInfo, DirectoryInfo> GetPackageVersionRuntimes(DirectoryInfo lib)
        {
            var packageVersions = new Dictionary <RuntimeInfo, DirectoryInfo>();

            if (lib != null && lib.Exists)
            {
                foreach (var targetFramework in lib.EnumerateDirectories("*", SearchOption.TopDirectoryOnly))
                {
                    if (RuntimesHelper.TryParseTFM(targetFramework.Name, out RuntimeInfo runtime))
                    {
                        packageVersions.Add(runtime, targetFramework);
                    }
                }
            }

            return(packageVersions);
        }
コード例 #5
0
        public IEnumerable <INugetResolverData> Resolve(
            AssemblyName assemblyName,
            IEnumerable <DirectoryInfo> cacheDirs,
            RuntimeInfo current,
            VersionMatchingStrategies assemblyMatchingStrategy,
            VersionMatchingStrategies packageMatchingStrategy)
        {
            List <INugetResolverData> files = new List <INugetResolverData>();

            if (RuntimesHelper.TryGetLoadableRuntimes(current, out IEnumerable <RuntimeInfo> validRuntimes))
            {
                cacheDirs.Foreach(cache => files.AddRange(GetAssemblyCandidatesFromCache(assemblyName, cache, validRuntimes, assemblyMatchingStrategy, packageMatchingStrategy)));
            }

            return(files
                   .OrderByDescending(d => d.PackageVersion)
                   .ThenByDescending(d => d.PackageTargetFramework, new RuntimeInfoFeatureComparer()));
        }
コード例 #6
0
        /// <summary>
        /// Creates a new instance of <see cref="Client{TConfiguration}"/>.
        /// </summary>
        /// <param name="link">The link object used to communicate with the remote.</param>
        public Client(IClientLink link)
        {
            Throw.If.Object.IsNull(link, nameof(link));

            Link = link;

            RuntimesHelper.TryGetCurrentRuntime(out _currentRuntime);

            Factory.Instance.Create(out ITestResultEndPoint result);
            Results = result;

            Link.StartOutput();
            Link.MessageReceived += OnSetupReceived;
            Link.MessageReceived += OnExecuteReceived;
            Link.ConnectInput();
            Link.ServerConnected += OnServerConnected;
            Link.WaitForConnection();
        }
コード例 #7
0
        private IEnumerable <IWorkerRemoteInfo> CreateRemoteInfos()
        {
            _log.Debug(nameof(CreateRemoteInfos));

            IList <IWorkerRemoteInfo> infos = new List <IWorkerRemoteInfo>();

            if (RuntimesHelper.TryGetMatchingRuntimes(TestAssemblyRuntime, out IEnumerable <RuntimeInfo> matchingRuntimes))
            {
                Func <IEnumerable <Version>, Version>       filter        = Configuration.SelectedRuntimes == SelectedExecutionRuntimes.Highest ? Enumerable.Max : Enumerable.Min;
                IDictionary <FrameworkIdentifiers, Version> versionfilter = matchingRuntimes
                                                                            .Where(r => Configuration.AvailableRuntimes.Contains(r))
                                                                            .GroupBy(r => r.Framework)
                                                                            .ToDictionary(g => g.Key, g => filter(g.Select(r => r.Version)));

                _log.Debug($"Selected versions are {versionfilter.Format()}.");

                foreach (RuntimeInfo runtime in matchingRuntimes)
                {
                    Factory.Instance.Create(out IWorkerRemoteInfo info, Configuration, runtime);
                    info.IsSelected = info.Configuration.HasExecutable &&
                                      (Configuration.SelectedRuntimes == SelectedExecutionRuntimes.All ||
                                       (versionfilter.ContainsKey(info.Runtime.Framework) && info.Runtime.Version == versionfilter[info.Runtime.Framework]));

                    _log.Debug($"Created worker remote: {info.Format()}");

                    infos.Add(info);
                }
            }

            if (infos.Count > 0)
            {
                _log.Info($"Defined {infos.Count.Format()} worker remotes.");
            }
            else
            {
                _log.Info("No remotes defined.");
            }

            return(infos);
        }
コード例 #8
0
        internal static List <FileInfo> GetAssemblyCandidates(AssemblyName assemblyName, List <DirectoryInfo> nugetCaches, RuntimeInfo current)
        {
            var candidates = new List <FileInfo>();

            if (RuntimesHelper.TryGetLoadableRuntimes(current, out IEnumerable <RuntimeInfo> validRuntimes))
            {
                foreach (var cache in nugetCaches)
                {
                    candidates.AddRange(GetAssemblyCandidatesFromCache(assemblyName, cache, validRuntimes, true));
                }

                if (!candidates.Any())
                {
                    foreach (var cache in nugetCaches)
                    {
                        candidates.AddRange(GetAssemblyCandidatesFromCache(assemblyName, cache, validRuntimes, false));
                    }
                }
            }

            return(candidates);
        }