Skip to content

Commit

Permalink
ALL the code!
Browse files Browse the repository at this point in the history
  • Loading branch information
developerdizzle committed Jun 22, 2012
1 parent b44fe71 commit f401a55
Show file tree
Hide file tree
Showing 16 changed files with 595 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

<!-- saved from url=(0065)https://raw.github.com/doctordizzle/TimeTracker/master/.gitignore -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/document_iterator.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/find_proxy.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/get_html_text.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/global_constants.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/name_injection_builder.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/number_injection_builder.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/string_finder.js"></script><script src="chrome-extension://lifbcibllhkdhoafpjfnlhfpfgnpldfl/change_sink.js"></script><meta name="document_iterator.js"><meta name="find_proxy.js"><meta name="get_html_text.js"><meta name="global_constants.js"><meta name="name_injection_builder.js"><meta name="number_injection_builder.js"><meta name="string_finder.js"><meta name="change_sink.js"><style type="text/css"></style></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#OS junk files
[Tt]humbs.db
*.DS_Store

#Visual Studio files
*.[Oo]bj
*.user
*.aps
*.pch
*.vspscc
*.vssscc
*_i.c
*_p.c
*.ncb
*.suo
*.tlb
*.tlh
*.bak
*.[Cc]ache
*.ilk
*.log
*.lib
*.sbr
*.sdf
*.opensdf
*.unsuccessfulbuild
ipch/
obj/
[Bb]in
[Dd]ebug*/
[Rr]elease*/
Ankh.NoLoad

#Tooling
_ReSharper*/
*.resharper
[Tt]est[Rr]esult*

#Project files
[Bb]uild/

#Subversion files
.svn

# Office Temp Files
~$*

#NuGet
packages/</pre></body><span id="skype_highlighting_settings" display="none" autoextractnumbers="1"></span><object id="skype_plugin_object" location.href="https://raw.github.com/doctordizzle/TimeTracker/master/.gitignore" location.hostname="raw.github.com" style="position: absolute; visibility: hidden; left: -100px; top: -100px; " width="0" height="0" type="application/x-vnd.skype.click2call.chrome.5.7.0"></object></html>
12 changes: 12 additions & 0 deletions SockPuppet.Demo/IClientObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SockPuppet.Demo
{
public interface IClientWindow
{
void alert(string message);
}
}
85 changes: 85 additions & 0 deletions SockPuppet.Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Fleck;

namespace SockPuppet.Demo
{
class Program
{
private static List<IWebSocketConnection> allSockets = new List<IWebSocketConnection>();

private static Dictionary<Guid, IClientWindow> clientWindows = new Dictionary<Guid, IClientWindow>();
private static Dictionary<Guid, dynamic> clientDynamicWindows = new Dictionary<Guid, dynamic>();

private static WebSocketServer server;

static void Main(string[] args)
{
string url = args.Length > 0 ? args[0] : "ws://localhost:8181";

server = new WebSocketServer(url);

server.Start(socket =>
{
socket.OnOpen = () => Open(socket);
socket.OnClose = () => Close(socket);
socket.OnMessage = message => Receive(socket, message);
});

Console.WriteLine("Type a message to send to the client (type 'exit' to close):");

var input = Console.ReadLine();
while (input != "exit")
{
foreach (IWebSocketConnection socket in allSockets)
{
//standard socket raw send method
socket.Send(input);

//find our dynamic sockpuppet for this socket, and call a dynamic method
clientDynamicWindows[socket.ConnectionInfo.Id].document.write("called from a dynamic object method: " + input);

//find our strongly typed interface sockpuppet for this socket, and call a typed method (that matches a method for our chosen context on the client)\
clientWindows[socket.ConnectionInfo.Id].alert("called from an interface method: " + input);
}

input = Console.ReadLine();
}
}

private static void Open(IWebSocketConnection socket)
{
//add our socket to a persistent collection so we can reference later
allSockets.Add(socket);

//create a strongly typed sockpuppet
IClientWindow puppet = SockPuppet.Puppet.New<IClientWindow>(r => socket.Send(r));
//add it to a dictionary so we can reference by socket id later
clientWindows.Add(socket.ConnectionInfo.Id, puppet);

//create a dynamic sockpuppet
dynamic dynamicPuppet = SockPuppet.Puppet.New(r => socket.Send(r));
//add it to a dictionary so we can reference by socket id later
clientDynamicWindows.Add(socket.ConnectionInfo.Id, dynamicPuppet);

Console.WriteLine("> Socket opened to " + socket.ConnectionInfo.ClientIpAddress);
}

private static void Close(IWebSocketConnection socket)
{
allSockets.Remove(socket);
clientWindows.Remove(socket.ConnectionInfo.Id);
clientDynamicWindows.Remove(socket.ConnectionInfo.Id);

Console.WriteLine("> Socket to " + socket.ConnectionInfo.ClientIpAddress + " closed");
}

private static void Receive(IWebSocketConnection socket, string message)
{
Console.WriteLine("> Message received from " + socket.ConnectionInfo.ClientIpAddress);
Console.WriteLine(message);
}
}
}
36 changes: 36 additions & 0 deletions SockPuppet.Demo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("SockPuppet.Demo")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SockPuppet.Demo")]
[assembly: AssemblyCopyright("Copyright © 2012")]
[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("5d66694e-6b83-46ad-b085-7c2aa895d887")]

// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
78 changes: 78 additions & 0 deletions SockPuppet.Demo/SockPuppet.Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A3A823C5-60BD-412E-88DE-AA13E1459915}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SockPuppet.Demo</RootNamespace>
<AssemblyName>SockPuppet.Demo</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>SockPuppet.Demo.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<Reference Include="Fleck">
<HintPath>..\packages\Fleck.0.9.6.12\lib\net40\Fleck.dll</HintPath>
</Reference>
<Reference Include="ImpromptuInterface">
<HintPath>..\SockPuppet\bin\Debug\ImpromptuInterface.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IClientObject.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SockPuppet\SockPuppet.csproj">
<Project>{FFAC15F2-504E-445B-9E6B-EA69443DB1DC}</Project>
<Name>SockPuppet</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.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>
-->
</Project>
3 changes: 3 additions & 0 deletions SockPuppet.Demo/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
4 changes: 4 additions & 0 deletions SockPuppet.Demo/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fleck" version="0.9.6.12" />
</packages>
30 changes: 30 additions & 0 deletions SockPuppet.Web/demo.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!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>
<title></title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="sockpuppet.client.js"></script>
</head>
<body>
<script type="text/javascript">
//create a new WebSocket object as usual
var server = new WebSocket("ws://localhost:8181");

//set out context to the window object - all sockpuppet method calls will be performed on this object
server.puppetContext(window);

//non sockpuppet calls are passed through to the standard onmessage function
server.onmessage = function (event) {
console.log('received data through standard server.onmessage: ' + event.data);
};

server.onopen = function () {
console.log('socket server opened');
};

server.onclose = function () {
console.log('socket server closed');
}
</script>
</body>
</html>
43 changes: 43 additions & 0 deletions SockPuppet.Web/sockpuppet.client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var oldWebSocket = window.WebSocket;
function WrappedWebSocket(loc) {
this.prototype = new oldWebSocket(loc);
this.__proto__ = this.prototype;
var wrapper = this;
this.onmessage = function (message) {
try {
var parsedData = JSON.parse(message.data);

if (parsedData.SockPuppetCall) {
var subContext = context;
var namespaces = parsedData.SockPuppetCall.Name.split('.');

var methodName = namespaces[namespaces.length - 1];

if (namespaces.length > 1) {
namespaces.splice(namespaces.length - 1, 1);

for (i in namespaces) {
subContext = subContext[namespaces[i]];
}
}

var arguments = parsedData.SockPuppetCall.Arguments;

subContext[methodName].apply(subContext, arguments);

return;
}
} catch (e) { }
wrapper.baseonmessage(message);
}
this.__defineSetter__('onmessage', function (val) {
wrapper.baseonmessage = val;
});

var context = window;
this.puppetContext = function (newContext) {
context = newContext;
}
}
window.WebSocket = WrappedWebSocket;

Loading

0 comments on commit f401a55

Please sign in to comment.