Beispiel #1
0
        /// <summary>
        /// Gets all the statusses of tha <see cref="IPatient"/> instance that matches the pattern.
        /// </summary>
        /// <param name="patientPattern">Pattern to determine the instances of <see cref="IPatient"/>.</param>
        /// <inheritDoc />
        public IEnumerable <PatientStatus> GetStatusses(string patientPattern = "*")
        {
            EnsureArg.IsNotNullOrEmpty(patientPattern, nameof(patientPattern));

            var ant = antFactory
                      .CreateNew(patientPattern);

            var patients = kernel.GetAll <IPatient>();

            var candidates = patients
                             .Where(_ => ant.IsMatch(_.Id))
                             .OrderBy(_ => _.Id);

            foreach (var candidate in candidates)
            {
                var status = new PatientStatus(candidate.Id, PatientStatusType.Red, defaultReason);

                try
                {
                    status = candidate.GetStatus() ?? status;
                }
                catch (Exception ex)
                {
                    status = new PatientStatus(candidate.Id, PatientStatusType.Red, ex.ToString());
                }

                yield return(status);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets all the locations of the requested fusion.
        /// </summary>
        /// <param name="fusionId">Id of the requested fusion.</param>
        /// <inheritDoc />
        public IEnumerable <string> GetAllLocations(string fusionId)
        {
            EnsureArg.IsNotNullOrEmpty(fusionId, nameof(fusionId));

            var pattern  = FormatFusionDirectory(fusionId, "*");
            var ant      = antFactory.CreateNew(pattern);
            var rootInfo = directoryInfoFactory.CreateNew(rootDirectory);

            if (!rootInfo.Exists)
            {
                return(new string[0]);
            }

            return(rootInfo
                   .GetDirectories()
                   .Where(_ => ant.IsMatch(_.Name))
                   .Select(_ => _.FullName));
        }
Beispiel #3
0
        /// <summary>
        /// Gets all the statusses of the given query.
        /// </summary>
        /// <param name="fusionPattern">Pattern that is used to query <see cref="IFusionProcess"/> instances.</param>
        /// <param name="patientPattern">Pattern that is used to query <see cref="IPatient"/> instances.</param>
        /// <param name="token">Token to cancel the request.</param>
        /// <inheritDoc />
        public async Task <HospitalStatus> GetStatusAsync(
            string fusionPattern,
            string patientPattern,
            CancellationToken token)
        {
            EnsureArg.IsNotNullOrEmpty(fusionPattern, nameof(fusionPattern));
            EnsureArg.IsNotNullOrEmpty(patientPattern, nameof(patientPattern));

            var fusionMatch = antFactory
                              .CreateNew(fusionPattern);

            var candidates = scheduleService.Processes
                             .Where(_ => fusionMatch.IsMatch(_.FusionId))
                             .OrderBy(_ => _.FusionId);

            var fusionStatusses = new List <FusionStatus>();

            foreach (var candidate in candidates)
            {
                var fusionStatus = await GetFusionStatusAsync(candidate, patientPattern, token);

                fusionStatusses.Add(fusionStatus);
            }

            var reason     = string.Empty;
            var statusType = GetLowestType(fusionStatusses);

            if (statusType != PatientStatusType.Green)
            {
                if (scheduleService.IsDeploying())
                {
                    reason     = deployReason;
                    statusType = PatientStatusType.Yellow;
                }
                else
                {
                    reason = $"One or more patients have the '{statusType.ToString()}' status.";
                }
            }

            return(new HospitalStatus(fusionStatusses, statusType, reason));
        }
Beispiel #4
0
        private string LocatePackage(PackageVersion version)
        {
            var pattern = configStore.Value?.Pack?
                          .GetActualPackagePattern(version);

            if (string.IsNullOrEmpty(pattern))
            {
                return(null);
            }

            var matcher           = antFactory.CreateNew(pattern);
            var directorySearcher = antDirectoryFactory.CreateNew(matcher);

            var results = directorySearcher
                          .SearchRecursively(packageRootDir, true)?
                          .Stale();

            return(results.Count() == 1
                ? results.FirstOrDefault()
                : null);
        }
Beispiel #5
0
        private IEnumerable <string> GetIpAddresses()
        {
            var ant = antFactory.CreateNew(configStore.Value.Rest.IpAddressPattern);

            var ipAddresses = NetworkInterface
                              .GetAllNetworkInterfaces()
                              .Where(i => i.OperationalStatus == OperationalStatus.Up)
                              .SelectMany(i => i.GetIPProperties().UnicastAddresses)
                              .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork)
                              .Select(a => a.Address.ToString())
                              .Concat(standardIpAddresses);

            if (!IsAdministratorRole())
            {
                ipAddresses = standardIpAddresses;
            }

            return(ipAddresses
                   .Distinct(StringComparer.OrdinalIgnoreCase)
                   .Where(_ => ant.IsMatch(_)));
        }
Beispiel #6
0
        /// <summary>
        /// Initializes a new <see cref="FusionBuilder"/> with all it's dependencies.
        /// </summary>
        /// <param name="logService">Service used for logging.</param>
        /// <param name="antFactory">Factory used to create <see cref="IAnt"/> instances.</param>
        /// <param name="configStore">Store that resolved app-level configuration.</param>
        /// <param name="packService">Service that is used to get the packages from.</param>
        /// <param name="nuGetPackageResolver">Resolver that handles required NuGet packages.</param>
        /// <param name="frameworkPackageEntryFactory">Factory used for creating framework instances of <see cref="IPackageEntry"/>.</param>
        /// <param name="fusionFilters">A collection of filters used to filter instances of <see cref="IPackageEntry"/>.</param>
        /// <param name="fusionInterceptors">A collection of interceptors that intercept the creation of <see cref="IPackageEntry"/>.</param>
        public FusionBuilder(
            ILog logService,
            IAntFactory antFactory,
            IConfigStore configStore,
            IPackService packService,
            INuGetPackageResolver nuGetPackageResolver,
            IFrameworkPackageEntryFactory frameworkPackageEntryFactory,
            IEnumerable <IFusionFilter> fusionFilters,
            IEnumerable <IFusionInterceptor> fusionInterceptors)
        {
            this.logService                   = logService;
            this.configStore                  = configStore;
            this.packService                  = packService;
            this.nuGetPackageResolver         = nuGetPackageResolver;
            this.frameworkPackageEntryFactory = frameworkPackageEntryFactory;

            this.fusionFilters      = fusionFilters.StaleReadOnly();
            this.fusionInterceptors = fusionInterceptors.StaleReadOnly();

            entryFilter = antFactory
                          .CreateNew(configStore?.Value?.Fuse?.EntryPattern);

            dependencyFiles = GetDependencyFiles().StaleReadOnly();
        }