Esempio n. 1
0
		public static IEnumerable<Message> ReadAllXml (XmlReader r)
		{
			while (r.Read ()) {
				if (r.IsStartElement ("Message")) {
					var m = new Message ();
					m.ReadXml (r.ReadSubtree ());
					yield return m;
				}
			}
		}
Esempio n. 2
0
		public void PostNewMessage (Message message)
		{
			if (_simulateErrors) {
				throw new ApplicationException ("Simulated network failure");
			}
			else {
				System.Diagnostics.Debug.WriteLine ("Posting");

				var data = string.Format (
					"from={0}&text={1}",
					Uri.EscapeDataString (message.From),
					Uri.EscapeDataString (message.Text));
				var dataBytes = Encoding.UTF8.GetBytes (data);

				var req = (HttpWebRequest)WebRequest.Create ("http://localhost:8080/Messages/New");
				req.Method = "POST";
				req.ContentType = "application/x-www-form-urlencoded";
				req.ContentLength = dataBytes.Length;
				using (var s = req.GetRequestStream ()) {
					s.Write (dataBytes, 0, dataBytes.Length);
				}
				req.GetResponse ();
			}
		}
Esempio n. 3
0
		public Task PostNewMessageAsync (Message message)
		{
			return Task.Factory.StartNew (delegate {
				PostNewMessage (message);
			});
		}