/// <summary> /// Post back the http data to the specified request. /// </summary> /// <param name="requestUri">The request uri.</param> /// <param name="postData">The http data to post back.</param> /// <param name="responseStreamProcessor">The response delegate method.</param> /// <returns>The http status code.</returns> public virtual HttpStatusCode Post(string requestUri, string postData, Nequeo.Threading.ActionHandler <Stream> responseStreamProcessor) { return(Post(requestUri, new DefaultRequestStreamProcessor(postData, _connection).Process, responseStreamProcessor)); }
/// <summary> /// Execute a select action /// </summary> /// <param name="action">The select action to execute.</param> public void Select(Nequeo.Threading.ActionHandler <ISelectDataSetGenericBase <TDataContext, TDataTable> > action) { // Check to see if the critical parameters // have been set, throw exception on each. if (action == null) { throw new ArgumentNullException("action"); } if (_selectInstance == null) { throw new ArgumentNullException("selectInstance"); } _selectInstance.ConfigurationDatabaseConnection = _configurationDatabaseConnection; action(_selectInstance); }
/// <summary> /// Execute an update action /// </summary> /// <param name="action">The update action to execute.</param> public void Update(Nequeo.Threading.ActionHandler <IUpdateEdmGenericBase <TDataContext, TLinqEntity> > action) { // Check to see if the critical parameters // have been set, throw exception on each. if (action == null) { throw new ArgumentNullException("action"); } if (_updateInstance == null) { throw new ArgumentNullException("updateInstance"); } _updateInstance.DataContext = new TDataContext(); _updateInstance.DataContext.Database.Connection.ConnectionString = _insertInstance.DefaultConnection(_configurationDatabaseConnection); action(_updateInstance); }
/// <summary> /// Execute a select action /// </summary> /// <param name="action">The select action to execute.</param> /// <param name="lazyLoading">Should lazy loading of references be applied.</param> public void Select(Nequeo.Threading.ActionHandler <ISelectEdmGenericBase <TDataContext, TLinqEntity> > action, Boolean lazyLoading = false) { // Check to see if the critical parameters // have been set, throw exception on each. if (action == null) { throw new ArgumentNullException("action"); } if (_selectInstance == null) { throw new ArgumentNullException("selectInstance"); } _selectInstance.DataContext = new TDataContext(); _selectInstance.DataContext.Configuration.LazyLoadingEnabled = lazyLoading; _selectInstance.DataContext.Database.Connection.ConnectionString = _insertInstance.DefaultConnection(_configurationDatabaseConnection); action(_selectInstance); }
/// <summary> /// Post back the http data to the specified request. /// </summary> /// <param name="requestUri">The request uri.</param> /// <param name="requestStreamProcessor">The request delegate method.</param> /// <param name="responseStreamProcessor">The response delegate method.</param> /// <returns>The http status code.</returns> public virtual HttpStatusCode Post( string requestUri, Nequeo.Threading.ActionHandler <Stream> requestStreamProcessor, Nequeo.Threading.ActionHandler <Stream> responseStreamProcessor) { // Make an initial post to the request uri Request(requestUri, "POST", requestStreamProcessor, responseStreamProcessor); // Loop making requests until // the correct response is made // by the http server. for (int i = 0; i < 10; i++) { bool post = false; // Get the response status code switch (StatusCode) { case HttpStatusCode.MultipleChoices: // 300 case HttpStatusCode.MovedPermanently: // 301 case HttpStatusCode.Found: // 302 case HttpStatusCode.SeeOther: // 303 break; case HttpStatusCode.TemporaryRedirect: // 307 post = true; break; default: return(StatusCode); } // If a null location is sent back // then exit the loop. if (_location == null) { break; } // Create the new request uri Uri uri = new Uri(new Uri(PreviousUri), _location); // Construct the new request uri for the // redirection post back. _baseUri = uri.Scheme + "://" + uri.Host; requestUri = uri.AbsolutePath + uri.Query; // If the redirection was sent back // then get the http request and on the // next loop post the data to the new http // request uri. Request( requestUri, post ? "POST" : "GET", post ? requestStreamProcessor : null, responseStreamProcessor); } // Return the http status code. return(StatusCode); }
/// <summary> /// Get the specified http request. /// </summary> /// <param name="requestUri">The request uri.</param> /// <param name="responseStreamProcessor">The response delegate method.</param> /// <returns>The http status code.</returns> public virtual HttpStatusCode Get(string requestUri, Nequeo.Threading.ActionHandler <Stream> responseStreamProcessor) { return(Request(requestUri, "GET", null, responseStreamProcessor)); }
/// <summary> /// Initiate the http request. /// </summary> /// <param name="requestUri">The request uri.</param> /// <param name="method">The http request method.</param> /// <param name="requestStreamProcessor">The request delegate method.</param> /// <param name="responseStreamProcessor">The response delegate method.</param> /// <returns>The http status code.</returns> public virtual HttpStatusCode Request(string requestUri, string method, Nequeo.Threading.ActionHandler <Stream> requestStreamProcessor, Nequeo.Threading.ActionHandler <Stream> responseStreamProcessor) { // Get the base uri from the adapter _html = ""; _baseUri = _connection.HttpHost; string uri = _baseUri; // If the request is not a SOAP call // then append the request uri to the base uri if (method != "SOAP") { uri += requestUri; } Uri requestRes = new Uri(uri); // Check if the URI is valid HTTP scheme. if ((requestRes.Scheme != Uri.UriSchemeHttp) && (requestRes.Scheme != Uri.UriSchemeHttps)) { throw new ArgumentException("Uri is not a valid HTTP scheme"); } // Create a new web request call. HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(uri); if (_connection.Proxy != null) { request.Proxy = _connection.Proxy; } // If the http connection is not // anonymous then create a new // network credential. if (_connection.Authentication != Nequeo.Net.Http.AuthenticationType.None) { if (_connection.Authentication != Nequeo.Net.Http.AuthenticationType.Anonymous) { request.Credentials = Credentials; } else { request.UseDefaultCredentials = true; } } // Assign the request properties. request.CookieContainer = CookieContainer; request.UserAgent = UserAgent; request.Accept = Accept; request.Method = method == "SOAP" ? "POST" : method; request.KeepAlive = true; // Create a new service point manger to // validate the certificate. ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(OnCertificateValidation); // If referer http header is set // then get the prevoius uri if null. if (SendReferer) { request.Referer = PreviousUri ?? uri; } // For each type of header request. foreach (string key in Headers.Keys) { request.Headers.Add(key, Headers[key].ToString()); } // If the request method is post. if (method == "POST") { // Assign the content type as post back content. request.ContentType = "application/x-www-form-urlencoded"; request.AllowAutoRedirect = false; } else if (method == "SOAP") { // Assign SOAP content type request.ContentType = "text/xml; charset=utf-8"; request.AllowAutoRedirect = false; // Set the SOAP action and request uri. request.Headers.Add("SOAPAction", requestUri); } else { // Assign the default content type. request.ContentType = ContentType; request.AllowAutoRedirect = true; } // Set the previous uri to the current // and the request uri to the current. _previousUri = uri; _requestUri = request.RequestUri; // If a client certificate is to be used // add the client certificate. if (_connection.ClientCertificate != null) { request.ClientCertificates.Add(_connection.ClientCertificate); } // If a time out has been set if (_connection.TimeOut > -1) { request.Timeout = _connection.TimeOut; } // Get the request stream, initialise a new request, // invoke the request delegate method. if (requestStreamProcessor != null) { using (Stream st = request.GetRequestStream()) requestStreamProcessor(st); } // Initialise a new response stream from the request. using (HttpWebResponse resp = (HttpWebResponse)request.GetResponse()) using (Stream sm = resp.GetResponseStream()) { _statusCode = resp.StatusCode; _location = resp.Headers["Location"]; // Set the base uri if (resp.ResponseUri.AbsoluteUri.StartsWith(BaseUri) == false) { _baseUri = resp.ResponseUri.Scheme + "://" + resp.ResponseUri.Host; } // Get the collection of cookies CookieCollection cc = request.CookieContainer.GetCookies(request.RequestUri); // This code fixes the situation when a server sets a cookie without the 'path'. // IE takes this as the root ('/') value, the HttpWebRequest class as the // RequestUri.AbsolutePath value. foreach (Cookie c in cc) { if (c.Path == request.RequestUri.AbsolutePath) { CookieContainer.Add(new Cookie(c.Name, c.Value, "/", c.Domain)); } } // Invoke the response delegate method. if (responseStreamProcessor != null) { responseStreamProcessor(sm); } } // Return the http status code. return(StatusCode); }
/// <summary> /// Email message constructor. /// </summary> /// <param name="position">The position of the message.</param> /// <param name="size">The size of the complete message.</param> /// <param name="headersOnly">The should only header data be returned.</param> /// <param name="headerLineCount">The number of header data lines to return.</param> /// <param name="client">The current client socket.</param> /// <param name="sslStream">The current secure socket layer client.</param> /// <param name="message">The message object that will contain the message data.</param> /// <param name="writeAttachmentToFile">Write the attachment to file.</param> /// <param name="rawEmailMessageOnly">Get the complete raw email message only.</param> /// <param name="connection">The current connection object.</param> /// <param name="callbackHandler">The progress call back handler.</param> public EmailMessage(long position, long size, bool headersOnly, long headerLineCount, Socket client, SslStream sslStream, Message message, bool writeAttachmentToFile, bool rawEmailMessageOnly, Pop3ConnectionAdapter connection, Nequeo.Threading.ActionHandler <long> callbackHandler) { try { _size = size; _client = client; _sslStream = sslStream; _connection = connection; _inboxPosition = position; _headersOnly = headersOnly; _headerLineCount = headerLineCount; _callbackHandler = callbackHandler; _rawEmailMessageOnly = rawEmailMessageOnly; _writeAttachmentToFile = writeAttachmentToFile; // Load the email asynchronously. // This point is blocked until the // receive is complete. LoadEmail(message); // If the decoded email message is // to be returned. if (!rawEmailMessageOnly) { // Get body (if it exists) IEnumerator multipartEnumerator = MultipartEnumerator; // For each multipart content, including // attachments iterate through the array. while (multipartEnumerator.MoveNext()) { // Get the multipart object index. MessageAttachment multipart = (MessageAttachment) multipartEnumerator.Current; // If this multipart object is a body type // then get the data stored. if (multipart.IsBody) { _body = multipart.Data; } // If this multipart object is an attachment type // then add the file name to the collection. if (multipart.IsAttachment) { // Create a new attachment class // and add the file data. Attachment attachment = new Attachment() { FileName = multipart.Filename, File = multipart.FileData, FileExtention = multipart.FileExtension, FileNoExtention = multipart.FileNoExtension, Name = multipart.Name, ContentTransferEncoding = multipart.ContentTransferEncoding, Decoded = multipart.Decoded, ContentDescription = multipart.ContentDescription, ContentType = multipart.ContentType }; // Add the attachment to the list. message.Attachments.Add(attachment); } } // Load the message data into the // message class. message.To = _to; message.Cc = _cc; message.Bcc = _bcc; message.Size = _size; message.Date = _date; message.From = _from; message.Subject = _subject; message.ReplyTo = _replyTo; message.Priority = _priority; message.Received = _received; message.ReturnPath = _returnPath; message.Importance = _importance; message.IsMultipart = _isMultipart; message.Organization = _organization; message.InboxPosition = _inboxPosition; // If the message body is a html message. if (_body.IndexOf("<html") > -1) { // A html message has been sent. message.MessageType = Nequeo.Net.Mail.MessageType.Html; // Get the starting index of the string // and the ending index of the string. int start = _body.IndexOf("<html"); int end = _body.LastIndexOf("</html>") + 7; // Extract only the html part of the message body. message.Body = _body.Substring(start, end - start); } else if (_body.IndexOf("<HTML") > -1) { // A rich text or html message has been sent. message.MessageType = Nequeo.Net.Mail.MessageType.RichText; // Get the starting index of the string // and the ending index of the string. int start = _body.IndexOf("<HTML"); int end = _body.LastIndexOf("</HTML>") + 7; // Extract only the html part of the message body. message.Body = _body.Substring(start, end - start); } else if (_body.ToLower().IndexOf("<xml") > -1) { // A xml message has been sent. message.MessageType = Nequeo.Net.Mail.MessageType.Xml; // Get the starting index of the string // and the ending index of the string. int start = _body.ToLower().IndexOf("<xml"); int end = _body.ToLower().LastIndexOf("</xml>") + 6; // Extract only the xml part of the message body. message.Body = _body.Substring(start, end - start); } else { // A normal text message has been sent. message.MessageType = Nequeo.Net.Mail.MessageType.Text; message.Body = _body; } } } catch (Exception ex) { throw new Exception(ex.Message); } }