Created
May 3, 2012 20:59
-
-
Save t2-support-gists/2589426 to your computer and use it in GitHub Desktop.
MMS Vb app3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AT&T API Samples - MMS app 3 | |
------------------------------ | |
This file describes how to set up, configure and run the VB Applications of the AT&T RESTFul sample applications. | |
It covers all steps required to register the application on DevConnect and, based on the generated API keys and secrets, | |
create and run one's own full-fledged sample applications. | |
1. Configuration | |
2. Installation | |
3. Parameters | |
4. Running the application | |
1. Configuration | |
Configuration consists of a few steps necessary to get an application registered on DevConnect with the proper services and | |
endpoints, depending on the type of client-side application (autonomous/non-autonomous). | |
To register an application, go to https://devconnect-api.att.com/ and login with your valid username and password. | |
Next, choose "My Apps" from the bar at the top of the page and click the "Setup a New Application" button. | |
Fill in the form, in particular all fields marked as "required". | |
Be careful while filling in the "OAuth Redirect URL" field. It should contain the URL that the oAuth provider will redirect | |
users to when he/she successfully authenticates and authorizes your application. | |
NOTE: You MUST select MMS in the list of services under field 'Services' in order to use this sample application code. | |
Select MO and provide the listener url. | |
Having your application registered, you will get back an important pair of data: an API key and Secret key. They are | |
necessary to get your applications working with the AT&T HTML5 APIs. See 'Adjusting parameters' below to learn how to use | |
these keys. | |
Initially your newly registered application is restricted to the "Sandbox" environment only. To move it to production, | |
you may promote it by clicking the "Promote to production" button. Notice that you will get a different API key and secret, | |
so these values in your application should be adjusted accordingly. | |
Depending on the kind of authentication used, an application may be based on either the Autonomous Client or the Web-Server | |
Client OAuth flow (see https://devconnect-api.att.com/docs/oauth-v1/client-credentials-grant-type or | |
https://devconnect-api.att.com/docs/oauth-v1/authorization-code-grant-type respectively). | |
2. Installation | |
** Requirements | |
1. To run the this sample application you need an IIS Server. | |
2. Change the value of "href" at the following line in Default.aspx to point to the location of the "common.css" of "style" folder: | |
<link rel="stylesheet" type="text/css" href="../../style/common.css"/> | |
3. Change the value of the "url" at the following line in common.css to point to the location of the "att.gif" of "images" folder. | |
div#header { background:url(../images/att.gif) left center no-repeat; margin: 10px 5px} | |
3. Parameters | |
Each sample application contains a config.web file. It holds configurable parameters described in an easy to read format. | |
Please populate the following parameters in config.web as specified below: | |
1) short_code : {set the value as per your registered application 'short code' field value} | |
2) ImageDirectory : {set the value to the path of the directory, which contains the received mms images } | |
3) NumOfFilesToDisplay : {set the value, so that application displays latest n images} | |
Note: If your application is promoted from Sandbox environment to Production environment and you decide to use production application settings, | |
you must update parameters 1-2 as per production application details. | |
4. Running the application | |
Suppose you copied the sample app files in your IIS server webroot/mms/app3/ folder, In order to run the sample application, type in'http://IIS_HOSTNAME/mms/app3/Default.aspx' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> | |
<title>AT&T Sample MMS Application 3 – MMS Gallery Application</title> | |
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> | |
<link rel="stylesheet" type="text/css" href="../../style/common.css"/ > | |
<body> | |
<form id="form1" runat="server"> | |
<div id="container"> | |
<!-- open HEADER --><div id="header"> | |
<div> | |
<div id="hcRight"> | |
<asp:Label ID="lblServerTime" runat="server"></asp:Label> | |
</div> | |
<div id="hcLeft">Server Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
var myDate = new Date(); | |
document.write(myDate); | |
</script></div> | |
<div id="hcLeft">Client Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
document.write("" + navigator.userAgent); | |
</script></div> | |
<div id="hcLeft">User Agent:</div> | |
</div> | |
<br clear="all" /> | |
</div><!-- close HEADER --> | |
<div id="wrapper"> | |
<div id="content"> | |
<h1>AT&T Sample MMS Application 3 – MMS Gallery Application</h1> | |
<h2>Feature 1: Web gallery of MMS photos sent to short code</h2> | |
</div> | |
</div> | |
<br /> | |
<p>Photos sent Photos sent to short code <asp:Label runat="server" ID="shortCodeLabel"></asp:Label>: | |
<asp:Label ID="lbl_TotalCount" runat="server"></asp:Label> | |
</p> | |
<div id="gallerywrapper" runat="server"> | |
</div> | |
<br clear="all" /> | |
<div align="center"> | |
<asp:Panel runat="server" ID="messagePanel"> | |
</asp:Panel> | |
</div> | |
<br clear="all" /> | |
<div id="footer"> | |
<div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&T Virtual Mobile</div> | |
<p>© 2011 AT&T Intellectual Property. All rights reserved. <a href="http://developer.att.com/" target="_blank">http://developer.att.com</a> | |
<br> | |
The Application hosted on this site are working examples intended to be used for reference in creating products to consume AT&T Services and not meant to be used as part of your product. The data in these pages is for test purposes only and intended only for use as a reference in how the services perform. | |
<br> | |
For download of tools and documentation, please go to <a href="https://devconnect-api.att.com/" target="_blank">https://devconnect-api.att.com</a> | |
<br> | |
For more information contact <a href="mailto:[email protected]">[email protected]</a> | |
</form> | |
</body></html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Imports System.Collections.Generic | |
Imports System.Linq | |
Imports System.Web | |
Imports System.Web.UI | |
Imports System.Web.UI.WebControls | |
Imports System.Net | |
Imports System.Configuration | |
Imports System.IO | |
Imports System.Xml | |
Imports System.Text | |
Imports System.Web.Script.Serialization | |
Imports System.Drawing | |
Imports System.Net.Security | |
Imports System.Security.Cryptography.X509Certificates | |
Public Partial Class _Default | |
Inherits System.Web.UI.Page | |
Private shortCode As String, directoryPath As String | |
Private numOfFilesToDisplay As Integer | |
Protected Sub Page_Load(sender As Object, e As EventArgs) | |
Dim currentServerTime As DateTime = DateTime.UtcNow | |
lblServerTime.Text = [String].Format("{0:ddd, MMM dd, yyyy HH:mm:ss}", currentServerTime) + " UTC" | |
If ConfigurationManager.AppSettings("short_code") Is Nothing Then | |
drawPanelForFailure("short_code is not defined in configuration file") | |
Return | |
End If | |
shortCode = ConfigurationManager.AppSettings("short_code").ToString() | |
shortCodeLabel.Text = shortCode.ToString() | |
If ConfigurationManager.AppSettings("ImageDirectory") Is Nothing Then | |
drawPanelForFailure("ImageDirectory is not defined in configuration file") | |
Return | |
End If | |
directoryPath = ConfigurationManager.AppSettings("ImageDirectory") | |
If ConfigurationManager.AppSettings("NumOfFilesToDisplay") Is Nothing Then | |
numOfFilesToDisplay = 5 | |
Else | |
numOfFilesToDisplay = Convert.ToInt32(ConfigurationManager.AppSettings("NumOfFilesToDisplay")) | |
End If | |
Dim columnCount As Integer = 0 | |
Dim TableRow As TableRow = Nothing | |
Dim tr As TableRow = Nothing | |
Dim totalFiles As Integer = 0 | |
Dim pictureTable As New Table() | |
Dim tbControl As New Table() | |
Dim _dir As New DirectoryInfo(Request.MapPath(directoryPath)) | |
Dim _imgs As List(Of FileInfo) = _dir.GetFiles().OrderBy(Function(f) f.CreationTime).ToList() | |
totalFiles = _imgs.Count | |
'string fileShownMessage = "Displaying" + numOfFilesToDisplay.ToString() + "out of " + _imgs.Count.ToString(); | |
Dim fileShownMessage As String = _imgs.Count.ToString() | |
lbl_TotalCount.Text = fileShownMessage | |
Dim fileCountIndex As Integer = 0 | |
For Each file As FileInfo In _imgs | |
If fileCountIndex = numOfFilesToDisplay Then | |
Exit For | |
End If | |
If columnCount = 0 Then | |
TableRow = New TableRow() | |
tr = New TableRow() | |
Dim TableCellImage As New TableCell() | |
Dim Image1 As New System.Web.UI.WebControls.Image() | |
Image1.ImageUrl = String.Format("{0}{1}", directoryPath, file.Name) | |
Image1.Width = 150 | |
Image1.Height = 150 | |
TableCellImage.Controls.Add(Image1) | |
TableRow.Controls.Add(TableCellImage) | |
Dim TableCellSubject As New TableCell() | |
TableCellSubject.Text = file.Name | |
TableCellSubject.Width = 150 | |
tr.Controls.Add(TableCellSubject) | |
columnCount += 1 | |
Else | |
Dim TableCellImage As New TableCell() | |
Dim Image1 As New System.Web.UI.WebControls.Image() | |
Image1.ImageUrl = String.Format("{0}{1}", directoryPath, file.Name) | |
Image1.Width = 150 | |
Image1.Height = 150 | |
TableCellImage.Controls.Add(Image1) | |
TableRow.Controls.Add(TableCellImage) | |
Dim TableCellSubject As New TableCell() | |
TableCellSubject.Text = file.Name | |
TableCellSubject.Width = 150 | |
tr.Controls.Add(TableCellSubject) | |
columnCount += 1 | |
If columnCount = 5 Then | |
columnCount = 0 | |
End If | |
fileCountIndex += 1 | |
End If | |
pictureTable.Controls.Add(TableRow) | |
pictureTable.Controls.Add(tr) | |
Next | |
messagePanel.Controls.Add(pictureTable) | |
End Sub | |
Public Sub drawPanelForFailure(message As String) | |
Dim table As New Table() | |
table.Font.Name = "Sans-serif" | |
table.Font.Size = 9 | |
table.BorderStyle = BorderStyle.Outset | |
table.Width = Unit.Pixel(650) | |
Dim rowOne As New TableRow() | |
Dim rowOneCellOne As New TableCell() | |
rowOneCellOne.Font.Bold = True | |
rowOneCellOne.Text = "ERROR:" | |
rowOne.Controls.Add(rowOneCellOne) | |
'rowOneCellOne.BorderWidth = 1; | |
table.Controls.Add(rowOne) | |
Dim rowTwo As New TableRow() | |
Dim rowTwoCellOne As New TableCell() | |
'rowTwoCellOne.BorderWidth = 1; | |
rowTwoCellOne.Text = message.ToString() | |
rowTwo.Controls.Add(rowTwoCellOne) | |
table.Controls.Add(rowTwo) | |
table.BorderWidth = 2 | |
table.BorderColor = Color.Red | |
table.BackColor = System.Drawing.ColorTranslator.FromHtml("#fcc") | |
messagePanel.Controls.Add(table) | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Listener.aspx.vb" Inherits="Listener" %> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
<div> | |
</div> | |
</form> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Imports System.Collections.Generic | |
Imports System.Linq | |
Imports System.Web | |
Imports System.Web.UI | |
Imports System.Web.UI.WebControls | |
Imports System.IO | |
Imports System.Text.RegularExpressions | |
Imports System.Text | |
Public Partial Class Listener | |
Inherits System.Web.UI.Page | |
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load | |
Dim random As New Random() | |
Dim currentServerTime As DateTime = DateTime.UtcNow | |
Dim receivedTime As String = currentServerTime.ToString("HH-MM-SS") | |
Dim receivedDate As String = currentServerTime.ToString("MM-dd-yyyy") | |
Dim inputStreamContents As String | |
Dim stringLength As Integer | |
Dim strRead As Integer | |
Dim str As System.IO.Stream = Request.InputStream | |
stringLength = Convert.ToInt32(str.Length) | |
Dim stringArray As Byte() = New Byte(stringLength - 1) {} | |
strRead = str.Read(stringArray, 0, stringLength) | |
inputStreamContents = System.Text.Encoding.UTF8.GetString(stringArray) | |
'System.IO.File.WriteAllText("D:\Webs\wincod\APIPlatform\2\0\1\PROD\Vb-RESTful\mms\app3\MoImages\WriteText.txt", inputStreamContents ) | |
Dim splitData As String() = Regex.Split(inputStreamContents, "</SenderAddress>") | |
Dim data As String = splitData(0).ToString() | |
Dim senderAddress As [String] = inputStreamContents.Substring(data.IndexOf("tel:") + 4, data.Length - (data.IndexOf("tel:") + 4)) | |
Dim parts As [String]() = Regex.Split(inputStreamContents, "--Nokia-mm-messageHandler-BoUnDaRy") | |
Dim lowerParts As [String]() = Regex.Split(parts(2), "BASE64") | |
Dim imageType As [String]() = Regex.Split(lowerParts(0), "image/") | |
Dim indexOfSemicolon As Integer = imageType(1).IndexOf(";") | |
Dim type As String = imageType(1).Substring(0, indexOfSemicolon) | |
Dim encoder As New System.Text.UTF8Encoding() | |
Dim utf8Decode As System.Text.Decoder = encoder.GetDecoder() | |
Dim todecode_byte As Byte() = Convert.FromBase64String(lowerParts(1)) | |
'Give Images directory as path example: "D:\folder" | |
If Directory.Exists("D:\Webs\wincod\APIPlatform\2\0\1\PROD\Vb-RESTful\mms\app3\MoImages\") Then | |
Else | |
'Give Images directory as path example: "D:\folder", same as above value | |
System.IO.Directory.CreateDirectory("D:\Webs\wincod\APIPlatform\2\0\1\PROD\Vb-RESTful\mms\app3\MoImages\") | |
End If | |
Dim fileNameToSave As String = "From_" & senderAddress & "_At_" + receivedTime & "_UTC_On_" & receivedDate & random.[Next]() | |
'Give Images directory as first argument example: "D:\folder", same as above value | |
'Dim fileNameToSave As String = "Testing" | |
Dim fs As New FileStream("D:\Webs\wincod\APIPlatform\2\0\1\PROD\Vb-RESTful\mms\app3\MoImages\" + fileNameToSave + "." + type, FileMode.CreateNew, FileAccess.Write) | |
fs.Write(todecode_byte, 0, todecode_byte.Length) | |
fs.Close() | |
'random.Next() | |
End Sub | |
End Class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<!-- | |
For more information on how to configure your ASP.NET application, please visit | |
http://go.microsoft.com/fwlink/?LinkId=169433 | |
--> | |
<configuration> | |
<system.web> | |
<compilation debug="true" targetFramework="4.0"/> | |
<customErrors mode="Off"></customErrors> | |
</system.web> | |
<appSettings> | |
<!-- This is mandatory key and value should be equal | |
to MMS Service registered application 'short code' | |
example: value="80750000" --> | |
<add key="short_code" value=""/> | |
<!-- This is mandatory key and value should point to the directory where mms listener saves images. | |
example: value="~\\vbapps\\mms\\app3\\MoImages\\"--> | |
<add key="ImageDirectory" value=""/> | |
<!-- This is optional key, which defines the number of images to be displayed, if this key is not defined, | |
by default latest 10 images will be displayed | |
example: value="15"--> | |
<add key="NumOfFilesToDisplay" value=""/> | |
</appSettings> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment