Question : Question about threading with XML

I am trying to modify the attached ASP.NET program, which reads and writes XML, to integrate with VoiceShot.  (They have a free demo if you register at voiceshot.com)

I have hosted this program and sucessfully modified this file (changed PIN from 1234 to 1235), and intend to use this as the basis of my own voice service.  But my question involves threading.

Here is a sample XML packet sent from the Voice Shot server to this webpage:
<campaign menuid="1-4567" callid="2145437" action="4" callerid="8182238964" dnis="8002848509"/>

It includes a callid which will enable my webpage to distinguish various calls.  But my question involves threading.


Here, the ParseXML() function is called from Page_Load.  I don't fully understand that, unles it's because the page is not loaded until it's called by the Voice Shot server.  So the loading of the page triggers the need to parse the XML. True?

Then, when there are multiple calls, wil there be multiple instances of this page?  If I have one list of valid callerid's in a database or textfile, how would I protect one page (thread) from clashing with another, when trying to read that list?

At the moment, there will be no writing or updating that list, so can multi-thread share such a list without needing to consider multi-threading?

Hope to hear from you...
newbieweb
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
<%@ Page Language="C#" aspcompat=true %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>
<%@ Import Namespace="System.Web.UI.HtmlControls" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Text.RegularExpressions" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>

   <script language="C#" runat=server>


	   Boolean ParseXML(string XMLContent, ref string KeyPress)
	   {
		 try
		 {
		   XmlDocument doc = new XmlDocument();
		   doc.LoadXml(XMLContent);

		   String MenuID, Duration, CallerID, CallID, DateAndTime, VoiceFileName, PromptID, Action;
		   XmlNode TempNode;

		   XmlElement root = doc.DocumentElement;
		   XmlAttributeCollection attrColl = root.Attributes;
		   //Determine if this a campaign start/stop event or prompt event
		   if (root.Name=="campaign")
		   {
			  //parse campaign attributes
			  MenuID      = attrColl["menuid"].Value;
			  Action      = attrColl["action"].Value;

			  if (Action=="4")
			  {
				 CallerID = attrColl["callerid"].Value;
			  }
			  else
			  {
				 Duration = attrColl["duration"].Value;
			  }
			  CallID      = attrColl["callid"].Value;
		   }
		   else
		   {
			  //parse prompt attributes
			  MenuID      = attrColl["menuid"].Value;
			  CallID      = attrColl["callid"].Value;
			  PromptID    = attrColl["promptid"].Value;
			  KeyPress    = attrColl["keypress"].Value;
		   }

		   return true;

		 }
		 catch (Exception e)
		 {
		   Response.Write(e.Message);
		   return false;

		 }

	   }


	   string CheckKeyPress(string KeyPress)
	   {
		  string ReturnXML = "";

		  switch (KeyPress)
		  {
			case "1235":
			   ReturnXML = "<prompt goto=\"2\" />";
			   break;
		  }

		  return ReturnXML;
	   }


	   void Page_Load(object sender, System.EventArgs e)
	   {
		  try
		  {
			 String XML, xmlcontent, PostResponse, campaign, KeyPress = "";
			 Byte[] Bindata = Request.BinaryRead(Request.TotalBytes);
			 XML = System.Text.Encoding.ASCII.GetString(Bindata);

			 //parse XML from VoiceShot
			 if (ParseXML(XML, ref KeyPress))
			 {
				//return response to VoiceShot
				XML = CheckKeyPress(KeyPress);
				Response.Write(XML);
			 }
			 else
				Response.Write("Failed");
		   }
		   catch (Exception error)
		   {
			 Response.Write(error.Message);
		   }
	   }

   </script>

Answer : Question about threading with XML

I think that will give the wrong result if A1 is a Monday, abhimail2002, e.g. for 9th August it gives 13th not 6th, try

=A1+4-WEEKDAY(A1-2)

regards, barry

 

Random Solutions  
 
programming4us programming4us