Permalink
Browse files

Silverlight added - small flex update

  • Loading branch information...
1 parent 1467c9a commit 9a13e9c47873a2c697f18e81731ceed8d812880e @eoftedal committed Apr 7, 2010
View
Binary file not shown.
View
@@ -0,0 +1,15 @@
+Config
+------
+
+Update the port number and hostname where the backend is running - MainPage.xaml.cs:
+ private const int port = 4502;
+ private const string hostname = "localhost";
+
+Remember that Silverlight only supports port 4502-4530
+
+
+Files
+-------
+SilverlightMalaRIA.sln - Visual Studio 2008 Solution file
+SilverlightMalaRIA - Code
+silverlight.html - File showing how to display on web
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightMalaRIA", "SilverlightMalaRIA\SilverlightMalaRIA.csproj", "{4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,8 @@
+<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ x:Class="SilverlightMalaRIA.App"
+ >
+ <Application.Resources>
+
+ </Application.Resources>
+</Application>
@@ -0,0 +1,66 @@
+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;
+
+namespace SilverlightMalaRIA
+{
+ public partial class App : Application
+ {
+
+ public App()
+ {
+ this.Startup += this.Application_Startup;
+ this.Exit += this.Application_Exit;
+ this.UnhandledException += this.Application_UnhandledException;
+
+ InitializeComponent();
+ }
+
+ private void Application_Startup(object sender, StartupEventArgs e)
+ {
+ this.RootVisual = new MainPage();
+ }
+
+ private void Application_Exit(object sender, EventArgs e)
+ {
+
+ }
+ private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
+ {
+ // If the app is running outside of the debugger then report the exception using
+ // the browser's exception mechanism. On IE this will display it a yellow alert
+ // icon in the status bar and Firefox will display a script error.
+ if (!System.Diagnostics.Debugger.IsAttached)
+ {
+
+ // NOTE: This will allow the application to continue running after an exception has been thrown
+ // but not handled.
+ // For production applications this error handling should be replaced with something that will
+ // report the error to the website and stop the application.
+ e.Handled = true;
+ Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
+ }
+ }
+ private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
+ {
+ try
+ {
+ string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
+ errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
+
+ System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+}
@@ -0,0 +1,9 @@
+<UserControl x:Class="SilverlightMalaRIA.MainPage"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ mc:Ignorable="d" d:DesignWidth="10" d:DesignHeight="10">
+ <Grid x:Name="LayoutRoot">
+
+ </Grid>
+</UserControl>
@@ -0,0 +1,126 @@
+using System;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Windows.Browser;
+using System.Windows.Controls;
+using System.Windows.Threading;
+
+namespace SilverlightMalaRIA
+{
+ public partial class MainPage : UserControl
+ {
+
+ private readonly Socket _socket;
+ private readonly HtmlDocument _document;
+
+ private const int port = 4502;
+ private const string hostname = "localhost";
+
+
+ public MainPage()
+ {
+ InitializeComponent();
+ UIThread.Dispatcher = Dispatcher;
+ _document = HtmlPage.Document;
+ try
+ {
+ Log("Connecting back to malaria server (" + hostname + ":" + port + ")...");
+ _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+ var args = new SocketAsyncEventArgs { RemoteEndPoint = new DnsEndPoint(hostname, port, AddressFamily.InterNetwork) };
+ args.Completed += OnConnected;
+ _socket.ConnectAsync(args);
+ }
+ catch (Exception ex)
+ {
+ Log(ex.Message);
+ }
+ }
+ public void OnConnected(object o, SocketAsyncEventArgs args)
+ {
+ if (_socket.Connected)
+ {
+ Log("Connected and ready");
+ Send("Silverlight hello", true);
+ }
+ else
+ {
+ Log("Failed to connect... :" + args.ConnectByNameError);
+ }
+ }
+ public void HandleIncomingTraffic()
+ {
+ var args = new SocketAsyncEventArgs();
+ var buffer = new byte[4096];
+ args.SetBuffer(buffer, 0, buffer.Length);
+ args.Completed += OnReceive;
+ _socket.ReceiveAsync(args);
+ }
+ public void OnReceive(object o, SocketAsyncEventArgs e)
+ {
+ string message = Encoding.UTF8.GetString(e.Buffer, 0, e.BytesTransferred);
+ Regex msgRex = new Regex("([^ ]+) ([^ ]+) ([^ ]+)");
+ Match match = msgRex.Match(message);
+ if (match.Success)
+ {
+ Log("Trying: [" + match.Groups[2].Value + "]");
+ WebClient client = new WebClient();
+ client.DownloadStringCompleted += DataDownloaded;
+ client.DownloadStringAsync(new Uri(match.Groups[2].Value));
+ }
+ else
+ {
+ Log("Don't understand : {" + message + "}");
+ HandleIncomingTraffic();
+ }
+ }
+
+ private void DataDownloaded(object sender, DownloadStringCompletedEventArgs e)
+ {
+ string data = e.Result;
+ Send(data.Length + ":" + data, false);
+ }
+
+ public void OnSend(object o, SocketAsyncEventArgs e)
+ {
+ Log("Data sent back: " + e.Buffer.Length);
+ }
+
+ public void Send(string message, bool skipLog)
+ {
+ Byte[] bytes = Encoding.UTF8.GetBytes(message);
+ var args = new SocketAsyncEventArgs();
+ args.SetBuffer(bytes, 0, bytes.Length);
+ if (!skipLog)
+ {
+ args.Completed += OnSend;
+ }
+ _socket.SendAsync(args);
+ HandleIncomingTraffic();
+ }
+
+
+
+ private void Log(string message)
+ {
+ UIThread.Run(() =>
+ {
+ var elm = _document.GetElementById("log");
+ var msg = _document.CreateElement("div");
+ msg.SetProperty("innerHTML", message + "<br />");
+ elm.AppendChild(msg);
+ });
+ }
+ }
+
+ public static class UIThread
+ {
+ public static Dispatcher Dispatcher { get; set; }
+ public static void Run(Action a)
+ {
+ Dispatcher.BeginInvoke(a);
+ }
+ }
+
+}
@@ -0,0 +1,7 @@
+<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+>
+ <Deployment.Parts>
+ </Deployment.Parts>
+
+</Deployment>
@@ -0,0 +1,35 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("SilverlightMalaRIA")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("SilverlightMalaRIA")]
+[assembly: AssemblyCopyright("")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("879ee22d-5676-4be7-906c-be591aab3892")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers
+// by using the '*' as shown below:
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,99 @@
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>9.0.30729</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{4CE79A2A-1FDD-472B-87A9-2375B8BA9E43}</ProjectGuid>
+ <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>SilverlightMalaRIA</RootNamespace>
+ <AssemblyName>SilverlightMalaRIA</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <SilverlightApplication>true</SilverlightApplication>
+ <SupportedCultures>
+ </SupportedCultures>
+ <XapOutputs>true</XapOutputs>
+ <GenerateSilverlightManifest>true</GenerateSilverlightManifest>
+ <XapFilename>SilverlightMalaRIA.xap</XapFilename>
+ <SilverlightManifestTemplate>Properties\AppManifest.xml</SilverlightManifestTemplate>
+ <SilverlightAppEntry>SilverlightMalaRIA.App</SilverlightAppEntry>
+ <TestPageFileName>TestPage.html</TestPageFileName>
+ <CreateTestPage>true</CreateTestPage>
+ <ValidateXaml>true</ValidateXaml>
+ <EnableOutOfBrowser>false</EnableOutOfBrowser>
+ <OutOfBrowserSettingsFile>Properties\OutOfBrowserSettings.xml</OutOfBrowserSettingsFile>
+ <UsePlatformExtensions>false</UsePlatformExtensions>
+ <ThrowErrorsInValidation>true</ThrowErrorsInValidation>
+ <LinkedServerProject>
+ </LinkedServerProject>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>Bin\Debug</OutputPath>
+ <DefineConstants>DEBUG;TRACE;SILVERLIGHT</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>Bin\Release</OutputPath>
+ <DefineConstants>TRACE;SILVERLIGHT</DefineConstants>
+ <NoStdLib>true</NoStdLib>
+ <NoConfig>true</NoConfig>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System.Windows" />
+ <Reference Include="mscorlib" />
+ <Reference Include="system" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Net" />
+ <Reference Include="System.Xml" />
+ <Reference Include="System.Windows.Browser" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="App.xaml.cs">
+ <DependentUpon>App.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="MainPage.xaml.cs">
+ <DependentUpon>MainPage.xaml</DependentUpon>
+ </Compile>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ApplicationDefinition Include="App.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:MarkupCompilePass1</Generator>
+ </ApplicationDefinition>
+ <Page Include="MainPage.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:MarkupCompilePass1</Generator>
+ </Page>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="Properties\AppManifest.xml" />
+ </ItemGroup>
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+ <ProjectExtensions>
+ <VisualStudio>
+ <FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
+ <SilverlightProjectProperties />
+ </FlavorProperties>
+ </VisualStudio>
+ </ProjectExtensions>
+</Project>
Oops, something went wrong.

0 comments on commit 9a13e9c

Please sign in to comment.