public void PopulateAndFindCompositeKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(WithCompositeKey))); for (var i = 0; i < 1000; i++) { tbl.Insert(new WithCompositeKey { ID = "ID{0}".Args(i), StartDate = new DateTime(1953, 12, 10), Description = "Descr{0}".Args(i) }); } Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("ID35", new DateTime(1953, 12, 10)); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Descr35", match1["Description"]); var match2 = tbl.FindByKey("ID35", new DateTime(1953, 07, 10)); Aver.IsNull(match2); }
public void BuildUsingAdHockSchema() { var schema = new Schema("TEZT", new Schema.FieldDef("ID", typeof(int), new List <FieldAttribute> { new FieldAttribute(required: true, key: true) }), new Schema.FieldDef("Description", typeof(string), new List <FieldAttribute> { new FieldAttribute(required: true) }) ); var tbl = new Rowset(schema); for (var i = 0; i < 1000; i++) { var row = new DynamicDoc(tbl.Schema); row["ID"] = i; row["Description"] = "Item-{0}".Args(i); tbl.Insert(row); } Aver.AreEqual(1000, tbl.Count); var match = tbl.FindByKey(178); Aver.IsNotNull(match); Aver.AreObjectsEqual("Item-178", match["Description"]); }
public void PopulateAndCloneThenFindKey_TypedRows() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { tbl.Insert(new Person { ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); } tbl = new Rowset(tbl);//make copy Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Popov-35", match1["LastName"]); //example of dynamic row access var match2 = tbl.FindByKey("POP36") as Person; Aver.IsNotNull(match2); Aver.AreEqual("Popov-36", match2.LastName);//example of typed row access var match3 = tbl.FindByKey("DoesNotExist"); Aver.IsNull(match3); }
public void PopulateAndFindKey_DynamicRows() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { var row = new DynamicDoc(tbl.Schema); row["ID"] = "POP{0}".Args(i); row["FirstName"] = "Oleg"; row["LastName"] = "Popov-{0}".Args(i); row["DOB"] = new DateTime(1953, 12, 10); row["YearsInSpace"] = 12; tbl.Insert(row); } Aver.AreEqual(1000, tbl.Count); var match1 = tbl.FindByKey("POP35"); Aver.IsNotNull(match1); Aver.AreObjectsEqual("Popov-35", match1["LastName"]); var match2 = tbl.FindByKey("POP36") as DynamicDoc; Aver.IsNotNull(match2); Aver.AreObjectsEqual("Popov-36", match2["LastName"]); var match3 = tbl.FindByKey("DoesNotExist"); Aver.IsNull(match3); }
/// <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); }
public void Rowset_FromJSON_DefMissed(bool rowsAsMap) { var row = new Person { Name = "Henry", Age = 43 }; var rowSet = new Rowset(row.Schema); rowSet.Add(row); var options = new Azos.Serialization.JSON.JSONWritingOptions { RowsetMetadata = true, RowsAsMap = rowsAsMap }; var json = rowSet.ToJSON(options); var map = JSONReader.DeserializeDataObject(json) as JSONDataMap; var schema = (map["Schema"] as IDictionary <string, object>); var defs = schema["FieldDefs"] as IList <object>; defs.RemoveAt(1); bool allMatched; var trg = RowsetBase.FromJSON(map, out allMatched); Aver.IsFalse(allMatched); var trgRow = trg[0]; Aver.AreEqual(trgRow.Schema.FieldCount, 1); Aver.AreObjectsEqual(trgRow["Name"], "Henry"); }
/// <summary> /// Runs one prepared query with the given values as parameters and returns a Rowset representing the result /// </summary> /// <param name="query">The prepared query</param> /// <param name="values">The key-value pair of values to use when running the query</param> /// <returns>The Rowset object representing the result</returns> public Rowset PrepareRowsetQuery(string query, Dictionary <string, object> values) { try { MySqlConnection connection = null; // create the correct command MySqlCommand command = this.PrepareQuery(ref connection, query); // add values foreach (KeyValuePair <string, object> pair in values) { command.Parameters.AddWithValue(pair.Key, pair.Value); } MySqlDataReader reader = command.ExecuteReader(); using (connection) using (reader) { // run the prepared statement return(Rowset.FromMySqlDataReader(reader)); } } catch (Exception e) { Log.Error($"MySQL error: {e.Message}"); throw; } }
public void PopulateAndDeleteNonExisting() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { tbl.Insert(new Person { ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); } var delete = new Person { ID = "NONE17" }; var idx = tbl.Delete(delete); //<-------------!!!!!! Aver.IsTrue(idx == -1); Aver.AreEqual(1000, tbl.Count); var match = tbl.FindByKey("POP17") as Person; Aver.IsNotNull(match); }
public void PopulateAndUpsertExisting() { var tbl = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 1000; i++) { tbl.Insert(new Person { ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); } var update = new Person { ID = "POP17", FirstName = "Yaroslav", LastName = "Suzkever", DOB = new DateTime(1952, 12, 10), YearsInSpace = 14 }; var res = tbl.Upsert(update);//<-------------!!!!!! Aver.IsTrue(res.Updated); var match = tbl.FindByKey("POP17") as Person; Aver.IsNotNull(match); Aver.AreEqual("Yaroslav", match.FirstName); Aver.AreEqual("Suzkever", match.LastName); }
public void Filtered_TypedRows() { var data = makeTypedRows(1000); var view = new Rowset(data, row => (int)row["YearsWithCompany"] > 500); Aver.AreEqual(499, view.Count); }
public Rowset GetChannelsForCharacter(int characterID, int corporationID) { Rowset firstQuery = Database.PrepareRowsetQuery( "SELECT" + " lscChannelPermissions.channelID, ownerID, displayName, motd, comparisonKey, memberless, !ISNULL(password) AS password," + " mailingList, cspa, temporary, 1 AS subscribed, estimatedMemberCount " + " FROM lscPrivateChannels" + " LEFT JOIN lscChannelPermissions ON lscPrivateChannels.channelID = -lscChannelPermissions.channelID" + " WHERE accessor = @characterID AND `mode` > 0 AND lscChannelPermissions.channelID < 0 ", new Dictionary <string, object>() { { "@characterID", characterID } } ); Rowset secondQuery = Database.PrepareRowsetQuery( "SELECT" + " lscChannelPermissions.channelID, ownerID, displayName, motd, comparisonKey, memberless, !ISNULL(password) AS password," + " mailingList, cspa, temporary, 1 AS subscribed, estimatedMemberCount " + " FROM lscGeneralChannels" + " LEFT JOIN lscChannelPermissions ON lscGeneralChannels.channelID = lscChannelPermissions.channelID" + $" WHERE accessor = @characterID AND `mode` > 0 AND lscChannelPermissions.channelID > 0 AND ((lscChannelPermissions.channelID < {MIN_CHANNEL_ENTITY_ID} AND lscChannelPermissions.channelID != @characterID) OR lscChannelPermissions.channelID = @corporationID)", new Dictionary <string, object>() { { "@characterID", characterID }, { "@corporationID", corporationID } } ); secondQuery.Rows.AddRange(firstQuery.Rows); return(secondQuery); /* * This is a more elegant solution, but the charset-guessing code goes nuts with the UNIONS as the tables are different * and as such it's impossible to know what table it comes from * return Database.PrepareRowsetQuery( * "SELECT" + * " lscChannelPermissions.channelID, ownerID, displayName, motd, comparisonKey, memberless, !ISNULL(password) AS password," + * " mailingList, cspa, temporary, 1 AS subscribed, estimatedMemberCount " + * " FROM lscPrivateChannels" + * " LEFT JOIN lscChannelPermissions ON lscPrivateChannels.channelID = -lscChannelPermissions.channelID" + * " WHERE accessor = @characterID AND `mode` > 0 AND lscChannelPermissions.channelID < 0 " + * "UNION " + * "SELECT" + * " lscChannelPermissions.channelID, ownerID, displayName, motd, comparisonKey, memberless, !ISNULL(password) AS password," + * " mailingList, cspa, temporary, 1 AS subscribed, estimatedMemberCount " + * " FROM lscGeneralChannels" + * " LEFT JOIN lscChannelPermissions ON lscGeneralChannels.channelID = lscChannelPermissions.channelID" + * $" WHERE accessor = @characterID AND `mode` > 0 AND lscChannelPermissions.channelID > 0 AND ((lscChannelPermissions.channelID < {MIN_CHANNEL_ENTITY_ID} AND lscChannelPermissions.channelID != @characterID) OR lscChannelPermissions.channelID = @corporationID)", * new Dictionary<string, object>() * { * {"@characterID", characterID}, * {"@corporationID", corporationID} * } * ); */ }
public void SimpleFiltered_TypedRows() { var data = makeTypedRows(1000); var view = new Rowset(data, row => row.SimpleFilterPredicate("*ov-22")); Aver.AreEqual(1, view.Count); Aver.AreObjectsEqual(22, view[0]["YearsWithCompany"]); }
private PyTuple GetChannelInformation(string channelType, int channelID, int?entityID, int callerCharacterID, PyDataType channelIDExtended, CallInformation call) { Row info; if (channelID < ChatDB.MIN_CHANNEL_ENTITY_ID || entityID == null || channelID >= ChatDB.MAX_CHANNEL_ENTITY_ID) { info = this.DB.GetChannelInfo(channelID, callerCharacterID); } else { info = this.DB.GetChannelInfoByRelatedEntity((int)entityID, callerCharacterID, channelID == entityID); } // check if the channel must include the list of members PyInteger actualChannelID = info.Line[0] as PyInteger; PyString displayName = info.Line[2] as PyString; string typeValue = this.DB.ChannelNameToChannelType(displayName); Rowset mods = null; Rowset chars = null; if (typeValue != ChatDB.CHANNEL_TYPE_REGIONID && typeValue != ChatDB.CHANNEL_TYPE_CONSTELLATIONID && typeValue != ChatDB.CHANNEL_TYPE_SOLARSYSTEMID2) { mods = this.DB.GetChannelMods(actualChannelID); chars = this.DB.GetChannelMembers(actualChannelID, callerCharacterID); // the extra field is at the end int extraIndex = chars.Header.Count - 1; // ensure they all have the owner information foreach (PyList row in chars.Rows) { // fill it with information row[extraIndex] = this.DB.GetExtraInfo(row[0] as PyInteger); } } else { // build empty rowsets for channels that should not reveal anyone unless they talk mods = new Rowset(new PyDataType[] { "accessor", "mode", "untilWhen", "originalMode", "admin", "reason" }); chars = new Rowset(new PyDataType[] { "charID", "corpID", "allianceID", "warFactionID", "role", "extra" }); } return(new PyTuple(3) { [0] = channelIDExtended, [1] = 1, [2] = new PyTuple(3) { [0] = info, [1] = mods, [2] = chars } }); }
public PyDataType SetHomeStation(PyInteger stationID, CallInformation call) { int callerCharacterID = call.Client.EnsureCharacterIsSelected(); call.Client.EnsureCharacterIsInStation(); Character character = this.ItemFactory.GetItem <Character>(callerCharacterID); // ensure the station selected is in the list of available stations for this character Station station = this.GetPotentialHomeStations(call.Client).Find(x => x.ID == stationID); if (station is null) { throw new CustomError("The selected station is not in your allowed list..."); } // we could check if the current station is the same as the new one // but in reality it doesn't matter much, if the user wants to pay twice for it, sure, why not // in practice it doesn't make much difference // it also simplifies code that needs to communicate between nodes // what we need to do tho is ensure there's no other clone in here in the first place Rowset clones = this.ItemDB.GetClonesForCharacter(character.ID, (int)character.ActiveCloneID); foreach (PyList entry in clones.Rows) { int locationID = entry[2] as PyInteger; // if a clone is already there, refuse to have the medical in there if (locationID == stationID) { throw new MedicalYouAlreadyHaveACloneContractAtThatStation(); } } using Wallet wallet = this.WalletManager.AcquireWallet(character.ID, 1000); { double contractCost = this.Container.Constants[Constants.costCloneContract]; wallet.EnsureEnoughBalance(contractCost); wallet.CreateJournalRecord(MarketReference.CloneTransfer, null, station.ID, -contractCost, $"Moved clone to {station.Name}"); } // set clone's station character.ActiveClone.LocationID = stationID; character.ActiveClone.Persist(); // persist character info character.Persist(); // invalidate client's cache this.Client.ServiceManager.jumpCloneSvc.OnCloneUpdate(character.ID); return(null); }
private PyDataType GetQuote(Character character, ItemEntity item) { if (item.Quantity < item.Type.PortionSize) { throw new QuantityLessThanMinimumPortion(item.Type); } int leftovers = item.Quantity % item.Type.PortionSize; int quantityToProcess = item.Quantity - leftovers; List <ReprocessingDB.Recoverables> recoverablesList = this.ReprocessingDB.GetRecoverables(item.Type.ID); Rowset recoverables = new Rowset( new PyList <PyString>(4) { [0] = "typeID", [1] = "unrecoverable", [2] = "station", [3] = "client" } ); foreach (ReprocessingDB.Recoverables recoverable in recoverablesList) { int ratio = recoverable.AmountPerBatch * quantityToProcess / item.Type.PortionSize; double efficiency = this.CalculateEfficiency(character, recoverable.TypeID); recoverables.Rows.Add( new PyList(4) { [0] = recoverable.TypeID, [1] = (1.0 - efficiency) * ratio, [2] = efficiency * this.mCorporation.TaxRate * ratio, [3] = efficiency * (1.0 - this.mCorporation.TaxRate) * ratio } ); } return(new Row( new PyList <PyString>(4) { [0] = "leftOvers", [1] = "quantityToProcess", [2] = "playerStanding", [3] = "recoverables" }, new PyList(4) { [0] = leftovers, [1] = quantityToProcess, [2] = GetStanding(character), [3] = recoverables } )); }
/// <summary> /// Reads data from reader into rowset. the reader is NOT disposed /// </summary> public static Rowset PopulateRowset(MySQLCRUDQueryExecutionContext context, MySqlDataReader reader, string target, Query query, QuerySource qSource, bool oneRow) { Schema.FieldDef[] toLoad; Schema schema = GetSchemaForQuery(target, query, reader, qSource, out toLoad); var store = context.DataStore; var result = new Rowset(schema); while (reader.Read()) { var row = Row.MakeRow(schema, query.ResultRowType); for (int i = 0; i < reader.FieldCount; i++) { var fdef = toLoad[i]; if (fdef == null) { continue; } var val = reader.GetValue(i); if (val == null || val is DBNull) { row[fdef.Order] = null; continue; } if (fdef.NonNullableType == typeof(bool)) { if (store.StringBool) { var bval = (val is bool) ? (bool)val : val.ToString().EqualsIgnoreCase(store.StringForTrue); row[fdef.Order] = bval; } else { row[fdef.Order] = val.AsNullableBool(); } } else { row[fdef.Order] = val; } } result.Add(row); if (oneRow) { break; } } return(result); }
public void Load(string service, string method, string query, CacheObjectType type) { Log.Debug($"Loading cache data for {service}::{method} of type {type}"); // if the cache already exists do not generate it again! if (this.Exists(service, method) == true) { return; } try { MySqlConnection connection = null; MySqlDataReader reader = Database.Query(ref connection, query); PyDataType cacheObject = null; using (connection) using (reader) { switch (type) { case CacheObjectType.Rowset: cacheObject = Rowset.FromMySqlDataReader(reader); break; case CacheObjectType.CRowset: cacheObject = CRowset.FromMySqlDataReader(reader); break; case CacheObjectType.TupleSet: cacheObject = TupleSet.FromMySqlDataReader(reader); break; case CacheObjectType.PackedRowList: cacheObject = PyPackedRowList.FromMySqlDataReader(reader); break; case CacheObjectType.IntIntDict: cacheObject = IntIntDictionary.FromMySqlDataReader(reader); break; case CacheObjectType.IndexRowset: cacheObject = IndexRowset.FromMySqlDataReader(reader, 0); break; } StoreCall(service, method, cacheObject, DateTime.UtcNow.ToFileTimeUtc()); } } catch (Exception) { Log.Error($"Cannot generate cache data for {service}::{method}"); throw; } }
public void Sorted1columnDESC_TypedRows() { var data = makeTypedRows(1000); var view = new Rowset(data, row => (int)row["YearsWithCompany"] > 500); Aver.AreEqual(499, view.Count); view.SortDefinition = "-YearsWithCompany"; Aver.AreObjectsEqual(999, view[0]["YearsWithCompany"]); }
public void Rowset_NoHeader() { var rowset = new Rowset(m_Row.Schema); rowset.Add(m_Row); rowset.Add(m_Row); var res = CSVWriter.Write(rowset, CSVWritingOptions.NoHeader); var str = m_Data + m_Data; Aver.AreEqual(str, res); }
public override RowsetBase Execute(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { var ctx = (MongoDbCRUDQueryExecutionContext)context; Connector.Collection collection; var qry = MakeQuery(ctx.Database, query, Source, out collection); Schema schema = null; var dtp = query.ResultDocType; if (dtp != null && typeof(TypedDoc).IsAssignableFrom(dtp)) { schema = Schema.GetForTypedDoc(query.ResultDocType); } Rowset result = null; if (schema != null) { result = new Rowset(schema); } var p = query[QUERY_PARAM_SKIP_COUNT]; var skipCount = p != null?p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_BY]; var fetchBy = p != null?p.Value.AsInt(0) : 0; p = query[QUERY_PARAM_FETCH_LIMIT]; var fetchLimit = p != null?p.Value.AsInt(-1) : -1; using (var cursor = collection.Find(qry, skipCount, oneRow ? 1: fetchBy)) foreach (var doc in cursor) { if (schema == null) { schema = Store.Converter.InferSchemaFromBSONDocument(doc); result = new Rowset(schema); } var row = Doc.MakeDoc(schema, query.ResultDocType); Store.Converter.BSONDocumentToDataDoc(doc, row, Store.TargetName); result.Add(row); if (fetchLimit > 0 && result.Count >= fetchLimit) { break; } } return(result); }
public void Rowset_Default() { var rowset = new Rowset(m_Row.Schema); rowset.Add(m_Row); rowset.Add(m_Row); var res = CSVWriter.Write(rowset); var str = m_Header + m_Data + m_Data; Aver.AreEqual(str, res); }
public void JSON_SerializeRow_ComplexTypedRow_WithSchema() { var row1 = new PersonWithNesting { ID = "A1", FirstName = "Joseph", LastName = "Mc'Cloud", DOB = new DateTime(1953, 12, 10), YearsInSpace = 12, LatestHistory = new HistoryItem { ID = "111", StartDate = DateTime.Now, Description = "Chaplin" }, History1 = new List <HistoryItem> { new HistoryItem { ID = "789211", StartDate = DateTime.Now, Description = "Chaplin with us" }, new HistoryItem { ID = "234234", StartDate = DateTime.Now, Description = "Chaplin with you" } }, History2 = new HistoryItem[2] }; var tbl1 = new Rowset(row1.Schema); tbl1.Add(row1); var json = tbl1.ToJSON(new Azos.Serialization.JSON.JSONWritingOptions { RowsetMetadata = true, SpaceSymbols = true, IndentWidth = 2, MemberLineBreak = true, ObjectLineBreak = true, RowsAsMap = true, Purpose = JSONSerializationPurpose.Marshalling }); //AS MAP Console.WriteLine(json); var tbl2 = json.JSONToDynamic(); var row2 = tbl2.Rows[0]; Aver.AreEqual("A1", row2.ID); Aver.AreEqual("Joseph", row2.FirstName); Aver.AreEqual("Mc'Cloud", row2.LastName); Aver.AreEqual("111", row2.LatestHistory.ID); Aver.AreEqual(2, row2.History1.Count); Aver.AreEqual("234234", row2.History1[1].ID); }
public override bool Equals(object obj) { Rowset rowset = obj as Rowset; if (obj == null) { return(false); } return(Name == rowset.Name && Alias == rowset.Alias); }
public PyDataType InstallCloneInStation(CallInformation call) { int callerCharacterID = call.Client.EnsureCharacterIsSelected(); int stationID = call.Client.EnsureCharacterIsInStation(); Character character = this.ItemFactory.GetItem <Character>(callerCharacterID); // check the maximum number of clones the character has assigned long maximumClonesAvailable = character.GetSkillLevel(Types.InfomorphPsychology); // the skill is not trained if (maximumClonesAvailable == 0) { throw new JumpCharStoringMaxClonesNone(); } // get list of clones (excluding the medical clone) Rowset clones = this.ItemDB.GetClonesForCharacter(character.ID, (int)character.ActiveCloneID); // ensure we don't have more than the allowed clones if (clones.Rows.Count >= maximumClonesAvailable) { throw new JumpCharStoringMaxClones(clones.Rows.Count, maximumClonesAvailable); } // ensure that the character has enough money int cost = this.GetPriceForClone(call); // get character's station Station station = this.ItemFactory.GetStaticStation(stationID); using Wallet wallet = this.WalletManager.AcquireWallet(character.ID, 1000); { wallet.EnsureEnoughBalance(cost); wallet.CreateJournalRecord( MarketReference.JumpCloneInstallationFee, null, station.ID, -cost, $"Installed clone at {station.Name}" ); } // create an alpha clone Type cloneType = this.TypeManager[Types.CloneGradeAlpha]; // create a new clone on the itemDB Clone clone = this.ItemFactory.CreateClone(cloneType, station, character); // finally create the jump clone and invalidate caches this.OnCloneUpdate(callerCharacterID); // persist the character information character.Persist(); return(null); }
public PyDataType GetKeyMap() { MySqlConnection connection = null; MySqlDataReader reader = Database.Query(ref connection, "SELECT accountKey as keyID, accountType as keyType, accountName as keyName, description FROM market_keyMap" ); using (connection) using (reader) { return(Rowset.FromMySqlDataReader(reader)); } }
public void JSON_SerializeRowset_TypedRows() { var rowset = new Rowset(Schema.GetForTypedDoc(typeof(Person))); for (var i = 0; i < 10; i++) { rowset.Insert(new Person { ID = "POP{0}".Args(i), FirstName = "Oleg", LastName = "Popov-{0}".Args(i), DOB = new DateTime(1953, 12, 10), YearsInSpace = 12 }); } // Serialization without schema var json = rowset.ToJson(Azos.Serialization.JSON.JsonWritingOptions.PrettyPrint); json.See(); var rowset2 = json.JsonToDynamic(); Aver.AreEqual("Popov-1", rowset2.Rows[1][2]); RowsetBase rowset3 = new Rowset(Schema.GetForTypedDoc(typeof(Person))); var res = Rowset.FromJSON <Person>(json, ref rowset3); Aver.AreEqual(10, res); Aver.AreEqual(10, rowset3.Count); Aver.AreObjectsEqual("Popov-1", rowset3[1][2]); var options = new Azos.Serialization.JSON.JsonWritingOptions { RowsetMetadata = true, IndentWidth = 2, ObjectLineBreak = true, MemberLineBreak = true, SpaceSymbols = true, ASCIITarget = false }; rowset3.Clear(); var json2 = rowset.ToJson(options); var res2 = Rowset.FromJSON <Person>(json2, ref rowset3); Aver.AreEqual(10, res); Aver.AreEqual(10, rowset3.Count); Aver.AreObjectsEqual("Popov-1", rowset3[1][2]); }
public void Rowset_Filter() { var rowset = new Rowset(m_Row.Schema); rowset.Add(m_Row); rowset.Add(m_Row); FieldFilterFunc filter = (r, k, fd) => fd.Name.EqualsIgnoreCase("SimpleStr") || fd.Name.EqualsIgnoreCase("IntValue"); var res = CSVWriter.Write(rowset, filter: filter); var str = m_FilteredHeader + m_FilteredData + m_FilteredData; Aver.AreEqual(str, res); }
public void Save() { var rowset = new Rowset(Schema.GetForTypedDoc(typeof(MyPerzon))); rowset.LogChanges = true; for (var i = 0; i < 100; i++) { rowset.Insert(new MyPerzon { GDID = new GDID(1, 1, (ulong)i), Name = "Jeka Koshmar", Age = i }); } var qryBetween5060 = new Query("CRUD.LoadPerzonsInAgeSpan", typeof(MyPerzon)) { new Query.Param("fromAge", 50), new Query.Param("toAge", 60) }; var rs = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(0, rs.Count); m_Store.Save(rowset); rowset.PurgeChanges(); rs = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(9, rs.Count); rowset[55]["Age"] = 900; //falls out of query rowset.Update(rowset[55]); rowset.Delete(rowset[59]); //physically deleted m_Store.Save(rowset); rs = m_Store.LoadOneRowset(qryBetween5060); Aver.IsNotNull(rs); Aver.AreEqual(7, rs.Count); Aver.AreObjectsEqual(58, rs.First()["Age"]); Aver.AreObjectsEqual(51, rs.Last()["Age"]); }
public async override Task <RowsetBase> ExecuteAsync(ICRUDQueryExecutionContext context, Query query, bool oneRow = false) { await Task.Delay(100); var result = new Rowset(Schema.GetForTypedDoc <Patient>()); var p = query.FindParamByName("Msg")?.Value.AsString(); result.Insert(new Patient { First_Name = "Jack", Last_Name = "Nice", Address1 = p }); result.Insert(new Patient { First_Name = "Mary", Last_Name = "Dice", Address1 = p }); return(result); }
public PyDataType GetStationExtraInfo(CallInformation call) { Rowset stations = new Rowset(new PyDataType [] { "stationID", "solarSystemID", "operationID", "stationTypeID", "ownerID" }); Rowset operationServices = new Rowset(new PyDataType[] { "operationID", "serviceID" }); Rowset services = new Rowset(new PyDataType[] { "serviceID", "serviceName" }); foreach (KeyValuePair <int, Station> pair in this.ItemManager.Stations) { stations.Rows.Add((PyList) new PyDataType [] { pair.Value.ID, pair.Value.LocationID, pair.Value.Operations.OperationID, pair.Value.StationType.ID, pair.Value.OwnerID }); } foreach (KeyValuePair <int, StationOperations> pair in this.StationManager.Operations) { foreach (int serviceID in pair.Value.Services) { operationServices.Rows.Add((PyList) new PyDataType[] { pair.Value.OperationID, serviceID }); } } foreach (KeyValuePair <int, string> pair in this.StationManager.Services) { services.Rows.Add((PyList) new PyDataType[] { pair.Key, pair.Value }); } return(new PyTuple(new PyDataType[] { stations, operationServices, services })); }