/// <summary>
 /// Initializes a new instance of the <see cref="FactoryOrchestratorVersionMismatchException"/> class.
 /// </summary>
 /// <param name="ip">The ip address of the Service.</param>
 /// <param name="serviceVersion">The service version.</param>
 public FactoryOrchestratorVersionMismatchException(IPAddress ip, string serviceVersion) : base(string.Format(CultureInfo.CurrentCulture, Resources.FactoryOrchestratorVersionMismatchException, ip?.ToString() ?? "", serviceVersion, FactoryOrchestratorClient.GetClientVersionString()))
 {
     ServiceVersion = serviceVersion;
     ClientVersion  = FactoryOrchestratorClient.GetClientVersionString();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FactoryOrchestratorVersionMismatchException"/> class.
 /// </summary>
 /// <param name="message">The error message that explains the reason for the exception.</param>
 /// <param name="innerException">The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no inner exception is specified.</param>
 public FactoryOrchestratorVersionMismatchException(string message, Exception innerException) : base(message, innerException)
 {
     ClientVersion  = FactoryOrchestratorClient.GetClientVersionString();
     ServiceVersion = Resources.Unknown;
 }
        /// <summary>
        /// Establishes a connection to the Factory Orchestrator Service.
        /// Throws an exception if it cannot connect.
        /// </summary>
        /// <param name="ignoreVersionMismatch">If true, ignore a Client-Service version mismatch.</param>
        public async Task Connect(bool ignoreVersionMismatch = false)
        {
            ServiceProvider serviceProvider = new ServiceCollection()
                                              .AddTcpIpcClient <IFactoryOrchestratorService>("Client", (_, options) =>
            {
                options.ConnectionTimeout     = 10000;
                options.ServerIp              = IpAddress;
                options.ServerPort            = Port;
                options.SslServerIdentity     = ServerIdentity;
                options.EnableSsl             = true;
                options.SslValidationCallback = ServerCertificateValidationCallback;
            })
                                              .BuildServiceProvider();

            // resolve IPC client factory
            var clientFactory = serviceProvider
                                .GetRequiredService <IIpcClientFactory <IFactoryOrchestratorService> >();

            // create client
            _IpcClient = clientFactory.CreateClient("Client");

            string serviceVersion;

            // Test a command to make sure connection works
            try
            {
                serviceVersion = await _IpcClient.InvokeAsync <string>(CreateIpcRequest("GetServiceVersionString"));
            }
            catch (Exception ex)
            {
                throw CreateIpcException(ex);
            }

            if (!ignoreVersionMismatch)
            {
                // Verify client and service are compatible
                var clientVersion = GetClientVersionString();
                var clientMajor   = clientVersion.Split('.').First();
                var serviceMajor  = serviceVersion.Split('.').First();

                if (clientMajor != serviceMajor)
                {
                    throw new FactoryOrchestratorVersionMismatchException(IpAddress, serviceVersion);
                }
            }

            try
            {
                HostName = await _IpcClient.InvokeAsync <string>(CreateIpcRequest("GetDnsHostName"));

                OSVersion = await _IpcClient.InvokeAsync <string>(CreateIpcRequest("GetOSVersionString"));

                await _IpcClient.InvokeAsync(CreateIpcRequest("Connect", new object[] { Dns.GetHostName(), $"OS: {Environment.OSVersion.VersionString}. Client version: {FactoryOrchestratorClient.GetClientVersionString()}." }));
            }
            catch (Exception)
            {
                HostName  = Resources.Unknown;
                OSVersion = Resources.Unknown;
            }

            IsConnected = true;
            OnConnected?.Invoke();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="FactoryOrchestratorVersionMismatchException"/> class.
 /// </summary>
 public FactoryOrchestratorVersionMismatchException() : base()
 {
     ClientVersion  = FactoryOrchestratorClient.GetClientVersionString();
     ServiceVersion = Resources.Unknown;
 }
Exemple #5
0
 /// <summary>
 /// Gets the build number of FactoryOrchestratorClient.
 /// </summary>
 /// <returns></returns>
 public static string GetClientVersionString()
 {
     return(FactoryOrchestratorClient.GetClientVersionString());
 }