Skip to content
Permalink
Browse files

Updating ZGuideExamples, build.sh

  • Loading branch information...
metadings committed Feb 14, 2019
1 parent d74e505 commit b6d261edadd05e7bc7153a4f995f3a46df0fe45f
Showing with 8,337 additions and 85 deletions.
  1. +19 −10 .travis.yml
  2. +0 −21 MacOSX.build.sh
  3. +27 −0 ZGuideExamples/AssemblyInfo.cs
  4. +121 −0 ZGuideExamples/Program.cs
  5. +179 −0 ZGuideExamples/ProgramRunner.cs
  6. +342 −0 ZGuideExamples/README.md
  7. +44 −0 ZGuideExamples/Z85Encode.cs
  8. +111 −0 ZGuideExamples/ZGuideExamples.mono.csproj
  9. +166 −0 ZGuideExamples/ZGuideExamples.vs.csproj
  10. +183 −0 ZGuideExamples/asyncsrv.cs
  11. +56 −0 ZGuideExamples/eagain.cs
  12. +153 −0 ZGuideExamples/espresso.cs
  13. +437 −0 ZGuideExamples/flcliapi.cs
  14. +109 −0 ZGuideExamples/flclient1.cs
  15. +209 −0 ZGuideExamples/flclient2.cs
  16. +74 −0 ZGuideExamples/flclient3.cs
  17. +61 −0 ZGuideExamples/flserver1.cs
  18. +86 −0 ZGuideExamples/flserver2.cs
  19. +97 −0 ZGuideExamples/flserver3.cs
  20. +58 −0 ZGuideExamples/hwclient.cs
  21. +57 −0 ZGuideExamples/hwserver.cs
  22. +51 −0 ZGuideExamples/identity.cs
  23. +96 −0 ZGuideExamples/interrupt.cs
  24. +241 −0 ZGuideExamples/lbbroker.cs
  25. +172 −0 ZGuideExamples/lpclient.cs
  26. +69 −0 ZGuideExamples/lpserver.cs
  27. +115 −0 ZGuideExamples/lvcache.cs
  28. +581 −0 ZGuideExamples/mdbroker.cs
  29. +205 −0 ZGuideExamples/mdcliapi.cs
  30. +193 −0 ZGuideExamples/mdcliapi2.cs
  31. +37 −0 ZGuideExamples/mdclient.cs
  32. +41 −0 ZGuideExamples/mdclient2.cs
  33. +106 −0 ZGuideExamples/mdp.cs
  34. +36 −0 ZGuideExamples/mdworker.cs
  35. +270 −0 ZGuideExamples/mdwrkapi.cs
  36. +44 −0 ZGuideExamples/mmiecho.cs
  37. +36 −0 ZGuideExamples/msgqueue.cs
  38. +63 −0 ZGuideExamples/mspoller.cs
  39. +79 −0 ZGuideExamples/msreader.cs
  40. +72 −0 ZGuideExamples/mtrelay.cs
  41. +66 −0 ZGuideExamples/mtserver.cs
  42. +66 −0 ZGuideExamples/pathopub.cs
  43. +64 −0 ZGuideExamples/pathosub.cs
  44. +106 −0 ZGuideExamples/peering1.cs
  45. +344 −0 ZGuideExamples/peering2.cs
  46. +237 −0 ZGuideExamples/ppqueue.cs
  47. +211 −0 ZGuideExamples/ppworker.cs
  48. +58 −0 ZGuideExamples/psenvpub.cs
  49. +47 −0 ZGuideExamples/psenvsub.cs
  50. +68 −0 ZGuideExamples/rrbroker.cs
  51. +41 −0 ZGuideExamples/rrclient.cs
  52. +67 −0 ZGuideExamples/rrworker.cs
  53. +107 −0 ZGuideExamples/rtdealer.cs
  54. +104 −0 ZGuideExamples/rtreq.cs
  55. +139 −0 ZGuideExamples/spqueue.cs
  56. +84 −0 ZGuideExamples/spworker.cs
  57. +128 −0 ZGuideExamples/suisnail.cs
  58. +59 −0 ZGuideExamples/syncpub.cs
  59. +63 −0 ZGuideExamples/syncsub.cs
  60. +54 −0 ZGuideExamples/tasksink.cs
  61. +58 −0 ZGuideExamples/tasksink2.cs
  62. +60 −0 ZGuideExamples/taskvent.cs
  63. +49 −0 ZGuideExamples/taskwork.cs
  64. +62 −0 ZGuideExamples/taskwork2.cs
  65. +112 −0 ZGuideExamples/ticlient.cs
  66. +358 −0 ZGuideExamples/titanic.cs
  67. +131 −0 ZGuideExamples/tripping.cs
  68. +29 −0 ZGuideExamples/version.cs
  69. +77 −0 ZGuideExamples/wuclient.cs
  70. +78 −0 ZGuideExamples/wuproxy.cs
  71. +58 −0 ZGuideExamples/wuserver.cs
  72. +4 −0 app.config
  73. +25 −0 appveyor.yml
  74. +19 −0 build.sh
  75. +1 −1 clrzmq4.mono.sln
  76. +7 −1 clrzmq4.vs.sln
  77. +0 −52 travis.preinstall.sh
@@ -1,23 +1,32 @@
solution: clrzmq4.mono.sln
language: csharp
mono: latest
sudo: required
solution: clrzmq4.mono.sln
#dotnet: 1.0.3

matrix:
include:
- os: linux
dist: trusty
mono: latest
dist: xenial

- os: osx
osx_image: xcode7.3
mono: latest
osx_image: xcode9.4
# osx_image: xcode7.3

before_install:
- chmod a+x ./travis.preinstall.sh
- sudo apt-get install -y libzmq5
# - chmod a+x ./travis.preinstall.sh

install:
- ./travis.preinstall.sh
- nuget restore clrzmq4.mono.sln
# - ./travis.preinstall.sh

before_script:
- chmod a+x ./MacOSX.build.sh
- msbuild clrzmq4.mono.sln /p:Configuration=Release
# - chmod a+x ./build.sh
# - ./build.sh

script:
- ./MacOSX.build.sh
- mono bin/Release/ZGuideExamples.exe EAgain
- mono bin/Release/ZGuideExamples.exe Espresso
- mono bin/Release/ZGuideExamples.exe AsyncSrv
- mono bin/Release/ZGuideExamples.exe SuiSnail

This file was deleted.

@@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("ZGuideExamples")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("metadings")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

@@ -0,0 +1,121 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

using ZeroMQ;

namespace Examples
{
static partial class Program
{
// INFO: You will find a "static int Main(string[] args)" in ProgramRunner.cs

public static bool Verbose = false;

static void Console_WriteZFrame(string format, ZFrame frame, params object[] data)
{
var renderer = new StringBuilder();

var list = new List<object>(data);

// here the renderer

renderer.Append(format);
renderer.Append(": ");
renderer.Append("{");
renderer.Append(0 + data.Length);
renderer.Append("}");

// now the message

frame.Position = 0;

if (frame.Length == 0)
list.Add("0");
else
list.Add(frame.ReadString());

frame.Position = 0;

Console.WriteLine(renderer.ToString(), list.ToArray());
}

static void Console_WriteZMessage(string format, ZMessage message, params object[] data)
{
Console_WriteZMessage(format, 0, message, data);
}

static void Console_WriteZMessage(string format, int messagesNotToRead, ZMessage message, params object[] data)
{
var renderer = new StringBuilder();

var list = new List<object>(data);

for (int i = messagesNotToRead, c = message.Count; i < c; ++i)
{
// here the renderer
if (i == messagesNotToRead)
{
renderer.Append(format);
renderer.Append(": ");
}
else
{
renderer.Append(", ");
}
renderer.Append("{");
renderer.Append( (i - messagesNotToRead) + data.Length );
renderer.Append("}");

// now the message
ZFrame frame = message[i];

frame.Position = 0;

if (frame.Length == 0)
list.Add("0");
else
list.Add(frame.ReadString());

frame.Position = 0;
}

Console.WriteLine(renderer.ToString(), list.ToArray());
}
}

public static class Ext {

public static string ToHexString(this byte[] hex) {
if (hex == null) {
return null;
}
if (hex.Length == 0) {
return string.Empty;
}
var s = new StringBuilder();
foreach (byte b in hex) {
s.Append(b.ToString("x2"));
}
return s.ToString();
}

public static byte[] ToHexBytes(this string hex)
{
if (hex == null) {
return null;
}
if (hex.Length == 0) {
return new byte[0];
}
int l = hex.Length / 2;
var b = new byte[l];
for (int i = 0; i < l; ++i) {
b[i] = Convert.ToByte(hex.Substring(i * 2, 2), 16);
}
return b;
}
}
}
@@ -0,0 +1,179 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Threading;

namespace Examples
{
static class ProgramRunner
{
static int Main(string[] args)
{
int returnMain = 0; // C good

int leaveOut = 0;
var dict = new Dictionary<string, string>();
FieldInfo[] fields = typeof(Program).GetFields(BindingFlags.Public | BindingFlags.Static).OrderBy(field => field.Name).ToArray();
foreach (string arg in args)
{
if (!arg.StartsWith("--", StringComparison.OrdinalIgnoreCase)) break;

leaveOut++;

int iOfEquals = arg.IndexOf('=');
string key, value;
if (-1 < iOfEquals)
{
key = arg.Substring(0, iOfEquals);
value = arg.Substring(iOfEquals + 1);
}
else {
key = arg.Substring(0);
value = null;
}
dict.Add(key, value);

FieldInfo keyField = fields.Where(field => string.Equals(field.Name, key.Substring(2), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (keyField != null)
{
if (keyField.FieldType == typeof(string))
{
keyField.SetValue(null, value);
}
else if (keyField.FieldType == typeof(bool))
{
bool equalsTrue = (value == null || value == string.Empty);
if (!equalsTrue)
equalsTrue = string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
if (!equalsTrue)
equalsTrue = string.Equals(value, "+", StringComparison.OrdinalIgnoreCase);

keyField.SetValue(null, equalsTrue);
}
}
}

var methods = typeof(Program).GetMethods(BindingFlags.Public | BindingFlags.Static).OrderBy(method => method.Name).ToList();
string command = (args.Length == 0) ? "help" : args[0 + leaveOut].ToLower();
if (command != "help")
{
var method = methods.FirstOrDefault(m => m.Name.Equals(command, StringComparison.OrdinalIgnoreCase));
if (method != null)
{
object[] parameters = null;
ParameterInfo[] arguments = method.GetParameters();

if (arguments.Length == 2)
{
parameters = new object[] {
dict, args.Skip(1 + leaveOut).ToArray() /* string[] args */
};
}
else if (arguments.Length == 1)
{
parameters = new object[] {
args.Skip(1 + leaveOut).ToArray() /* string[] args */
};
}

object result = DebugStackTrace<TargetInvocationException>.Invoke(
method, /* static */null, parameters);

if (method.ReturnType == typeof(bool))
{
return (bool)result ? 0 : 1;
}
if (method.ReturnType == typeof(int))
{
return (int)result;
}
return 0; // method.ReturnType == typeof(Void)
}

returnMain = 1; // C bad
Console.WriteLine();
Console.WriteLine("Command invalid.");
}

Console.WriteLine();
Console.WriteLine("Usage: ./" + AppDomain.CurrentDomain.FriendlyName + " [--option] <command> World");

if (fields.Length > 0)
{
Console.WriteLine();
Console.WriteLine("Available [option]s:");
Console.WriteLine();
foreach (FieldInfo field in fields)
{
Console.WriteLine(" --{0}", field.Name);
}
}

Console.WriteLine();
Console.WriteLine("Available <command>s:");
Console.WriteLine();

foreach (MethodInfo method in methods)
{
if (method.Name == "Main")
continue;
if (0 < method.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), true).Length)
continue;

Console.WriteLine(" {0}", method.Name);
}

Console.WriteLine();
return returnMain;
}
}


internal static class DebugStackTrace<TException>
where TException : Exception
{
[System.Diagnostics.DebuggerNonUserCode]
[System.Diagnostics.DebuggerStepThrough]
public static object Invoke(MethodInfo method, object target, params object[] args)
{
// source : http://csharptest.net/350/throw-innerexception-without-the-loosing-stack-trace/

try
{
return method.Invoke(target, args);
}
catch (TException te)
{
if (te.InnerException == null)
throw te;

Exception innerException = te.InnerException;

var savestack = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), innerException, "InternalPreserveStackTrace", false, false);
if (savestack != null) savestack();

throw innerException; // -- now we can re-throw without trashing the stack /**/

// PreserveStackTrace(te);
// throw te;
}
}

// http://stackoverflow.com/a/2085377/1352471 (Anton Tykhyy on In C#, how can I rethrow InnerException without losing stack trace?)
static void PreserveStackTrace(Exception e)
{
var ctx = new StreamingContext(StreamingContextStates.CrossAppDomain);
var mgr = new ObjectManager(null, ctx);
var si = new SerializationInfo(e.GetType(), new FormatterConverter());

e.GetObjectData(si, ctx);
mgr.RegisterObject(e, 1, si); // prepare for SetObjectData
mgr.DoFixups(); // ObjectManager calls SetObjectData

// voila, e is unmodified save for _remoteStackTraceString
}

}
}

0 comments on commit b6d261e

Please sign in to comment.
You can’t perform that action at this time.