view datagear/command/Command.cs @ 17:4a3115ba746d

fix CommandType enum
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 24 Nov 2020 03:11:50 +0900
parents 7352793b5dbe
children 8fe565f8acb8
line wrap: on
line source

using System;
using System.IO;
using Christie_net.codegear;
using Christie_net.daemon;
using Christie_net.datagear.dg;

namespace Christie_net.datagear.command {
public abstract class Command {
    public CommandType type;
    public string key;
    public string toDgmName; // for take
    public string fromDgmName = "local"; // for remotetake/reply
    public int? cgmID = -1; // for localtake
    public CodeGear cg; // for localtake
    public DataGear<object> dg; // for put/localtake/reply
    public Type clazz; // for remote
    public Connection connection = null; // for reply

    public Command(CommandBuilder cb) {
        this.type =  cb.type;
        this.key = cb.key;
        this.toDgmName = cb.toDgmName;
        this.fromDgmName = cb.fromDgmname;
        this.cgmID = cb.cgmID;
        this.cg = cb.cg;
        this.dg = cb.dg;
        this.clazz = cb.clazz;
        this.connection = cb.connection;
    }

    // instead of any Constoractor args
    protected void CheckNeedParam(CommandBuilder cb) { }

    public abstract void Execute();

    // for remote
    public abstract MemoryStream Convert();

    public RemoteMessage CreateRemoteMessage() {
        return new RemoteMessage(type.id, fromDgmName, key, clazz.Name);
    }

    public void SetDg(Object obj) {
        this.dg.SetData(obj);
    }

    public override string ToString() {
        return "Command : type = " + type + ", key = " + key + "toDgmName = " + toDgmName +
               " fromDgmName = " + fromDgmName + " cgmID = " + cgmID + " cg = " + cg + " dg = " + dg + " clazz = " +
               clazz + "connection = " + connection;
    }
}
}