예제 #1
0
                public void ReadSSET(out int LogUploadPeriod, out int LogMaxSize, out string AppTraceLevel, out string ComTraceLevel, bool optionalCloseConn = false)
                {
                    List <string> resps = SendCommand("SSET?", 1, optionalCloseConn);

                    string[] Vals = resps[0].Split('=');
                    if (Vals.Length != 2)
                    {
                        ResponseException ex = new ResponseException("Invalid response received.", "SSET?", resps);
                        LogMsg(TraceEventType.Warning, ex.ToString());
                        throw ex;
                    }

                    Vals = Vals[1].Split(',');

                    if (Vals.Length != 4)
                    {
                        ResponseException ex = new ResponseException("Invalid response received.", "SSET?", resps);
                        LogMsg(TraceEventType.Warning, ex.ToString());
                        throw ex;
                    }

                    try
                    {
                        LogUploadPeriod = Convert.ToInt32(Vals[0]);
                        LogMaxSize      = Convert.ToInt32(Vals[1]);
                        AppTraceLevel   = Vals[2];
                        ComTraceLevel   = Vals[3];
                    }
                    catch (Exception ex)
                    {
                        ResponseException exe = new ResponseException("Exception occured when parsing the response received.", "SSET?", resps, ex);
                        LogMsg(TraceEventType.Warning, exe.ToString());
                        throw ex;
                    }
                }
예제 #2
0
        public void TestNoStatusCode()
        {
            Response          response = new Response(null);
            ResponseException error    = new ResponseException(response);

            Assert.IsTrue(error.ToString() == "amadeus.exceptions.ResponseException: [---]");
        }
예제 #3
0
        public void ToString_does_include_response_message()
        {
            var response = new Response("Something bad happened.");
            var ex       = new ResponseException(response);

            Assert.Equal("ResponseException: ErrorMessage: Something bad happened.", ex.ToString());
        }
예제 #4
0
        public void ToString_does_indicate_success_string_if_response_success()
        {
            var response = new Response(success: true);
            var ex       = new ResponseException(response);

            Assert.Equal("ResponseException: Success: True", ex.ToString());
        }
예제 #5
0
                public string ReadCBT(string ID, BNAC_Table.ID_Type idType, bool optionalCloseConn = false)
                {
                    string        command = "CBT=" + BNAC_Table.CreateID(ID, idType) + "?";
                    List <string> resps   = SendCommand(command, 1, optionalCloseConn);

                    string[] Vals = resps[0].Split('=');
                    if (Vals.Length != 2)
                    {
                        ResponseException ex = new ResponseException("Invalid response received.", command, resps);
                        LogMsg(TraceEventType.Warning, ex.ToString());
                        throw ex;
                    }

                    return(Vals[1]);
                }
예제 #6
0
                public string SetSSET(string LogUploadPeriod, string LogMaxSize, string AppTraceLevel, string ComTraceLevel, bool optionalCloseConn = false, int optionalRetries = 3)
                {
                    string resp;
                    string command = "SSET=" + LogUploadPeriod + ","
                                     + LogMaxSize + ","
                                     + AppTraceLevel + ","
                                     + ComTraceLevel;

                    List <string> resps = SendCommand(command, 1, optionalRetries: optionalRetries);

                    if (resps[0].StartsWith("SSET="))
                    {
                        resp = resps[0].Substring(5);
                    }
                    else
                    {
                        ResponseException ex = new ResponseException("Invalid response received.", command, resps);
                        LogMsg(TraceEventType.Warning, ex.ToString());
                        throw ex;
                    }

                    return(resp);
                }
예제 #7
0
                public string ReadCBT(string ID, BNAC_Table.ID_Type idType, out BNAC_Table.Entry tableEntry, bool optionalCloseConn = false)
                {
                    string response = ReadCBT(ID, idType, optionalCloseConn);

                    if (response == "E" || response == "M")
                    {
                        tableEntry = null;      //not found or memory error!
                    }
                    else
                    {
                        try
                        {
                            tableEntry = new BNAC_Table.Entry(response.Split(','));
                        }
                        catch (Exception e)
                        {
                            ResponseException ex = new ResponseException("Exception occurred when trying to parse the CBT response.", "Inaccessible", response, e);
                            List <string>     re = new List <string>();
                            LogMsg(TraceEventType.Warning, ex.ToString());
                            throw ex;
                        }
                    }
                    return(response);
                }
예제 #8
0
                /// <summary>
                /// Send a command to a STXETX device
                /// </summary>
                /// <param name="command">The command to send</param>
                /// <param name="NumResponses">The number of STXETX replies required</param>
                /// <param name="optionalCloseConn">Set to true if the connection should be closed when this function is done. Default: false</param>
                /// <param name="optionalRetries">Number of retries to get the command sent. Default: 3</param>
                /// <param name="optionalTimeout">Timeout (in seconds) when waiting for an STXETX response. Default: 10 seconds</param>
                /// <returns></returns>
                public List <string> SendCommand(string command, int NumResponses = 0,
                                                 bool optionalCloseConn           = false, int optionalRetries = 3,
                                                 int optionalTimeout = 10)
                {
                    List <string> Responses = new List <string>();

                    try
                    {
                        while (optionalRetries-- > 0)
                        {
                            if (stxetxClient.SendCommand(command))
                            {
                                string reply  = null;
                                bool   result = true;
                                int    giveUp = NumResponses + 3;
                                while (result && Responses.Count < NumResponses && giveUp-- > 0)
                                {
                                    result = stxetxClient.ReceiveData(out reply, optionalTimeout * 1000);
                                    if (reply != null)
                                    {
                                        Responses.Add(reply);
                                    }
                                }
                                //see if we found all the responses we were looking for
                                if (Responses.Count < NumResponses)
                                {
                                    ResponseException ex = new ResponseException(
                                        "Did not receive the desired number of responses: found "
                                        + Responses.Count.ToString() + " of " + NumResponses.ToString(),
                                        command, Responses);

                                    LogMsg(TraceEventType.Warning, ex.ToString());
                                    throw ex;
                                }
                                break;
                            }
                            else if (optionalRetries < 1)
                            {
                                UnresponsiveConnectionException ex = new UnresponsiveConnectionException(
                                    "Failed to send the data: connection is unresponsive.", command);
                                LogMsg(TraceEventType.Warning, ex.ToString());
                                throw ex;
                            }
                        }
                    }
                    catch (Exception ee)
                    {
                        ResponseException ex = new ResponseException(
                            "Received an exception when trying to send or receive a command",
                            command, Responses, ee);

                        LogMsg(TraceEventType.Warning, ex.ToString());
                        throw ex;
                    }

                    finally
                    {
                        if (optionalCloseConn == true)
                        {
                            try { Dispose(); }
                            catch { }
                        }
                    }

                    return(Responses);
                }
예제 #9
0
        public void TestNilResponse()
        {
            ResponseException error = new ResponseException(null);

            Assert.IsTrue(error.ToString() == "amadeus.exceptions.ResponseException: [---]");
        }