private void HandleSqlInsert(string value)
        {
            using (EventHubDbContext sqlContext = new EventHubDbContext())
            {
                try
                {
                    JObject        json        = JObject.Parse(value);
                    SqlTwitterItem twitterItem = new SqlTwitterItem()
                    {
                        TwittId         = json["id"].Value <string>(),
                        CreatedAt       = json["created_at"].Value <DateTime>(),
                        Path            = eventHubClient.Path,
                        ProfileImageUrl = json["user"]["profile_image_url"].Value <string>(),
                        Source          = json["source"].Value <string>(),
                        Text            = json["text"].Value <string>(),
                        UserId          = json["user"]["Id"].Value <string>(),
                        UserName        = json["user"]["name"].Value <string>()
                    };

                    sqlContext.TwitterItems.Add(twitterItem);
                    int rows = sqlContext.SaveChanges();
                    Trace.WriteLine(string.Format("SQL Azure rows inserted {0}", rows), "Information");
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex.ToString());
                    Trace.WriteLine(value);
                }
            }
        }
예제 #2
0
 private void HandleSqlInsert(string value)
 {
     using (EventHubDbContext sqlContext = new EventHubDbContext())
     {
         JArray items = JArray.Parse(value);
         foreach (var item in items.Children())
         {
             try
             {
                 var twitterItem = item.ToObject <SqlTwitterItem>();
                 twitterItem.Path = eventHubClient.Path;
                 sqlContext.TwitterItems.Add(twitterItem);
             }
             catch (Exception ex)
             {
                 Trace.WriteLine(ex.ToString());
                 Trace.WriteLine(item.ToString());
             }
         }
         try
         {
             int rows = sqlContext.SaveChanges();
             Trace.WriteLine(string.Format("SQL Azure rows inserted {0}", rows), "Information");
         }
         catch (Exception ex)
         {
             Trace.WriteLine(ex.ToString());
         }
     }
 }