Beispiel #1
0
        private void WriteXmlFile(PaymentOrders_Response formattedResponse)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(PaymentOrders_Response));
            string        sXml, sXmlFilePath;
            XmlDocument   xmlDocument = new XmlDocument();

            using (var stringWriter = new StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(stringWriter))
                {
                    xmlSerializer.Serialize(writer, formattedResponse);
                    sXml = stringWriter.ToString();

                    xmlDocument.LoadXml(sXml);
                    //C:\Users\samer.azar\Desktop\test\TATAPPO_{0}{1}_{2}.xml => TATAPPO_<<PONum>><<Date of File PreparationYYYYMMDD>>_<<incremental#>>.XML
                    sXmlFilePath = string.Format(
                        Helper.GetRegistryKeyValue(Constants._PioRegistryPath,
                                                   Constants._Pio_AccountPayable_SftpPath),
                        formattedResponse.Message.Select(x => x.INVOICE_NUM).FirstOrDefault(),
                        DateTime.Today.ToString("yyyyMMdd"),
                        1);
                    if (!File.Exists(sXmlFilePath))
                    {
                        xmlDocument.Save(sXmlFilePath);
                    }
                }
            }
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            string sUrl;
            HttpResponseMessage         response;
            PaymentOrder_Response       formattedResponse;
            PaymentOrders_Response      finalResponse;
            List <List <PaymentOrder> > paymentOrders;

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
                // Compose the URL
                client.BaseAddress = new Uri(Helper.GetRegistryKeyValue(Constants._PioRegistryPath, Constants._PioServer));
                // AccountPayablePath in Registry = api/AccountsPayable/PaymentOrders?payerId={0}&dateFrom={1}&dateTo={2}
                sUrl = string.Format("{0}{1}",
                                     client.BaseAddress,
                                     string.Format(Helper.GetRegistryKeyValue(Constants._PioRegistryPath, Constants._Pio_AccountPayable),
                                                   301,
                                                   "2018-04-01T00:00:00",
                                                   "2018-04-03T00:00:00"));

                response = client.GetAsync(sUrl).Result;
                if (response.IsSuccessStatusCode)
                {
                    formattedResponse = JsonConvert.DeserializeObject <PaymentOrder_Response>(response.Content.ReadAsStringAsync().Result);
                    if (!formattedResponse.Message.GetType().Equals(typeof(string)))
                    {
                        formattedResponse = new PaymentOrder_Response(
                            formattedResponse.SuccessCode,
                            JsonConvert.DeserializeObject <List <List <PaymentOrder> > >(formattedResponse.Message.ToString()));
                        paymentOrders = (List <List <PaymentOrder> >)formattedResponse.Message;

                        foreach (List <PaymentOrder> paymentOrderList in paymentOrders)
                        {
                            finalResponse = new PaymentOrders_Response(formattedResponse.SuccessCode, paymentOrderList);
                            WriteXmlFile(finalResponse);
                        }
                    }
                }
            }
        }