Esempio n. 1
0
 internal static void WriteApiTransactionsNode(XmlWriter oXmlTextWriter, API_TRANSACTIONS apiTransactions)
 {
     try
     {
         oXmlTextWriter.WriteStartElement("yesws:table");
         oXmlTextWriter.WriteElementString("yesws:name", "api_transactions");
         oXmlTextWriter.WriteStartElement("yesws:rows");
         oXmlTextWriter.WriteStartElement("yesws:row");
         oXmlTextWriter.WriteStartElement("yesws:columns");
         WriteColumnNode(oXmlTextWriter, "transactionid", transactionID);
         WriteColumnNode(oXmlTextWriter, "email", email);
         if (!string.IsNullOrEmpty(apiTransactions.type))
         {
             WriteColumnNode(oXmlTextWriter, "type", apiTransactions.type);
         }
         if (!string.IsNullOrEmpty(apiTransactions.brand))
         {
             WriteColumnNode(oXmlTextWriter, "brand", apiTransactions.brand);
         }
         WriteColumnNode(oXmlTextWriter, "mmid", Convert.ToString(apiTransactions.mmid));
         WriteColumnNode(oXmlTextWriter, "lastupdatedate", DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.f"));
         oXmlTextWriter.WriteEndElement();
         oXmlTextWriter.WriteEndElement();
         oXmlTextWriter.WriteEndElement();
         oXmlTextWriter.WriteEndElement();
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Esempio n. 2
0
        public static int TriggerMail(USERS userDetails, API_TRANSACTIONS apiTransactions,
                                      API_CONFIRMATIONS apiConfirmations, API_PROMOS apiPromos)
        {
            transactionID = DateTime.Now.ToString("ddhhmmssff");
            HttpWebRequest request = null;
            HttpWebRequest request2 = null;
            var num = 0;
            var num2 = 0;
            try
            {
                var s = CreateXMLData(userDetails, apiTransactions, apiConfirmations, apiPromos);
                request = (HttpWebRequest) WebRequest.Create(ysApiURL);
                request.Method = "POST";
                request.ContentType = "application/xml; charset=UTF-8; type=entry";
                request.Timeout = 0x30d40;
                var cache = new CredentialCache();
                cache.Add(new Uri(ysApiURL), "Basic",
                          new NetworkCredential(ysApiDomain + "/" + ysApiUsername, ysApiPassword));
                request.Credentials = cache;
                var proxy = new WebProxy(proxyAddress)
                                {
                                    Credentials = new NetworkCredential(proxyUsername, proxyPassword, proxyDomain)
                                };
                request.Proxy = proxy;
                var requestStream = request.GetRequestStream();
                var bytes = new UTF8Encoding().GetBytes(s);
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Flush();
                requestStream.Close();
                var response = request.GetResponse();
                var response2 = (HttpWebResponse) response;
                var responseStream = response.GetResponseStream();
                var reader2 = new StreamReader(responseStream);
                var reader3 = XmlReader.Create(new StringReader(reader2.ReadToEnd()));
                while (reader3.Read())
                {
                    _logger.Debug("\nReader3 Value: " + reader3.Value + "\n");
                    if (reader3.IsStartElement() && ((reader3.Name == "yesws:statusCode") && reader3.Read()))
                    {
                        if (reader3.Value.ToLower().Trim() == Constants.submittedText)
                        {
                            num = 1;
                        }
                        else
                        {
                            num = 0;
                        }
                    }
                    if (((num == 1) && reader3.IsStartElement()) &&
                        ((reader3.Name == "yesws:statusURI") && reader3.Read()))
                    {
                        statusURL = reader3.Value.ToLower().Trim();
                        request2 = (HttpWebRequest) WebRequest.Create(statusURL);
                        request2.Method = "GET";
                        request2.Timeout = 0x30d40;
                        var cache2 = new CredentialCache();
                        cache2.Add(new Uri(statusURL), "Basic",
                                   new NetworkCredential(ysApiDomain + "/" + ysApiUsername, ysApiPassword));
                        request2.Credentials = cache2;
                        request2.Proxy = proxy;
                        var response3 = request2.GetResponse();
                        var response4 = (HttpWebResponse) response3;
                        var stream = response3.GetResponseStream();
                        var reader4 = new StreamReader(stream);
                        var reader = XmlReader.Create(new StringReader(reader4.ReadToEnd()));
                        while (reader.Read())
                        {
                            _logger.Debug("\n InnerReader Value: " + reader.Value + "\n");

                            if (reader.IsStartElement() && ((reader.Name == "yesws:statusCode") && reader.Read()))
                            {
                                if (reader.Value.ToLower().Trim() == Constants.CompletedText)
                                {
                                    num2 = 1;
                                }
                                else
                                {
                                    num2 = 0;
                                }
                            }
                        }
                        reader.Close();
                        stream.Close();
                        response3.Close();
                    }
                }
                reader2.Close();
                responseStream.Close();
                response.Close();
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return num2;
        }
Esempio n. 3
0
 internal static string CreateXMLData(USERS userDetails, API_TRANSACTIONS apiTransactions,
                                      API_CONFIRMATIONS apiConfirmations, API_PROMOS apiPromos)
 {
     string str2;
     try
     {
         email = userDetails.email;
         if (apiConfirmations != null)
         {
             transactionTable = Constants.ApiConfirmationsTable;
         }
         else if (apiPromos != null)
         {
             transactionTable = Constants.ApiPromosTable;
         }
         var sb = new StringBuilder();
         var w = new StringWriter(sb);
         var oXmlTextWriter = new XmlTextWriter(w);
         string str = null;
         oXmlTextWriter.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
         oXmlTextWriter.WriteStartElement("yesws:subscribeAndSend");
         oXmlTextWriter.WriteAttributeString("xmlns:yesws", "https://services.yesmail.com");
         oXmlTextWriter.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
         oXmlTextWriter.WriteAttributeString("xsi:schemaLocation",
                                             "https://services.yesmail.com docs/xsd/subscribeandsend.xsd");
         oXmlTextWriter.WriteAttributeString("schemaVersion", "1.0");
         WriteSubscriberNode(oXmlTextWriter, userDetails);
         oXmlTextWriter.WriteStartElement("yesws:sideTable");
         WriteApiTransactionsNode(oXmlTextWriter, apiTransactions);
         if (transactionTable == Constants.ApiConfirmationsTable)
         {
             WriteApiConfirmationsNode(oXmlTextWriter, apiConfirmations);
         }
         else if (transactionTable == Constants.ApiPromosTable)
         {
             WriteApiPromosNode(oXmlTextWriter, apiPromos);
         }
         oXmlTextWriter.WriteEndElement();
         oXmlTextWriter.WriteStartElement("yesws:subscriberMessage");
         oXmlTextWriter.WriteElementString("yesws:masterId", Convert.ToString(apiTransactions.mmid));
         oXmlTextWriter.WriteEndElement();
         oXmlTextWriter.WriteEndElement();
         str = w.ToString();
         oXmlTextWriter.Close();
         w.Flush();
         sb.Length = 0;
         str2 = str;
     }
     catch (Exception exception)
     {
         throw exception;
     }
     _logger.Debug("CreateXML: " + str2);
     return str2;
 }