Ejemplo n.º 1
0
        private static void WriteConflictToJson(string outputFileName, conflict conflict)
        {
            string json     = JsonConvert.SerializeObject(conflict);
            var    niceJson = Newtonsoft.Json.Linq.JToken.Parse(json).ToString();

            System.IO.File.WriteAllText(outputFileName, niceJson);
        }
Ejemplo n.º 2
0
        public static int MakeJson(string outputFileName)
        {
            string connectionString = "Server=SCOTT-PC\\SQLExpress;Database=Trump;Trusted_Connection=True;";

            var mediaOutlets = new List <mediaOutlet>();

            var    conflicts = new List <conflict>();
            int    stories   = 0;
            string query     = "SELECT * FROM ConflictTimelineView ORDER BY Conflict, MediaOutlet";

            using (SqlConnection conn = new SqlConnection(connectionString)) {
                using (SqlCommand cmd = new SqlCommand(query, conn)) {
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    SqlDataReader reader = cmd.ExecuteReader();

                    conflict    currentConflict    = null;
                    mediaOutlet currentMediaOutlet = null;
                    while (reader.Read())
                    {
                        var conflictName = reader["Conflict"].ToString();
                        if (currentConflict == null || (conflictName != currentConflict.name))
                        {
                            var oldConflict = currentConflict;

                            currentConflict = new conflict(conflictName, reader["ConflictDescription"].ToString(), reader["ID"].ToString());
                            conflicts.Add(currentConflict);
                            currentMediaOutlet = null;

                            if (oldConflict != null && oldConflict.mediaOutlets.Count != 0)
                            {
                                WriteConflictToJson(outputFileName + oldConflict.id + ".json", oldConflict);
                            }
                        }

                        var mediaOutletName = reader["MediaOutlet"].ToString();
                        if (currentMediaOutlet == null || (mediaOutletName != currentMediaOutlet.name))
                        {
                            currentMediaOutlet = new mediaOutlet(mediaOutletName);
                            currentConflict.mediaOutlets.Add(currentMediaOutlet);
                        }

                        currentMediaOutlet.data.Add(Makedata(reader));
                        stories++;
                    }
                }
            }
            //WriteTopicsToJson(outputFileName, conflicts);
            return(stories);
        }