Exemplo n.º 1
0
        public static void UpdateOldMatchResults()
        {
            var matches = Results.FindAs <Model.MatchData>(Query.NotExists("steamids"));

            matches.SetFlags(QueryFlags.NoCursorTimeout);
            var count = matches.Count();

            log.DebugFormat("Updating {0} old match results...", count);
            int i = 0;

            foreach (var match in matches)
            {
                i++;
                if (i % 20 == 0)
                {
                    log.DebugFormat("Current: {0} of {1}", i, count);
                }
                match.ranked   = false;
                match.steamids =
                    match.teams[0].players.Select(x => x.steam_id)
                    .Union(match.teams[1].players.Select(y => y.steam_id))
                    .ToArray();
                foreach (var player in match.teams.SelectMany(team => team.players))
                {
                    player.ConvertData();
                }
                Results.Save(match);
            }
            log.InfoFormat("Updated [{0}] old matches.", count);
        }
Exemplo n.º 2
0
 public void CheckAndInit()
 {
     if (profile.metrics == null)
     {
         profile.metrics = new Dictionary <string, ModMetric>();
         var matches = Database.Mongo.Results.FindAs <MatchData>(Query.And(Query.EQ("ranked", true), Query.EQ("steamids", steam.steamid)));
         foreach (var match in matches)
         {
             if (!profile.metrics.ContainsKey(match.mod))
             {
                 profile.metrics[match.mod] = new ModMetric();
             }
             var goodguys = match.teams[0].players.Any(m => m.steam_id == steam.steamid);
             if ((goodguys && match.good_guys_win) || (!goodguys && !match.good_guys_win))
             {
                 profile.metrics[match.mod].wins++;
             }
             else
             {
                 profile.metrics[match.mod].losses++;
             }
         }
     }
     if (!profile.metrics.ContainsKey("reflex"))
     {
         profile.metrics["reflex"] = new ModMetric();
     }
     Database.Mongo.Users.Save(this);
 }
Exemplo n.º 3
0
        public void RemoveMessage(string queueName, IMessage message)
        {
            var collectionName = _queueCollectionNameProvider.GetCollectionName(queueName);
            var collection     = GetMongoCollection(collectionName);

            collection.Remove(MongoQuery.EQ("_id", message.Id.ToString()));
        }
Exemplo n.º 4
0
        /// <summary>Update the published event version of aggregate.
        /// </summary>
        /// <param name="aggregateRootId"></param>
        /// <param name="version"></param>
        public void UpdatePublishedVersion(string aggregateRootId, long version)
        {
            var collection = GetMongoCollection();
            var document   = collection.FindOne(MongoQuery.EQ("AggregateRootId", aggregateRootId));

            document["Version"] = version;
            collection.Save(document);
        }
Exemplo n.º 5
0
        public bool IsEventStreamExist(string aggregateRootId, Type aggregateRootType, Guid id)
        {
            var collectionName = _eventCollectionNameProvider.GetCollectionName(aggregateRootId, aggregateRootType);
            var collection     = GetMongoCollection(collectionName);
            var query          = MongoQuery.EQ("Id", id.ToString());
            var count          = collection.Count(query);

            return(count > 0);
        }
        public virtual long Delete(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(0);
            }

            var query = DbQuery.EQ(ObjectIdKey, new ObjectId(id));

            return(this.Delete(query));
        }
Exemplo n.º 7
0
        public IEnumerable <EventStream> Query(string aggregateRootId, Type aggregateRootType, long minStreamVersion, long maxStreamVersion)
        {
            var collectionName = _eventCollectionNameProvider.GetCollectionName(aggregateRootId, aggregateRootType);
            var collection     = GetMongoCollection(collectionName);

            var query = MongoQuery.And(
                MongoQuery.EQ("AggregateRootId", aggregateRootId),
                MongoQuery.GTE("Version", minStreamVersion),
                MongoQuery.LTE("Version", maxStreamVersion));

            var documents = collection.Find(query).SetSortOrder("Version");
            var events    = documents.Select(x => ToEventStream(x));

            return(events);
        }
Exemplo n.º 8
0
        public User ConvertData()
        {
            //Detect steamid from accountid
            steam_id = account_id.ToSteamID64();
            var user = Mongo.Users.FindOneAs <User>(Query.EQ("steam.steamid", steam_id));

            if (user != null)
            {
                user_id = user.Id;
                avatar  = user.steam.avatarfull;
                name    = user.profile.name;
            }
            else
            {
                log.Error("Can't find user for steam ID: " + steam_id + " account ID: " + account_id);
            }
            return(user);
        }
Exemplo n.º 9
0
        void RegisterClient()
        {
            //Figure out UID
            User user = null;

            foreach (var steamid in InitData.SteamIDs.Where(steamid => steamid != null && steamid.Length == 17))
            {
                var userb = Mongo.Users.FindOneAs <User>(Query.EQ("steam.steamid", steamid));
                if (userb != null)
                {
                    var browser = Browser.Find(m => m.user != null && m.user.Id == userb.Id);
                    if (browser.Any())
                    {
                        user = userb; break;
                    }
                    ;
                }
            }

            if (user == null)
            {
                this.AsyncSend(NotifyMessage("Account Link", "Sign into the same account on the website and in Steam, make sure your browser is connected to the lobby server (see the bottom right of the browser), and try again.", true), ar => { });
                return;
            }
            SteamID = user.steam.steamid;
            UID     = user.Id;

            Inited = true;

            //Find if the user is online
            var browsersn = Browser.Find(e => e.user != null && e.user.Id == UID);

            foreach (var browser in browsersn)
            {
                browser.SendManagerStatus(true);
                //set the current mod (helps after manager restart)
                if (browser.lobby != null)
                {
                    SetMod(SteamID, D2MPMaster.Mods.Mods.ByID(browser.lobby.mod));
                }
            }
        }
Exemplo n.º 10
0
        public virtual long Update(T entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            try
            {
                BsonDocument bson = entity.ToBsonDocument();
                ObjectId     id   = bson[ObjectIdKey].AsObjectId;

                if (id != null)
                {
                    var query  = DbQuery.EQ(ObjectIdKey, id);
                    var update = DbUpdate.Replace <T>(entity);
                    return(this.Update(query, update));
                }
            }
            catch (KeyNotFoundException) { }

            return(0);
        }
Exemplo n.º 11
0
        /// <summary>Get the current event published version for the specified aggregate.
        /// </summary>
        /// <param name="aggregateRootId"></param>
        /// <returns></returns>
        public long GetEventPublishedVersion(string aggregateRootId)
        {
            var document = GetMongoCollection().FindOne(MongoQuery.EQ("AggregateRootId", aggregateRootId));

            return(document["Version"].AsInt64);
        }
Exemplo n.º 12
0
        public virtual T GetById(string id)
        {
            var query = DbQuery.EQ(ObjectIdKey, new ObjectId(id));

            return(this.GetItem(query));
        }
Exemplo n.º 13
0
 /// <summary>
 /// Deletes the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 public virtual void Delete(T value)
 {
     collection.Remove(Query2.EQ("Id", value.Id));
 }