示例#1
0
        public void SaveProgramData(IEnumerable <DBProgram> programs)
        {
            Console.WriteLine("Saving program data to local DB");
            const string kProgramIDParam   = "@programID";
            const string kProgramDataParam = "@programData";
            const string kMD5Param         = "@md5";
            string       sql = string.Format("insert or replace into {0} ({1}, {2}, {3}) values ({4}, {5}, {6})",
                                             kProgramsTableName, kProgramIdColumnName, kProgramDataColumnName, kMD5ColumnName,
                                             kProgramIDParam, kProgramDataParam, kMD5Param);

            using (var transaction = connection_.BeginTransaction())
            {
                foreach (var program in programs)
                {
                    Dictionary <string, string> paramDictionary = new Dictionary <string, string>();
                    int rowCount = ExecuteSQLCommand(sql, new Dictionary <string, string>()
                    {
                        { kProgramIDParam, program.programID },
                        { kProgramDataParam, JSONClient.Serialize(program) },
                        { kMD5Param, program.md5 }
                    });
                    if (rowCount != 1)
                    {
                        throw new Exception("Expected exactly 1 row changed, got " + rowCount);
                    }
                }
                transaction.Commit();
            }
        }
示例#2
0
        public void SaveProgramImages(IEnumerable <SDProgramImageResponse> programImages)
        {
            Console.WriteLine("Saving program images to local DB");
            const string kImageIdParam       = "@programID";
            const string kImageResponseParam = "@json";
            string       sql = string.Format("insert or replace into {0} ({1}, {2}) values ({3}, {4});",
                                             kImagesTableName, kImageIdColumnName, kImageDataColumnName,
                                             kImageIdParam, kImageResponseParam);

            using (var transaction = connection_.BeginTransaction())
            {
                foreach (var programImage in programImages)
                {
                    if (programImage.code > 0)
                    {
                        continue;
                    }
                    int rowCount = ExecuteSQLCommand(sql, new Dictionary <string, string>()
                    {
                        { kImageIdParam, programImage.programID },
                        { kImageResponseParam, JSONClient.Serialize(programImage) }
                    });
                    if (rowCount != 1)
                    {
                        throw new Exception("Expected exactly 1 row changed, got " + rowCount);
                    }
                }
                transaction.Commit();
            }
        }
示例#3
0
        public void SaveRawSDProgramResponses(IEnumerable <ProgramCache.SDProgram> programs)
        {
            Console.WriteLine("Saving Program JSON Responses to local DB");
            const string kProgramIDParam       = "@programID";
            const string kProgramResponseParam = "@programResponse";
            string       sql = string.Format("insert or replace into {0} ({1}, {2}) values ({3}, {4})",
                                             kProgramsTableName, kProgramIdColumnName, kProgramRawResponseColumnName,
                                             kProgramIDParam, kProgramResponseParam);

            using (var transaction = connection_.BeginTransaction())
            {
                foreach (var program in programs)
                {
                    if (program.code > 0)
                    {
                        continue;
                    }
                    Dictionary <string, string> paramDictionary = new Dictionary <string, string>();
                    int rowCount = ExecuteSQLCommand(sql, new Dictionary <string, string>()
                    {
                        { kProgramIDParam, program.programID },
                        { kProgramResponseParam, JSONClient.Serialize(program) },
                    });
                    if (rowCount != 1)
                    {
                        throw new Exception("Expected exactly 1 row changed, got " + rowCount);
                    }
                }
                transaction.Commit();
            }
        }
示例#4
0
 public void SaveConfig()
 {
     using (Stream output_stream = File.OpenWrite(config_path_))
     {
         byte[] bytes = Encoding.UTF8.GetBytes(JSONClient.Serialize(config_));
         output_stream.Write(bytes, 0, bytes.Length);
         output_stream.Flush();
         output_stream.Close();
     }
 }
示例#5
0
        private void SelectedLineupsListBox_SelectedValueChanged(object sender, EventArgs e)
        {
            RemoveSelectedLineupButton.Enabled = selected_lineup_for_removal != null;

            if (selected_lineup_for_removal != null)
            {
                var channel_list = SDChannelReader.GetChannelListByLineupUri(selected_lineup_for_removal.sdLineup.uri);
                JSONClient.DisplayJSON(channel_list);
                string serialized = JSONClient.Serialize(channel_list);
                System.IO.File.WriteAllBytes("channel_list.json", Encoding.UTF8.GetBytes(serialized));
            }
        }
示例#6
0
        internal void SaveSeriesInfos(IEnumerable <DBSeriesInfo> seriesInfos)
        {
            Console.WriteLine("Saving series info to local DB");
            const string kSeriesIdParam   = "@seriesID";
            const string kSeriesDataParam = "@seriesData";
            string       sql = string.Format("insert or replace into {0} ({1}, {2}) values ({3}, {4})",
                                             kSeriesInfoTableName, kSeriesIdColumnName, kSeriesDataColumnName,
                                             kSeriesIdParam, kSeriesDataParam);

            using (var transsaction = connection_.BeginTransaction())
            {
                foreach (var seriesInfo in seriesInfos)
                {
                    int rowCount = ExecuteSQLCommand(sql, new Dictionary <string, string>()
                    {
                        { kSeriesIdParam, seriesInfo.id },
                        { kSeriesDataParam, JSONClient.Serialize(seriesInfo) }
                    });
                }
                transsaction.Commit();
            }
        }
示例#7
0
        internal void SaveSchedules(IEnumerable <SDStationScheduleResponse> stationSchedules)
        {
            Console.WriteLine("Saving schedules to local DB");
            const string kStationIDParam       = "@stationID";
            const string kDayParam             = "@day";
            const string kScheduleEntriesParam = "@scheduleEntries";
            const string kMD5Param             = "@md5";
            string       sql = string.Format("insert or replace into {0} ({1}, {2}, {3}, {4}) values ({5}, {6}, {7}, {8});",
                                             kSchedulesTableName, kStationIDColumnName, kDayColumnName, kScheduleEntriesColumnName, kMD5ColumnName,
                                             kStationIDParam, kDayParam, kScheduleEntriesParam, kMD5Param);

            using (var transaction = connection_.BeginTransaction())
            {
                foreach (var stationSchedule in stationSchedules)
                {
                    if (stationSchedule.code > 0)
                    {
                        continue;
                    }
                    int rowCount = ExecuteSQLCommand(sql,
                                                     new Dictionary <string, string>()
                    {
                        { kStationIDParam, stationSchedule.stationID },
                        { kDayParam, stationSchedule.metadata.startDate },
                        { kScheduleEntriesParam, JSONClient.Serialize(stationSchedule) },
                        { kMD5Param, stationSchedule.metadata.md5 }
                    });
                    if (rowCount != 1)
                    {
                        throw new Exception("Expected exactly 1 row changed, got " + rowCount);
                    }
                }
                transaction.Commit();
            }
            PruneSchedules();
        }