# HG changeset patch # User riono # Date 1605977542 -32400 # Node ID 7352793b5dbe079c4221cb7b1e9df95cb1dadc9d # Parent 49521c7269bcc976580ad8f94d280dfcd9a660c8 add some Commands diff -r 49521c7269bc -r 7352793b5dbe daemon/Connection.cs --- a/daemon/Connection.cs Sat Nov 21 02:21:04 2020 +0900 +++ b/daemon/Connection.cs Sun Nov 22 01:52:22 2020 +0900 @@ -47,11 +47,12 @@ /// /// public void Write(Command cmd) { - byte[] stream = cmd.Convert(); + MemoryStream stream = cmd.Convert(); + byte[] buffer = stream.ToArray(); try { while (stream.Length > 0) { - socket.Send(stream); + socket.Send(buffer); } } catch (Exception e) { Console.WriteLine(e.StackTrace); diff -r 49521c7269bc -r 7352793b5dbe datagear/command/Command.cs --- a/datagear/command/Command.cs Sat Nov 21 02:21:04 2020 +0900 +++ b/datagear/command/Command.cs Sun Nov 22 01:52:22 2020 +0900 @@ -6,6 +6,7 @@ namespace Christie_net.datagear.command { public abstract class Command { + private CommandType _type; public CommandTypeEtx type; public string key; public string toDgmName; // for take @@ -17,7 +18,8 @@ public Connection connection = null; // for reply public Command(CommandBuilder cb) { - this.type = cb.type; + this._type = cb.type.commandType; + this.type = new CommandTypeEtx(_type); this.key = cb.key; this.toDgmName = cb.toDgmName; this.fromDgmName = cb.fromDgmname; @@ -34,7 +36,7 @@ public abstract void Execute(); // for remote - public abstract byte[] Convert(); + public abstract MemoryStream Convert(); public RemoteMessage CreateRemoteMessage() { return new RemoteMessage(type.id, fromDgmName, key, clazz.Name); diff -r 49521c7269bc -r 7352793b5dbe datagear/command/CommandBuilder.cs --- a/datagear/command/CommandBuilder.cs Sat Nov 21 02:21:04 2020 +0900 +++ b/datagear/command/CommandBuilder.cs Sun Nov 22 01:52:22 2020 +0900 @@ -5,6 +5,7 @@ namespace Christie_net.datagear.command { public class CommandBuilder { + private CommandType _type; protected internal CommandTypeEtx type; protected internal string key = null; protected internal string toDgmName = null; // for take @@ -17,8 +18,9 @@ //private CommandFactory factory = new CommandFactory(); - public CommandBuilder init(CommandTypeEtx type) { - this.type = type; + public CommandBuilder init(CommandType type) { + this._type = type; + this.type = new CommandTypeEtx(_type); this.key = null; this.toDgmName = null; this.fromDgmname = "local"; @@ -29,7 +31,5 @@ this.connection = null; return this; } - - } } \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/CommandType.cs --- a/datagear/command/CommandType.cs Sat Nov 21 02:21:04 2020 +0900 +++ b/datagear/command/CommandType.cs Sun Nov 22 01:52:22 2020 +0900 @@ -20,7 +20,9 @@ public static Dictionary hash = new Dictionary(); // コマンド対応表 private static int lastID = 0; // total command number - public CommandTypeEtx() { + // コマンドごとにコンストラクタ内の処理をする必要がある + public CommandTypeEtx(CommandType type) { + commandType = type; StoreValues(); id = IncrementLastID(); } diff -r 49521c7269bc -r 7352793b5dbe datagear/command/ConvertedCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/ConvertedCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,22 @@ +namespace Christie_net.datagear.command { +public class ConvertedCommand { + private byte[] command; + private byte[] data; + + public ConvertedCommand() { + } + + public ConvertedCommand(byte[] command, byte[] data) { + this.command = command; + this.data = data; + } + + public byte[] GetCommand() { + return command; + } + + public byte[] GetData() { + return data; + } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/FinishCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/FinishCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,16 @@ +using System; +using System.IO; + +namespace Christie_net.datagear.command { +public class FinishCommand : Command{ + public FinishCommand(CommandBuilder cb) : base(cb) { } + + public override void Execute() { + Environment.Exit(0); + } + + public override MemoryStream Convert() { + return null; + } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/PeekCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/PeekCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,5 @@ +namespace Christie_net.datagear.command { +public class PeekCommand : TakeCommand{ + public PeekCommand(CommandBuilder cb) : base(cb) { } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/PutCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/PutCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,33 @@ +using System; +using System.IO; +using Christie_net.datagear.dg; +using MessagePack; + +namespace Christie_net.datagear.command { +public class PutCommand : Command{ + public PutCommand(CommandBuilder cb) : base(cb) { + this.clazz = dg.GetClazz(); + } + + public override void Execute() { + } + + // commandとdata, dataSizeをMemoryStreamに変換する + public override MemoryStream Convert() { + MemoryStream stream = new MemoryStream(); + + try { + byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); + byte[] data = new MessagePackDataGear(dg.GetData()).GetMessagePack(); + byte[] dataSize = MessagePackSerializer.Serialize(data.Length); + + stream.Write(command, 0, command.Length); + stream.Write(data, 0, data.Length); + stream.Write(dataSize, 0, dataSize.Length); + } catch (IOException e) { + Console.WriteLine(e.StackTrace); + } + return stream; + } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/RemoteTakeCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/RemoteTakeCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,18 @@ +using System.IO; +using Christie_net.datagear.dg; + +namespace Christie_net.datagear.command { +public class RemoteTakeCommand : Command{ + public RemoteTakeCommand(CommandBuilder cb) : base(cb) { + this.dg = new MessagePackDataGear(this.clazz); + } + + public override void Execute() { + new CommandBuilder().init(CommandType.REPLY). + } + + public override MemoryStream Convert() { + throw new System.NotImplementedException(); + } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/ReplyCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/ReplyCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,16 @@ +namespace Christie_net.datagear.command { +public class ReplyCommand : PutCommand { + + public ReplyCommand(CommandBuilder cb) : base(cb) { + } + + // 自身を書き込み実行させる + public override void Execute() { + connection.Write(this); + } + + public void SetData(object data) { + this.dg.SetData(data); + } +} +} \ No newline at end of file diff -r 49521c7269bc -r 7352793b5dbe datagear/command/TakeCommand.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datagear/command/TakeCommand.cs Sun Nov 22 01:52:22 2020 +0900 @@ -0,0 +1,16 @@ +using System.IO; + +namespace Christie_net.datagear.command { +public class TakeCommand : Command{ + public TakeCommand(CommandBuilder cb) : base(cb) { + this.clazz = dg.GetClazz(); + } + public override void Execute() { + //cg.getIdg() + } + + public override MemoryStream Convert() { + return null; + } +} +} \ No newline at end of file