Permalink
Browse files

mer sæssæmæss

  • Loading branch information...
1 parent b809f6b commit a1296afe93c12c4088a8eab0d9907346237ae118 Unknown committed Dec 8, 2011
@@ -6,6 +6,8 @@
using System.Text;
using System.Net;
using System.IO;
+using JoMAR.Models;
+using Newtonsoft.Json;
namespace JoMAR.Controllers
{
@@ -16,65 +18,14 @@ public class EssemessController : Controller
public ActionResult Index()
{
- // used to build entire input
- StringBuilder sb = new StringBuilder();
-
- // used on each read operation
- byte[] buf = new byte[8192];
-
- // prepare the web page we will be asking for
- HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://malmen.hin.no/pswin/sms/sendsms");
-
- string parameter = "RCV=4747281944&";
- parameter += "SND=4797177229&";
- parameter += "TXT=JoMAR ja JoMAR hahahaha";
- byte[] byteArray = Encoding.UTF8.GetBytes(parameter);
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = byteArray.Length;
-
- // POST
- request.Method = "POST";
-
- // Say who it is
- request.UserAgent = "JoMAR Chat in ASP.NET";
-
- // prepare request
- Stream dataStream = request.GetRequestStream();
- dataStream.Write(byteArray, 0, byteArray.Length);
- dataStream.Close();
-
- // execute the request
- HttpWebResponse response = (HttpWebResponse)
- request.GetResponse();
-
- // we will read data via the response stream
- Stream resStream = response.GetResponseStream();
-
- string tempString = null;
- int count = 0;
-
- do
- {
- // fill the buffer with data
- count = resStream.Read(buf, 0, buf.Length);
-
- // make sure we read some data
- if (count != 0)
- {
- // translate from bytes to ASCII text
- tempString = Encoding.ASCII.GetString(buf, 0, count);
-
- // continue building the string
- sb.Append(tempString);
- }
- }
- while (count > 0); // any more data to read?
-
- ViewBag.mama = sb.ToString();
-
- resStream.Close();
- response.Close();
-
+ //ViewBag.mama = SMS.Send("mama speaking", 4797177229, 4741800072);
+ String jsonresult = SMS.Get(4799104626);
+ //JsonSerializer ser = new JsonSerializer();
+ //JsonReader re = new JsonReader();
+
+ //SMS m;
+ //ser.Deserialize();
+ ViewBag.mama = jsonresult;
return View();
}
View
@@ -41,6 +41,9 @@
<HintPath>..\packages\EntityFramework.4.1.10331.0\lib\EntityFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
+ <Reference Include="Newtonsoft.Json">
+ <HintPath>..\packages\Newtonsoft.Json.4.0.4\lib\net40\Newtonsoft.Json.dll</HintPath>
+ </Reference>
<Reference Include="System.Data.Entity" />
<Reference Include="System.Data.Linq" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
@@ -80,6 +83,7 @@
</Compile>
<Compile Include="Models\AccountModels.cs" />
<Compile Include="Models\ChatModels.cs" />
+ <Compile Include="Models\SMS.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
View
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+using System.Text;
+using System.Net;
+using System.IO;
+
+namespace JoMAR.Models
+{
+ public class SMS
+ {
+ //"id":228,"SND":"4741800072","RCV":"26112","TXT":"heia runar!!????@@@@?????$?????? :-Q","date":"\/Date(1323340897680)\/","status":"received"
+ private int id;
+ private long snd;
+ private long rcv;
+ private string txt;
+ private DateTime date;
+ private string status;
+
+ public SMS()
+ {
+ }
+
+ /// <summary>
+ /// Any logging here?
+ /// </summary>
+ /// <param name="message">The message to send</param>
+ /// <param name="sender">The sender's phone number</param>
+ /// <param name="receiver">The receiver's phone number</param>
+ public static Boolean Send(String message, long sender, long receiver) {
+ // used to build entire input
+ StringBuilder sb = new StringBuilder();
+
+ // used on each read operation
+ byte[] buf = new byte[8192];
+
+ // prepare the web page we will be asking for
+ HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://malmen.hin.no/pswin/sms/sendsms");
+
+ // Prepare request parameters
+ string parameter = "RCV=" + receiver;
+ parameter += "&SND=" + sender;
+ parameter += "&TXT=" + message;
+ byte[] byteArray = Encoding.UTF8.GetBytes(parameter);
+ request.ContentType = "application/x-www-form-urlencoded";
+ request.ContentLength = byteArray.Length;
+
+ // POST
+ request.Method = "POST";
+
+ // Say who it is
+ request.UserAgent = "JoMAR Chat in ASP.NET";
+
+ // prepare request
+ Stream dataStream = request.GetRequestStream();
+ dataStream.Write(byteArray, 0, byteArray.Length);
+ dataStream.Close();
+
+ // execute the request
+ HttpWebResponse response = (HttpWebResponse) request.GetResponse();
+
+ // we will read data via the response stream
+ Stream resStream = response.GetResponseStream();
+
+ string tempString = null;
+ int count = 0;
+
+ if (HttpStatusCode.OK == response.StatusCode)
+ {
+ do
+ {
+ // fill the buffer with data
+ count = resStream.Read(buf, 0, buf.Length);
+
+ // make sure we read some data
+ if (count != 0)
+ {
+ // translate from bytes to ASCII text
+ tempString = Encoding.ASCII.GetString(buf, 0, count);
+
+ // continue building the string
+ sb.Append(tempString);
+ }
+ }
+ while (count > 0); // any more data to read?
+ }
+ else return false;
+
+ // Close streams
+ resStream.Close();
+ response.Close();
+
+ // Success
+ return true;
+ }
+
+ /// <summary>
+ /// Fetch all SMS's sent by the given number
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <returns></returns>
+ public static String Get(long sender)
+ {
+ // used to build entire input
+ StringBuilder sb = new StringBuilder();
+
+ // used on each read operation
+ byte[] buf = new byte[8192];
+
+ // prepare the web page we will be asking for
+ HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://malmen.hin.no/pswin/SMS/ChatInNumber/" + sender);
+
+ // Say who it is
+ request.UserAgent = "JoMAR Chat in ASP.NET";
+
+ // execute the request
+ HttpWebResponse response = (HttpWebResponse) request.GetResponse();
+
+ // we will read data via the response stream
+ Stream resStream = response.GetResponseStream();
+
+ string tempString = null;
+ int count = 0;
+
+ if (HttpStatusCode.OK == response.StatusCode)
+ {
+ do
+ {
+ // fill the buffer with data
+ count = resStream.Read(buf, 0, buf.Length);
+
+ // make sure we read some data
+ if (count != 0)
+ {
+ // translate from bytes to ASCII text
+ tempString = Encoding.ASCII.GetString(buf, 0, count);
+
+ // continue building the string
+ sb.Append(tempString);
+ }
+ }
+ while (count > 0); // any more data to read?
+ }
+ else return null;
+
+ // Close streams
+ resStream.Close();
+ response.Close();
+
+ // Success
+ return sb.ToString();
+ }
+ }
+}
@@ -5,6 +5,4 @@
<h2>Essemess output</h2>
-<iframe>
- @ViewBag.mama
-</iframe>
+@ViewBag.mama
View
@@ -6,4 +6,5 @@
<package id="jQuery.UI.Combined" version="1.8.11" />
<package id="EntityFramework" version="4.1.10331.0" />
<package id="Modernizr" version="1.7" />
+ <package id="Newtonsoft.Json" version="4.0.4" />
</packages>
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit a1296af

Please sign in to comment.