public MongoDBVolume(TrendingSystemService director) : base(director) { foreach (var tEntity in TrendingHost.AllEntities) { m_DBUpdates.Register(new DBUpdate(tEntity, TrendingHost.GetDimensionNamesForEntity(tEntity))); } }
protected override void DoWriteGauge(SocialTrendingGauge gauge) { var date = RoundDatePerDetalization(App.TimeSource.UTCNow, DetalizationLevel); var update = m_DBUpdates[gauge.Entity]; if (update == null) { throw new MongoSocialException(StringConsts.TRENDING_GAUSE_UNKNOWN_ENTITY_ERROR.Args(gauge.Entity, nameof(DoWriteGauge))); } update.G_Entity = gauge.G_Entity; update.G_Shard = gauge.G_Shard; update.DateTime = date; update.Value = gauge.Value; update.Count = gauge.Count; update.Dimensions = TrendingHost.MapGaugeDimensions(gauge.Entity, gauge.Dimensions); var collection = m_Database[gauge.Entity]; var r = collection.Update(update.MongoUpdateEntry); //Log(NFX.Log.MessageType.Debug , "MongoDBVolume.DoWriteGauge", gauge.Entity+ " : " + r.ToJSON(JSONWritingOptions.PrettyPrint)); }
protected override List <TrendingEntity> DoGetTreding(TrendingQuery query) { var result = new List <TrendingEntity>(); IEnumerable <string> collections; if (query.EntityType.IsNotNullOrWhiteSpace()) { if (!TrendingHost.HasEntity(query.EntityType)) { return(result); } collections = new[] { query.EntityType }; } else { collections = TrendingHost.AllEntities; } foreach (var collection in collections) { var sort = new BSONDocument().Set(new BSONInt32Element(DBConsts.FIELD_VALUE, -1)); var qry = new Query(); var betweenDate = new BSONDocument(); betweenDate.Set(new BSONDateTimeElement("$gte", query.StartDate)); betweenDate.Set(new BSONDateTimeElement("$lte", query.EndDate)); qry.Set(new BSONDocumentElement("dt", betweenDate)); if (query.DimensionFilter.IsNotNullOrEmpty()) { TrendingHost.MapGaugeDimensions(collection, query.DimensionFilter) .ForEach(pair => qry.Set(new BSONStringElement(pair.Key, pair.Value))); } var find = new Query(); find.Set(new BSONDocumentElement("$query", qry)); find.Set(new BSONDocumentElement("$orderby", sort)); var fetchBy = 1000; if (query.FetchCount < fetchBy) { fetchBy = query.FetchCount; } using (var cursor = m_Database[collection].Find(find, query.FetchStart, fetchBy)) { foreach (var doc in cursor) { if (result.Count >= query.FetchCount) { break; } var doc_dt = doc[DBConsts.FIELD_DATETIME].ObjectValue; var dt = doc[DBConsts.FIELD_DATETIME].ObjectValue.AsDateTime(); var dl = MapDetalizationToMinutes(DetalizationLevel); var gshr = RowConverter.GDID_BSONtoCLR((BSONBinaryElement)doc[DBConsts.FIELD_G_SHARD]); var gent = RowConverter.GDID_BSONtoCLR((BSONBinaryElement)doc[DBConsts.FIELD_G_ENTITY]); var val = doc[DBConsts.FIELD_VALUE].ObjectValue.AsULong(); result.Add(new TrendingEntity(dt, dl, query.EntityType, gshr, gent, val ) ); } } } return(result); }