EDN Admin
Well-known member
I am trying to utilize a pause in my code.
The code works correctly, sleep occurs in the wrong space.
Id like everything in the btnBuildXML_Click method to complete. Once everything has completed, then I would like the sleep to be invoked for 15 seconds, and then start the GetMessageDeliveryStatus process.
In the current placement in the code, it makes everything sleep for 15 seconds, then completes.
How can I get the btnBuildXML_Click to complete entirely, sleep for 15 seconds, then invoke the GetMessageDeliveryStatus method.
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//Added:
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Text.RegularExpressions;
using System.Text;
using System.Windows.Browser;
using System.Collections;
using System.ComponentModel;
using Messaging.Web;
namespace Messaging
{
public partial class MainPage : UserControl
{
//User Input Selection
public string pkPersonnelType; //This needs to be substituted with the collection variable
public string pkPersonnelId; //This needs to be substituted with the collection variable
public string groupId; //This needs to be substituted with the collection variable
public string groupName; //This needs to be substituted with the collection variable
public string SendToUserName; //This needs to be substituted with the collection variable
public string messagetype; //This to come from Form
//System Variables:
public string PostURL;
public string ClientUserName;
public string SprintPassword;
public string SourceClientUser;
public string SourceClientIPAddress;
public string SourceClientBrowser;
public string TimeStampSubmit;
public string TimeStampResponse;
public string IsoSendToRequest;
public string IsoSendToResponse;
public string IsoDeliveryRequest;
public string IsoDeliveryResponse;
public string messageID;
public string messageKey;
public XDocument xDocSendToRequest;
public XDocument xDocSendToResponse;
public XDocument xDocDeliveryResponse;
//Tenative:
public string flag; //For Determining Query: Submit Send To; Submit Delivery Request
public string Platform
{
get { return (string)GetValue(PlatformProperty); }
set { SetValue(PlatformProperty, value); }
}
public static readonly DependencyProperty PlatformProperty = DependencyProperty.Register("Platform", typeof(string), typeof(MainPage), new PropertyMetadata(string.Empty));
public string BrowserInformation { get { return (string)GetValue(BrowserInformationProperty); } set { SetValue(BrowserInformationProperty, value); } }
public static readonly DependencyProperty BrowserInformationProperty = DependencyProperty.Register("BrowserInformation", typeof(string), typeof(MainPage), new PropertyMetadata(string.Empty));
//Temporary Place holder in lieu of collection
string[] recipients = { "Recipient1", "Recipient2", "Recipient3" };
public MainPage()
{
InitializeComponent();
//System Variables
PostURL = "http://123.jsp";
ClientUserName = "abc";
ClientPassword = "17221";
IsoSendToRequest = "SprintOutput.xml";
IsoSendToResponse = "Response.xml";
IsoDeliveryRequest = "DeliveryRequest.xml";
//User Inputs:
txtMessage.Text = "Enter Message Here..."; //This comes from the form
txtSubject.Text = "Text Message from User: "; //This comes from the form
txtPhone.Text = "8005551212"; //This will Come from the selected users or groups in Collection
SendToUserName = "Send To User Name is Here..."; //This will Come from the selected users or groups in Collection
//This can predicated on a checkbox:
messagetype = "SMS";
//This will not show True Info until running from the WebServer (Not Local Debugging)
SourceClientUser = App.UserID; // App.Current.Resources["username"].ToString();
SourceClientBrowser = "";
SourceClientIPAddress = "";//App.Current.Resources["txtUserIP"].ToString();
var browserInfo = HtmlPage.BrowserInformation;
BrowserInformation = "You are using " + browserInfo.Name + " (Product Name: " + browserInfo.ProductName + " - " + browserInfo.ProductVersion + ") Version: " + browserInfo.BrowserVersion;
Platform = "You are on " + browserInfo.Platform + " platform and using User Agent: " + browserInfo.UserAgent;
flag = "S";
}
//Ensure that they dont click button more than once in a specified time frame to avoid duplicate messages:
private void btnBuildXML_Click(object sender, RoutedEventArgs e)
{
//Set the Submit Time:
TimeStampSubmit = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
//Create Send To XML Packet:
XDocument xDocSendToBuild = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XComment("SPRINT EMG Version 1.6 Output XML"),
new XElement("TELEMESSAGE",
new XElement("TELEMESSAGE_CONTENT",
new XElement("MESSAGE",
new XElement("MESSAGE_INFORMATION",
new XElement("SUBJECT", txtSubject.Text),
new XElement("TIME_STAMP", TimeStampSubmit)),
new XElement("USER_FROM",
new XElement("CIML",
new XElement("NAML",
new XElement("LOGIN_DETAILS",
new XElement("USER_NAME", ClientUserName),
new XElement("PASSWORD", ClientPassword))))),
new XElement("MESSAGE_CONTENT",
new XElement("TEXT_MESSAGE",
new XElement("MESSAGE_INDEX", 0),
new XElement("TEXT", txtMessage.Text))),
new XElement("USER_TO",
new XElement("CIML",
new XElement("DEVICE_INFORMATION",
//Insert a comment for username or group name here:
new XElement("DEVICE_TYPE",
new XAttribute("DEVICE_TYPE", messagetype)),
//new test
new XComment(SendToUserName),
new XElement("DEVICE_VALUE", txtPhone.Text))
)))),
new XElement("VERSION", "1.6"))
);
//End of XML Comment:
xDocSendToBuild.Add(new XComment("End of XML File."));
//Needs to be implemented in the loop for more than one item if more than one recipient:
foreach (string r in recipients)
{
// xDocument.Descendants("USER_TO").Descendants("CIML").Last().Add(new XElement("DEVICE_INFORMATION", new XElement("DEVICE_TYPE", new XAttribute("DEVICE_TYPE", "messagetype")), new XComment(SendToUserName), new XElement("DEVICE_VALUE", "new Phone")));
}
//Turn the following into reusable component so it can be shared:
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isolatesFileStream =
new IsolatedStorageFileStream(IsoSendToRequest, FileMode.Create, isolatedStorageFile))
{
// Complete Saving of ISO:
xDocSendToBuild.Save(isolatesFileStream);
}
}
txtXMLToSend.Text = xDocSendToBuild.ToString();
xDocSendToRequest = XDocument.Parse(xDocSendToBuild.ToString());
//Calls the Post to HTTP procedure:
svcMediator.MediatorServiceClient mediator = new svcMediator.MediatorServiceClient();
mediator.PostToExternalServiceCompleted += new EventHandler<svcMediator.PostToExternalServiceCompletedEventArgs>(mediator_PostToExternalServiceCompleted);
mediator.PostToExternalServiceAsync(PostURL, LoadData(IsoSendToRequest));
//Pause for x seconds (5000=5 seconds) so system can get delivery status
System.Threading.Thread.Sleep(15000);
//Get Delivery Status:
GetMessageDeliveryStatus(messageID, messageKey);
}
void mediator_PostToExternalServiceCompleted(object sender, svcMediator.PostToExternalServiceCompletedEventArgs e)
{
TimeStampResponse = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
if (e.Error == null)
{
xDocSendToResponse = XDocument.Parse(e.Result);
var resp = from b in xDocSendToResponse.Descendants()
where b.Name == "RESPONSE"
select b;
//There should only be one Response here:
foreach (XElement RESPONSE in resp)
{
//ensure that error trapping occurs if XML doesnt contain the elements:
string messageid = RESPONSE.Element("MESSAGE_ID").Value;
string messagekey = RESPONSE.Element("MESSAGE_KEY").Value;
string messagestatus = RESPONSE.Element("RESPONSE_STATUS").Value;
string messagedesc = RESPONSE.Element("RESPONSE_STATUS_DESC").Value;
//Update the parent value, (parent value should be updated solely on one response).
messageID = messageid;
messageKey = messagekey;
}
txtHTTPResponse.Text = xDocSendToResponse.ToString();
}
else
{
var x = e.Error;
}
//ensure appropriate Error Trapping.
//Write Data to Database:
WriteToAuditTable();
//Pause for x seconds (5000=5 seconds) so system can get delivery status
//System.Threading.Thread.Sleep(15000);
//Get Delivery Status:
// GetMessageDeliveryStatus(messageID, messageKey);
}
public static string LoadData(string fileName)
{
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, file);
StreamReader streamReader = new StreamReader(fileStream);
string data = streamReader.ReadToEnd();
//New:
fileStream.Flush();
//End of New
streamReader.Close();
return data;
}
//Get the Delivery Audit Information:
private void GetMessageDeliveryStatus(string MId, string MKey)
{
//Convert to XML :
XDocument xDocument = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XComment("SPRINT EMG Version 1.3 Response XML. This code queries the database for the delivery information."),
new XElement("TELEMESSAGE",
new XElement("TELEMESSAGE_CONTENT",
new XElement("MESSAGE_STATUS_QUERY",
new XElement("MESSAGE_ID", MId),
new XElement("MESSAGE_KEY", MKey))),
new XElement("VERSION", "1.3")));
//Turn the following into reusable component so it can be shared:
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isolatesFileStream =
new IsolatedStorageFileStream(IsoDeliveryRequest, FileMode.Create, isolatedStorageFile))
{
// Complete Saving of ISF.
xDocument.Save(isolatesFileStream);
}
}
//Now Query the Telemessage Database for the responses:
//The following needs to be changed either using a parameter or new method in order to process the return data:
svcMediator.MediatorServiceClient delmediator = new svcMediator.MediatorServiceClient();
delmediator.PostToExternalServiceCompleted += new EventHandler<svcMediator.PostToExternalServiceCompletedEventArgs>(delmediator_DelToExternalServiceCompleted);
delmediator.PostToExternalServiceAsync(PostURL, LoadData(IsoDeliveryRequest));
}
void delmediator_DelToExternalServiceCompleted(object sender, svcMediator.PostToExternalServiceCompletedEventArgs e)
{
TimeStampResponse = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
if (e.Error == null)
{
xDocDeliveryResponse = XDocument.Parse(e.Result);
var resp = from b in xDocDeliveryResponse.Descendants()
where b.Name == "RESPONSE"
select b;
//These Needs to be Modified:
foreach (XElement RESPONSE in resp)
{
//ensure that error trapping occurs if XML doesnt contain the elements:
string messageid = RESPONSE.Element("MESSAGE_ID").Value;
string messagekey = RESPONSE.Element("MESSAGE_KEY").Value;
string messagestatus = RESPONSE.Element("RESPONSE_STATUS").Value;
string messagedesc = RESPONSE.Element("RESPONSE_STATUS_DESC").Value;
//Update the parent value, (parent value should be updated solely on one response).
messageID = messageid;
messageKey = messagekey;
}
txtDeliveryResponse.Text = xDocDeliveryResponse.ToString();
}
else
{
var x = e.Error;
}
//ensure appropriate Error Trapping.
//Write Data to Database:
WriteToAuditDeliveryTable();
}
//txtXMLToSend.Text = LoadData(IsoDeliveryRequest);
private void WriteToAuditTable()
{
//This procedure writes the Send To and Response Data to the SQL tblMessagingAudit Table
Messaging.Web.DeptDomainContext objctx = new Messaging.Web.DeptDomainContext();
objctx = new Web.DeptDomainContext();
Web.tblMessagingAudit ma = new Web.tblMessagingAudit();
ma.MessageID = messageID;
ma.MessageKey = messageKey;
ma.Message = txtMessage.Text;
ma.MessageType = messagetype;
ma.SourceBrowser = SourceClientBrowser;
ma.SourceIPAddress = SourceClientIPAddress;
ma.TimeStampResponse = DateTime.ParseExact(TimeStampResponse, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.TimeStampSubmit = DateTime.ParseExact(TimeStampSubmit, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.SourceUser = SourceClientUser;
ma.XMLSendTo = xDocSendToRequest.ToString();
ma.XMLResponse = xDocSendToResponse.ToString();
// ma.XMLDelivery = xDocDeliveryResponse.ToString();
ma.Subject = txtSubject.Text;
objctx.tblMessagingAudits.Add(ma);
try
{
objctx.SubmitChanges(submitOperation =>
{
if (submitOperation.HasError)
{
MessageBox.Show(submitOperation.Error.Message);
}
},
null);
// MessageBox.Show("Added Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Adding Data failed due to " + ex.Message);
}
}
private void WriteToAuditDeliveryTable()
{
//This procedure writes the Send To and Response Data to the SQL tblMessagingAudit Table
Messaging.Web.DeptDomainContext objctx = new Messaging.Web.DeptDomainContext();
objctx = new Web.DeptDomainContext();
Web.tblMessagingAuditDelivery ma = new Web.tblMessagingAuditDelivery();
ma.MessageID = messageID;
ma.MessageKey = messageKey;
ma.TimeStampDeliveryResponse = DateTime.ParseExact(TimeStampResponse, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.XMLDelivery = xDocDeliveryResponse.ToString();
objctx.tblMessagingAuditDeliveries.Add(ma);
try
{
objctx.SubmitChanges(submitOperation =>
{
if (submitOperation.HasError)
{
MessageBox.Show(submitOperation.Error.Message);
}
},
null);
// MessageBox.Show("Added Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Adding Data failed due to " + ex.Message);
}
}[/code]
<br/>
View the full article
The code works correctly, sleep occurs in the wrong space.
Id like everything in the btnBuildXML_Click method to complete. Once everything has completed, then I would like the sleep to be invoked for 15 seconds, and then start the GetMessageDeliveryStatus process.
In the current placement in the code, it makes everything sleep for 15 seconds, then completes.
How can I get the btnBuildXML_Click to complete entirely, sleep for 15 seconds, then invoke the GetMessageDeliveryStatus method.
<pre class="prettyprint using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
//Added:
using System.Xml;
using System.Xml.Linq;
using System.IO;
using System.IO.IsolatedStorage;
using System.Text.RegularExpressions;
using System.Text;
using System.Windows.Browser;
using System.Collections;
using System.ComponentModel;
using Messaging.Web;
namespace Messaging
{
public partial class MainPage : UserControl
{
//User Input Selection
public string pkPersonnelType; //This needs to be substituted with the collection variable
public string pkPersonnelId; //This needs to be substituted with the collection variable
public string groupId; //This needs to be substituted with the collection variable
public string groupName; //This needs to be substituted with the collection variable
public string SendToUserName; //This needs to be substituted with the collection variable
public string messagetype; //This to come from Form
//System Variables:
public string PostURL;
public string ClientUserName;
public string SprintPassword;
public string SourceClientUser;
public string SourceClientIPAddress;
public string SourceClientBrowser;
public string TimeStampSubmit;
public string TimeStampResponse;
public string IsoSendToRequest;
public string IsoSendToResponse;
public string IsoDeliveryRequest;
public string IsoDeliveryResponse;
public string messageID;
public string messageKey;
public XDocument xDocSendToRequest;
public XDocument xDocSendToResponse;
public XDocument xDocDeliveryResponse;
//Tenative:
public string flag; //For Determining Query: Submit Send To; Submit Delivery Request
public string Platform
{
get { return (string)GetValue(PlatformProperty); }
set { SetValue(PlatformProperty, value); }
}
public static readonly DependencyProperty PlatformProperty = DependencyProperty.Register("Platform", typeof(string), typeof(MainPage), new PropertyMetadata(string.Empty));
public string BrowserInformation { get { return (string)GetValue(BrowserInformationProperty); } set { SetValue(BrowserInformationProperty, value); } }
public static readonly DependencyProperty BrowserInformationProperty = DependencyProperty.Register("BrowserInformation", typeof(string), typeof(MainPage), new PropertyMetadata(string.Empty));
//Temporary Place holder in lieu of collection
string[] recipients = { "Recipient1", "Recipient2", "Recipient3" };
public MainPage()
{
InitializeComponent();
//System Variables
PostURL = "http://123.jsp";
ClientUserName = "abc";
ClientPassword = "17221";
IsoSendToRequest = "SprintOutput.xml";
IsoSendToResponse = "Response.xml";
IsoDeliveryRequest = "DeliveryRequest.xml";
//User Inputs:
txtMessage.Text = "Enter Message Here..."; //This comes from the form
txtSubject.Text = "Text Message from User: "; //This comes from the form
txtPhone.Text = "8005551212"; //This will Come from the selected users or groups in Collection
SendToUserName = "Send To User Name is Here..."; //This will Come from the selected users or groups in Collection
//This can predicated on a checkbox:
messagetype = "SMS";
//This will not show True Info until running from the WebServer (Not Local Debugging)
SourceClientUser = App.UserID; // App.Current.Resources["username"].ToString();
SourceClientBrowser = "";
SourceClientIPAddress = "";//App.Current.Resources["txtUserIP"].ToString();
var browserInfo = HtmlPage.BrowserInformation;
BrowserInformation = "You are using " + browserInfo.Name + " (Product Name: " + browserInfo.ProductName + " - " + browserInfo.ProductVersion + ") Version: " + browserInfo.BrowserVersion;
Platform = "You are on " + browserInfo.Platform + " platform and using User Agent: " + browserInfo.UserAgent;
flag = "S";
}
//Ensure that they dont click button more than once in a specified time frame to avoid duplicate messages:
private void btnBuildXML_Click(object sender, RoutedEventArgs e)
{
//Set the Submit Time:
TimeStampSubmit = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
//Create Send To XML Packet:
XDocument xDocSendToBuild = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XComment("SPRINT EMG Version 1.6 Output XML"),
new XElement("TELEMESSAGE",
new XElement("TELEMESSAGE_CONTENT",
new XElement("MESSAGE",
new XElement("MESSAGE_INFORMATION",
new XElement("SUBJECT", txtSubject.Text),
new XElement("TIME_STAMP", TimeStampSubmit)),
new XElement("USER_FROM",
new XElement("CIML",
new XElement("NAML",
new XElement("LOGIN_DETAILS",
new XElement("USER_NAME", ClientUserName),
new XElement("PASSWORD", ClientPassword))))),
new XElement("MESSAGE_CONTENT",
new XElement("TEXT_MESSAGE",
new XElement("MESSAGE_INDEX", 0),
new XElement("TEXT", txtMessage.Text))),
new XElement("USER_TO",
new XElement("CIML",
new XElement("DEVICE_INFORMATION",
//Insert a comment for username or group name here:
new XElement("DEVICE_TYPE",
new XAttribute("DEVICE_TYPE", messagetype)),
//new test
new XComment(SendToUserName),
new XElement("DEVICE_VALUE", txtPhone.Text))
)))),
new XElement("VERSION", "1.6"))
);
//End of XML Comment:
xDocSendToBuild.Add(new XComment("End of XML File."));
//Needs to be implemented in the loop for more than one item if more than one recipient:
foreach (string r in recipients)
{
// xDocument.Descendants("USER_TO").Descendants("CIML").Last().Add(new XElement("DEVICE_INFORMATION", new XElement("DEVICE_TYPE", new XAttribute("DEVICE_TYPE", "messagetype")), new XComment(SendToUserName), new XElement("DEVICE_VALUE", "new Phone")));
}
//Turn the following into reusable component so it can be shared:
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isolatesFileStream =
new IsolatedStorageFileStream(IsoSendToRequest, FileMode.Create, isolatedStorageFile))
{
// Complete Saving of ISO:
xDocSendToBuild.Save(isolatesFileStream);
}
}
txtXMLToSend.Text = xDocSendToBuild.ToString();
xDocSendToRequest = XDocument.Parse(xDocSendToBuild.ToString());
//Calls the Post to HTTP procedure:
svcMediator.MediatorServiceClient mediator = new svcMediator.MediatorServiceClient();
mediator.PostToExternalServiceCompleted += new EventHandler<svcMediator.PostToExternalServiceCompletedEventArgs>(mediator_PostToExternalServiceCompleted);
mediator.PostToExternalServiceAsync(PostURL, LoadData(IsoSendToRequest));
//Pause for x seconds (5000=5 seconds) so system can get delivery status
System.Threading.Thread.Sleep(15000);
//Get Delivery Status:
GetMessageDeliveryStatus(messageID, messageKey);
}
void mediator_PostToExternalServiceCompleted(object sender, svcMediator.PostToExternalServiceCompletedEventArgs e)
{
TimeStampResponse = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
if (e.Error == null)
{
xDocSendToResponse = XDocument.Parse(e.Result);
var resp = from b in xDocSendToResponse.Descendants()
where b.Name == "RESPONSE"
select b;
//There should only be one Response here:
foreach (XElement RESPONSE in resp)
{
//ensure that error trapping occurs if XML doesnt contain the elements:
string messageid = RESPONSE.Element("MESSAGE_ID").Value;
string messagekey = RESPONSE.Element("MESSAGE_KEY").Value;
string messagestatus = RESPONSE.Element("RESPONSE_STATUS").Value;
string messagedesc = RESPONSE.Element("RESPONSE_STATUS_DESC").Value;
//Update the parent value, (parent value should be updated solely on one response).
messageID = messageid;
messageKey = messagekey;
}
txtHTTPResponse.Text = xDocSendToResponse.ToString();
}
else
{
var x = e.Error;
}
//ensure appropriate Error Trapping.
//Write Data to Database:
WriteToAuditTable();
//Pause for x seconds (5000=5 seconds) so system can get delivery status
//System.Threading.Thread.Sleep(15000);
//Get Delivery Status:
// GetMessageDeliveryStatus(messageID, messageKey);
}
public static string LoadData(string fileName)
{
IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream fileStream = new IsolatedStorageFileStream(fileName, FileMode.OpenOrCreate, file);
StreamReader streamReader = new StreamReader(fileStream);
string data = streamReader.ReadToEnd();
//New:
fileStream.Flush();
//End of New
streamReader.Close();
return data;
}
//Get the Delivery Audit Information:
private void GetMessageDeliveryStatus(string MId, string MKey)
{
//Convert to XML :
XDocument xDocument = new XDocument(
new XDeclaration("1.0", "UTF-8", "yes"),
new XComment("SPRINT EMG Version 1.3 Response XML. This code queries the database for the delivery information."),
new XElement("TELEMESSAGE",
new XElement("TELEMESSAGE_CONTENT",
new XElement("MESSAGE_STATUS_QUERY",
new XElement("MESSAGE_ID", MId),
new XElement("MESSAGE_KEY", MKey))),
new XElement("VERSION", "1.3")));
//Turn the following into reusable component so it can be shared:
using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isolatesFileStream =
new IsolatedStorageFileStream(IsoDeliveryRequest, FileMode.Create, isolatedStorageFile))
{
// Complete Saving of ISF.
xDocument.Save(isolatesFileStream);
}
}
//Now Query the Telemessage Database for the responses:
//The following needs to be changed either using a parameter or new method in order to process the return data:
svcMediator.MediatorServiceClient delmediator = new svcMediator.MediatorServiceClient();
delmediator.PostToExternalServiceCompleted += new EventHandler<svcMediator.PostToExternalServiceCompletedEventArgs>(delmediator_DelToExternalServiceCompleted);
delmediator.PostToExternalServiceAsync(PostURL, LoadData(IsoDeliveryRequest));
}
void delmediator_DelToExternalServiceCompleted(object sender, svcMediator.PostToExternalServiceCompletedEventArgs e)
{
TimeStampResponse = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)
if (e.Error == null)
{
xDocDeliveryResponse = XDocument.Parse(e.Result);
var resp = from b in xDocDeliveryResponse.Descendants()
where b.Name == "RESPONSE"
select b;
//These Needs to be Modified:
foreach (XElement RESPONSE in resp)
{
//ensure that error trapping occurs if XML doesnt contain the elements:
string messageid = RESPONSE.Element("MESSAGE_ID").Value;
string messagekey = RESPONSE.Element("MESSAGE_KEY").Value;
string messagestatus = RESPONSE.Element("RESPONSE_STATUS").Value;
string messagedesc = RESPONSE.Element("RESPONSE_STATUS_DESC").Value;
//Update the parent value, (parent value should be updated solely on one response).
messageID = messageid;
messageKey = messagekey;
}
txtDeliveryResponse.Text = xDocDeliveryResponse.ToString();
}
else
{
var x = e.Error;
}
//ensure appropriate Error Trapping.
//Write Data to Database:
WriteToAuditDeliveryTable();
}
//txtXMLToSend.Text = LoadData(IsoDeliveryRequest);
private void WriteToAuditTable()
{
//This procedure writes the Send To and Response Data to the SQL tblMessagingAudit Table
Messaging.Web.DeptDomainContext objctx = new Messaging.Web.DeptDomainContext();
objctx = new Web.DeptDomainContext();
Web.tblMessagingAudit ma = new Web.tblMessagingAudit();
ma.MessageID = messageID;
ma.MessageKey = messageKey;
ma.Message = txtMessage.Text;
ma.MessageType = messagetype;
ma.SourceBrowser = SourceClientBrowser;
ma.SourceIPAddress = SourceClientIPAddress;
ma.TimeStampResponse = DateTime.ParseExact(TimeStampResponse, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.TimeStampSubmit = DateTime.ParseExact(TimeStampSubmit, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.SourceUser = SourceClientUser;
ma.XMLSendTo = xDocSendToRequest.ToString();
ma.XMLResponse = xDocSendToResponse.ToString();
// ma.XMLDelivery = xDocDeliveryResponse.ToString();
ma.Subject = txtSubject.Text;
objctx.tblMessagingAudits.Add(ma);
try
{
objctx.SubmitChanges(submitOperation =>
{
if (submitOperation.HasError)
{
MessageBox.Show(submitOperation.Error.Message);
}
},
null);
// MessageBox.Show("Added Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Adding Data failed due to " + ex.Message);
}
}
private void WriteToAuditDeliveryTable()
{
//This procedure writes the Send To and Response Data to the SQL tblMessagingAudit Table
Messaging.Web.DeptDomainContext objctx = new Messaging.Web.DeptDomainContext();
objctx = new Web.DeptDomainContext();
Web.tblMessagingAuditDelivery ma = new Web.tblMessagingAuditDelivery();
ma.MessageID = messageID;
ma.MessageKey = messageKey;
ma.TimeStampDeliveryResponse = DateTime.ParseExact(TimeStampResponse, "yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
ma.XMLDelivery = xDocDeliveryResponse.ToString();
objctx.tblMessagingAuditDeliveries.Add(ma);
try
{
objctx.SubmitChanges(submitOperation =>
{
if (submitOperation.HasError)
{
MessageBox.Show(submitOperation.Error.Message);
}
},
null);
// MessageBox.Show("Added Successfully");
}
catch (Exception ex)
{
MessageBox.Show("Adding Data failed due to " + ex.Message);
}
}[/code]
<br/>
View the full article