Skip to content

Commit

Permalink
massive code style cleanup, c# 6 language level features
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Jul 8, 2018
1 parent 5a7b616 commit 87de771
Show file tree
Hide file tree
Showing 54 changed files with 1,226 additions and 1,151 deletions.
10 changes: 4 additions & 6 deletions dotnet/Razorvine.Pyrolite/DebugHelper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ namespace DebugHelper
/// </summary>
public static class Program
{
public static void Main(string[] args)
public static void Main()
{
Unpickler u=new Unpickler();
byte[] data;
object result;


Console.WriteLine("here we go; 1");
data=PickleUtils.str2bytes("\u0080\u0002carray\narray\nq\u0000U\u0001iq\u0001]q\u0002\u0086q\u0003Rq\u0004.");
result=u.loads(data);
var data = PickleUtils.str2bytes("\u0080\u0002carray\narray\nq\u0000U\u0001iq\u0001]q\u0002\u0086q\u0003Rq\u0004.");
var result = u.loads(data);
PrettyPrint.print(result);

Console.WriteLine("here we go; 2");
Expand Down
13 changes: 7 additions & 6 deletions dotnet/Razorvine.Pyrolite/EchoExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using Razorvine.Pyro;
// ReSharper disable CheckNamespace
// ReSharper disable PossibleNullReferenceException

namespace Pyrolite.TestPyroEcho
{
Expand All @@ -11,7 +12,7 @@ namespace Pyrolite.TestPyroEcho
/// </summary>
public static class Program
{
public static void Main(String[] args) {
public static void Main(string[] args) {

char test;
if(args.Length==1)
Expand All @@ -21,21 +22,21 @@ public static void Main(String[] args) {
test = Console.ReadLine().Trim().ToLowerInvariant()[0];
}

setConfig();
SetConfig();
try {
switch(test)
{
case 'e':
Console.WriteLine("\r\nRunning ECHO test.\r\n");
new TestEcho().Run();
TestEcho.Run();
break;
case 'h':
Console.WriteLine("\r\nRunning HANDSHAKE test.\r\n");
new TestHandshake().Run();
TestHandshake.Run();
break;
case 's':
Console.WriteLine("\r\nRunning STREAMING test.\r\n");
new TestStreaming().Run();
TestStreaming.Run();
break;
default:
Console.Error.WriteLine("invalid choice");
Expand All @@ -48,7 +49,7 @@ public static void Main(String[] args) {
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
}

static void setConfig()
private static void SetConfig()
{
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
if(tracedir!=null) {
Expand Down
20 changes: 11 additions & 9 deletions dotnet/Razorvine.Pyrolite/EchoExample/TestEcho.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Pyrolite.TestPyroEcho
/// <summary>
/// This custom proxy adds custom annotations to the pyro messages
/// </summary>
// ReSharper disable once ArrangeTypeModifiers
// ReSharper disable once UnusedMember.Global
class CustomProxy : PyroProxy
{
public CustomProxy(PyroURI uri): base(uri)
Expand All @@ -30,11 +32,11 @@ public override IDictionary<string, byte[]> annotations()
/// <summary>
/// Test Pyro with the Pyro echo server.
/// </summary>
public class TestEcho {
private static readonly byte[] hmacKey = null; // Encoding.UTF8.GetBytes("foo");
public static class TestEcho {
private static readonly byte[] HmacKey = null; // Encoding.UTF8.GetBytes("foo");


public void Run() {
public static void Run() {

Console.WriteLine("Testing Pyro echo server (make sure it's running, with nameserver enabled)...");
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
Expand All @@ -45,17 +47,17 @@ public void Run() {
if(Config.SERIALIZER==Config.SerializerType.serpent)
Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");

NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: hmacKey);
NameServerProxy ns = NameServerProxy.locateNS(null, hmacKey: HmacKey);
using(dynamic p = new PyroProxy(ns.lookup("test.echoserver")))
{
p.pyroHmacKey=hmacKey;
p.pyroHmacKey=HmacKey;
p.pyroHandshake = "banana";

// non-dynamic way of constructing a proxy is:
// PyroProxy p=new PyroProxy("localhost",9999,"test.echoserver");

Console.WriteLine("echo(), param=42:");
Object result=p.echo(42);
object result=p.echo(42);
Console.WriteLine("return value:");
PrettyPrint.print(result);

Expand All @@ -76,7 +78,7 @@ public void Run() {

// some more examples

String s="This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";
string s="This string is way too long. This string is way too long. This string is way too long. This string is way too long. ";
s=s+s+s+s+s;
Console.WriteLine("echo param:");
PrettyPrint.print(s);
Expand All @@ -85,7 +87,7 @@ public void Run() {
PrettyPrint.print(result);

Console.WriteLine("dict test.");
IDictionary<string, object> map = new Dictionary<string, object>()
IDictionary<string, object> map = new Dictionary<string, object>
{
{"value", 42},
{"message", "hello"},
Expand All @@ -105,7 +107,7 @@ public void Run() {
Debug.Assert(p2.pyroMethods.Contains("echo"));
if(p2.pyroHmacKey!=null) {
string hmac2 = Encoding.UTF8.GetString(p2.pyroHmacKey);
Debug.Assert(hmac2==Encoding.UTF8.GetString(hmacKey));
Debug.Assert(hmac2==Encoding.UTF8.GetString(HmacKey));
}

Console.WriteLine("remote iterator test.");
Expand Down
27 changes: 17 additions & 10 deletions dotnet/Razorvine.Pyrolite/EchoExample/TestHandshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using Razorvine.Pyro;
// ReSharper disable CheckNamespace
// ReSharper disable PossibleNullReferenceException
// ReSharper disable once InconsistentNaming

namespace Pyrolite.TestPyroEcho
{
Expand All @@ -27,20 +29,25 @@ public override IDictionary<string, byte[]> annotations()

public override void validateHandshake(object handshake_response) {
// the handshake example server returns a list.
var response_list = (IList<object>) handshake_response;
Console.WriteLine("Proxy received handshake response data: "+ string.Join(",", response_list));
var responseList = (IList<object>) handshake_response;
Console.WriteLine("Proxy received handshake response data: "+ string.Join(",", responseList));
}

public override void responseAnnotations(IDictionary<string, byte[]> annotations, ushort msgtype) {
Console.WriteLine(" Got response (type={0}). Annotations:", msgtype);
foreach(var ann in annotations) {
string value;
if(ann.Key=="CORR") {
value = new Guid(ann.Value).ToString();
} else if (ann.Key=="HMAC") {
value = "[...]";
} else {
value = ann.Value.ToString();
switch (ann.Key)
{
case "CORR":
value = new Guid(ann.Value).ToString();
break;
case "HMAC":
value = "[...]";
break;
default:
value = ann.Value.ToString();
break;
}
Console.WriteLine(" {0} -> {1}", ann.Key, value);
}
Expand All @@ -51,9 +58,9 @@ public override void responseAnnotations(IDictionary<string, byte[]> annotations
/// Test Pyro with the Handshake example server to see
/// how custom annotations and handshake handling is done.
/// </summary>
public class TestHandshake {
public static class TestHandshake {

public void Run() {
public static void Run() {

Console.WriteLine("Testing Pyro handshake and custom annotations. Make sure the server from the pyro handshake example is running.");
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
Expand Down
11 changes: 6 additions & 5 deletions dotnet/Razorvine.Pyrolite/EchoExample/TestStreaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
using System.Collections;
using Razorvine.Pyro;
// ReSharper disable CheckNamespace
// ReSharper disable PossibleNullReferenceException

namespace Pyrolite.TestPyroEcho
{

/// <summary>
/// Test Pyro with streaming.
/// </summary>
public class TestStreaming {
public static class TestStreaming {

public void Run() {
public static void Run() {

setConfig();
SetConfig();
// Config.SERIALIZER = Config.SerializerType.pickle;

Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);
Expand Down Expand Up @@ -71,8 +72,8 @@ public void Run() {
}
}
}
static void setConfig()

private static void SetConfig()
{
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
if(tracedir!=null) {
Expand Down
27 changes: 13 additions & 14 deletions dotnet/Razorvine.Pyrolite/FlameExample/TestFlame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,40 @@ namespace Pyrolite.TestPyroFlame
/// Test Pyro with a Flame server
/// </summary>
public static class TestFlame {
private static readonly byte[] HmacKey = null;

static byte[] hmacKey = null;

public static void Main(String[] args) {
public static void Main() {
try {
Test();
} catch (Exception x) {
Console.WriteLine("unhandled exception: {0}",x);
}
}
public static void Test() {

private 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();
SetConfig();
using(dynamic flame=new PyroProxy("localhost",9999,"Pyro.Flame"))
{
if(hmacKey!=null) flame.pyroHmacKey = hmacKey;
if(HmacKey!=null) flame.pyroHmacKey = HmacKey;

Console.WriteLine("builtin:");
using(dynamic r_max=(FlameBuiltin)flame.builtin("max"))
using(dynamic rMax=(FlameBuiltin)flame.builtin("max"))
{
if(hmacKey!=null) r_max.pyroHmacKey = hmacKey;
if(HmacKey!=null) rMax.pyroHmacKey = HmacKey;

int maximum=(int)r_max(new []{22,99,1}); // invoke remote max() builtin function
int maximum=(int)rMax(new []{22,99,1}); // invoke remote max() builtin function
Console.WriteLine("maximum="+maximum);
}

using(dynamic r_module=(FlameModule)flame.module("socket"))
using(dynamic rModule=(FlameModule)flame.module("socket"))
{
if(hmacKey!=null) r_module.pyroHmacKey = hmacKey;
if(HmacKey!=null) rModule.pyroHmacKey = HmacKey;

String hostname=(String)r_module.gethostname(); // get remote hostname
string hostname=(string)rModule.gethostname(); // get remote hostname
Console.WriteLine("hostname="+hostname);
}

Expand All @@ -63,7 +62,7 @@ public static void Test() {
}
}

static void setConfig()
private static void SetConfig()
{
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
if(tracedir!=null) {
Expand Down
28 changes: 13 additions & 15 deletions dotnet/Razorvine.Pyrolite/NamingExample/TestNaming.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* part of Pyrolite, by Irmen de Jong (irmen@razorvine.net) */

using System;
using System.Collections.Generic;
using Razorvine.Pyro;
// ReSharper disable CheckNamespace

Expand All @@ -12,31 +11,30 @@ namespace Pyrolite.TestPyroNaming
/// Test Pyro with the Pyro name server.
/// </summary>
public static class TestNaming {
private static readonly byte[] HmacKey = null;

static byte[] hmacKey = null;

public static void Main(String[] args) {
public static void Main() {
try {
Test();
} catch (Exception x) {
Console.WriteLine("unhandled exception: {0}",x);
}
Console.WriteLine("\r\nEnter to exit:"); Console.ReadLine();
}
public static void Test() {

private static void Test() {

Console.WriteLine("Testing Pyro nameserver connection (make sure it's running with a broadcast server)...");
Console.WriteLine("Pyrolite version: "+Config.PYROLITE_VERSION);

setConfig();
SetConfig();
// Config.SERIALIZER = Config.SerializerType.pickle;

Console.WriteLine("serializer used: {0}", Config.SERIALIZER);
if(Config.SERIALIZER==Config.SerializerType.serpent)
Console.WriteLine("note that for the serpent serializer, you need to have the Razorvine.Serpent assembly available.");

using(NameServerProxy ns=NameServerProxy.locateNS(null, hmacKey: hmacKey))
using(NameServerProxy ns=NameServerProxy.locateNS(null, hmacKey: HmacKey))
{
Console.WriteLine("discovered ns at "+ns.hostname+":"+ns.port);
ns.ping();
Expand All @@ -54,13 +52,13 @@ public static void Test() {


Console.WriteLine("\nobjects registered in the name server:");
IDictionary<string,string> objects = ns.list(null, null);
var objects = ns.list(null, null);
foreach(string key in objects.Keys) {
Console.WriteLine(key + " --> " + objects[key]);
}

Console.WriteLine("\nobjects registered in the name server, with metadata:");
IDictionary<string, Tuple<string, ISet<string>>> objectsm = ns.list_with_meta(null, null);
var objectsm = ns.list_with_meta(null, null);
foreach(string key in objectsm.Keys) {
var registration = objectsm[key];
Console.WriteLine(key + " --> " + registration.Item1);
Expand Down Expand Up @@ -94,12 +92,12 @@ public static void Test() {

using(PyroProxy p=new PyroProxy(ns.lookup("Pyro.NameServer")))
{
p.pyroHmacKey = hmacKey;
p.pyroHmacKey = HmacKey;
p.call("ping");
}

int num_removed=ns.remove(null, "dotnet.", null);
Console.WriteLine("number of removed entries: {0}",num_removed);
int numRemoved=ns.remove(null, "dotnet.", null);
Console.WriteLine("number of removed entries: {0}",numRemoved);

try {
Console.WriteLine("uri=" + ns.lookup("dotnet.test")); // should fail....
Expand All @@ -110,8 +108,8 @@ public static void Test() {
}

}
static void setConfig()

private static void SetConfig()
{
string tracedir=Environment.GetEnvironmentVariable("PYRO_TRACE_DIR");
if(tracedir!=null) {
Expand Down
Loading

0 comments on commit 87de771

Please sign in to comment.