Mercurial > hg > Database > Christie-sharp
changeset 50:476b6efeca5b
bug fixing
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 11 Jan 2022 16:43:29 +0900 |
parents | 6d733b2ea461 |
children | 486683ead53f |
files | Christie_net.csproj Test/Example/FizzBuzz/Counter.cs Test/Example/FizzBuzz/StartFizzBuzz.cs daemon/Connection.cs daemon/IncomingTcpConnection.cs daemon/OutboundTcpConnection.cs datagear/LocalDataGearManager.cs datagear/RemoteDataGearManager.cs datagear/command/PutCommand.cs datagear/dg/DataGear.cs datagear/dg/MessagePackDataGear.cs |
diffstat | 11 files changed, 42 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/Christie_net.csproj Mon Jan 10 03:16:33 2022 +0900 +++ b/Christie_net.csproj Tue Jan 11 16:43:29 2022 +0900 @@ -3,7 +3,7 @@ <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> - <StartupObject>Christie_net.Test.Example.OddEven.StarOddEven</StartupObject> + <StartupObject>Christie_net.Test.Example.FizzBuzz.StartFizzBuzz</StartupObject> </PropertyGroup> <ItemGroup>
--- a/Test/Example/FizzBuzz/Counter.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/Test/Example/FizzBuzz/Counter.cs Tue Jan 11 16:43:29 2022 +0900 @@ -5,13 +5,14 @@ namespace Christie_net.Test.Example.FizzBuzz { public class Counter: CodeGear { - [Take] private int count; + [Take] private int num; public override void Run(CodeGearManager cgm) { - if (count <= 100) { - GetDgm("FizzBuzz").Put("num", count); - cgm.GetLocalDGM().Put("cunt", count+1); - + if (num <= 100) { + GetDgm("FizzBuzz").Put("num", num); + + cgm.GetLocalDGM().Put("num", num+1); + //Console.WriteLine("call"); cgm.Setup(new Counter()); } else { GetDgm("FizzBuzz").Put("num", -1);
--- a/Test/Example/FizzBuzz/StartFizzBuzz.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/Test/Example/FizzBuzz/StartFizzBuzz.cs Tue Jan 11 16:43:29 2022 +0900 @@ -4,7 +4,7 @@ namespace Christie_net.Test.Example.FizzBuzz { public class StartFizzBuzz : StartCodeGear { - //[Take] private int i = 1; + [Take] private int i = 1; public StartFizzBuzz(CodeGearManager cgm) : base(cgm) { } @@ -15,7 +15,7 @@ fizzbuzz.Setup(new FizzBuzz()); counter.CreateRemoteDGM("FizzBuzz", "localhost", 10002); //fizzbuzz.CreateRemoteDGM("Counter", "localhost", 10001); - counter.GetLocalDGM().Put("count", 1); + counter.GetLocalDGM().Put("num", 1); } } } \ No newline at end of file
--- a/daemon/Connection.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/daemon/Connection.cs Tue Jan 11 16:43:29 2022 +0900 @@ -53,10 +53,6 @@ /// </summary> /// <param name="cmd"></param> public void Write(Command cmd) { - // Debug - //RTCommand rtcmd = (RTCommand)cmd.dg.GetData(); - //Console.WriteLine("length:" + cmd.dg); - byte[] buffer = cmd.Convert(); try {
--- a/daemon/IncomingTcpConnection.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/daemon/IncomingTcpConnection.cs Tue Jan 11 16:43:29 2022 +0900 @@ -1,15 +1,10 @@ using System; -using System.Collections.Generic; -using System.Data; using System.IO; -using System.Runtime.InteropServices; using Christie_net.codegear; using Christie_net.datagear; using Christie_net.datagear.command; using Christie_net.datagear.dg; -using Christie_net.Test.Example.RemoteTake; using MessagePack; -using Microsoft.VisualBasic; using CommandType = Christie_net.datagear.command.CommandType; @@ -29,61 +24,45 @@ } public void Run() { - - while (true) { //TODO: Data長がわからないので1024で仮置き → ぴったしで読み込む必要がある - byte[] streamData = new byte[1024]; - try { - connection.stream.Read(streamData); - } catch (Exception e) { - Console.WriteLine(e); - } - + byte[] streamData = new byte[100000]; + + int length = 0; try { - // データはRemotemessage(Command), length, dataの順で入っている - //int dataLength = connection.socket.Receive(deserializeCommand); + length = connection.stream.Read(streamData); - // Debug - //Console.WriteLine("length: " + dataLength); + } catch (Exception e) { + Console.WriteLine(e.StackTrace); + } + - RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(streamData); - CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); + // データはRemotemessage(Command), length, dataの順で入っている + //int dataLength = connection.socket.Receive(deserializeCommand); - // Debug - //Console.WriteLine("incoming:" + msg.type); + // Debug + Console.WriteLine("length:" + length); + + RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(streamData); + CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); + + try { byte[] data; switch (type) { case CommandType.PUT: - //data = new byte[MessagePackSerializer.Deserialize<int>(deserializeCommand)]; - //connection.socket.Receive(data); data = msg.data; try { MessagePackDataGear<object> dg = new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); - - // Debug - // var ty = Type.GetType(msg.clazz); - // var obj = MessagePackSerializer.Deserialize<dynamic>(msg.data); - - //Console.WriteLine("obj type: "+ obj); - //Dictionary<dynamic,dynamic> test = (Dictionary<dynamic, dynamic>) obj; - // foreach (var VARIABLE in test) { - // Console.WriteLine("key:" + VARIABLE.Key + " val:" + VARIABLE.Value); - // } - - //RTCommand cmd = (RTCommand) obj; - //Console.WriteLine("***type:" + msg.type + " key:" + msg.key + " fromDgm:" + msg.fromDmgName + " class:" + msg.clazz); - //Console.WriteLine("data :" + cmd.line); - + cgm.GetLocalDGM().Put(msg.key, dg); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } - break; + case CommandType.REMOTEPEEK: case CommandType.REMOTETAKE: try { @@ -94,9 +73,11 @@ cgm.GetLocalDGM().RunCommand(cm); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); + } catch (Exception e) { + Console.WriteLine(e); } - break; + case CommandType.REPLY: // 待っていたwaitlistに渡してcsにセット data = msg.data; @@ -110,14 +91,14 @@ } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } - break; + default: break; } - } catch (IOException e) { - Console.WriteLine(e.StackTrace); - } + } catch (Exception e) { + Console.WriteLine("call: " + e.StackTrace); + } } } }
--- a/daemon/OutboundTcpConnection.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/daemon/OutboundTcpConnection.cs Tue Jan 11 16:43:29 2022 +0900 @@ -32,7 +32,5 @@ } } } - - } } \ No newline at end of file
--- a/datagear/LocalDataGearManager.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/datagear/LocalDataGearManager.cs Tue Jan 11 16:43:29 2022 +0900 @@ -26,8 +26,6 @@ public override void RunCommand(Command cm) { switch (cm.type) { case CommandType.PUT: - // Debug - //Console.WriteLine("data:" + cm.key + " dg:" + cm.dg.GetData().ToString()); dataGears.SetData(cm); if (waitList.ContainsKey(cm.key)) { RunCommand(waitList.GetAndRemoveCommand(cm.key));
--- a/datagear/RemoteDataGearManager.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/datagear/RemoteDataGearManager.cs Tue Jan 11 16:43:29 2022 +0900 @@ -32,10 +32,7 @@ connection = new Connection(socket, cgm); connection.name = dgmname; - - // Debug - //Console.WriteLine("connect:" + connection); - + lock (syncObj) { connect = true; Monitor.Pulse(syncObj); @@ -71,11 +68,6 @@ if (!connect) { ConnectWait(); } - - // Debug - //Console.WriteLine("connect:" + connection.name); - //Console.WriteLine("data:" + cmd.command); - connection.Write(cm); }
--- a/datagear/command/PutCommand.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/datagear/command/PutCommand.cs Tue Jan 11 16:43:29 2022 +0900 @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; using Christie_net.datagear.dg; -using Christie_net.Test.Example.RemoteTake; using MessagePack; namespace Christie_net.datagear.command { @@ -19,28 +17,13 @@ MemoryStream stream = new MemoryStream(); try { - // byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); - // byte[] data = new MessagePackDataGear<object>(dg.GetData()).GetMessagePack(); - // byte[] dataSize = MessagePackSerializer.Serialize(data.Length); - // - // stream.Write(command); - // stream.Write(dataSize); - // stream.Write(data); - - //var dgData = dg.GetData(); - byte[] data = new MessagePackDataGear<dynamic>(dg.GetData()).GetMessagePack(); byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage(data)); - + // Debug - // var ms = MessagePackSerializer.Deserialize<RemoteMessage>(command); - // Console.WriteLine("**type:" + ms.type + " key:" + ms.key + " fromDgm:" + ms.fromDmgName + " class:" + ms.clazz +" data: null"); - // var cmd = MessagePackSerializer.Deserialize<object>(data); - // Dictionary<dynamic,dynamic> test = (Dictionary<dynamic, dynamic>) cmd; - // foreach (var VARIABLE in test) { - // Console.WriteLine("key:" + VARIABLE.Key + " val:" + VARIABLE.Value); - // } - + // RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(command); + // Console.WriteLine("serialize msg:" + msg); + stream.Write(command); stream.Position = 0;
--- a/datagear/dg/DataGear.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/datagear/dg/DataGear.cs Tue Jan 11 16:43:29 2022 +0900 @@ -17,15 +17,11 @@ } public void SetData(T data) { - // debug - //Console.WriteLine("data ****" + data.GetType() + " clazz;" + clazz + ", d:" + data); - var dataClazz = data.GetType(); if (dataClazz == clazz) { this.data = data; return; } - Console.WriteLine("call1"); var dataSuperClazz = dataClazz.BaseType; while (dataSuperClazz != null) { @@ -36,15 +32,14 @@ dataSuperClazz = dataSuperClazz.BaseType; } - Console.WriteLine("call2"); - + var interfaces = dataClazz.GetInterfaces(); foreach (var interfaze in interfaces) if (interfaze == clazz) { this.data = data; return; } - Console.WriteLine("call3"); + throw new InvalidCastException("datagear cannot set class from " + dataClazz.GetType().Name + " to " +data.GetType().Name); }
--- a/datagear/dg/MessagePackDataGear.cs Mon Jan 10 03:16:33 2022 +0900 +++ b/datagear/dg/MessagePackDataGear.cs Tue Jan 11 16:43:29 2022 +0900 @@ -25,10 +25,6 @@ if (messagePack != null) return messagePack; try { - // Debug - // Console.WriteLine("data:" + data); - // Console.WriteLine(); - messagePack = MessagePackSerializer.Serialize(data); SetDataSize(messagePack.Length); @@ -44,10 +40,6 @@ if (data == null) try { var dataObj = MessagePackSerializer.Deserialize<T>(messagePack); - - // Debug - //Console.WriteLine("MSP data: " + dataObj.GetType()); - var convertData = MessagePackDataFormed(dataObj);