예제 #1
0
 private static void Sync(Emailer emailer)
 {
     var orderId = 1;
     var mongo = new MongoClient("mongodb://localhost");
     var db = mongo.GetServer().GetDatabase("awaitdefer");
     var order = db.GetCollection("orders").FindOneById(orderId);
     var user = db.GetCollection("users").FindOneById(order["customer"].AsBsonDocument["id"]);
     var trackingInformation = Tracking.Track(order["trackingId"].AsString);
     var message = new
         {
             subject = "Order: " + order["name"],
             email = user["email"],
             body = "Tracking: " + trackingInformation
         };
     emailer.SendEmail(message);
 }
예제 #2
0
        public async Task Async(Emailer emailer)
        {
            var orderId = 1;
            var mongo   = new MongoClient("mongodb://localhost");
            var db      = mongo.GetServer().GetDatabase("awaitdefer");
            var order   = await db.GetCollection("orders").FindOneByIdAsync(orderId);

            var userTask = db.GetCollection("users").FindOneByIdAsync(order["customer"].AsBsonDocument["id"]);
            var trackingInformationTask = Tracking.TrackAsync(order["trackingId"].AsString);
            var user = await userTask;
            var trackingInformation = await trackingInformationTask;
            var message             = new
            {
                subject = "Order: " + order["name"],
                email   = user["email"],
                body    = "Tracking: " + trackingInformation
            };
            await emailer.SendEmailAsync(message);
        }