Beispiel #1
0
        public static Equipments FetchEquipments(string userid)
        {
            Equipments equipments = new Equipments();

            try
            {
                MongoServer server = MongoServer.Create("mongodb://127.0.0.1:27017");
                MongoDatabase db = server.GetDatabase("Game", Credentials, new SafeMode(true));
                MongoCollection<BsonDocument> coll = db.GetCollection("Equipments");

                QueryDocument query = new QueryDocument("userid", userid);

                var cursor = coll.Find(query);

                foreach (BsonDocument item in cursor)
                {
                    string code = item["code"].AsString;
                    int count = item["count"].AsInt32;

                    equipments.Items.Add(code, count);
                }

                server.Disconnect();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            return equipments;
        }
Beispiel #2
0
        public Equipments FetchEquipments(string userid)
        {
            Equipments equipments = new Equipments();

            try
            {
                MongoServer server = MongoServer.Create(DbSettings.ConnectionString);
                MongoDatabase db = server.GetDatabase(DbConstants.DbNameGame, Credentials, new SafeMode(true));
                MongoCollection<BsonDocument> coll = db.GetCollection(DbConstants.CollectionNameEquipments);

                QueryDocument query = new QueryDocument("userid", userid);

                var cursor = coll.Find(query);

                foreach (BsonDocument item in cursor)
                {
                    string code = item["code"].AsString;
                    int count = item["count"].IsString ? Int32.Parse(item["count"].AsString) : item["count"].AsInt32;

                    equipments.Items.Add(code, count);
                }

                server.Disconnect();
            }
            catch (Exception ex)
            {
                log.Error("FetchEquipments: " + ex.ToString());
            }

            return equipments;
        }
Beispiel #3
0
        public static byte[] Serialize(Equipments equipments)
        {
            MemoryStream stream = new MemoryStream();

            Serializer.Serialize<Equipments>(stream, equipments);

            stream.Seek(0, SeekOrigin.Begin);

            return stream.ToArray();
        }
Beispiel #4
0
 public void OnEquipmentsFetched(Equipments equipments)
 {
     if (this.Listener.IsDebugLogEnabled)
     {
         this.Listener.LogDebug(this, string.Format("Equipments Fetched: {0} items", equipments.Items.Keys.Count));
     }
     this.Listener.OnEquipmentsReceived(this, equipments);
 }