/// <summary> /// Simple helper method that creates a correct util.Rowset ready to be sent /// to the EVE Online client based on the given MySqlDataReader /// </summary> /// <param name="reader"></param> /// <returns></returns> public static PyDataType FromMySqlDataReader(MySqlDataReader reader) { // ensure the result is not empty if (reader.FieldCount == 0) { return(new PyObjectData(TYPE_NAME, new PyDictionary())); } // create the main container for the util.Rowset PyDictionary arguments = new PyDictionary(); // create the header for the rows PyList header = new PyList(); for (int i = 0; i < reader.FieldCount; i++) { header.Add(reader.GetName(i)); } // store the header and specify the type of rows the Rowset contains arguments["header"] = header; arguments["RowClass"] = new PyToken(ROW_TYPE_NAME); // finally fill the list of lines the rowset has with the final PyDataTypes // based off the column's values PyList rowlist = new PyList(); while (reader.Read() == true) { PyList linedata = new PyList(); for (int i = 0; i < reader.FieldCount; i++) { linedata.Add(Utils.ObjectFromColumn(reader, i)); } rowlist.Add(linedata); } arguments["lines"] = rowlist; return(new PyObjectData(TYPE_NAME, arguments)); }
public PyObject Encode() { PyTuple header = new PyTuple(); PyTuple args = new PyTuple(); PyToken exception = new PyToken(exception_type); PyDict keywords = new PyDict(); args.Items.Add(new PyString(reason)); keywords.Set("reasonArgs", reasonArgs); keywords.Set("clock", new PyLongLong(clock)); keywords.Set("region", new PyString(region)); keywords.Set("reason", new PyString(reason)); keywords.Set("version", new PyFloat(version)); keywords.Set("build", new PyInt(build)); keywords.Set("codename", new PyString(codename)); keywords.Set("machoVersion", new PyInt(machoVersion)); header.Items.Add(exception); header.Items.Add(args); header.Items.Add(keywords); return(new PyObjectEx(false, header)); }
/* * [PyObjectEx Type1] * header: * [PyToken "blue.DBRowDescriptor"] * [PyTuple 1] * [PyTuple columns.Count] * columns as * [PyTuple 2] * [PyString "columnName"] * [PyInt columnDBType] * [PyList] (optional) * keywords * create with: new DBRowDescriptor(); */ public DBRowDescriptor(PyTuple header) : base() { if (header == null) { throw new InvalidDataException("DBRowDescriptor: null header."); } if (header.Items.Count < 2) { throw new InvalidDataException("DBRowDescriptor: Wrong tuple size expected 2 got " + header.Items.Count); } if (header.Items.Count == 3 && header.Items[2] is PyList) { keywords = header.Items[2] as PyList; } PyTuple tuple = header.Items[1] as PyTuple; if (tuple == null) { throw new InvalidDataException("DBRowDescriptor: null tuple."); } if (tuple.Items.Count > 1) { throw new InvalidDataException("DBRowDescriptor: Wrong tuple size expected 1 got" + tuple.Items.Count); } PyTuple columns = tuple.Items[0] as PyTuple; if (columns == null) { throw new InvalidDataException("DBRowDescriptor: no columns."); } int columnCount = columns.Items.Count; if (keywords != null) { columnCount += keywords.Items.Count; } Columns = new List <Column>(columnCount); foreach (var obj in columns.Items) { PyTuple entry = obj as PyTuple; if (entry == null || entry.Items.Count < 2) { continue; } PyString name = entry.Items[0] as PyString; if (name == null) { continue; } Columns.Add(new Column(name.Value, (FieldType)entry.Items[1].IntValue)); } if (keywords != null) { foreach (var obj in keywords.Items) { PyTuple entry = obj as PyTuple; if (entry == null || entry.Items.Count < 2) { continue; } PyString name = entry.Items[0] as PyString; if (name == null) { continue; } PyToken token = entry.Items[1] as PyToken; if (token == null) { continue; } Columns.Add(new Column(name.Value, token.Token)); } } }
public bool Decode(PyObject data) { if (data.Type != PyObjectType.ObjectEx) { Log.Error("PyException", "Wrong container type"); return(false); } PyObjectEx p = data.As <PyObjectEx>(); if (p.IsType2 == true) { Log.Error("PyException", "Wrong PyObjectEx type, expected Normal, but got Type2"); return(false); } if (p.Header.Type != PyObjectType.Tuple) { Log.Error("PyException", "Wrong item 1 type"); return(false); } PyTuple args = p.Header.As <PyTuple>(); if (args.Items.Count != 3) { Log.Error("PyException", "Wrong tuple 1 item count, expected 3 but got " + args.Items.Count); return(false); } if (args.Items[0].Type != PyObjectType.Token) { Log.Error("PyException", "Wrong tuple item 1 type"); return(false); } PyToken type = args.Items[0].As <PyToken>(); exception_type = type.Token; if (exception_type.StartsWith("exceptions.") == false) { Log.Warning("PyException", "Trying to decode a non-exception packet: " + exception_type); return(false); } if (args.Items[1].Type != PyObjectType.Tuple) { Log.Error("PyException", "Wrong tuple item 2 type"); return(false); } PyTuple msg = args.Items[1].As <PyTuple>(); if (msg.Items.Count != 1) { Log.Error("PyException", "Wrong item 2 tuple count, expected 1 but got " + msg.Items.Count); return(false); } if (msg.Items[0].Type != PyObjectType.String) { Log.Error("PyException", "Wrong tuple 2 item 1 type"); return(false); } PyString msg_data = msg.Items[0].As <PyString>(); message = msg_data.Value; if (args.Items[2].Type != PyObjectType.Dict) { Log.Error("PyException", "Wrong tuple 1 item 3 type"); return(false); } PyDict info = args.Items[2].As <PyDict>(); if (info.Contains("origin") == false) { Log.Error("PyException", "Dict item 1 doesnt has key origin"); return(false); } origin = info.Get("origin").As <PyString>().Value; if (info.Contains("reasonArgs") == false) { Log.Error("PyException", "Dict item 1 doesn has key reasonArgs"); return(false); } reasonArgs = info.Get("reasonArgs").As <PyDict>(); if (info.Contains("clock") == false) { Log.Error("PyException", "Dict item 1 doesnt has key clock"); return(false); } clock = info.Get("clock").IntValue; if (info.Contains("loggedOnUserCount") == false) { Log.Error("PyException", "Dict item 1 doesnt has key loggedOnUserCount"); return(false); } loggedOnUserCount = info.Get("loggedOnUserCount"); if (info.Contains("region") == false) { Log.Error("PyException", "Dict item 1 doesnt has key region"); return(false); } region = info.Get("region").As <PyString>().Value; if (info.Contains("reason") == false) { Log.Error("PyException", "Dict item 1 doesnt has key reason"); return(false); } reason = info.Get("reason").As <PyString>().Value; if (info.Contains("version") == false) { Log.Error("PyException", "Dict item 1 doesnt has key version"); return(false); } version = info.Get("version").As <PyFloat>().Value; if (info.Contains("build") == false) { Log.Error("PyException", "Dict item 1 doesnt has key build"); return(false); } build = info.Get("build").As <PyInt>().Value; if (info.Contains("reasonCode") == false) { Log.Error("PyException", "Dict item 1 doesnt has key reasonCode"); return(false); } reasonCode = info.Get("reasonCode").StringValue; if (info.Contains("codename") == false) { Log.Error("PyException", "Dict item 1 doesnt has key codename"); return(false); } codename = info.Get("codename").As <PyString>().Value; if (info.Contains("machoVersion") == false) { Log.Error("PyException", "Dict item 1 doesnt has key machoVersion"); return(false); } machoVersion = info.Get("machoVersion").As <PyInt>().Value; return(true); }
/// <summary> /// Converts the given <paramref name="data"/> to it's byte array representation. /// Tokens are basic ASCII strings with a variable length up to 255 bytes /// /// The following opcodes are supported /// <seealso cref="Opcode.Token" /> 2 bytes minimum, the string data comes right after the length indicator /// </summary> /// <param name="writer">Where to write the encoded data to</param> /// <param name="data">The value to write</param> private static void ProcessToken(BinaryWriter writer, PyToken token) { writer.WriteOpcode(Opcode.Token); writer.Write((byte)token.Token.Length); writer.Write(Encoding.ASCII.GetBytes(token)); }
public void TokenMarshaling_TooLong() { PyToken token = new PyToken(sTokenMarshal_TooLong); Assert.Catch(() => Marshal.Marshal.ToByteArray(token, false)); }
private void ProcessToken(PyToken token) { this.mStringBuilder.AppendFormat("[PyToken {0} bytes: '{1}']", token.Token.Length, token.Token); this.mStringBuilder.AppendLine(); }
protected bool Equals(PyToken other) { return(Token == other.Token); }