-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dotnet fixes for per-proxy hmac in examples
- Loading branch information
Showing
11 changed files
with
783 additions
and
747 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,61 @@ | ||
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */ | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using Razorvine.Pickle; | ||
|
||
namespace Pyrolite.PickleExample | ||
{ | ||
class PickleTest | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// going to pickle a c# datastructure | ||
|
||
var map = new Dictionary<string, object>(); | ||
map["apple"] = 42; | ||
map["microsoft"] = "hello"; | ||
var values = new List<double>(); | ||
values.AddRange(new double[] { 1.11, 2.22, 3.33, 4.44, 5.55} ); | ||
map["values"] = values; | ||
// You can add many other types if you like. See the readme about the type mappings. | ||
|
||
const string PickleFilename = "testpickle.dat"; | ||
|
||
Console.WriteLine("Writing pickle to '{0}'", PickleFilename); | ||
|
||
var pickler = new Pickler(true); | ||
using(FileStream fos = new FileStream(PickleFilename, FileMode.Create)) | ||
{ | ||
pickler.dump(map, fos); | ||
} | ||
|
||
Console.WriteLine("Done. Try unpickling it in python.\n"); | ||
|
||
Console.WriteLine("Reading a pickle created in python..."); | ||
|
||
// the following pickle was created in Python 3.4. | ||
// it is this data: [1, 2, 3, (11, 12, 13), {'banana', 'grape', 'apple'}] | ||
byte[] pythonpickle = new byte[] {128, 4, 149, 48, 0, 0, 0, 0, 0, 0, 0, 93, 148, 40, 75, 1, 75, 2, 75, 3, 75, 11, 75, 12, 75, 13, 135, 148, 143, 148, 40, 140, 6, 98, 97, 110, 97, 110, 97, 148, 140, 5, 103, 114, 97, 112, 101, 148, 140, 5, 97, 112, 112, 108, 101, 148, 144, 101, 46}; | ||
var unpickler = new Unpickler(); | ||
object result = unpickler.loads(pythonpickle); | ||
|
||
Console.WriteLine("type: {0}", result.GetType()); | ||
var list = (ArrayList) result; | ||
int integer1 = (int)list[0]; | ||
int integer2 = (int)list[1]; | ||
int integer3 = (int)list[2]; | ||
object[] tuple = (object[]) list[3]; | ||
HashSet<object> set = (HashSet<object>) list[4]; | ||
Console.WriteLine("1-3: integers: {0}, {1}, {2}", integer1, integer2, integer3); | ||
Console.WriteLine("4: tuple: ({0}, {1}, {2})", tuple[0], tuple[1], tuple[2]); | ||
Console.WriteLine("5: set: {0}", string.Join(",", set)); | ||
} | ||
} | ||
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */ | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using Razorvine.Pickle; | ||
|
||
namespace Pyrolite.PickleExample | ||
{ | ||
class PickleTest | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
// going to pickle a c# datastructure | ||
|
||
var map = new Dictionary<string, object>(); | ||
map["apple"] = 42; | ||
map["microsoft"] = "hello"; | ||
var values = new List<double>(); | ||
values.AddRange(new double[] { 1.11, 2.22, 3.33, 4.44, 5.55} ); | ||
map["values"] = values; | ||
// You can add many other types if you like. See the readme about the type mappings. | ||
|
||
const string PickleFilename = "testpickle.dat"; | ||
|
||
Console.WriteLine("Writing pickle to '{0}'", PickleFilename); | ||
|
||
var pickler = new Pickler(true); | ||
using(FileStream fos = new FileStream(PickleFilename, FileMode.Create)) | ||
{ | ||
pickler.dump(map, fos); | ||
} | ||
|
||
Console.WriteLine("Done. Try unpickling it in python.\n"); | ||
|
||
Console.WriteLine("Reading a pickle created in python..."); | ||
|
||
// the following pickle was created in Python 3.4. | ||
// it is this data: [1, 2, 3, (11, 12, 13), {'banana', 'grape', 'apple'}] | ||
byte[] pythonpickle = new byte[] {128, 4, 149, 48, 0, 0, 0, 0, 0, 0, 0, 93, 148, 40, 75, 1, 75, 2, 75, 3, 75, 11, 75, 12, 75, 13, 135, 148, 143, 148, 40, 140, 6, 98, 97, 110, 97, 110, 97, 148, 140, 5, 103, 114, 97, 112, 101, 148, 140, 5, 97, 112, 112, 108, 101, 148, 144, 101, 46}; | ||
var unpickler = new Unpickler(); | ||
object result = unpickler.loads(pythonpickle); | ||
|
||
Console.WriteLine("type: {0}", result.GetType()); | ||
var list = (ArrayList) result; | ||
int integer1 = (int)list[0]; | ||
int integer2 = (int)list[1]; | ||
int integer3 = (int)list[2]; | ||
object[] tuple = (object[]) list[3]; | ||
HashSet<object> set = (HashSet<object>) list[4]; | ||
Console.WriteLine("1-3: integers: {0}, {1}, {2}", integer1, integer2, integer3); | ||
Console.WriteLine("4: tuple: ({0}, {1}, {2})", tuple[0], tuple[1], tuple[2]); | ||
Console.WriteLine("5: set: {0}", string.Join(",", set)); | ||
|
||
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine(); | ||
} | ||
} | ||
} |
105 changes: 54 additions & 51 deletions
105
dotnet/Pyrolite.PickleExample/Pyrolite.PickleExample.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,55 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> | ||
<PropertyGroup> | ||
<ProjectGuid>{840FD314-D643-4CD1-9A18-E1DDDD3B2338}</ProjectGuid> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>Pyrolite.PickleExample</RootNamespace> | ||
<AssemblyName>Pyrolite.PickleExample</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>Full</DebugType> | ||
<Optimize>False</Optimize> | ||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="PickleTest.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Pyrolite\Pyrolite.csproj"> | ||
<Project>{E6EAC69D-D42A-4A86-AFBE-18A1013BFDAB}</Project> | ||
<Name>Pyrolite</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> | ||
<PropertyGroup> | ||
<ProjectGuid>{840FD314-D643-4CD1-9A18-E1DDDD3B2338}</ProjectGuid> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>Pyrolite.PickleExample</RootNamespace> | ||
<AssemblyName>Pyrolite.PickleExample</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DebugSymbols>True</DebugSymbols> | ||
<DebugType>Full</DebugType> | ||
<Optimize>False</Optimize> | ||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DebugSymbols>False</DebugSymbols> | ||
<DebugType>None</DebugType> | ||
<Optimize>True</Optimize> | ||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> | ||
<DefineConstants>TRACE</DefineConstants> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> | ||
<PlatformTarget>x86</PlatformTarget> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core"> | ||
<RequiredTargetFramework>3.5</RequiredTargetFramework> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="PickleTest.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Pyrolite\Pyrolite.csproj"> | ||
<Project>{E6EAC69D-D42A-4A86-AFBE-18A1013BFDAB}</Project> | ||
<Name>Pyrolite</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,80 @@ | ||
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */ | ||
|
||
using System; | ||
using System.Text; | ||
using Razorvine.Pyro; | ||
|
||
namespace Pyrolite.TestPyroFlame | ||
{ | ||
|
||
/// <summary> | ||
/// Test Pyro with a Flame server | ||
/// </summary> | ||
public class TestFlame { | ||
|
||
public static void Main(String[] args) { | ||
try { | ||
Test(); | ||
} catch (Exception x) { | ||
Console.WriteLine("unhandled exception: {0}",x); | ||
} | ||
} | ||
|
||
public static void Test() { | ||
|
||
Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)..."); | ||
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION); | ||
|
||
setConfig(); | ||
using(dynamic flame=new PyroProxy("localhost",9999,"Pyro.Flame")) | ||
{ | ||
Console.WriteLine("builtin:"); | ||
using(dynamic r_max=(FlameBuiltin)flame.builtin("max")) | ||
{ | ||
int maximum=(int)r_max(new int[]{22,99,1}); // invoke remote max() builtin function | ||
Console.WriteLine("maximum="+maximum); | ||
} | ||
|
||
using(dynamic r_module=(FlameModule)flame.module("socket")) | ||
{ | ||
String hostname=(String)r_module.gethostname(); // get remote hostname | ||
Console.WriteLine("hostname="+hostname); | ||
} | ||
|
||
int sum=(int)flame.evaluate("9+9"); | ||
Console.WriteLine("sum="+sum); | ||
|
||
flame.execute("import sys; sys.stdout.write('HELLO FROM C#\\n')"); | ||
|
||
using(FlameRemoteConsole console=(FlameRemoteConsole)flame.console()) | ||
{ | ||
console.interact(); | ||
} | ||
} | ||
} | ||
|
||
static void setConfig() | ||
{ | ||
Config.SERIALIZER = Config.SerializerType.pickle; // flame requires pickle | ||
|
||
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR"); | ||
if(tracedir!=null) { | ||
Config.MSG_TRACE_DIR=tracedir; | ||
} | ||
} | ||
} | ||
|
||
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */ | ||
|
||
using System; | ||
using System.Text; | ||
using Razorvine.Pyro; | ||
|
||
namespace Pyrolite.TestPyroFlame | ||
{ | ||
|
||
/// <summary> | ||
/// Test Pyro with a Flame server | ||
/// </summary> | ||
public class TestFlame { | ||
|
||
static protected byte[] hmacKey; // just ignore this if you don't specify a PYRO_HMAC_KEY environment var | ||
|
||
public static void Main(String[] args) { | ||
try { | ||
Test(); | ||
} catch (Exception x) { | ||
Console.WriteLine("unhandled exception: {0}",x); | ||
} | ||
} | ||
|
||
public static void Test() { | ||
|
||
Console.WriteLine("Testing Pyro flame server (make sure it's running on localhost 9999)..."); | ||
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION); | ||
|
||
setConfig(); | ||
using(dynamic flame=new PyroProxy("localhost",9999,"Pyro.Flame")) | ||
{ | ||
if(hmacKey!=null) flame.pyroHmacKey = hmacKey; | ||
|
||
Console.WriteLine("builtin:"); | ||
using(dynamic r_max=(FlameBuiltin)flame.builtin("max")) | ||
{ | ||
if(hmacKey!=null) r_max.pyroHmacKey = hmacKey; | ||
|
||
int maximum=(int)r_max(new int[]{22,99,1}); // invoke remote max() builtin function | ||
Console.WriteLine("maximum="+maximum); | ||
} | ||
|
||
using(dynamic r_module=(FlameModule)flame.module("socket")) | ||
{ | ||
if(hmacKey!=null) r_module.pyroHmacKey = hmacKey; | ||
|
||
String hostname=(String)r_module.gethostname(); // get remote hostname | ||
Console.WriteLine("hostname="+hostname); | ||
} | ||
|
||
int sum=(int)flame.evaluate("9+9"); | ||
Console.WriteLine("sum="+sum); | ||
|
||
flame.execute("import sys; sys.stdout.write('HELLO FROM C#\\n')"); | ||
|
||
using(FlameRemoteConsole console=(FlameRemoteConsole)flame.console()) | ||
{ | ||
console.interact(); | ||
} | ||
|
||
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine(); | ||
} | ||
} | ||
|
||
static void setConfig() | ||
{ | ||
string hmackeyEnv=Environment.GetEnvironmentVariable("PYRO_HMAC_KEY"); | ||
if(hmackeyEnv!=null) { | ||
hmacKey=Encoding.UTF8.GetBytes(hmackeyEnv); | ||
} | ||
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR"); | ||
if(tracedir!=null) { | ||
Config.MSG_TRACE_DIR=tracedir; | ||
} | ||
Config.SERIALIZER = Config.SerializerType.pickle; // flame requires the pickle serializer | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.