private void LoadConfiguration() { //PaCell scell = new PaCell(ConfigObject.tp, path + "configuration.pac", false); //object[] conf = (object[])scell.Root.Get(); //configuration = conf; //scell.Close(); string p = path + "configuration.bin"; var fs = File.Open(p, FileMode.Open); configuration = (object[])ByteFlow.Deserialize(new BinaryReader(fs), ConfigObject.tp); if (ismaster) { // Послать приказ другим. TODO: надо бы сделать посылку конфигурации, тогда можно будет от мастера "плясать"??? int nnodes = ((object[])configuration[1]).Count(); for (int nd = 1; nd < nnodes; nd++) { indicomm.Order(nd - 1, _loadconfiguration, 0, null); // нулевая таблица несущественна } } }
/// <summary> /// в канал посылается команда, у которой есть параметры: таблица и сообщение /// </summary> /// <param name="chan"></param> /// <param name="command"></param> /// <param name="tab"></param> /// <param name="message"></param> /// <returns></returns> public object Order(int chan, int command, int tab, object message) { IndividualChannel ch = masterchannels[chan]; // Определяем сигнатуру var typtyp = tass[tab].signatures[command]; ch.bw.Write((byte)command); // посылаем таблицу ch.bw.Write(tab); // посылаем посылку //PaCell.SetPO(typtyp.Item1, ch.bw, message); ByteFlow.Serialize(ch.bw, message, typtyp.Item1); ch.Flush(); object res = null; // Если нужно, принимаем результат if (typtyp.Item2.Vid != PTypeEnumeration.none) { res = ByteFlow.Deserialize(ch.br, typtyp.Item2); // PaCell.GetPO(typtyp.Item2, ch.br); } return(res); }
public static void Test() { PType tp_point = new PTypeRecord( new NamedType("x", new PType(PTypeEnumeration.real)), new NamedType("y", new PType(PTypeEnumeration.real))); PType tp_figure = new PTypeUnion( new NamedType("nothing", new PType(PTypeEnumeration.none)), new NamedType("point", tp_point), new NamedType("polygon", new PTypeSequence(tp_point)), new NamedType("circle", new PTypeRecord( new NamedType("center", tp_point), new NamedType("radius", new PType(PTypeEnumeration.real))))); PType tp_sequ = new PTypeSequence(tp_figure); object sequ = new object[] { new object[] { 1, new object[] { 3.5, 7.8 } }, new object[] { 2, new object[] { new object[] { 0.0, 0.0 }, new object[] { 1.0, 0.0 }, new object[] { 1.0, 1.0 }, new object[] { 0.0, 1.0 } } }, new object[] { 3, new object[] { new object[] { 5.0, 5.0 }, 4.99 } } }; // Выполним текстовую сериализацию TextFlow.Serialize(Console.Out, sequ, tp_sequ); Console.WriteLine(); // Создадим Stream, сделаем бинарную сериализацию, будем считать, что это файл Stream stream = new MemoryStream(); ByteFlow.Serialize(new BinaryWriter(stream), sequ, tp_sequ); // Десериализуем стрим (бинарный файл) stream.Position = 0L; object sequ_1 = ByteFlow.Deserialize(new BinaryReader(stream), tp_sequ); // Проверим полученное значение Console.WriteLine(tp_sequ.Interpret(sequ_1)); }