Mercurial > hg > Database > Christie-sharp
view codegear/CodeGear.cs @ 71:1169915705ab default tip
fix TopologyNode connect
author | KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 06 Feb 2022 16:47:41 +0900 |
parents | dc3f59937772 |
children |
line wrap: on
line source
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using Christie_net.annotation; using Christie_net.datagear; using Christie_net.datagear.command; using Christie_net.datagear.dg; namespace Christie_net.codegear { public abstract class CodeGear { private InputDataGear idg; private List<Command> commandList = new List<Command>(); private CodeGearManager cgm; private DataGearManager localDgm; private CodeGearExecutor cge; public CodeGear() { idg = new InputDataGear(this); } public abstract void Run(CodeGearManager cgm); public void Setup(CodeGearManager cgm, int priority = 5) { this.cgm = cgm; this.cge = new CodeGearExecutor(this, this.cgm, priority); this.localDgm = cgm.GetLocalDGM(); foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { if (Attribute.IsDefined(field, typeof(Take))) { SetCommand(CommandType.TAKE, "local", field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(Peek))) { SetCommand(CommandType.PEEK, "local", field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(TakeFrom))) { TakeFrom attri = (TakeFrom) field.GetCustomAttribute(typeof(TakeFrom)); SetCommand(CommandType.TAKE, attri.name, field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(PeekFrom))) { PeekFrom attri = (PeekFrom) field.GetCustomAttribute(typeof(PeekFrom)); SetCommand(CommandType.PEEK, attri.name, field.Name, new DataGear<object>(field.FieldType)); } } idg.FinishInput(cgm, commandList); } public void SetCommand(CommandType type, string toDgmName, string key, DataGear<object> dg) { Command command = new CommandBuilder().Init(type).Cg(this) .CgmID(cgm.cgmID) .ToDgmName(toDgmName) .Key(key) .Dg(dg) .Build(); commandList.Add(command); } public DataGearManager GetLocalDgm() { return localDgm; } public DataGearManager GetDgm(string dgmName) { return cgm.GetDGM(dgmName); } public CodeGear Put(string dgmName, string key, object data) { GetDgm(dgmName).Put(key, data); return this; } public CodeGear Put(string key, object data) { localDgm.Put(key, data); return this; } public bool ContainsDgm(string dgmName) { return cgm.ContainsDgm(dgmName); } public void Finish(string managerKey) { if (cgm.GetDgmList().ContainsKey(managerKey)) ; cgm.GetDgmList()[managerKey].Finish(); } public void Flip(string dgmName, string key) { foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { if (field.Name == key) { try { GetDgm(dgmName).Put(key, field.GetValue(this)); } catch {} } } } public InputDataGear GetIdg() { return idg; } public CodeGearExecutor GetCge() { return cge; } } }