Esempio n. 1
0
        static bool AddHTTPTransaction(int ussdCampaignID, long ussdTransactionID, int menuID, string mobileNumber, string error, out long transactionID)
        {
            transactionID = -1;
            HTTPTransaction model = new HTTPTransaction
            {
                USSDTransactionId = ussdTransactionID,
                USSDCampaignId    = ussdCampaignID,
                MenuId            = menuID,
                MobileNumber      = mobileNumber,
                Errors            = error
            };

            //using (var command = DB.ExactUSSD.GetStoredProcCommand("usp_InsertHTTPTransaction"))
            //{
            //    DB.ExactUSSD.AddInParameter(command, "@USSDCampaignIDRef", System.Data.DbType.Int32, ussdCampaignID);
            //    DB.ExactUSSD.AddInParameter(command, "@USSDTransactionIDRef", System.Data.DbType.Int64, ussdTransactionID);
            //    DB.ExactUSSD.AddInParameter(command, "@MenuIDRef", System.Data.DbType.Int32, menuID);
            //    DB.ExactUSSD.AddInParameter(command, "@MobileNumber", System.Data.DbType.String, mobileNumber);

            //    if(!String.IsNullOrEmpty(error))
            //        DB.ExactUSSD.AddInParameter(command, "@Error", System.Data.DbType.String, error);
            //    using (var reader = DB.ExactUSSD.ExecuteReader(command))
            //    {
            //        if (reader.Read())
            //            hasAdded = ((transactionID = Convert.ToInt32(reader["transactionID"])) > 0);
            //    }
            //}
            Logic.Instance.HTTPTransactions.Insert(model);
            transactionID = model.Id;
            return(transactionID > 0 ? true :false);
        }
Esempio n. 2
0
        ///############################################################
        /// <summary>
        /// Retrieves an HTTP Transaction, including the file (message body) retrieved as part of the HTTP Request/Response.
        /// </summary>
        /// <param name="sURL">String representing the required URL.</param>
        /// <param name="oConfiguration">RequestConfiguration object representing the required HTTP Request configuration settings.</param>
        /// <returns>HTTPTransaction object representing the defined HTTP Request.</returns>
        ///############################################################
        /// <LastUpdated>September 1, 2007</LastUpdated>
        public static HTTPTransaction GetFile(string sURL, RequestConfiguration oConfiguration)
        {
            //#### .Connect to the sURL then collect the .Response's Stream
            HTTPTransaction oReturn = Connect(sURL, oConfiguration, "GET");

            oReturn.ResponseFile = oReturn.Response.GetResponseStream();

            //#### Return the above determined oReturn value to the caller
            return(oReturn);

/*
 *                      StreamReader oStreamReader;
 *                      string sFileContents;
 *
 *                              //#### Open the .GetResponseStream, reading it's sFileContents
 *                      oStreamReader = new StreamReader(m_oWebResponse.GetResponseStream());
 *                      sFileContents = oStreamReader.ReadToEnd();
 *
 *                              //#### Ensure we .Close the oConnection to clean up it's .WebRequest and .WebResponse
 *                      Close();
 *
 *                              //#### Convert the sFileContents back into a Stream to return to the caller
 * //! this conversion is WRONG!
 *                      return new MemoryStream( Encoding.ASCII.GetBytes(sFileContents) );
 */
        }
Esempio n. 3
0
        ///############################################################
        /// <summary>
        /// Retrieves an HTTP Transaction, containing only the configured HTTP Request.
        /// </summary>
        /// <param name="sURL">String representing the required URL.</param>
        /// <param name="oConfiguration">RequestConfiguration object representing the required HTTP Request configuration settings.</param>
        /// <returns>HTTPTransaction object representing the defined HTTP Request.</returns>
        ///############################################################
        /// <LastUpdated>September 11, 2007</LastUpdated>
        public static HTTPTransaction Get(string sURL, RequestConfiguration oConfiguration)
        {
            HTTPTransaction oReturn = new HTTPTransaction();

            //#### Setup the oReturn value with the passed sURL, it's related .Request and the .Timeout
            oReturn.URL             = sURL;
            oReturn.Request         = (HttpWebRequest)WebRequest.Create(sURL);
            oReturn.Request.Timeout = oConfiguration.Timeout;

            //#### If the passed oConfiguration has a .Proxy set, set it within the oReturn value
            if (oConfiguration.Proxy != null)
            {
                oReturn.Request.Proxy = oConfiguration.Proxy;
            }

            //#### If we are supposed to .UseBasicAuthorization in the .Request
            if (oConfiguration.UseBasicAuthorization)
            {
                //#### Determine the sBasicAuthHeader, .Encoding the ":" delimited sUsername/sPassword as a byte array as we go
//! Is there a specific advantage to utilize .ASCII in place of .Default?
// Encoding.Default.GetBytes(String.Format("{0}:{1}", sUsername, sPassword));
// Encoding.ASCII.GetBytes(String.Format("{0}:{1}", sUsername, sPassword));
                string sBasicAuthHeader = "Basic " +
                                          Convert.ToBase64String(Encoding.ASCII.GetBytes(oConfiguration.Username + ":" + oConfiguration.Password)
                                                                 );

                //#### .Add the sBasicAuthHeader into the oReturn value's .Request
                oReturn.Request.Headers.Add("Authorization", sBasicAuthHeader);
            }

            //#### Return the above determined oReturn value to the caller
            return(oReturn);
        }
Esempio n. 4
0
        ///############################################################
        /// <summary>
        /// Retrieves an HTTP Transaction, containing only the HTTP Header information retrieved as part of the HTTP Request/Response.
        /// </summary>
        /// <param name="sURL">String representing the required URL.</param>
        /// <param name="oConfiguration">RequestConfiguration object representing the required HTTP Request configuration settings.</param>
        /// <returns>HTTPTransaction object representing the defined HTTP Request.</returns>
        ///############################################################
        /// <LastUpdated>September 1, 2007</LastUpdated>
        public static HTTPTransaction GetHeaders(string sURL, RequestConfiguration oConfiguration)
        {
            //#### .Connect to the sURL, signaling the request to only retreve the HEADers
            HTTPTransaction oReturn = Connect(sURL, oConfiguration, "HEAD");

            //#### Ensure we .Close the request to clean up the open connections/handles/etc.
            oReturn.Close();

            //#### Return the above determined oReturn value to the caller
            return(oReturn);
        }