Ejemplo n.º 1
0
        private static void processSeriesDescriptionsResponses()
        {
            // process request response
            foreach (KeyValuePair <string, sdGenericDescriptions> response in seriesDescriptionResponses)
            {
                ++processedObjects; reportProgress();

                string series_id = response.Key.Replace("EP", "SH");
                sdGenericDescriptions description = response.Value;

                // determine which seriesInfo this belongs to
                MxfSeriesInfo mxfSeriesInfo = sdMxf.With[0].getSeriesInfo(series_id.Substring(2, 8));

                // populate descriptions
                mxfSeriesInfo.ShortDescription = description.Description100;
                mxfSeriesInfo.Description      = description.Description1000;

                // serialize JSON directly to a file
                string filepath = string.Format("{0}\\{1}", Helper.Epg123CacheFolder, series_id);
                using (StreamWriter writer = File.CreateText(filepath))
                {
                    try
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        serializer.Serialize(writer, description);
                    }
                    catch { }
                }
            }
        }
Ejemplo n.º 2
0
        private static bool buildAllGenericSeriesInfoDescriptions()
        {
            // reset counters
            processedObjects = 0;
            Logger.WriteMessage(string.Format("Entering buildAllGenericSeriesInfoDescriptions() for {0} series.",
                                              totalObjects = sdMxf.With[0].SeriesInfos.Count));
            ++processStage; reportProgress();

            // fill mxf programs with cached values and queue the rest
            foreach (MxfSeriesInfo series in sdMxf.With[0].SeriesInfos)
            {
                // sports events will not have a generic description
                if (series.tmsSeriesId.StartsWith("SP"))
                {
                    ++processedObjects; reportProgress();
                    continue;
                }

                // import the cached description if exists, otherwise queue it up
                string   filepath = string.Format("{0}\\SH{1}0000", Helper.Epg123CacheFolder, series.tmsSeriesId);
                FileInfo file     = new FileInfo(filepath);
                if (file.Exists && (file.Length > 0))
                {
                    ++processedObjects; reportProgress();
                    using (StreamReader reader = File.OpenText(filepath))
                    {
                        JsonSerializer        serializer = new JsonSerializer();
                        sdGenericDescriptions cached     = (sdGenericDescriptions)serializer.Deserialize(reader, typeof(sdGenericDescriptions));
                        if (cached.Code == 0)
                        {
                            series.ShortDescription = cached.Description100;
                            series.Description      = cached.Description1000;
                        }
                    }
                    File.SetLastAccessTimeUtc(filepath, DateTime.UtcNow);
                }
                else
                {
                    // must use EP to query generic series description
                    seriesDescriptionQueue.Add(string.Format("EP{0}0000", series.tmsSeriesId));
                }
            }
            Logger.WriteVerbose(string.Format("Found {0} cached series descriptions.", processedObjects));

            // maximum 500 queries at a time
            if (seriesDescriptionQueue.Count > 0)
            {
                Parallel.For(0, (seriesDescriptionQueue.Count / MAXIMGQUERIES + 1), new ParallelOptions {
                    MaxDegreeOfParallelism = MAXPARALLELDOWNLOADS
                }, i =>
                {
                    downloadGenericSeriesDescriptions(i * MAXIMGQUERIES);
                });

                processSeriesDescriptionsResponses();
                if (processedObjects != totalObjects)
                {
                    Logger.WriteWarning("Problem occurred during buildGenericSeriesInfoDescriptions(). Did not process all series descriptions.");
                }
            }
            Logger.WriteInformation(string.Format("Processed {0} series descriptions.", processedObjects));
            Logger.WriteMessage("Exiting buildAllGenericSeriesInfoDescriptions(). SUCCESS.");
            seriesDescriptionQueue = null; seriesDescriptionResponses = null;
            return(true);
        }