/// <summary>
        /// Takes serialized version of the PowerMenuServiceRequestModel
        /// </summary>
        /// <param name="requests"></param>
        /// <returns></returns>
        public bool SendPowerMenuAccountRequests(PowerMenuSystemRequestModel request)
        {
            bool returnValue = false;

            using (HttpClient client = new HttpClient())
            {
                try
                {
                    System.Net.Http.HttpResponseMessage response = client.PostAsXmlAsync(Configuration.PowerMenuWebServiceUrl, request).Result;

                    var responseData = response.Content.ReadAsStringAsync();

                    if (response.StatusCode.Equals(System.Net.HttpStatusCode.OK) || response.StatusCode.Equals(System.Net.HttpStatusCode.NoContent))
                    {
                        returnValue = true;
                        _log.WriteInformationLog(string.Format("PowerMenu response: {0}", response.Content.ReadAsStringAsync().Result));
                    }
                    else
                    {
                        _log.WriteErrorLog(String.Format("Error communicating with powermenu service request: {0} - HttpResposne: {1}", request, response.StatusCode));
                        throw new Exception("There was an error communicating with the powermenu service");
                    }
                }
                catch (Exception ex)
                {
                    _log.WriteErrorLog("Error communicating with the powermenu service", ex);
                    throw new Exception("There was an error communicating with the powermenu service");
                }
            }

            return(returnValue);
        }
        public static string ToXML(this PowerMenuSystemRequestModel PowerMenuRequest)
        {
            string returnValue = "";

            using (MemoryStream stream = new MemoryStream()) {
                using (XmlWriter writer = XmlWriter.Create(stream)) {
                    // Remove the xmlns namespaces from the xml responses
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    ns.Add("", "");

                    new XmlSerializer(typeof(PowerMenuSystemRequestModel), string.Empty).Serialize(writer, PowerMenuRequest, ns);
                    returnValue = Encoding.UTF8.GetString(stream.ToArray());
                }
            }

            if (returnValue.Length > 0)
            {
                return(returnValue);
            }
            else
            {
                throw new Exception(String.Format("Serialization failed for Power Menu: {0}", returnValue));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Serialize and send xml object to PowerMenu
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 public bool SendAccountRequestToPowerMenu(PowerMenuSystemRequestModel request)
 {
     return(_pmRepository.SendPowerMenuAccountRequests(request));
 }