Пример #1
0
        private async Task SynchronizeComonentHostInstancesAndPackagesAsync(NodeServer node)
        {
            // get expected instances on node
            // get instances currently on node
            // request to end all instances and start them again
            // if there's a discrepency
            INodeAccessService nodeAccess = NodeAccessFactory.Get(node);
            IComponentHostSettingsDataAccess componentSettingsDataAccess = ComponentHostSettingsDataAccessFactory.Get();

            IEnumerable <ComponentHostInstanceSettings> requiredComponentHostInstances = await componentSettingsDataAccess.GetComponentInstanceSettingsAsync(node);

            IEnumerable <Package> requiredComponentHostPackages = await componentSettingsDataAccess.GetComponentPackagesAsync(node);


            ComponentHostInstanceSettings primerComponentHost = requiredComponentHostInstances.First();

            // start host process
            string hostPackageName = await NodeSettingsAccessFactory.Get().GetComponentHostPackageName();

            NodeBasicProcessInformation primerHostProcess = await nodeAccess.StartProcessAsync(hostPackageName, (id : 0, args : new Dictionary <string, string> {
                { "--port", "4999" }
            }));

            IComponentHostAccessService  primerHostProcessAccess     = ComponentHostAccessFactory.Get(primerHostProcess.ProcessUri);
            IEnumerable <PackageDetails> remoteComponentHostPackages = await primerHostProcessAccess.GetComponentHostPackageConfigurationAsync();

            try
            {
                requiredComponentHostPackages
                //.AsParallel()
                //.ForAll
                .Select(package =>
                {
                    var remoteInstallation        = remoteComponentHostPackages?.Where(x => string.Compare(package.Name, x.PackageName, true) == 0).ToList() ?? default;
                    PackageDetails packageDetails = null;
                    using (var packageStream = File.OpenRead(package.PackagePath))
                    {
                        if (remoteInstallation is null || !remoteInstallation.Any())
                        {// component host doesn't have required package
                            packageDetails = primerHostProcessAccess.UploadComponentHostPackageAsync(packageStream).Result;
                        }
                        else if (!remoteInstallation.Any(x => x.PackageVersion == package.Version))
                        {
                            // check if any instances are running with the loaded package
                            packageDetails = primerHostProcessAccess.UpdateComponentHostPackageAsync(packageStream).Result;
                        }
                    }
 public static IComponentHostAccessService GetComponentHostAccessService(this NodeBasicProcessInformation processInformation)
 => ComponentHostAccessFactory.Get(processInformation.ProcessUri);