Exemplo n.º 1
0
        public static EPG_DB LoadFromJSON()
        {
            if (_instance == null)
            {
                _instance = new EPG_DB();
            }
            bool deleteJson = false;

            using (StreamReader r = new StreamReader(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepgCache.json"))
            {
                try
                {
                    string json = r.ReadToEnd();
                    _instance.DB = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <int, Dictionary <int, Dictionary <int, List <PrgInfo> > > > > >(json);
                    EPGEventArgs epgEvent = new EPGEventArgs();
                    epgEvent.Error = false;
                    _instance.epgEventFinish(_instance, epgEvent);
                    _instance.Loaded = true;
                }catch (Exception ex)
                {
                    deleteJson       = true;
                    _instance.Loaded = false;
                    Console.WriteLine("Error trying read epg json: " + ex.ToString());
                }
            }
            if (deleteJson)
            {
                File.Delete(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepgCache.json");
            }

            return(_instance);
        }
Exemplo n.º 2
0
 private void FinishLoadEpg(EPG_DB epg, EPGEventArgs e)
 {
     if (e.Error)
     {
         MessageBox.Show("EPG işlenirken hata oluştu, lütfen URL'nizi kontrol edin", "EPG HATASI", MessageBoxButtons.OK, MessageBoxIcon.Error);
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = "Error";
         });
     }
     else
     {
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = "Yüklendi";
         });
     }
 }
Exemplo n.º 3
0
 private void FinishLoadEpg(EPG_DB epg, EPGEventArgs e)
 {
     if (e.Error)
     {
         MessageBox.Show(Strings.ERROR_EPG, "EPG ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = Strings.ERROR;
         });
     }
     else
     {
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = Strings.LOADED;
         });
     }
 }
Exemplo n.º 4
0
 private void FinishLoadEpg(EPG_DB epg, EPGEventArgs e)
 {
     if (e.Error)
     {
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = Strings.ERROR;
         });
         Logger.Current.Error("Error processing EPG: " + e.Error.ToString());
     }
     else
     {
         lbProcessingEPG.Invoke((System.Threading.ThreadStart) delegate
         {
             lbProcessingEPG.Text = Strings.LOADED;
         });
         Logger.Current.Info("EPG Loaded correct");
     }
 }
Exemplo n.º 5
0
        private void Parse()
        {
            EPGEventArgs epgEvent = new EPGEventArgs();

            epgEvent.Error = false;
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepg.xml");
                XmlNodeList list_programs = doc.SelectNodes("/tv/programme");
                foreach (XmlNode prg in list_programs)
                {
                    PrgInfo prginfo      = new PrgInfo();
                    string  formatString = "yyyyMMddHHmmss";
                    prginfo.StartTime = DateTime.ParseExact(prg.Attributes["start"].Value.Split(' ')[0], formatString, CultureInfo.InvariantCulture);
                    prginfo.StopTime  = DateTime.ParseExact(prg.Attributes["stop"].Value.Split(' ')[0], formatString, CultureInfo.InvariantCulture);
                    string channelID = prg.Attributes["channel"].Value;

                    prginfo.Title = prg.SelectSingleNode("title").InnerText;
                    try
                    {
                        prginfo.Description = prg.SelectSingleNode("desc").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Description = "No Description";
                    }

                    XmlNodeList categories = prg.SelectNodes("category");
                    foreach (XmlNode cat in categories)
                    {
                        if (prginfo.Categories == null)
                        {
                            prginfo.Categories = new List <string>();
                        }
                        prginfo.Categories.Add(cat.InnerText);
                    }
                    try
                    {
                        prginfo.Stars = prg.SelectSingleNode("star-rating").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Stars = "-";
                    }

                    try
                    {
                        prginfo.Logo = prg.SelectSingleNode("icon").Attributes["src"].InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Logo = null;
                    }
                    try
                    {
                        prginfo.Country = prg.SelectSingleNode("country").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Country = "-";
                    }
                    try
                    {
                        prginfo.Rating = prg.SelectSingleNode("review").InnerText;
                    }
                    catch (Exception ex)
                    {
                        prginfo.Rating = "-";
                    }

                    if (!DB.ContainsKey(channelID))
                    {
                        DB[channelID] = new Dictionary <int, Dictionary <int, Dictionary <int, List <PrgInfo> > > >();
                    }
                    if (!DB[channelID].ContainsKey(prginfo.StartTime.Year))
                    {
                        DB[channelID][prginfo.StartTime.Year] = new Dictionary <int, Dictionary <int, List <PrgInfo> > >();
                    }
                    if (!DB[channelID][prginfo.StartTime.Year].ContainsKey(prginfo.StartTime.Month))
                    {
                        DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month] = new Dictionary <int, List <PrgInfo> >();
                    }
                    if (!DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month].ContainsKey(prginfo.StartTime.Day))
                    {
                        DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month][prginfo.StartTime.Day] = new List <PrgInfo>();
                    }
                    DB[channelID][prginfo.StartTime.Year][prginfo.StartTime.Month][prginfo.StartTime.Day].Add(prginfo);
                }
                using (StreamWriter file = File.CreateText(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepgCache.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, DB);
                }
                epgEventFinish(this, epgEvent);
                Loaded = true;
            }catch (Exception ex)
            {
                File.Delete(System.Environment.GetEnvironmentVariable("USERPROFILE") + "\\amiiptvepg.xml");
                epgEvent.Error = true;
                epgEventFinish(this, epgEvent);
                Loaded = false;
            }
        }