public static List<FacebookStreamEntry> JSONToStreamEntries(JSONObject obj) { List<FacebookStreamEntry> entries = new List<FacebookStreamEntry>(); try { JSONObject data = obj.Dictionary["data"]; foreach (JSONObject dataEntry in data.Array) { FacebookStreamEntry entry = new FacebookStreamEntry() { ActorID = dataEntry.Dictionary["actor_id"].Integer, CreatedTime = TimeHelpers.UnixToDateTime(dataEntry.Dictionary["created_time"].Integer), Message = dataEntry.Dictionary["message"].String, PostID = dataEntry.Dictionary["post_id"].String }; entries.Add(entry); } } catch (Exception ex) { Logger.Warn("Failed to parse a JSON object to a facebook entry. Exception detail: " + ex); } return entries; }
static void NewStreamEntry(FacebookStreamEntry entry) { Logger.Info("Writing new post to database: " + entry.Message); try { s_db.CreateStreamEntry(entry); } catch (Exception ex) { Logger.Warn("Failed to write entry to database. Exception detail: " + ex.ToString()); } }
public void CreateStreamEntry(FacebookStreamEntry entry) { try { string sqlCommand = string.Format(SQL_WRITE_COMMAND, entry.PostID, entry.ActorID, MySqlHelper.EscapeString(entry.Message), entry.CreatedTime.ToString("yyyy-MM-dd HH:mm:ss")); MySqlCommand command = new MySqlCommand(sqlCommand, m_connection); command.ExecuteNonQuery(); } catch (MySqlException ex) { //Ignore duplicate key errors if (ex.Number != DUPLICATE_KEY_ERROR_CODE) { throw ex; } } }