private void LoadOldConfigFile()
    {
      Log.Info("Trying to load old config file format");

      _configFile = new WebepgConfigFile();

      Xml xmlreader = new Xml(_configFileDir + "\\WebEPG.xml");

      _configFile.Info = new WebepgInfo();
      _configFile.Info.GrabDays = xmlreader.GetValueAsInt("General", "MaxDays", 2);
      _configFile.Info.GrabberDir = xmlreader.GetValueAsString("General", "GrabberDir", null);

      int AuthCount = xmlreader.GetValueAsInt("AuthSites", "Count", 0);
      if (AuthCount > 0)
      {
        _configFile.Sites = new List<SiteAuth>();
        for (int i = 1; i <= AuthCount; i++)
        {
          SiteAuth site = new SiteAuth();
          site.id = xmlreader.GetValueAsString("Auth" + i.ToString(), "Site", "");
          site.username = xmlreader.GetValueAsString("Auth" + i.ToString(), "Login", "");
          site.password = xmlreader.GetValueAsString("Auth" + i.ToString(), "Password", "");
          _configFile.Sites.Add(site);
        }
      }

      _configFile.Channels = new List<ChannelMap>();

      int channelCount = xmlreader.GetValueAsInt("ChannelMap", "Count", 0);

      for (int i = 1; i <= channelCount; i++)
      {
        ChannelMap channel = new ChannelMap();
        channel.displayName = xmlreader.GetValueAsString(i.ToString(), "DisplayName", "");
        string grabber = xmlreader.GetValueAsString(i.ToString(), "Grabber1", "");
        ;
        //if (mergedList.ContainsKey(channel.displayName))
        //{
        //  channel.merged = mergedList[channel.displayName];
        //  foreach (MergedChannel mergedChannel in channel.merged)
        //    mergedChannel.grabber = grabber;
        //}
        //else
        //{
        channel.id = xmlreader.GetValueAsString(i.ToString(), "ChannelID", "");
        channel.grabber = grabber;
        //}
        _configFile.Channels.Add(channel);
      }

      int mergeCount = xmlreader.GetValueAsInt("MergeChannels", "Count", 0);
      Dictionary<string, List<MergedChannel>> mergedList = new Dictionary<string, List<MergedChannel>>();

      if (mergeCount > 0)
      {
        for (int i = 1; i <= mergeCount; i++)
        {
          int channelcount = xmlreader.GetValueAsInt("Merge" + i.ToString(), "Channels", 0);
          if (channelcount > 0)
          {
            List<MergedChannel> mergedChannels = new List<MergedChannel>();
            ChannelMap channel = new ChannelMap();
            channel.displayName = xmlreader.GetValueAsString("Merge" + i.ToString(), "DisplayName", "");
            channel.merged = new List<MergedChannel>();
            for (int c = 1; c <= channelcount; c++)
            {
              MergedChannel mergedChannel = new MergedChannel();
              mergedChannel.id = xmlreader.GetValueAsString("Merge" + i.ToString(), "Channel" + c.ToString(), "");
              mergedChannel.start = xmlreader.GetValueAsString("Merge" + i.ToString(), "Start" + c.ToString(), "0:0");
              mergedChannel.end = xmlreader.GetValueAsString("Merge" + i.ToString(), "End" + c.ToString(), "0:0");
              channel.merged.Add(mergedChannel);
            }

            _configFile.Channels.Add(channel);
          }
        }
      }

      xmlreader.Clear();
      xmlreader.Dispose();
    }
Beispiel #2
0
    /// <summary>
    /// Loads the config.
    /// </summary>
    /// <returns>bool - success/fail</returns>
    private bool LoadConfig()
    {
      if (!File.Exists(_configFile))
      {
        Log.Info("File not found: {0}", _configFile);
        return false;
      }

      Log.Info("Loading Config File: {0}", _configFile);
      try
      {
        XmlSerializer s = new XmlSerializer(typeof (WebepgConfigFile));
        using (TextReader r = new StreamReader(_configFile))
        {
          _config = (WebepgConfigFile)s.Deserialize(r);
        }
      }
      catch (InvalidOperationException ex)
      {
        Log.Error("WebEPG: Error loading config: {0}", ex.Message);
        return false;
      }

      return true;
      //string grabberDir;
      //int maxGrabDays;
      //int channelCount;

      //Hashtable idList = new Hashtable();

      //_channels = new ArrayList();

      //_xmlreader = new MediaPortal.Webepg.Profile.Xml(_configFile);
      //maxGrabDays = _xmlreader.GetValueAsInt("General", "MaxDays", 1);
      //grabberDir = _xmlreader.GetValueAsString("General", "GrabberDir", _baseDirectory + "\\WebEPG\\grabbers\\");
      //_epgGrabber = new WebListingGrabber(maxGrabDays, grabberDir);

      //int AuthCount = _xmlreader.GetValueAsInt("AuthSites", "Count", 0);
      //if (AuthCount > 0)
      //{
      //  HTTPAuth authService = new HTTPAuth();
      //  for (int i = 1; i <= AuthCount; i++)
      //  {
      //    string site = _xmlreader.GetValueAsString("Auth" + i.ToString(), "Site", "");
      //    string login = _xmlreader.GetValueAsString("Auth" + i.ToString(), "Login", "");
      //    string password = _xmlreader.GetValueAsString("Auth" + i.ToString(), "Password", "");
      //    NetworkCredential auth = new NetworkCredential(login, password);
      //    authService.Add(site, auth);
      //  }
      //  GlobalServiceProvider.Add<IHttpAuthentication>(authService);
      //}

      //int MergeCount = _xmlreader.GetValueAsInt("MergeChannels", "Count", 0);

      //if (MergeCount > 0)
      //{
      //  _mergedList = new MergeInfo[MergeCount];

      //  for (int i = 1; i <= MergeCount; i++)
      //  {
      //    MergeInfo merged = new MergeInfo();
      //    merged.count = _xmlreader.GetValueAsInt("Merge" + i.ToString(), "Channels", 0);
      //    merged.name = _xmlreader.GetValueAsString("Merge" + i.ToString(), "DisplayName", "");
      //    merged.channels = new MergeChannelData[merged.count];
      //    for (int c = 1; c <= merged.count; c++)
      //    {
      //      string channelId = _xmlreader.GetValueAsString("Merge" + i.ToString(), "Channel" + c.ToString(), "");
      //      MergeChannelData mergeTime = new MergeChannelData();
      //      MergeChannelLocation location = new MergeChannelLocation();
      //      location.mergeChannel = c - 1;
      //      location.mergeNum = i - 1;
      //      string start = _xmlreader.GetValueAsString("Merge" + i.ToString(), "Start" + c.ToString(), "0:0");
      //      string end = _xmlreader.GetValueAsString("Merge" + i.ToString(), "End" + c.ToString(), "0:0");
      //      mergeTime.time = new TimeRange(start, end);
      //      merged.channels[c - 1] = mergeTime;
      //      _mergedChannels.Add(channelId, location);
      //    }
      //    _mergedList[i - 1] = merged;
      //  }
      //}

      //channelCount = _xmlreader.GetValueAsInt("ChannelMap", "Count", 0);

      //for (int i = 1; i <= channelCount; i++)
      //{
      //  GrabberInfo channel = new GrabberInfo();
      //  channel.copies = 0;
      //  channel.iscopy = false;
      //  channel.isMerged = false;
      //  channel.name = _xmlreader.GetValueAsString(i.ToString(), "DisplayName", "");
      //  channel.id = _xmlreader.GetValueAsString(i.ToString(), "ChannelID", "");
      //  channel.grabber = _xmlreader.GetValueAsString(i.ToString(), "Grabber1", "");
      //  channel.Linked = _xmlreader.GetValueAsBool(i.ToString(), "Grabber1-Linked", false);
      //  if (channel.Linked)
      //  {
      //    channel.linkStart = _xmlreader.GetValueAsInt(i.ToString(), "Grabber1-Start", 18);
      //    channel.linkEnd = _xmlreader.GetValueAsInt(i.ToString(), "Grabber1-End", 23);
      //  }

      //  object obj = idList[channel.id];
      //  if (obj == null)
      //  {
      //    idList.Add(channel.id, i - 1);
      //  }
      //  else
      //  {
      //    int pos = (int)obj;
      //    GrabberInfo orig = (GrabberInfo)_channels[pos];
      //    orig.copies++;
      //    channel.id += orig.copies.ToString();
      //    channel.copies = pos;
      //    channel.iscopy = true;
      //    _channels.RemoveAt(pos);
      //    _channels.Insert(pos, orig);
      //  }

      //  if (_mergedChannels.Contains(channel.id))
      //    channel.isMerged = true;

      //  _channels.Add(channel);
      //}

      //return true;
    }
    private void LoadWebepgConfigFile()
    {
      if (File.Exists(_configFileDir + "\\WebEPG.xml"))
      {
        Log.Info("WebEPG Config: Loading Existing WebEPG.xml");

        XmlSerializer s = new XmlSerializer(typeof (WebepgConfigFile));
        TextReader r = null;
        try
        {
          r = new StreamReader(_configFileDir + "\\WebEPG.xml");
          _configFile = (WebepgConfigFile)s.Deserialize(r);
          r.Close();
        }
        catch (InvalidOperationException ex)
        {
          if (r != null)
          {
            r.Close();
          }
          Log.Error("WebEPG: Error loading config {0}: {1}", _configFileDir + "\\WebEPG.xml",
                    ex.Message);
          LoadOldConfigFile();
        }
      }

      // no file found set defaults
      if (_configFile == null)
      {
        _configFile = new WebepgConfigFile();
        _configFile.Channels = new List<ChannelMap>();
        _configFile.RadioChannels = new List<ChannelMap>();
        _configFile.Info = new WebepgInfo();
        _configFile.Info.GrabDays = 2;
      }

      TvMappings.ChannelMapping = new Dictionary<string, ChannelMap>();
      foreach (ChannelMap channel in _configFile.Channels)
      {
        TvMappings.ChannelMapping.Add(channel.displayName, channel);
        if (channel.merged != null && channel.merged.Count == 0)
        {
          channel.merged = null;
        }
      }
      TvMappings.OnChannelMappingChanged();

      RadioMappings.ChannelMapping = new Dictionary<string, ChannelMap>();
      foreach (ChannelMap channel in _configFile.RadioChannels)
      {
        RadioMappings.ChannelMapping.Add(channel.displayName, channel);
        if (channel.merged != null && channel.merged.Count == 0)
        {
          channel.merged = null;
        }
      }
      RadioMappings.OnChannelMappingChanged();

      nMaxGrab.Value = _configFile.Info.GrabDays;
    }