Esempio n. 1
0
 public EmitScope(WriterEmitContext context, Action loadValue, EmitScope parent, bool chainUp, ushort?manifest)
 {
     this.context   = context;
     this.loadValue = loadValue;
     this.parent    = parent;
     this.chainUp   = chainUp;
     this.manifest  = manifest;
 }
        private static void ExtractInHistory(EmitScope insert, string threadId, BsonDocument hisotry)
        {
            var user = hisotry.GetValue("user").AsString;

            var date = hisotry.GetValue("date").AsString;

            var type = hisotry.GetValue("type").AsString;

            insert.Emit(user, type, DateTime.Parse(date), threadId);
        }
        private static void ExtractInMessage(EmitScope scope, string threadId, BsonDocument message)
        {
            var replyAuthorId = message.GetElement("authorId").Value.AsString;

            var replyOn = message.GetElement("createdOn").Value.AsString;

            scope.Emit(replyAuthorId, "Reply", DateTime.Parse(replyOn), threadId);

            BsonArray histories = message.GetElement("histories").Value.AsBsonArray;

            foreach (BsonDocument hisotry in histories)
            {
                ExtractInHistory(scope, threadId, hisotry);
            }
        }
        private static void ExtractInThread(BsonDocument item, EmitScope scope)
        {
            var threadId = item.GetValue("id").AsString;

            var authorId = item.GetValue("authorId").AsString;

            var createdOn = item.GetValue("createdOn").AsString;

            scope.Emit(authorId, "Ask", DateTime.Parse(createdOn), threadId);

            var messages = item.GetElement("messages").Value.AsBsonArray;

            foreach (BsonDocument message in messages)
            {
                ExtractInMessage(scope, threadId, message);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="args">[repository] [user collection name] [thread collection name] [target collection name]</param>
        /// <returns></returns>
        public async Task RunAsync(string[] args)
        {
            var repository = args[0];

            var threadCollectionName = args[1];

            var client = new MongoClient(_connectionStringProvider.GetConnectionString(string.Format("mongo:{0}", repository)));

            var database = client.GetDatabase(repository);

            var threadCollection = database.GetCollection <BsonDocument>(threadCollectionName);

            var list = await threadCollection.Find("{}").ToListAsync();

            using (var scope = new EmitScope(new SqlConnection(_connectionStringProvider.GetConnectionString("EasIndexConnection"))))
            {
                list.ForEach(item =>
                {
                    ExtractInThread(item, scope);
                });
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Creates the current value loading scope, proceeding from the parent till the newly created scope.
 /// Scope walking can be disabled by setting <paramref name="chainUp"/> to false.
 /// </summary>
 /// <param name="loadValue">Loads the current value.</param>
 /// <param name="chainUp">If true, the value will be loaded from the parent object. If not, only currently passed <paramref name="loadValue"/> will be called.</param>
 /// <returns></returns>
 public IDisposable Scope(Action loadValue, bool chainUp = true, ushort?manifest = null)
 {
     return(current = new EmitScope(this, loadValue, current, chainUp, manifest));
 }