Example #1
0
        /// <summary>
        /// Starts the client so it is going to be able to live in another thread.
        /// </summary>
        /// <returns></returns>
        public bool StartClient()
        {
            bool result = false;

            if (!this.ableToRun)
            {
                KSPMGlobals.Globals.Log.WriteTo(Error.ErrorType.ServerClientUnableToRun.ToString());
                return(false);
            }
            try
            {
                this.aliveFlag = true;

                ///Creating the asynchronous call wich is going to handle the UDP command processing.
                ProcessUDPMessageAsync processUDPMessages = new ProcessUDPMessageAsync(this.ProcessUDPCommandAsyncMethod);
                processUDPMessages.BeginInvoke(this.OnProcessUDPCommandComplete, processUDPMessages);

                ///Creating the asynchronous call wich is going to handle the connection process.
                ConnectAsync connectionProcess = new ConnectAsync(this.HandleConnectionProcess);
                connectionProcess.BeginInvoke(this.AsyncConnectionProccesComplete, connectionProcess);

                ///Starting to receive TCP streams.
                this.ReceiveTCPStream();

                result = true;
            }
            catch (System.Exception ex)
            {
                KSPMGlobals.Globals.Log.WriteTo(ex.Message);
                this.ableToRun = false;
            }
            return(result);
        }
Example #2
0
        protected void AsyncConnectionProccesComplete(System.IAsyncResult result)
        {
            ConnectAsync caller = (ConnectAsync)result.AsyncState;

            caller.EndInvoke(result);
            this.OnUserConnected(null);
            KSPMGlobals.Globals.Log.WriteTo(string.Format("[{0}]Connection complete", this.id));
        }
Example #3
0
 /// <summary>
 /// Create a retry policy for authentication execptions.
 /// </summary>
 private IAsyncPolicy CreateAuthenticationPolicy()
 {
     return(Policy
            .Handle <AuthenticationException>()
            .WaitAndRetryAsync(_options.RetryCount,
                               retryAttempt => GetSleepDuration(retryAttempt),
                               onRetry: async(exception, timeSpan, count, context) =>
     {
         _logger.LogWarning($"{exception.Message} Retry attempt {count} waiting {timeSpan.TotalSeconds} seconds before next retry.");
         await ConnectAsync.Invoke().ConfigureAwait(false);
     }));
 }