Example #1
0
        public void SendMessage(Message message, IErrorMessageLog errorLog)
        {
            if (string.IsNullOrEmpty(message.Guid) || string.IsNullOrEmpty(_connectionString))
                return;
            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    if (!_tableExists)
                    {
                        CreateTable(connection);
                    }

                    using (var cmd = new SqlCommand("insert into ProxyGluedApiLog (Guid, Description) values (@Guid, @Description)", connection))
                    {
                        cmd.Parameters.AddWithValue("@Guid", message.Guid);
                        cmd.Parameters.AddWithValue("@Description", DateTime.Now);
                        var rowAffected = cmd.ExecuteNonQuery();

                        message.StatusCode = rowAffected > 0 ?
                            HttpStatusCode.OK : HttpStatusCode.NotAcceptable;
                    }
                }
            }
            catch (Exception ex)
            {
                message.StatusCode = HttpStatusCode.NotAcceptable;
                errorLog.Write(message, ex.Message);
            }
        }
Example #2
0
        public void SendMessage(Message message, IErrorMessageLog errorLog)
        {
            var requestUri = GetRequestUri(message.CustomerGuid, message.Credentials);
            if (message.Content.Length < 50)
            {
                message.StatusCode = HttpStatusCode.NoContent;
                errorLog.Write(message, "Content is invalid");
                return;
            }

            var data = Encoding.UTF8.GetBytes(message.Content);
            var request = (HttpWebRequest)WebRequest.Create(requestUri);
            request.ContentType = "application/xml";
            request.Method = "POST";

            if (!string.IsNullOrEmpty(message.Guid))
                request.Headers.Add("X-Flex-Message-Id", message.Guid);

            request.GetRequestStream().Write(data, 0, data.Length);
            request.GetRequestStream().Close();

            try
            {
                using (var webResponse = (HttpWebResponse)request.GetResponse())
                {
                    var responseStream = webResponse.GetResponseStream();
                    if (responseStream != null)
                    {
                        message.StatusCode = webResponse.StatusCode;
                    }

                    if (!message.StatusCode.Equals(HttpStatusCode.OK))
                    {
                        errorLog.Write(message, webResponse.StatusDescription);
                    }
                }
            }
            catch (Exception ex)
            {
                message.StatusCode = HttpStatusCode.NotAcceptable;
                errorLog.Write(message, ex.Message);
            }
        }
Example #3
0
        public void SendMessage(Message message, IErrorMessageLog errorLog)
        {
            var fileName = Path.Combine(Path.GetTempPath(), "LogGluedApiProxy.txt");
            var sb = new StringBuilder();
            sb.Append(DateTime.Now);
            sb.Append(" Guid = ");
            sb.Append(message.Guid);
            sb.AppendLine();

            try
            {
                File.AppendAllText(fileName, sb.ToString());
                message.StatusCode = HttpStatusCode.OK;
            }
            catch(Exception ex)
            {
                message.StatusCode = HttpStatusCode.NotAcceptable;
                errorLog.Write(message, ex.Message);
            }
        }