TvDatabase.TvBusinessLayer.GetNowAndNext C# (CSharp) Method

GetNowAndNext() public method

public GetNowAndNext ( List aEpgChannelList ) : NowAndNext>.Dictionary
aEpgChannelList List
return NowAndNext>.Dictionary
    public Dictionary<int, NowAndNext> GetNowAndNext(List<Channel> aEpgChannelList)
    {
      Dictionary<int, NowAndNext> nowNextList = new Dictionary<int, NowAndNext>();
      string provider = ProviderFactory.GetDefaultProvider().Name.ToLowerInvariant();
      string connectString = ProviderFactory.GetDefaultProvider().ConnectionString;
      MySqlConnection MySQLConnect = null;
      MySqlDataAdapter MySQLAdapter = null;
      MySqlCommand MySQLCmd = null;

      SqlDataAdapter MsSqlAdapter = null;
      SqlConnection MsSqlConnect = null;
      SqlCommand MsSqlCmd = null;

      try
      {
        switch (provider)
        {
          case "mysql":
            MySQLConnect = new MySqlConnection(connectString);
            MySQLAdapter = new MySqlDataAdapter();
            MySQLAdapter.TableMappings.Add("Table", "Program");
            MySQLConnect.Open();
            MySQLCmd = new MySqlCommand(BuildCommandTextMiniGuide(provider, aEpgChannelList), MySQLConnect);
            MySQLAdapter.SelectCommand = MySQLCmd;
            break;
          case "sqlserver":
            //MSSQLConnect = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;" + connectString);
            MsSqlConnect = new SqlConnection(connectString);
            MsSqlAdapter = new SqlDataAdapter();
            MsSqlAdapter.TableMappings.Add("Table", "Program");
            MsSqlConnect.Open();
            MsSqlCmd = new SqlCommand(BuildCommandTextMiniGuide(provider, aEpgChannelList), MsSqlConnect);
            MsSqlAdapter.SelectCommand = MsSqlCmd;
            break;
          default:
            //MSSQLConnect = new System.Data.OleDb.OleDbConnection("Provider=SQLOLEDB;" + connectString);
            Log.Info("BusinessLayer: No connect info for provider {0} - aborting", provider);
            return nowNextList;
        }

        using (DataSet dataSet = new DataSet("Program"))
        {
          // ToDo: check if column fetching wastes performance
          switch (provider)
          {
            case "sqlserver":
              if (MsSqlAdapter != null)
              {
                MsSqlAdapter.Fill(dataSet);
              }
              break;
            case "mysql":
              if (MySQLAdapter != null)
              {
                MySQLAdapter.Fill(dataSet);
              }
              break;
          }

          nowNextList = BuildNowNextFromDataSet(dataSet);
        }
      }
      catch (Exception ex)
      {
        Log.Info("BusinessLayer: GetNowNext failed {0}", ex.Message);
      }
      finally
      {
        switch (provider)
        {
          case "mysql":
            if (MySQLConnect != null)
            {
              MySQLConnect.Close();
            }
            if (MySQLAdapter != null)
            {
              MySQLAdapter.Dispose();
            }
            if (MySQLCmd != null)
            {
              MySQLCmd.Dispose();
            }
            if (MySQLConnect != null)
            {
              MySQLConnect.Dispose();
            }
            break;
          case "sqlserver":
            if (MsSqlConnect != null)
            {
              MsSqlConnect.Close();
            }
            if (MsSqlAdapter != null)
            {
              MsSqlAdapter.Dispose();
            }
            if (MsSqlCmd != null)
            {
              MsSqlCmd.Dispose();
            }
            if (MsSqlConnect != null)
            {
              MsSqlConnect.Dispose();
            }
            break;
        }
      }
      return nowNextList;
    }

Usage Example

示例#1
0
    private Dictionary<int, NowAndNext> GetNowAndNext(List<Channel> tvChannelList, DateTime nextEPGupdate)
    {
      Dictionary<int, NowAndNext> getNowAndNextSegment = new Dictionary<int, NowAndNext>();
      Dictionary<int, NowAndNext> getNowAndNext = new Dictionary<int, NowAndNext>();
      int idGroup = TVHome.Navigator.CurrentGroup.IdGroup;

      TvBusinessLayer layer = new TvBusinessLayer();
      if (_listNowNext.TryGetValue(idGroup, out getNowAndNext))
      {
        bool updateNow = (DateTime.Now >= nextEPGupdate);
        if (updateNow)
        {
          getNowAndNext = new Dictionary<int, NowAndNext>();
          List<List<Channel>> tvChannelListSegments = SplitChannelList(tvChannelList, 100);
          foreach (List<Channel> tvChannelListSegment in tvChannelListSegments)
          {
            getNowAndNextSegment = layer.GetNowAndNext(tvChannelListSegment);
            getNowAndNext = getNowAndNext.Concat(getNowAndNextSegment).ToDictionary(x => x.Key, x => x.Value);
          }

          _listNowNext[idGroup] = getNowAndNext;
        }
      }
      else
      {
        getNowAndNext = new Dictionary<int, NowAndNext>();
        List<List<Channel>> tvChannelListSegments = SplitChannelList(tvChannelList, 100);
        foreach (List<Channel> tvChannelListSegment in tvChannelListSegments)
        {
          getNowAndNextSegment = layer.GetNowAndNext(tvChannelListSegment);
          getNowAndNext = getNowAndNext.Concat(getNowAndNextSegment).ToDictionary(x => x.Key, x => x.Value);
        }
        _listNowNext.Add(idGroup, getNowAndNext);
      }
      return getNowAndNext;
    }
TvBusinessLayer