Example #1
0
        public AppViewModel()
        {
            _configManager = new ServiceConfigManager();
            _certifyClient = new CertifyServiceClient(_configManager, GetDefaultServerConnection(_configManager));

            Init();
        }
Example #2
0
        public AppModel()
        {
            /*if (!(this is DesignViewModel))
             * {
             * // certifyManager = new CertifyManager();
             * }*/
            CertifyClient   = new CertifyServiceClient();
            ProgressResults = new ObservableCollection <RequestProgressState>();

            this.ImportedManagedSites = new ObservableCollection <ManagedSite>();
            this.ManagedSites         = new ObservableCollection <ManagedSite>();
        }
Example #3
0
        public AppViewModel()
        {
            CertifyClient = new CertifyServiceClient(GetDefaultServerConnection());

            Init();
        }
        public AppViewModel()
        {
            CertifyClient = new CertifyServiceClient();

            Init();
        }
        /// <summary>
        /// Attempt connection to the given service, or default if none supplied.
        /// </summary>
        /// <param name="conn">If null, default will be used</param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <bool> InitServiceConnections(ServerConnection conn, CancellationToken cancellationToken)
        {
            //check service connection
            IsServiceAvailable = false;

            ConnectionState = "Connecting...";

            if (conn == null)
            {
                // check default connection
                IsServiceAvailable = await CheckServiceAvailable(_certifyClient);
            }

            var maxAttempts       = 3;
            var attemptsRemaining = maxAttempts;

            ICertifyClient clientConnection = _certifyClient;

            while (!IsServiceAvailable && attemptsRemaining > 0 && cancellationToken.IsCancellationRequested != true)
            {
                var connectionConfig = conn ?? GetDefaultServerConnection(_configManager);
                Debug.WriteLine("Service not yet available. Waiting a few seconds..");

                if (attemptsRemaining != maxAttempts)
                {
                    // the service could still be starting up or port may be reallocated
                    var waitMS = (maxAttempts - attemptsRemaining) * 1000;
                    await Task.Delay(waitMS, cancellationToken);
                }

                if (!cancellationToken.IsCancellationRequested)
                {
                    // restart client in case port has reallocated
                    clientConnection = new CertifyServiceClient(_configManager, connectionConfig);

                    IsServiceAvailable = await CheckServiceAvailable(clientConnection);

                    if (!IsServiceAvailable)
                    {
                        attemptsRemaining--;

                        // give up
                        if (attemptsRemaining == 0)
                        {
                            ConnectionState = IsServiceAvailable ? "Connected" : "Not Connected";
                            return(false);
                        }
                    }
                }
            }

            if (cancellationToken.IsCancellationRequested == true)
            {
                ConnectionState = IsServiceAvailable ? "Connected" : "Not Connected";
                return(false);
            }

            // wire up stream events
            clientConnection.OnMessageFromService          += CertifyClient_SendMessage;
            clientConnection.OnRequestProgressStateUpdated += UpdateRequestTrackingProgress;
            clientConnection.OnManagedCertificateUpdated   += CertifyClient_OnManagedCertificateUpdated;

            // connect to status api stream & handle events
            try
            {
                await clientConnection.ConnectStatusStreamAsync();
            }
            catch (Exception exp)
            {
                // failed to connect to status signalr hub
                Log?.Error($"Failed to connect to status hub: {exp}");

                ConnectionState = IsServiceAvailable ? "Connected" : "Not Connected";
                return(false);
            }

            // replace active connection
            _certifyClient = clientConnection;


            ConnectionState = IsServiceAvailable ? "Connected" : "Not Connected";
            return(true);
        }