Exemplo n.º 1
0
 public CommandException(CommandErrorCode errorCode, string message)
     : base(message)
 {
     ErrorCode = errorCode;
 }
Exemplo n.º 2
0
        protected IEnumerable <string> getResponses()
        {
            bool completata = false;

            if (!Connected)
            {
                error_message = Properties.Messaggi.erroreConnessioneServer;
                error_code    = ServerErrorCode.ConnessioneInterrotta;
                yield return(null);

                yield break;
            }
            while (!completata)
            {
                //Prima linea con codice di errore
                string response = control_stream_reader.ReadLine();
                if (response == null)
                {
                    error_message = Properties.Messaggi.erroreConnessioneServer;
                    error_code    = ServerErrorCode.ConnessioneInterrotta;
                    control_stream_reader.Close();
                    Connected = false;
                    yield return(null);

                    yield break;
                }
                response = response.Trim();
                CommandErrorCode errorCode = (CommandErrorCode)Int32.Parse(response.Split(' ')[0]); //Extract code from response
                switch (errorCode)
                {
                case CommandErrorCode.OK:
                    completata = true;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                        yield return(response);
                    } while (response != null && response.Length > 0);
                    if (response == null)
                    {
                        error_message = Properties.Messaggi.erroreConnessioneServer;
                        error_code    = ServerErrorCode.ConnessioneInterrotta;
                        control_stream_reader.Close();
                        Connected = false;
                        yield break;
                    }
                    break;

                case CommandErrorCode.OKIntermedio:
                    do
                    {
                        response = control_stream_reader.ReadLine();
                        yield return(response);
                    } while (response != null && response.Length > 0);
                    if (response == null)
                    {
                        error_message = Properties.Messaggi.erroreConnessioneServer;
                        error_code    = ServerErrorCode.ConnessioneInterrotta;
                        control_stream_reader.Close();
                        Connected = false;
                        yield break;
                    }
                    break;

                case CommandErrorCode.FormatoDatiErrato:
                    error_message = Properties.Messaggi.formatoDatiErrato;
                    error_code    = ServerErrorCode.FormatoDatiErrato;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.UtenteNonLoggato:
                    error_message = Properties.Messaggi.nonLoggato;
                    error_code    = ServerErrorCode.UtenteNonLoggato;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.FileEsistente:
                    error_message = Properties.Messaggi.fileEsistente;
                    error_code    = ServerErrorCode.FileEsistente;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.LimiteFileSuperato:
                    error_message = Properties.Messaggi.limiteFileSuperato;
                    error_code    = ServerErrorCode.LimiteFileSuperato;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.DatiIncompleti:
                    error_message = Properties.Messaggi.datiInconsistenti;
                    error_code    = ServerErrorCode.DatiIncompleti;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.DatiErrati:
                    error_message = Properties.Messaggi.datiErrati;
                    error_code    = ServerErrorCode.DatiErrati;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                case CommandErrorCode.MomentoSbagliato:
                    error_message = Properties.Messaggi.momentoSbagliato;
                    error_code    = ServerErrorCode.MomentoSbagliato;
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    yield return(null);

                    yield break;

                default:
                    do
                    {
                        response = control_stream_reader.ReadLine();
                    }while (response != null && response.Length > 0);
                    throw new ServerException(Properties.Messaggi.erroreServer, ServerErrorCode.Default);
                }
            }
        }
Exemplo n.º 3
0
 public CommandException(CommandErrorCode errorCode, string message)
     : base(message)
 {
     ErrorCode = errorCode;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandException"/> class.
 /// </summary>
 /// <param name="message">The description of the exception.</param>
 /// <param name="commandLine">The command line that was input.</param>
 /// <param name="errorCode">The type of error that occured.</param>
 /// <param name="innerException">The exception that was thrown.</param>
 public CommandException(string message, string commandLine, CommandErrorCode errorCode, Exception innerException)
     : base(message, innerException)
 {
     CommandLine = commandLine;
     ErrorCode   = errorCode;
 }