From 78eea41d65fb380ff9bfb77fdd0540f3b33297db Mon Sep 17 00:00:00 2001
From: georgius <juraj.horvath@inmail.sk>
Date: Sat, 14 Jul 2012 23:30:13 +0200
Subject: [PATCH] turn off tuning channel cache

---
 .../SetupTv/Sections/ScanSettings.Designer.cs      |   52 ++++++++++++-------
 .../TVLibrary/SetupTv/Sections/ScanSettings.cs     |    5 ++
 .../CardAllocation/CardAllocationCache.cs          |   41 +++++++++++++++-
 3 files changed, 78 insertions(+), 20 deletions(-)

diff --git a/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.Designer.cs b/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.Designer.cs
index f9c0df6..efda2a2 100644
--- a/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.Designer.cs
+++ b/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.Designer.cs
@@ -79,6 +79,7 @@ namespace SetupTv.Sections
       this.columnHeaderAudioPriority = new System.Windows.Forms.DataGridViewTextBoxColumn();
       this.columnHeaderAudioName = new System.Windows.Forms.DataGridViewTextBoxColumn();
       this.columnHeaderAudioReusable = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+      this.useTuningChannelCache = new MediaPortal.UserInterface.Controls.MPCheckBox();
       this.tabControl1.SuspendLayout();
       this.tabPageApplication.SuspendLayout();
       this.groupBox8.SuspendLayout();
@@ -103,9 +104,9 @@ namespace SetupTv.Sections
       // 
       // tabControl1
       // 
-      this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.tabControl1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.tabControl1.Controls.Add(this.tabPageApplication);
       this.tabControl1.Controls.Add(this.tabPageScan);
       this.tabControl1.Controls.Add(this.tabPageSoftwareEncoder);
@@ -130,13 +131,14 @@ namespace SetupTv.Sections
       // 
       // groupBox8
       // 
-      this.groupBox8.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox8.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox8.Controls.Add(this.useTuningChannelCache);
       this.groupBox8.Controls.Add(this.lblPriority);
       this.groupBox8.Controls.Add(this.mpComboBoxPrio);
       this.groupBox8.Location = new System.Drawing.Point(6, 6);
       this.groupBox8.Name = "groupBox8";
-      this.groupBox8.Size = new System.Drawing.Size(464, 50);
+      this.groupBox8.Size = new System.Drawing.Size(464, 69);
       this.groupBox8.TabIndex = 81;
       this.groupBox8.TabStop = false;
       this.groupBox8.Text = "TVService";
@@ -162,12 +164,12 @@ namespace SetupTv.Sections
       // 
       // groupBox6
       // 
-      this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.groupBox6.Controls.Add(this.label45);
       this.groupBox6.Controls.Add(this.label44);
       this.groupBox6.Controls.Add(this.delayDetectUpDown);
-      this.groupBox6.Location = new System.Drawing.Point(6, 62);
+      this.groupBox6.Location = new System.Drawing.Point(6, 81);
       this.groupBox6.Name = "groupBox6";
       this.groupBox6.Size = new System.Drawing.Size(464, 107);
       this.groupBox6.TabIndex = 80;
@@ -176,14 +178,14 @@ namespace SetupTv.Sections
       // 
       // label45
       // 
-      this.label45.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.label45.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.label45.Location = new System.Drawing.Point(6, 27);
       this.label45.Name = "label45";
       this.label45.Size = new System.Drawing.Size(452, 35);
       this.label45.TabIndex = 80;
       this.label45.Text = "Some cards (e.g. Hauppauge Nova-T 500) take a long time to initialize after stand" +
-          "by. Therefore use this option below to force a delay should it be required.";
+    "by. Therefore use this option below to force a delay should it be required.";
       // 
       // label44
       // 
@@ -510,7 +512,7 @@ namespace SetupTv.Sections
       this.label2.AutoSize = true;
       this.label2.Location = new System.Drawing.Point(19, 377);
       this.label2.Name = "label2";
-      this.label2.Size = new System.Drawing.Size(357, 13);
+      this.label2.Size = new System.Drawing.Size(352, 13);
       this.label2.TabIndex = 6;
       this.label2.Text = "Number of tuners each reusable encoder can be used with (0 = unlimited)";
       // 
@@ -564,9 +566,9 @@ namespace SetupTv.Sections
       this.mpListViewVideo.AllowUserToAddRows = false;
       this.mpListViewVideo.AllowUserToDeleteRows = false;
       this.mpListViewVideo.AllowUserToResizeRows = false;
-      this.mpListViewVideo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.mpListViewVideo.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.mpListViewVideo.BackgroundColor = System.Drawing.SystemColors.Window;
       this.mpListViewVideo.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
       this.mpListViewVideo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
@@ -656,9 +658,9 @@ namespace SetupTv.Sections
       this.mpListViewAudio.AllowUserToAddRows = false;
       this.mpListViewAudio.AllowUserToDeleteRows = false;
       this.mpListViewAudio.AllowUserToResizeRows = false;
-      this.mpListViewAudio.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.mpListViewAudio.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.mpListViewAudio.BackgroundColor = System.Drawing.SystemColors.Window;
       this.mpListViewAudio.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.None;
       this.mpListViewAudio.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
@@ -708,6 +710,17 @@ namespace SetupTv.Sections
       this.columnHeaderAudioReusable.Name = "columnHeaderAudioReusable";
       this.columnHeaderAudioReusable.Width = 55;
       // 
+      // useTuningChannelCache
+      // 
+      this.useTuningChannelCache.AutoSize = true;
+      this.useTuningChannelCache.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+      this.useTuningChannelCache.Location = new System.Drawing.Point(9, 46);
+      this.useTuningChannelCache.Name = "useTuningChannelCache";
+      this.useTuningChannelCache.Size = new System.Drawing.Size(147, 17);
+      this.useTuningChannelCache.TabIndex = 79;
+      this.useTuningChannelCache.Text = "use tuning channel cache";
+      this.useTuningChannelCache.UseVisualStyleBackColor = true;
+      // 
       // ScanSettings
       // 
       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -798,5 +811,6 @@ namespace SetupTv.Sections
     private System.Windows.Forms.Label label24;
     private System.Windows.Forms.NumericUpDown numericUpDownReuseLimit;
     private System.Windows.Forms.Label label2;
+    private MediaPortal.UserInterface.Controls.MPCheckBox useTuningChannelCache;
   }
 }
\ No newline at end of file
diff --git a/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.cs b/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.cs
index a4d05fa..1e8dad0 100644
--- a/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.cs
+++ b/TvEngine3/TVLibrary/SetupTv/Sections/ScanSettings.cs
@@ -121,6 +121,7 @@ namespace SetupTv.Sections
       delayDetectUpDown.Value = Convert.ToDecimal(layer.GetSetting("delayCardDetect", "0").Value);
 
       checkBoxEnableLinkageScanner.Checked = (layer.GetSetting("linkageScannerEnabled", "no").Value == "yes");
+      useTuningChannelCache.Checked = (layer.GetSetting("useTuningChannelCache", "true").Value == "true");
 
       mpComboBoxPrio.Items.Clear();
       mpComboBoxPrio.Items.Add("Realtime");
@@ -188,6 +189,10 @@ namespace SetupTv.Sections
       s.Value = numericUpDownReuseLimit.Value.ToString();
       s.Persist();
 
+      s = layer.GetSetting("useTuningChannelCache", "true");
+      s.Value = useTuningChannelCache.Checked ? "true" : "false";
+      s.Persist();
+
       foreach (DisplaySoftwareEncoder encoder in _bindingVideoEncoders)
       {
         encoder.Persist();
diff --git a/TvEngine3/TVLibrary/TvService/CardManagement/CardAllocation/CardAllocationCache.cs b/TvEngine3/TVLibrary/TvService/CardManagement/CardAllocation/CardAllocationCache.cs
index fd92db5..0903fc2 100644
--- a/TvEngine3/TVLibrary/TvService/CardManagement/CardAllocation/CardAllocationCache.cs
+++ b/TvEngine3/TVLibrary/TvService/CardManagement/CardAllocation/CardAllocationCache.cs
@@ -13,6 +13,42 @@ namespace TvService
     private static readonly IDictionary<int, IDictionary<int, bool>> _channelMapping = new Dictionary<int, IDictionary<int, bool>>();
     private static readonly TvBusinessLayer _businessLayer = new TvBusinessLayer();
 
+    // specifies if tuning channel cache can be used
+    private static Boolean useTuningChannelCache = true;
+    // specifies if value for UseTuningChannelCache property is set 
+    private static Boolean useTuningChannelCacheSet = false;
+
+    private static Boolean UseTuningChannelCache
+    {
+        get
+        {
+          if (!CardAllocationCache.useTuningChannelCacheSet)
+          {
+            // if value is not set, read it from database
+            // if value is not in database, use default value
+
+            try
+            {
+              CardAllocationCache.useTuningChannelCache = _businessLayer.GetSetting("useTuningChannelCache", "true").Value == "true";
+              CardAllocationCache.useTuningChannelCacheSet = true;
+            }
+            catch
+            {
+              // in case of error, use default value
+              CardAllocationCache.useTuningChannelCache = true;
+              CardAllocationCache.useTuningChannelCacheSet = true;
+            }
+          }
+
+          return CardAllocationCache.useTuningChannelCache;
+        }
+        set
+        {
+          CardAllocationCache.useTuningChannelCache = value;
+          CardAllocationCache.useTuningChannelCacheSet = true;
+        }
+    }
+
     public static IList<IChannel> GetTuningDetailsByChannelId(Channel channel)
     {
       IList<IChannel> tuningDetails;
@@ -21,7 +57,10 @@ namespace TvService
       if (!tuningChannelMappingFound)
       {        
         tuningDetails = _businessLayer.GetTuningChannelsByDbChannel(channel);
-        _tuningChannelMapping.Add(channel.IdChannel, tuningDetails);
+        if (CardAllocationCache.UseTuningChannelCache)
+        {
+          _tuningChannelMapping.Add(channel.IdChannel, tuningDetails);
+        }
       }
       return tuningDetails;
     }
-- 
1.7.9.msysgit.0

