private IErlObject executeRPC(ErlAtom module, ErlAtom func, ErlList args, ErlMbox mbox = null) { var lnode = ensureLocalNode("executeRPC"); var mowner = mbox == null; if (mowner) { mbox = lnode.CreateMbox(); } try { var timeoutMs = this.CallTimeoutMs; if (timeoutMs <= 0) { timeoutMs = DEFAULT_RPC_TIMEOUT_MS; } return(mbox.RPC(m_RemoteName, module, func, args, timeoutMs, remoteCookie: m_RemoteCookie)); } catch (Exception error) { throw new ErlDataAccessException(StringConsts.ERL_DS_RPC_EXEC_ERROR.Args( "{0}:{1}({2})".Args(module, func, args.ToString().TakeFirstChars(20)), error.ToMessageWithType(), error)); } finally { if (mowner) { lnode.CloseMbox(mbox); } } }
//副本pve 副本pvp 秒杀奖励就放在这个位置 public void parseMAward(ErlList date) { for (int i = 0; i < date.Value.Length; i++) { parseMAward(date.Value[i] as ErlArray); } }
/// <summary> /// Converts ErlCRUD response to CLR CRUD rowset /// </summary> /// <remarks> /// An Example data packet is field defs as speced in schema: /// "tca_jaba": has two field in PK /// [ /// {tca_jaba, {1234, tav}, "User is cool", true}, /// {tca_jaba, {2344, zap}, "A bird wants to drink", false}, /// {tca_jaba, {8944, tav}, "Have you seen this?", false} /// ] /// /// "aaa": has one field in PK - notice no tuple in key /// [ /// {aaa, 1234, tav, "User is cool", true}, /// {aaa, 2344, zap, "A bird wants to drink", false}, /// {aaa, 8944, tav, "Have you seen this?", false} /// ] /// </remarks> public RowsetBase ErlCRUDResponseToRowset(string schemaName, ErlList erlData, Type tRow = null) { var crudSchema = GetCRUDSchemaForName(schemaName); var tSchema = tRow == null ? crudSchema : Schema.GetForTypedRow(tRow); var result = new Rowset(tSchema); foreach (var elm in erlData) { var tuple = elm as ErlTuple; if (tuple == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR + "ErlCRUDResponseToRowset(list element is not tuple)"); } var row = ErlTupleToRow(schemaName, tuple, crudSchema); if (tRow != null) { var trow = Row.MakeRow(tSchema, tRow); row.CopyFields(trow); row = trow; } result.Add(row); } return(result); }
//解析ErlKVMessgae public void parseKVMsg(ErlKVMessage message) { ErlArray list = message.getValue("msg") as ErlArray; if (list == null) { return; } MailManagerment.Instance.clearMail(); //先清理邮箱 for (int i = 0; i < list.Value.Length; i++) { ErlList conList = list.Value [i] as ErlList; int index = 0; string uid = "0"; int src = 0; int type = 0; int stime = 0; int etime = 0; string theme; string content; Annex[] annex = null; int state = 0; uid = ((conList.Value [index] as ErlArray).Value [1]).getValueString(); src = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); type = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); stime = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); etime = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); theme = ((conList.Value [++index] as ErlArray).Value [1]).getValueString(); content = ((conList.Value [++index] as ErlArray).Value [1]).getValueString(); ErlList listc = (conList.Value [++index] as ErlArray).Value [1] as ErlList; annex = MailManagerment.Instance.parseAnnex(listc); state = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); MailManagerment.Instance.createMail(uid, src, type, stime, etime, theme, content, annex, state); } }
public override void read(ErlKVMessage message) { ErlType type = message.getValue("msg") as ErlType; if (type is ErlList) { ErlList list = type as ErlList; string [] results = new string[5]; for (int i = 0; i < results.Length; ++i) { results[i] = list.Value [i].getValueString(); } GuildManagerment.Instance.createGuildShakeResult(results); //投掷/重投成功,减去相应次数 if (!isReShake) { GuildManagerment.Instance.getGuildLuckyNvShenInfo().shakeCount--; } else { GuildManagerment.Instance.getGuildLuckyNvShenInfo().reShakeCount--; } if (callBack != null) { callBack(); callBack = null; } } else { } }
public ErlList addList(ErlList li) { List <ErlType> teamList = new List <ErlType>(); if (_value == null) { for (int i = 0; i < li.Value.Length; i++) { teamList.Add(li.Value[i]); } } else { for (int i = 0; i < _value.Length; i++) { teamList.Add(_value[i]); } for (int ii = 0; ii < li.Value.Length; ii++) { teamList.Add(li.Value[ii]); } // return } return(new ErlList(teamList.ToArray())); }
//更新神秘商店数据 public void updateMysticalShop(ErlList list) { if (mysticalShop == null) { initShop(ShopType.MYSTICAL_SHOP); } mysticalShop.updateGoods(list); }
internal static ErlTuple EncodeRPCcast( ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader) { /*{'$gen_cast', { cast, Mod, Fun, Args, GroupLeader}} */ return(new ErlTuple( ConstAtoms.GenCast, new ErlTuple(ConstAtoms.Cast, mod, fun, args, gleader))); }
public override void read(ErlKVMessage message) { if (message.getValue("add_mail") != null) { ErlType mailType = message.getValue("add_mail") as ErlType; ErlList conList = mailType as ErlList; int index = 0; string uid = "0"; int src = 0; int type = 0; int stime = 0; int etime = 0; string theme; string content; Annex[] annex = null; int state = 0; uid = ((conList.Value [index] as ErlArray).Value [1]).getValueString(); src = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); type = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); stime = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); etime = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); theme = ((conList.Value [++index] as ErlArray).Value [1]).getValueString(); content = ((conList.Value [++index] as ErlArray).Value [1]).getValueString(); ErlList listc = (conList.Value [++index] as ErlArray).Value [1] as ErlList; annex = MailManagerment.Instance.parseAnnex(listc); state = StringKit.toInt(((conList.Value [++index] as ErlArray).Value [1]).getValueString()); MailManagerment.Instance.createMail(uid, src, type, stime, etime, theme, content, annex, state); GameObject mainWin = GameObject.Find("MainWindow"); GameObject win = GameObject.Find("MailWindow"); if (mainWin != null) { // UiManager.Instance.createMessageLintWindow(LanguageConfigManager.Instance.getLanguage("newMail01")); (mainWin.GetComponent <MainWindow> ()).showMailNum(); } else if (win != null) { (win.GetComponent <MailWindow> ()).Initialize(0); (win.GetComponent <MailWindow> ()).mailContent.reLoad(MailManagerment.Instance.getSortAllMail()); (win.GetComponent <MailWindow> ()).changeButton(true); } } if (message.getValue("del_mail") != null) { ErlType erlType = message.getValue("del_mail") as ErlType; ErlList array = erlType as ErlList; for (int i = 0; i < array.Value.Length; i++) { MailManagerment.Instance.addNeedDelUids((array.Value [i] as ErlString).getValueString()); } MailManagerment.Instance.runDeleteUids(); GameObject mainWin = GameObject.Find("MainWindow"); if (mainWin != null) { (mainWin.GetComponent <MainWindow> ()).showMailNum(); } } }
//构建胜利者 private void createWinner(BattleDataErlang battleData, ErlList el, int frame) { //[{"1",1}] BattleClipErlang battleClip = new BattleClipErlang(); battleClip.frame = frame; battleData.battleClip.Add(battleClip); battleClip.isWinnerClip = true; battleData.winnerID = StringKit.toInt((el.Value [0] as ErlArray).Value [1].getValueString()); }
//构建开场buff public void createOpenBuff(BattleDataErlang battleData, ErlType et) { if (et is ErlList) { battleData.isStart = true; ErlList el = et as ErlList; Array.Reverse(el.Value); // 开场技不计入回合 createFight(battleData, el); } }
public static ErlType complexAnalyse(ByteBuffer data) { int position = data.position; int num2 = data.readByte(); data.position = position; if ((num2 == ErlArray.TAG[0]) || (num2 == ErlArray.TAG[1])) { ErlArray array = new ErlArray(null); array.bytesRead(data); return array; } switch (num2) { case 0x6a: { ErlNullList list = new ErlNullList(); list.bytesRead(data); return list; } case 0x6c: { ErlList list2 = new ErlList(null); list2.bytesRead(data); return list2; } case 100: { ErlAtom atom = new ErlAtom(null); atom.bytesRead(data); return atom; } case 0x6b: { ErlString str = new ErlString(null); str.sampleBytesRead(data); return str; } case 110: { ErlLong @long = new ErlLong(); @long.bytesRead(data); return @long; } case 0x6d: { ErlByteArray array2 = new ErlByteArray(null); array2.bytesRead(data); return array2; } } return null; }
public override void read(ErlKVMessage message) { ErlArray arr = message.getValue("msg") as ErlArray; if (arr == null) { return; } for (int i = 0; i < arr.Value.Length; i++) { ErlArray data = arr.Value[i] as ErlArray; ErlArray head = data.Value[0] as ErlArray; ErlList body = data.Value[1] as ErlList; string className = head.Value[0].getValueString(); int key = StringKit.toInt(head.Value[1].getValueString()); for (int j = 0; j < body.Value.Length; j++) { string fieldName = (body.Value[j] as ErlArray).Value[0].getValueString(); string fieldValue = (body.Value[j] as ErlArray).Value[1].getValueString(); Type type = Type.GetType(className); if (type == null) { Debug.LogError("class no find : " + className); return; } IGMUpdateConfigManager inst = type.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public).GetValue(null, null) as IGMUpdateConfigManager; if (inst == null) { Debug.LogError("class no instance" + className); return; } if (!inst.getSamples().ContainsKey(key)) { inst.createSample(key); } MethodInfo method = inst.getSamples()[key].GetType().GetMethod("parse_" + fieldName, BindingFlags.Instance | BindingFlags.NonPublic); if (method == null) { Debug.LogError("no find field GMUpdate Method: perse_" + fieldName + "() (node: this method need private)"); return; } method.Invoke(inst.getSamples()[key], new object[] { fieldValue }); method = null; inst = null; } } }
/// <summary> /// Convert Row to a hierarchical term that corresponds to the row's schema. /// The Erlang term is in the form: /// <code>{SchemaName::atom(), [{FieldName::atom(), Value}]}.</code> /// </summary> /// <param name="row">Row to convert to Erlang object</param> /// <param name="targetName">Target to use to lookup field attributes in the row</param> /// <param name="schemaName">Alternative schema name to use for the outermost name of the schema in the output.</param> /// <param name="outputDefVals">When false no field values are included in output if they are equal to default values</param> public static IErlObject ToErlObject(this Row row, string targetName = null, string schemaName = null, bool outputDefVals = true) { var list = new ErlList(); for (int i = 0; i < row.Count(); ++i) { var fld = row.Schema[i]; var atr = fld[targetName]; var clrVal = row[i]; IErlObject erlVal; // Primitive types are converted using the schema type mapping functions if (clrVal is Row) { // If the row is nested, traverse the hierarchy recursively: var child = (Row)clrVal; if (ts_VisitedRows == null) { ts_VisitedRows = new HashSet <Row>(ReferenceEqualityComparer <Row> .Instance); } if (ts_VisitedRows.Contains(child)) { throw new ErlDataAccessException(StringConsts.ERL_CANNOT_CONVERT_TYPES_CYCLE_ERROR .Args(row.Schema.Name, fld.Name)); } ts_VisitedRows.Add(child); try { erlVal = child.ToErlObject(targetName, null, outputDefVals); } finally { ts_VisitedRows.Remove(child); } list.Add(erlVal); } // Skip default values if instructed to do so with outputDefVals else if (clrVal != null && (outputDefVals || atr.Default == null || !clrVal.Equals(atr.Default))) { erlVal = SchemaMap.ClrToErlValue(atr.BackendType, clrVal); list.Add(new ErlTuple(new ErlAtom(fld.Name), erlVal)); } else if (clrVal == null && atr.Default != null) { erlVal = SchemaMap.ClrToErlValue(atr.BackendType, atr.Default); list.Add(new ErlTuple(new ErlAtom(fld.Name), erlVal)); } } return(new ErlTuple(new ErlAtom(schemaName ?? row.Schema.Name), list)); }
private IErlObject ioProcessRequests( ErlPatternMatcher pm, ErlList requests, IErlObject replyAs) { foreach (var r in requests) { IErlObject term = r; if (pm.Match(ref term, replyAs) < 0) { return(term); } } return(s_ReplyPattern.Subst( new ErlVarBind { { RA, replyAs }, { R, (IErlObject)Tuple.Create(ConstAtoms.Error, ConstAtoms.Request) } })); }
private Annex[] parse(Annex[] annex, ErlList list) { if (list == null) { return(null); } annex = new Annex[list.Value.Length]; for (int i = 0; i < list.Value.Length; i++) { annex[i] = new Annex(); string str = ((list.Value[i] as ErlArray).Value[0] as ErlAtom).getValueString(); if (str == "exp") { string strs = PrizeType.PRIZE_EXP + "," + "0" + "," + ((list.Value[i] as ErlArray).Value[1] as ErlType).getValueString(); annex[i].exp = new PrizeSample(strs, ','); } else if (str == "rmb") { string strs = PrizeType.PRIZE_RMB + "," + "0" + "," + ((list.Value[i] as ErlArray).Value[1] as ErlType).getValueString(); annex[i].rmb = new PrizeSample(strs, ','); } else if (str == "money") { string strs = PrizeType.PRIZE_MONEY + "," + "0" + "," + ((list.Value[i] as ErlArray).Value[1] as ErlType).getValueString(); annex[i].money = new PrizeSample(strs, ','); } else if (str == "pve") { string strs = PrizeType.PRIZE_PVE + "," + "0" + "," + ((list.Value[i] as ErlArray).Value[1] as ErlType).getValueString(); annex[i].pve = new PrizeSample(strs, ','); } else if (str == "pvp") { string strs = PrizeType.PRIZE_PVP + "," + "0" + "," + ((list.Value[i] as ErlArray).Value[1] as ErlType).getValueString(); annex[i].pvp = new PrizeSample(strs, ','); } else if (str == "prop") { string strs = (((list.Value[i] as ErlArray).Value[1] as ErlArray).Value[0]).getValueString() + "," + (((list.Value[i] as ErlArray).Value[1] as ErlArray).Value[1]).getValueString() + "," + (((list.Value[i] as ErlArray).Value[1] as ErlArray).Value[2]).getValueString(); annex[i].prop = new PrizeSample(strs, ','); } } return(annex); }
//构建添加buffer private void createBufferAdd(BattleSkillMsg msg, ErlArray array) { //技能释放者 string str1 = array.Value [0].getValueString(); msg.userID = StringKit.toInt(str1); //技能编号sid string str2 = array.Value [1].getValueString(); msg.skillSID = StringKit.toInt(str2); //技能编号id string str3 = array.Value [2].getValueString(); msg.skillID = StringKit.toInt(str3); //buff影响效果 if (!(array.Value [3] is ErlNullList)) //控制型buffer无效果 { ErlList list = array.Value [3] as ErlList; if (list.Value.Length > 0) { BuffEffectType[] effects = new BuffEffectType[list.Value.Length]; for (int i = 0; i < list.Value.Length; i++) { ErlArray arr = list.Value [i] as ErlArray; string str41 = (arr.Value [0] as ErlAtom).Value; int effect = StringKit.toInt(arr.Value [1].getValueString()); BuffEffectType eff = new BuffEffectType(); eff.type = str41; eff.effect = effect; effects [i] = eff; } msg.effects = effects; } } //被添加buffer者 string str5 = array.Value [4].getValueString(); int[] arrInt4 = new int[1] { StringKit.toInt(str5) }; msg.targets = arrInt4; }
/// <summary> /// Convert Row to a hierarchical term that corresponds to the row's schema. /// The Erlang term is in the form: /// <code>{SchemaName::atom(), [{FieldName::atom(), Value}]}.</code> /// </summary> /// <param name="row">Row to convert to Erlang object</param> /// <param name="targetName">Target to use to lookup field attributes in the row</param> /// <param name="schemaName">Alternative schema name to use for the outermost name of the schema in the output.</param> /// <param name="outputDefVals">When false no field values are included in output if they are equal to default values</param> public static IErlObject ToErlObject(this Row row, string targetName = null, string schemaName = null, bool outputDefVals = true) { var list = new ErlList(); for (int i = 0; i < row.Count(); ++i) { var fld = row.Schema[i]; var atr = fld[targetName]; var clrVal = row[i]; IErlObject erlVal; // Primitive types are converted using the schema type mapping functions if (clrVal is Row) { // If the row is nested, traverse the hierarchy recursively: var child = (Row)clrVal; if (ts_VisitedRows == null) ts_VisitedRows = new HashSet<Row>(ReferenceEqualityComparer<Row>.Instance); if (ts_VisitedRows.Contains(child)) throw new ErlDataAccessException(StringConsts.ERL_CANNOT_CONVERT_TYPES_CYCLE_ERROR .Args(row.Schema.Name, fld.Name)); ts_VisitedRows.Add(child); try { erlVal = child.ToErlObject(targetName, null, outputDefVals); } finally { ts_VisitedRows.Remove(child); } list.Add(erlVal); } // Skip default values if instructed to do so with outputDefVals else if (clrVal != null && (outputDefVals || atr.Default == null || !clrVal.Equals(atr.Default))) { erlVal = SchemaMap.ClrToErlValue(atr.BackendType, clrVal); list.Add(new ErlTuple(new ErlAtom(fld.Name), erlVal)); } else if (clrVal == null && atr.Default != null) { erlVal = SchemaMap.ClrToErlValue(atr.BackendType, atr.Default); list.Add(new ErlTuple(new ErlAtom(fld.Name), erlVal)); } } return new ErlTuple(new ErlAtom(schemaName ?? row.Schema.Name), list); }
/// <summary> /// Converts ErlCRUD response to CLR CRUD rowset /// </summary> /// <remarks> /// An Example data packet is field defs as speced in schema: /// "tca_jaba": has two field in PK /// [ /// {tca_jaba, {1234, tav}, "User is cool", true}, /// {tca_jaba, {2344, zap}, "A bird wants to drink", false}, /// {tca_jaba, {8944, tav}, "Have you seen this?", false} /// ] /// /// "aaa": has one field in PK - notice no tuple in key /// [ /// {aaa, 1234, tav, "User is cool", true}, /// {aaa, 2344, zap, "A bird wants to drink", false}, /// {aaa, 8944, tav, "Have you seen this?", false} /// ] /// </remarks> public RowsetBase ErlCRUDResponseToRowset(string schemaName, ErlList erlData) { var crudSchema = GetCRUDSchemaForName(schemaName); var result = new Rowset(crudSchema); foreach (var elm in erlData) { var tuple = elm as ErlTuple; if (tuple == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR + "ErlCRUDResponseToRowset(list element is not tuple)"); } var row = ErlTupleToRow(schemaName, tuple, crudSchema); result.Add(row); } return(result); }
/// <summary> /// 二进制数据解析 走到这里,肯定是erlang标准二进制数据 /// </summary> /// <returns>The analyse.</returns> /// <param name="data">Data.</param> public static ErlType complexAnalyse(ByteBuffer data) { int position = data.position; int tag = data.readByte(); data.position = position; // MonoBehaviour.print("----------complexAnalyse--------------"+tag); if (tag == ErlArray.TAG [0] || tag == ErlArray.TAG [1]) { ErlArray erlArray = new ErlArray(null); erlArray.bytesRead(data); return(erlArray); } else if (tag == ErlNullList.TAG) { ErlNullList erlNullList = new ErlNullList(); erlNullList.bytesRead(data); return(erlNullList); } else if (tag == ErlList.TAG) { ErlList erlList = new ErlList(null); erlList.bytesRead(data); return(erlList); } else if (tag == ErlAtom.TAG) { ErlAtom erlAtom = new ErlAtom(null); erlAtom.bytesRead(data); return(erlAtom); } else if (tag == ErlString.TAG) { ErlString erlString = new ErlString(null); erlString.sampleBytesRead(data); return(erlString); } else { return(null); } }
private IErlObject ioProcessPutChars(ErlAtom encoding, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject replyAs) { string term; if (mod == ConstAtoms.Io_Lib && fun == ConstAtoms.Format && args.Count == 2) { try { term = ErlObject.Format(args); } catch { term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); } } else { term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); } Node.IoOutput(encoding, new ErlString(term)); return(s_ReplyPattern.Subst( new ErlVarBind { { RA, replyAs }, { R, ConstAtoms.Ok } })); }
public override void read(ErlKVMessage message) { LastBattleKillBossData data; ErlArray info = message.getValue("msg") as ErlArray; LastBattleManagement.Instance.killBossCount = StringKit.toInt(info.Value[0].getValueString()); ErlList infos1 = info.Value[1] as ErlList; ErlArray infos; if (infos1 != null) { LastBattleManagement.Instance.killBossDatas.Clear(); for (int i = 0; i < infos1.Value.Length; i++) { infos = infos1.Value[i] as ErlArray; if (infos != null) { data = new LastBattleKillBossData(); //data.killBossTime = TimeKit.timeTransform(StringKit.toInt(infos.Value[0].getValueString()) * 1000); data.killBossTime = transformTime(StringKit.toInt(infos.Value[0].getValueString())); data.serverName = infos.Value[1].getValueString(); data.playerName = infos.Value[2].getValueString(); if (BossInfoSampleManager.Instance.getBossInfoSampleBySid(StringKit.toInt(infos.Value[3].getValueString())) != null) { data.bossName = BossInfoSampleManager.Instance.getBossInfoSampleBySid(StringKit.toInt(infos.Value[3].getValueString())).name; } else { data.bossName = ""; } data.killBossCount = infos.Value[4].getValueString(); LastBattleManagement.Instance.killBossDatas.Add(data); } } } if (callBack != null) { callBack(); } }
public override void read(ErlKVMessage message) { if (type == 1) { return; } ErlList list = message.getValue("msg") as ErlList; Dictionary <string, PlatFormUserInfo> dictionary; dictionary = new Dictionary <string, PlatFormUserInfo>(); for (int i = 0; i < list.Value.Length; i++) { ErlArray _array1 = list.Value [i] as ErlArray; string uid = _array1.Value [0].getValueString(); ErlList list2 = _array1.Value [1] as ErlList; PlatFormUserInfo info = new PlatFormUserInfo(""); if (list2 == null || list2.Value == null || list2.Value.Length < 2) { continue; } ErlArray _array2 = list2.Value [0] as ErlArray; info.sex = _array2.Value[1].getValueString(); _array2 = list2.Value [1] as ErlArray; info.face = _array2.Value[1].getValueString(); dictionary.Add(uid, info); } if (callback != null) { callback(dictionary); callback = null; } }
//todo: Implement filter that may be passed here from Insert/Update/Upsert protected virtual int CRUDWrite(Row row, bool delete = false) { var rowTuple = m_Map.RowToErlTuple(row, delete); var rowArgs = new ErlList(); rowArgs.Add(rowTuple); // nfx_crud:write({secdef, {}, ...}) var result = this.ExecuteRPC(NFX_CRUD_MOD, delete ? NFX_DELETE_FUN : NFX_WRITE_FUN, rowArgs); if (result == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_INVALID_RESPONSE_PROTOCOL_ERROR + "CRUDWrite==null"); } var bind = result.Match(CRUD_WRITE_OK_PATTERN); if (bind == null) { throw new ErlDataAccessException(StringConsts.ERL_DS_CRUD_WRITE_FAILED_ERROR + result.ToString()); } return(bind[AFFECTED].ValueAsInt); }
public void updateGoods(ErlList list) { ErlArray arr1; Goods good; if (showList == null) { showList = new ArrayList(); } if (showList.Count > 0) { showList.Clear(); } for (int j = 0; j < space.Count; j++) { good = space [j] as Goods; good.isShowInMytical = false; } for (int i = 0; i < list.Value.Length; i++) { arr1 = list.Value [i] as ErlArray; Goods goods; for (int j = 0; j < space.Count; j++) { goods = space [j] as Goods; if (StringKit.toInt((arr1.Value [0]).getValueString()) == goods.sid) { goods.showIndex = i; goods.isShowInMytical = true; goods.isBuy = StringKit.toInt((arr1.Value [1] as ErlType).getValueString()); showList.Add(goods.Clone()); break; } } } }
public void ErlTermSerializeTest() { { var b = new byte[] { 131, 100, 0, 3, 97, 98, 99 }; var t = new ErlAtom("abc"); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 109, 0, 0, 0, 3, 1, 2, 3 }; var t = new ErlBinary(new byte[] { 1, 2, 3 }); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b1 = new byte[] { 131, 100, 0, 4, 116, 114, 117, 101 }; var t1 = new ErlBoolean(true); var os1 = new ErlOutputStream(t1); Assert.AreEqual(b1, os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray()); var es1 = new ErlInputStream(b1); Assert.AreEqual(t1, es1.Read()); var b2 = new byte[] { 131, 100, 0, 5, 102, 97, 108, 115, 101 }; var t2 = new ErlBoolean(false); var os2 = new ErlOutputStream(t2); Assert.AreEqual(b2, os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray()); var es2 = new ErlInputStream(b2); Assert.AreEqual(t2, es2.Read()); } { var b = new byte[] { 131, 97, 127 }; var t = new ErlByte(127); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 70, 64, 36, 62, 249, 219, 34, 208, 229 }; var t = new ErlDouble(10.123); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 108, 0, 0, 0, 3, 97, 1, 70, 64, 36, 61, 112, 163, 215, 10, 61, 108, 0, 0, 0, 2, 100, 0, 4, 116, 114, 117, 101, 107, 0, 1, 97, 106, 106 }; var t = new ErlList(1, 10.12, new ErlList(true, "a")); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b1 = new byte[] { 131, 98, 255, 255, 255, 251 }; var t1 = new ErlLong(-5); var os1 = new ErlOutputStream(t1); Assert.AreEqual(b1, os1.GetBuffer().TakeWhile((_, i) => i < b1.Length).ToArray()); var es1 = new ErlInputStream(b1); Assert.AreEqual(t1, es1.Read()); var b2 = new byte[] { 131, 97, 5 }; var t2 = new ErlLong(5); var os2 = new ErlOutputStream(t2); Assert.AreEqual(b2, os2.GetBuffer().TakeWhile((_, i) => i < b2.Length).ToArray()); var es2 = new ErlInputStream(b2); Assert.AreEqual(t2, es2.Read()); var b3 = new byte[] { 131, 98, 0, 16, 0, 0 }; var t3 = new ErlLong(1024 * 1024); var os3 = new ErlOutputStream(t3); Assert.AreEqual(b3, os3.GetBuffer().TakeWhile((_, i) => i < b3.Length).ToArray()); var es3 = new ErlInputStream(b3); Assert.AreEqual(t3, es3.Read()); var b4 = new byte[] { 131, 110, 6, 0, 0, 0, 0, 0, 0, 4 }; var t4 = new ErlLong(1024L * 1024 * 1024 * 1024 * 4); var os4 = new ErlOutputStream(t4); Assert.AreEqual(b4, os4.GetBuffer().TakeWhile((_, i) => i < b4.Length).ToArray()); var es4 = new ErlInputStream(b4); Assert.AreEqual(t4, es4.Read()); var b5 = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 }; var t5 = new ErlLong(1L << 63); var os5 = new ErlOutputStream(t5); Assert.AreEqual(b5, os5.GetBuffer().TakeWhile((_, i) => i < b5.Length).ToArray()); var es5 = new ErlInputStream(b5); Assert.AreEqual(t5, es5.Read()); var b6 = new byte[] { 131, 110, 8, 1, 0, 0, 0, 0, 0, 0, 0, 128 }; var t6 = new ErlLong(-1L << 63); var os6 = new ErlOutputStream(t6); Assert.AreEqual(b6, os6.GetBuffer().TakeWhile((_, i) => i < b6.Length).ToArray()); var es6 = new ErlInputStream(b6); Assert.AreEqual(t6, es6.Read()); var b7 = new byte[] { 131, 110, 8, 0, 255, 255, 255, 255, 255, 255, 255, 255 }; var es7 = new ErlInputStream(b7); var t7 = new ErlLong(-1); Assert.AreEqual(t7, es7.Read()); var bi7 = new byte[] { 131, 98, 255, 255, 255, 255 }; var os7 = new ErlOutputStream(t7); Assert.AreEqual(bi7, os7.GetBuffer().TakeWhile((_, i) => i < bi7.Length).ToArray()); } { var b = new byte[] { 131, 103, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 0, 0, 0, 0, 1 }; var t = new ErlPid("b@pipit", 38, 0, 1); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 102, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 0, 0, 0, 38, 1 }; var t = new ErlPort("b@pipit", 38, 1); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 114, 0, 3, 100, 0, 7, 98, 64, 112, 105, 112, 105, 116, 1, 0, 0, 0, 181, 0, 0, 0, 0, 0, 0, 0, 0 }; var t = new ErlRef("b@pipit", 181, 0, 0, 1); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 107, 0, 3, 115, 116, 114 }; var t = new ErlString("str"); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } { var b = new byte[] { 131, 104, 3, 97, 1, 100, 0, 1, 97, 104, 2, 97, 10, 70, 63, 241, 247, 206, 217, 22, 135, 43 }; var t = new ErlTuple(1, new ErlAtom("a"), new ErlTuple(10, 1.123)); var os = new ErlOutputStream(t); Assert.AreEqual(b, os.GetBuffer().TakeWhile((_, i) => i < b.Length).ToArray()); var es = new ErlInputStream(b); Assert.AreEqual(t, es.Read()); } }
public override void read(ErlKVMessage message) { ErlType data = message.getValue("msg") as ErlType; if (data != null) { if (!(data is ErlArray)) { string str = (data as ErlAtom).Value; if (str == "none") { MessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("mining_no_enemy_team")); } else if (str == "rob_close") { MessageWindow.ShowAlert(LanguageConfigManager.Instance.getLanguage("mining_rob_close")); } } else { ErlArray arr = data as ErlArray; EnemyMineralInfo info = new EnemyMineralInfo(); int i = 0; info.serverName = arr.Value [i++].getValueString(); info.playerName = arr.Value [i++].getValueString(); info.HeadIconId = StringKit.toInt(arr.Value [i++].getValueString()); info.playerLevel = arr.Value [i++].getValueString(); info.localId = StringKit.toInt(arr.Value [i++].getValueString()); info.sid = StringKit.toInt(arr.Value [i++].getValueString()); info.combat = StringKit.toInt(arr.Value [i++].getValueString()); //info.count = StringKit.toInt(arr.Value[i++].getValueString()); ErlList counts = arr.Value [i++] as ErlList; for (int j = 0; j < counts.Value.Length; j++) { ErlArray arr_1 = counts.Value [j] as ErlArray; if (arr_1.Value [0].getValueString() == "goods") { ErlArray goods = arr_1.Value [1] as ErlArray; info.count = StringKit.toInt(goods.Value [1].getValueString()); } else if (arr_1.Value [0].getValueString() == "money") { info.count = StringKit.toInt(arr_1.Value [1].getValueString()); } } ErlArray teamInfo = arr.Value [i++] as ErlArray; ErlArray tempArray; for (int j = 0; j < teamInfo.Value.Length; j++) { //地雷,暂时这么处理 tempArray = teamInfo.Value [j] as ErlArray; if (tempArray == null) { info.roles [j] = "0"; info.evoLv [j] = "0"; } else { info.roles [j] = tempArray.Value [0].getValueString(); info.evoLv [j] = tempArray.Value [1].getValueString(); } } MiningManagement.Instance.AddEnemyMineral(info); if (this.callback != null) { callback(); } } } }
internal static ErlTuple EncodeRPC( ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader) { /*{Self, {call, Mod, Fun, Args, GroupLeader}} */ return(new ErlTuple(from, new ErlTuple(ConstAtoms.Call, mod, fun, args, gleader))); }
/// <summary> /// Compile a string fmt into an Erlang term /// </summary> internal static IErlObject Parse( string fmt, ref int pos, ref int argc, params object[] args) { var items = new List<IErlObject>(); IErlObject result = null; pos = skipWSAndComments(fmt, pos); if (pos < fmt.Length) { switch (fmt[pos++]) { case '{': if (State.Ok != pTuple(fmt, ref pos, ref items, ref argc, args)) throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "tuple", pos); result = new ErlTuple(items, false); break; case '[': if (fmt[pos] == ']') { result = new ErlList(); pos++; break; } else if (State.Ok == pList(fmt, ref pos, ref items, ref argc, args)) { result = new ErlList(items, false); break; } throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "list", pos); case '$': /* char-value? */ result = new ErlByte(Convert.ToByte(fmt[pos++])); break; case '~': if (State.Ok != pFormat(fmt, ref pos, ref items, ref argc, args)) throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "term", pos); result = items[0]; break; default: char c = fmt[--pos]; if (char.IsLower(c)) { /* atom ? */ string s = pAtom(fmt, ref pos); result = createAtom(s); } else if (char.IsUpper(c) || c == '_') { result = pVariable(fmt, ref pos); } else if (char.IsDigit(c) || c == '-') { /* integer/float ? */ string s = pDigit(fmt, ref pos); if (s.IndexOf('.') < 0) result = new ErlLong(long.Parse(s, CultureInfo.InvariantCulture)); else result = new ErlDouble(double.Parse(s, CultureInfo.InvariantCulture)); } else if (c == '"') { /* string ? */ string s = pString(fmt, ref pos); result = new ErlString(s); } else if (c == '\'') { /* quoted atom ? */ string s = pQuotedAtom(fmt, ref pos); result = createAtom(s); } break; } } if (result == null) throw new ErlException(StringConsts.ERL_INVALID_VALUE_ERROR.Args(fmt)); return result; }
internal static ErlTuple EncodeRPC( ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader) { /*{Self, {call, Mod, Fun, Args, GroupLeader}} */ return new ErlTuple(from, new ErlTuple(ConstAtoms.Call, mod, fun, args, gleader)); }
internal static ErlTuple EncodeRPCcast( ErlPid from, string mod, string fun, ErlList args, IErlObject gleader) { return EncodeRPCcast(from, new ErlAtom(mod), new ErlAtom(fun), args, gleader); }
private IErlObject rpcCall(ErlPid from, ErlRef eref, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject groupLeader) { // We spawn a new task, so that RPC calls wouldn't block the RPC server thread Task.Factory.StartNew(() => { var type = Type.GetType(mod); if (type == null) { sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, "unknown type: {0}".Args(mod))); return; } // TODO: add LRU caching //var method = type.GetMethod(fun.Value, BindingFlags.Static | BindingFlags.Public); string methodName = fun.Value; if (args.Count == 0) { var pi = type.GetProperty(fun, BindingFlags.Static | BindingFlags.Public); if (pi != null) { try { var result = pi.GetValue(null, null); sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject())); } catch (Exception e) { sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message))); }; return; } } var mi = type.GetMethods(BindingFlags.Static | BindingFlags.Public) .Where(m => m.Name == methodName && m.GetParameters().Count() == args.Count) .FirstOrDefault(); if (mi == null) { sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, "unknown method: {0}".Args(fun))); return; } var pars = mi.GetParameters(); var margs = new object[pars.Length]; for (int i = 0; i < pars.Length; i++) { var par = pars[i]; var val = args[i]; margs[i] = val.AsType(par.ParameterType); } try { var result = mi.Invoke(type, margs); sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Ok, result.ToErlObject())); } catch (Exception e) { sendRpcReply(from, eref, ErlTuple.Create(ConstAtoms.Error, new ErlString(e.Message))); } }); return (IErlObject)null; }
internal static ErlTuple EncodeRPCcast( ErlPid from, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject gleader) { /*{'$gen_cast', { cast, Mod, Fun, Args, GroupLeader}} */ return new ErlTuple( ConstAtoms.GenCast, new ErlTuple(ConstAtoms.Cast, mod, fun, args, gleader)); }
/// <summary> /// Substitute variables in a string contained in args[0]. The /// substitution values begin with args[1] /// </summary> internal static string Format(ErlList args) { string fmt = args.Count == 0 ? string.Empty : ((ErlString)args[0]).ToString(false); return internalFormat(fmt, args.Value.Skip(1).ToList<object>()); }
/// <summary> /// Substitute variables in a fmt string /// </summary> /// <param name="fmt">Format string containing substitution variables (e.g. '~w')</param> /// <param name="args">List of arguments</param> internal static string Format(string fmt, ErlList args) { return(internalFormat(fmt, args.Value.ToList <object>())); }
/// <summary> /// Compile a string fmt into an Erlang term /// </summary> internal static IErlObject Parse( string fmt, ref int pos, ref int argc, params object[] args) { var items = new List <IErlObject>(); IErlObject result = null; pos = skipWSAndComments(fmt, pos); if (pos < fmt.Length) { switch (fmt[pos++]) { case '{': if (State.Ok != pTuple(fmt, ref pos, ref items, ref argc, args)) { throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "tuple", pos); } result = new ErlTuple(items, false); break; case '[': if (fmt[pos] == ']') { result = new ErlList(); pos++; break; } else if (State.Ok == pList(fmt, ref pos, ref items, ref argc, args)) { result = new ErlList(items, false); break; } throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "list", pos); case '<': if (pos < fmt.Length - 1 && fmt[pos] == '<') { var i = ++pos; var str = fmt[i] == '"'; if (str) { pos++; } for (; i < fmt.Length && fmt[i - 1] != '>' && fmt[i] != '>'; ++i) { ; } if (i == fmt.Length) { break; } var end = ++i - (str ? 3 : 2); var len = end - pos + 1; byte[] bytes; if (str) { var cnt = Encoding.UTF8.GetByteCount(fmt.ToCharArray(), pos, len); bytes = new byte[cnt]; Encoding.UTF8.GetBytes(fmt, pos, len, bytes, 0); } else { var beg = pos - 2; bytes = fmt.Substring(pos, len) .Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => { var n = int.Parse(s); if (n < 0 || n > 255) { throw new ErlException ("Invalid binary in format string: {0}".Args(fmt.Substring(beg, len + 4))); } return((byte)n); }) .ToArray(); } result = new ErlBinary(bytes, 0, bytes.Length); pos = i + 1; } break; case '$': /* char-value? */ result = new ErlByte(Convert.ToByte(fmt[pos++])); break; case '~': if (State.Ok != pFormat(fmt, ref pos, ref items, ref argc, args)) { throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "term", pos); } result = items[0]; break; default: char c = fmt[--pos]; if (char.IsLower(c)) { /* atom ? */ string s = pAtom(fmt, ref pos); result = createAtom(s); } else if (char.IsUpper(c) || c == '_') { result = pVariable(fmt, ref pos); } else if (char.IsDigit(c) || c == '-') { /* integer/float ? */ string s = pDigit(fmt, ref pos); if (s.IndexOf('.') < 0) { result = new ErlLong(long.Parse(s, CultureInfo.InvariantCulture)); } else { result = new ErlDouble(double.Parse(s, CultureInfo.InvariantCulture)); } } else if (c == '"') { /* string ? */ string s = pString(fmt, ref pos); result = new ErlString(s); } else if (c == '\'') { /* quoted atom ? */ string s = pQuotedAtom(fmt, ref pos); result = createAtom(s); } break; } } if (result == null) { throw new ErlException(StringConsts.ERL_INVALID_VALUE_ERROR.Args(fmt)); } return(result); }
/// <summary> /// Substitute variables in a fmt string /// </summary> /// <param name="fmt">Format string containing substitution variables (e.g. '~w')</param> /// <param name="args">List of arguments</param> internal static string Format(string fmt, ErlList args) { return internalFormat(fmt, args.Value.ToList<object>()); }
/// <summary> /// Compile a string fmt into an Erlang term /// </summary> internal static IErlObject Parse( string fmt, ref int pos, ref int argc, params object[] args) { var items = new List<IErlObject>(); IErlObject result = null; pos = skipWSAndComments(fmt, pos); if (pos < fmt.Length) { switch (fmt[pos++]) { case '{': if (State.Ok != pTuple(fmt, ref pos, ref items, ref argc, args)) throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "tuple", pos); result = new ErlTuple(items, false); break; case '[': if (fmt[pos] == ']') { result = new ErlList(); pos++; break; } else if (State.Ok == pList(fmt, ref pos, ref items, ref argc, args)) { result = new ErlList(items, false); break; } throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "list", pos); case '<': if (pos < fmt.Length - 1 && fmt[pos] == '<') { var i = ++pos; var str = fmt[i] == '"'; if (str) pos++; for (; i < fmt.Length && fmt[i - 1] != '>' && fmt[i] != '>'; ++i); if (i == fmt.Length) break; var end = ++i - (str ? 3 : 2); var len = end - pos + 1; byte[] bytes; if (str) { var cnt = Encoding.UTF8.GetByteCount(fmt.ToCharArray(), pos, len); bytes = new byte[cnt]; Encoding.UTF8.GetBytes(fmt, pos, len, bytes, 0); } else { var beg = pos - 2; bytes = fmt.Substring(pos, len) .Split(new char[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries) .Select(s => { var n = int.Parse(s); if (n < 0 || n > 255) throw new ErlException ("Invalid binary in format string: {0}".Args(fmt.Substring(beg, len+4))); return (byte)n; }) .ToArray(); } result = new ErlBinary(bytes, 0, bytes.Length); pos = i+1; } break; case '$': /* char-value? */ result = new ErlByte(Convert.ToByte(fmt[pos++])); break; case '~': if (State.Ok != pFormat(fmt, ref pos, ref items, ref argc, args)) throw new ErlException(StringConsts.ERL_PARSING_AT_ERROR, "term", pos); result = items[0]; break; default: char c = fmt[--pos]; if (char.IsLower(c)) { /* atom ? */ string s = pAtom(fmt, ref pos); result = createAtom(s); } else if (char.IsUpper(c) || c == '_') { result = pVariable(fmt, ref pos); } else if (char.IsDigit(c) || c == '-') { /* integer/float ? */ string s = pDigit(fmt, ref pos); if (s.IndexOf('.') < 0) result = new ErlLong(long.Parse(s, CultureInfo.InvariantCulture)); else result = new ErlDouble(double.Parse(s, CultureInfo.InvariantCulture)); } else if (c == '"') { /* string ? */ string s = pString(fmt, ref pos); result = new ErlString(s); } else if (c == '\'') { /* quoted atom ? */ string s = pQuotedAtom(fmt, ref pos); result = createAtom(s); } break; } } if (result == null) throw new ErlException(StringConsts.ERL_INVALID_VALUE_ERROR.Args(fmt)); return result; }
public static ErlType toErlType(string strValue , string strType) { if (string.IsNullOrEmpty(strValue)) { return new ErlNullList(); } switch (strType) { case "atom": return new ErlAtom (strValue); case "string": return new ErlString (strValue); case "byte": return new ErlByte (toInt (strValue)); case "int": return new ErlInt (toInt (strValue)); case "double": return new ErlDouble (toLong(strValue)); case "clist": if (strValue.Length > 0) { char[] c = strValue.ToCharArray (); ErlInt[] eb = new ErlInt[c.Length]; for (int i = 0; i < c.Length; i++) { eb [i] = new ErlInt (c [i]); } ErlList el = new ErlList (eb); return el; } return new ErlNullList(); default : if (strType.Length>5&&strType.Substring (0, 4) == "list") { string tmpValue = strValue.Substring (1, strValue.Length - 2); string tmpType = strType.Substring (5, strType.Length - 6); ErlType[] list = toErlTypeArray (tmpValue,tmpType , ':'); ErlList elist = new ErlList (list); return elist; } if (strType.Length>6&&strType.Substring (0, 5) == "array") { string tmpValue = strValue.Substring (1, strValue.Length - 2); string tmpType = strType.Substring (6, strType.Length - 7); ErlType[] list = toErlTypeArray (tmpValue,tmpType , ':'); ErlArray elist = new ErlArray (list); return elist; } return new ErlNullList (); } }
/// <summary> /// Convert an Erlang hierarchical term representing a schema to a Row. /// </summary> /// <param name="row">Row to update</param> /// <param name="data"> /// Data to update row with. /// The data must be in the form {SchemaName::atom, [{FieldName::atom(), Value}]}. /// </param> /// <param name="schema">Alternative schema to use in place of row.Schema</param> /// <param name="targetName">Name of the target for looking up field attributes</param> /// <param name="schemaName">Alternative name of the top-most 'SchemaName' atom used in the "data".</param> /// <param name="knownSchemas">List of known schemas to use when initializing a field a DynamicRow type.</param> public static void Update(this Row row, IErlObject data, Schema schema = null, string targetName = null, string schemaName = null, Registry <Schema> knownSchemas = null) { if (schema == null) { schema = row.Schema; } if (schemaName == null) { schemaName = schema.Name; } if (data == null) { data = new ErlTuple(new ErlAtom(schemaName), new ErlList()); } // Input data must be in the form: {SchemaName::atom(), [{FieldName::atom(), Value}]} // where Value can be any primitive value or a hierarchical value with another Row type. if (!checkKeyValueTuple(data) || ((ErlTuple)data)[1].TypeOrder != ErlTypeOrder.ErlList) { throw new ErlDataAccessException( StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name)); } var dataList = ((ErlTuple)data)[1] as ErlList; // Make sure that the first element of the tuple matches the schema name if (!((ErlTuple)data)[0].ValueAsString.Equals(schemaName)) { throw new ErlDataAccessException( StringConsts.ERL_DS_CRUD_RESP_SCH_MISMATCH_ERROR.Args(data.ToString(), schema.Name)); } // Contains a set of field names that are present in configuration var presentFieldNames = new HashSet <string>(); foreach (var item in dataList.Where(checkKeyValueTuple).Cast <ErlTuple>()) { presentFieldNames.Add(item[0].ValueAsString); } ErlList newList = null; foreach (var fld in schema.Where(fd => typeof(Row).IsAssignableFrom(fd.Type))) { if (!presentFieldNames.Contains(fld.Name)) { if (newList == null) { newList = (ErlList)dataList.Clone(); } // Add: {FieldName::atom(), []} newList.Add(new ErlTuple(new ErlAtom(fld.Name), new ErlList())); } } // If no new items were added to the list use current list: if (newList == null) { newList = dataList; } foreach (var item in newList.Where(checkKeyValueTuple).Cast <ErlTuple>()) { var name = item[0].ValueAsString; var value = item[1]; var fdef = schema[name]; var attr = fdef[targetName]; if (!attr.Visible || (attr.Metadata != null && attr.Metadata.Navigate("$readonly|$read-only|$read_only").ValueAsBool())) { continue; } // If this field is defined in the schema as a Row type, then we need to descend into the // value's hierarchical structure and treat it as a nested row if (typeof(Row).IsAssignableFrom(fdef.Type)) { // Get the row associated Schema chldSch; var chldRow = row[fdef.Order] as Row; // If the row has a field of Row type initialized, use its Schema value. if (chldRow != null) { chldSch = chldRow.Schema; } else { // Otherwise lookup the schema from the given registry if (!knownSchemas.TryGetValue(name, out chldSch)) { throw new ErlDataAccessException( StringConsts.ERL_DS_SCHEMA_NOT_KNOWN_ERROR.Args(name, data.ToString())); } // Construct the field's value as dynmiac row of the looked up schema type chldRow = new DynamicRow(chldSch); chldRow.ApplyDefaultFieldValues(); row[fdef.Order] = chldRow; } if (value.TypeOrder != ErlTypeOrder.ErlList) { throw new ErlDataAccessException( StringConsts.ERL_DS_SCHEMA_INVALID_VALUE_ERROR.Args(chldSch.Name, value)); } // Recursively update the field's value from given data by using the field's schema: chldRow.Update(item, chldSch, targetName, knownSchemas: knownSchemas); } else { // This is a primitive value type var clr = SchemaMap.ErlToClrValue(value, schema, fdef, null, data); row.SetFieldValue(fdef, clr); } } }
private IErlObject ioProcessGetUntil(ErlAtom encoding, IErlObject prompt, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject replyAs) { return s_ReplyPattern.Subst( new ErlVarBind{ {RA, replyAs}, {R, (IErlObject)Tuple.Create(ConstAtoms.Error, ConstAtoms.Request)} }); }
/// <summary> /// Substitute variables in a string contained in args[0]. The /// substitution values begin with args[1] /// </summary> internal static string Format(ErlList args) { string fmt = args.Count == 0 ? string.Empty : ((ErlString)args[0]).ToString(false); return(internalFormat(fmt, args.Value.Skip(1).ToList <object>())); }
private IErlObject ioProcessRequests( ErlPatternMatcher pm, ErlList requests, IErlObject replyAs) { foreach (var r in requests) { IErlObject term = r; if (pm.Match(ref term, replyAs) < 0) return term; } return s_ReplyPattern.Subst( new ErlVarBind{ {RA, replyAs}, {R, (IErlObject)Tuple.Create(ConstAtoms.Error, ConstAtoms.Request) }}); }
public static ErlType[] listToErlTypeArray(List<Object> list ) { ErlType[] et= new ErlType[list.Count ]; bool isList = false; if (list.Count > 0) { if (list [0].ToString () == "(erllist)") { et = new ErlType[list.Count - 1]; isList = true; list.RemoveAt (0); } }// = new ErlType[list.Count]; //string[] strTypeArray = strType.Split(','); int k = 0; for (int i = 0; i < list.Count; i++) { if (list [i].GetType ().Name.Contains ("List")) { List<Object> tmpList = list [i] as List<Object>; if (tmpList.Count > 0) { if (tmpList [0].ToString () == "(erlist)") { tmpList.RemoveAt (0); et [i] = new ErlList (listToErlTypeArray (tmpList)); } else { if (isList) { et [i] = new ErlList (listToErlTypeArray (tmpList)); } else { et [i] = new ErlArray ( listToErlTypeArray (tmpList)); } } } else { et [i] = new ErlArray (new ErlType[0]); } } else { string tmpstr = list [i].ToString (); string tmpType = "string"; if (tmpstr == "(erllist)") { isList = true; } else { if (list [i].GetType ().Name.ToLower ().Contains ("int")) { int count = StringKit.toInt (list [i].ToString ()); if (count < 255) { tmpType = "byte"; } else { tmpType = "int"; } } else if (tmpstr.ToLower ().Contains ("(erlatom)")) { tmpstr = tmpstr.Substring (0, tmpstr.Length - 9); tmpType = "atom"; } else if (tmpstr.ToLower ().Contains ("(clist)")) { tmpstr = tmpstr.Substring (0, tmpstr.Length - 7); tmpType = "clist"; } et [i] = toErlType (tmpstr, tmpType); } k ++; } } return et; }
private IErlObject ioProcessPutChars(ErlAtom encoding, ErlAtom mod, ErlAtom fun, ErlList args, IErlObject replyAs) { string term; if (mod == ConstAtoms.Io_Lib && fun == ConstAtoms.Format && args.Count == 2) try { term = ErlObject.Format(args); } catch { term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); } else term = "{0}:{1}({2})".Args(mod, fun, args.ToString(true)); Node.OnIoOutput(encoding, new ErlString(term)); return s_ReplyPattern.Subst( new ErlVarBind { { RA, replyAs }, { R, ConstAtoms.Ok } }); }