public static void Serialize(string filepath, Inventories inventory) { using (var file = File.Create(filepath)) { Serializer.Serialize(file, inventory); file.Flush(); } }
public static byte[] Serialize(Inventories inventories) { MemoryStream stream = new MemoryStream(); Serializer.Serialize<Inventories>(stream, inventories); stream.Seek(0, SeekOrigin.Begin); return stream.ToArray(); }
public void SetInventories(Inventories inventories) { if (inventories != null) { _inventories.Clear(); _inventories.AddRange(inventories.Items); } }
public void OnInventoriesReceived(Game game, Inventories inventories) { PBGameState.ProcessEvent((c) => c.OnInventoriesReceived(this, inventories)); }
public Inventories GetInventories(string userid) { Inventories inventories = new Inventories(); try { MongoServer server = MongoServer.Create(DbSettings.ConnectionString); MongoDatabase db = server.GetDatabase(DbConstants.DbNameGame, Credentials, new SafeMode(true)); MongoCollection<BsonDocument> coll = db.GetCollection(DbConstants.CollectionNameInventory); QueryDocument query = new QueryDocument("userid", userid); var cursor = coll.Find(query); foreach (BsonDocument item in cursor) { ObjectId id = item["_id"].AsObjectId; var code = item["code"].AsString; var name = item["name"].AsString; float weight = item["weight"].IsDouble ? (float)item["weight"].AsDouble : float.Parse(item["weight"].AsString); var description = item["description"].AsString; GameItem gameItem = new GameItem(id.ToString(), code, name, weight, description); inventories.Items.Add(gameItem); } server.Disconnect(); } catch (Exception ex) { log.Error(ex.ToString()); } return inventories; }
public void OnInventoryFetched(Inventories inventories) { if (this.Listener.IsDebugLogEnabled) { this.Listener.LogDebug(this, string.Format("Inventory Fetched: {0} items", inventories.Items.Count)); } this.listener.OnInventoriesReceived(this, inventories); }
public override void OnInventoriesReceived(GameControllerBase mainGame, Inventories inventories) { base.OnInventoriesReceived(mainGame, inventories); InventoryEngine.Instance.SetInventories(inventories); }