Ejemplo n.º 1
0
        /// <summary>
        /// Trims a response from the server and splits into an array so the actual data can be used/read.
        /// </summary>
        /// <param name="prefix"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string[] TrimAndSplitTcpResponse(DataPrefix prefix, string str)
        {
            // Trim the prefix and delimiter from the start of the response
            string response = str.Remove(0, prefix.GetDescription().Length).TrimStart(Constants.Delimiter.ToCharArray());

            // Trim the end of file tag
            response = response.TrimEnd("<EOF>".ToCharArray());

            // Split the data into an array
            string[] responseArray = response.Split(Convert.ToChar(Constants.Delimiter));

            return(responseArray);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a response to the client based on the results from the database
        /// </summary>
        /// <param name="prefix">The type of request that has been made</param>
        /// <param name="dbResponse">The response from the database</param>
        /// <returns></returns>
        private string BuildTcpResponse(DataPrefix prefix, Response dbResponse)
        {
            StringBuilder sb = new StringBuilder();

            if (dbResponse.Status == StatusCode.Success)
            {
                sb.Append(prefix.GetDescription());
                sb.Append(Constants.Delimiter);
                sb.Append(StatusCode.Success);
                sb.Append(Constants.Delimiter);
                sb.Append(Constants.EndOfFile);
            }
            else
            {
                sb.Append(prefix.GetDescription());
                sb.Append(Constants.Delimiter);
                sb.Append(StatusCode.Failure);
                sb.Append(Constants.Delimiter);
                sb.Append(dbResponse.Error);
                sb.Append(Constants.EndOfFile);
            }

            return(sb.ToString());
        }