From 3d95fc8fea5c68f0db4dd6ce9ddcbc98a1c49c36 Mon Sep 17 00:00:00 2001
From: Snow78 <m.goepp@gmx.de>
Date: Sun, 27 Oct 2013 15:29:28 +0100
Subject: [PATCH] EPGUpdate

Signed-off-by: Snow78 <m.goepp@gmx.de>
---
 .../TVLibrary/SetupTv/Sections/Epg.Designer.cs     | 72 +++++++++++-----------
 .../ChannelLinkage/ChannelLinkageGrabber.cs        | 30 +++++++++
 TvEngine3/TVLibrary/TvService/Epg/EpgCard.cs       |  8 ++-
 TvEngine3/TVLibrary/TvService/Epg/EpgGrabber.cs    |  2 +-
 4 files changed, 73 insertions(+), 39 deletions(-)

diff --git a/TvEngine3/TVLibrary/SetupTv/Sections/Epg.Designer.cs b/TvEngine3/TVLibrary/SetupTv/Sections/Epg.Designer.cs
index 4c47280..226e997 100644
--- a/TvEngine3/TVLibrary/SetupTv/Sections/Epg.Designer.cs
+++ b/TvEngine3/TVLibrary/SetupTv/Sections/Epg.Designer.cs
@@ -74,8 +74,8 @@
       // 
       // groupBox9
       // 
-      this.groupBox9.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox9.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.groupBox9.Controls.Add(this.label31);
       this.groupBox9.Controls.Add(this.edTitleTemplate);
       this.groupBox9.Controls.Add(this.label27);
@@ -96,19 +96,19 @@
       // 
       // label31
       // 
-      this.label31.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.label31.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.label31.Location = new System.Drawing.Point(326, 80);
       this.label31.Name = "label31";
       this.label31.Size = new System.Drawing.Size(125, 106);
       this.label31.TabIndex = 37;
       this.label31.Text = "%TITLE%\r\n%DESCRIPTION%\r\n%GENRE%\r\n%STARRATING%\r\n%STARRATING_STR%\r\n%CLASSIFICATION%" +
-          "\r\n%PARENTALRATING%\r\n%NEWLINE%";
+    "\r\n%PARENTALRATING%\r\n%NEWLINE%";
       // 
       // edTitleTemplate
       // 
-      this.edTitleTemplate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.edTitleTemplate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.edTitleTemplate.Location = new System.Drawing.Point(75, 19);
       this.edTitleTemplate.Name = "edTitleTemplate";
       this.edTitleTemplate.Size = new System.Drawing.Size(245, 20);
@@ -144,8 +144,8 @@
       // 
       // edDescriptionTemplate
       // 
-      this.edDescriptionTemplate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.edDescriptionTemplate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.edDescriptionTemplate.Location = new System.Drawing.Point(75, 45);
       this.edDescriptionTemplate.Name = "edDescriptionTemplate";
       this.edDescriptionTemplate.Size = new System.Drawing.Size(245, 20);
@@ -162,8 +162,8 @@
       // 
       // edTitleTest
       // 
-      this.edTitleTest.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.edTitleTest.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.edTitleTest.Location = new System.Drawing.Point(75, 100);
       this.edTitleTest.Name = "edTitleTest";
       this.edTitleTest.ReadOnly = true;
@@ -181,9 +181,9 @@
       // 
       // edDescriptionTest
       // 
-      this.edDescriptionTest.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.edDescriptionTest.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.edDescriptionTest.Location = new System.Drawing.Point(75, 126);
       this.edDescriptionTest.Multiline = true;
       this.edDescriptionTest.Name = "edDescriptionTest";
@@ -204,8 +204,8 @@
       // 
       // groupBox2
       // 
-      this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.groupBox2.Controls.Add(this.numericUpDownEpgRefresh);
       this.groupBox2.Controls.Add(this.numericUpDownEpgTimeOut);
       this.groupBox2.Controls.Add(this.checkBoxEnableEPGWhileIdle);
@@ -240,6 +240,7 @@
       // 
       // numericUpDownEpgTimeOut
       // 
+      this.numericUpDownEpgTimeOut.DecimalPlaces = 2;
       this.numericUpDownEpgTimeOut.Location = new System.Drawing.Point(86, 42);
       this.numericUpDownEpgTimeOut.Maximum = new decimal(new int[] {
             3600,
@@ -318,8 +319,9 @@
       // 
       // numericUpDownTSEpgTimeout
       // 
-      this.numericUpDownTSEpgTimeout.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.numericUpDownTSEpgTimeout.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
+      this.numericUpDownTSEpgTimeout.DecimalPlaces = 2;
       this.numericUpDownTSEpgTimeout.Location = new System.Drawing.Point(70, 42);
       this.numericUpDownTSEpgTimeout.Maximum = new decimal(new int[] {
             3600,
@@ -368,8 +370,8 @@
       // 
       // groupBox7
       // 
-      this.groupBox7.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
-                  | System.Windows.Forms.AnchorStyles.Right)));
+      this.groupBox7.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
       this.groupBox7.Controls.Add(this.checkboxSameTransponder);
       this.groupBox7.Controls.Add(this.label1);
       this.groupBox7.Controls.Add(this.checkBoxEnableCRCCheck);
@@ -382,17 +384,6 @@
       this.groupBox7.TabStop = false;
       this.groupBox7.Text = "General";
       // 
-      // checkBoxEnableCRCCheck
-      // 
-      this.checkBoxEnableCRCCheck.AutoSize = true;
-      this.checkBoxEnableCRCCheck.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
-      this.checkBoxEnableCRCCheck.Location = new System.Drawing.Point(11, 42);
-      this.checkBoxEnableCRCCheck.Name = "checkBoxEnableCRCCheck";
-      this.checkBoxEnableCRCCheck.Size = new System.Drawing.Size(115, 17);
-      this.checkBoxEnableCRCCheck.TabIndex = 12;
-      this.checkBoxEnableCRCCheck.Text = "Enable CRC check";
-      this.checkBoxEnableCRCCheck.UseVisualStyleBackColor = true;
-      //
       // checkboxSameTransponder
       // 
       this.checkboxSameTransponder.AutoSize = true;
@@ -413,7 +404,18 @@
       this.label1.Size = new System.Drawing.Size(321, 26);
       this.label1.TabIndex = 13;
       this.label1.Text = "(This will increase stability of EPG grabbing.If your provider doesn\'t \r\nbroadcas" +
-          "t CRC checksums, you have to disable it)";
+    "t CRC checksums, you have to disable it)";
+      // 
+      // checkBoxEnableCRCCheck
+      // 
+      this.checkBoxEnableCRCCheck.AutoSize = true;
+      this.checkBoxEnableCRCCheck.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
+      this.checkBoxEnableCRCCheck.Location = new System.Drawing.Point(11, 42);
+      this.checkBoxEnableCRCCheck.Name = "checkBoxEnableCRCCheck";
+      this.checkBoxEnableCRCCheck.Size = new System.Drawing.Size(115, 17);
+      this.checkBoxEnableCRCCheck.TabIndex = 12;
+      this.checkBoxEnableCRCCheck.Text = "Enable CRC check";
+      this.checkBoxEnableCRCCheck.UseVisualStyleBackColor = true;
       // 
       // checkBoxAlwaysUpdate
       // 
@@ -453,9 +455,9 @@
       // 
       // tabControlEpg
       // 
-      this.tabControlEpg.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.tabControlEpg.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.tabControlEpg.Controls.Add(this.tabPage1);
       this.tabControlEpg.Location = new System.Drawing.Point(0, 0);
       this.tabControlEpg.Name = "tabControlEpg";
diff --git a/TvEngine3/TVLibrary/TvService/ChannelLinkage/ChannelLinkageGrabber.cs b/TvEngine3/TVLibrary/TvService/ChannelLinkage/ChannelLinkageGrabber.cs
index 8023f6f..f631f92 100644
--- a/TvEngine3/TVLibrary/TvService/ChannelLinkage/ChannelLinkageGrabber.cs
+++ b/TvEngine3/TVLibrary/TvService/ChannelLinkage/ChannelLinkageGrabber.cs
@@ -87,6 +87,36 @@ namespace TvService
         ChannelLinkageMap map = new ChannelLinkageMap(dbPortalChannel.IdChannel, dbLinkedChannnel.IdChannel,
                                                       lChannel.Name);
         map.Persist();
+        Log.Info("start crosslinking for channel with name={0}, networkId={1}, transportId={2}, serviceId={3} delete DBentries",
+                     lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId);
+        Gentle.Framework.Broker.Execute("delete from ChannelLinkageMap WHERE idPortalChannel=" + dbLinkedChannnel.IdChannel);
+        Log.Info("start crosslinking for channel with name={0}, networkId={1}, transportId={2}, serviceId={3} DBentries deleted",
+                     lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId);
+        foreach (LinkedChannel lChannel2 in pChannel.LinkedChannels)
+        {
+          Log.Info("start crosslinking for channel with name={0}, networkId={1}, transportId={2}, serviceId={3} getchannel  name={4}, networkId={5}, transportId={6}, serviceId={7}",
+                     lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId, lChannel2.Name, lChannel2.NetworkId, lChannel2.TransportId, lChannel2.ServiceId);
+          Channel dbLinkedChannnel2 = layer.GetChannelByTuningDetail(lChannel2.NetworkId, lChannel2.TransportId,
+                                                                    lChannel2.ServiceId);
+          if (dbLinkedChannnel2 == null)
+          {
+            Log.Info("Linked channel with name={0}, networkId={1}, transportId={2}, serviceId={3} not found",
+                     lChannel2.Name, lChannel2.NetworkId, lChannel2.TransportId, lChannel2.ServiceId);
+            continue;
+          }
+          Log.Info("crosslinking channel with name={0}, networkId={1}, transportId={2}, serviceId={3} to name={4}, networkId={5}, transportId={6}, serviceId={7}",
+                     lChannel2.Name, lChannel2.NetworkId, lChannel2.TransportId, lChannel2.ServiceId, lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId);
+          //dbLinkedChannnel2.DisplayName = lChannel.Name;
+          //dbLinkedChannnel2.Persist();
+          ChannelLinkageMap map2 = new ChannelLinkageMap(dbLinkedChannnel.IdChannel, dbLinkedChannnel2.IdChannel,
+                                                        lChannel2.Name);
+          Log.Info("Persist crosslink channel with name={0}, networkId={1}, transportId={2}, serviceId={3} to name={4}, networkId={5}, transportId={6}, serviceId={7}",
+                      lChannel2.Name, lChannel2.NetworkId, lChannel2.TransportId, lChannel2.ServiceId, lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId);     
+          map2.Persist();
+          Log.Info("Persist crosslink channel finished with name={0}, networkId={1}, transportId={2}, serviceId={3} to name={4}, networkId={5}, transportId={6}, serviceId={7}",
+                      lChannel2.Name, lChannel2.NetworkId, lChannel2.TransportId, lChannel2.ServiceId, lChannel.Name, lChannel.NetworkId, lChannel.TransportId, lChannel.ServiceId);     
+
+        }        
       }
     }
 
diff --git a/TvEngine3/TVLibrary/TvService/Epg/EpgCard.cs b/TvEngine3/TVLibrary/TvService/Epg/EpgCard.cs
index bc1e0a6..1e06567 100644
--- a/TvEngine3/TVLibrary/TvService/Epg/EpgCard.cs
+++ b/TvEngine3/TVLibrary/TvService/Epg/EpgCard.cs
@@ -37,7 +37,7 @@ namespace TvService
   {
     #region const
 
-    private int _epgTimeOut = (10 * 60); // 10 mins
+    private float _epgTimeOut = (10 * 60); // 10 mins
 
     #endregion
 
@@ -90,7 +90,7 @@ namespace TvService
       _grabStartTime = DateTime.MinValue;
       _state = EpgState.Idle;
 
-      _epgTimer.Interval = 30000;
+      _epgTimer.Interval = 15000;
       _epgTimer.Elapsed += _epgTimer_Elapsed;
       _eventHandler = controller_OnTvServerEvent;
       _dbUpdater = new EpgDBUpdater(_tvController, "IdleEpgGrabber", true);
@@ -231,7 +231,8 @@ namespace TvService
       _tvController.OnTvServerEvent += _eventHandler;
       TvBusinessLayer layer = new TvBusinessLayer();
       Setting s = layer.GetSetting("timeoutEPG", "10");
-      if (Int32.TryParse(s.Value, out _epgTimeOut) == false)
+      Log.Epg("EpgCard: grab timeout: #{0} ", s.Value);
+      if (float.TryParse(s.Value, out _epgTimeOut) == false)
       {
         _epgTimeOut = 10;
       }
@@ -257,6 +258,7 @@ namespace TvService
       Log.Epg("EpgCard: unable to grab epg transponder: {0} ch: {1} started on {2}",
               TransponderList.Instance.CurrentIndex, channel.DisplayName, _user.CardId);
       Log.Epg("{0}", _currentTransponder.Tuning.ToString());
+      _currentTransponder.OnTimeOut();
     }
 
     /// <summary>
diff --git a/TvEngine3/TVLibrary/TvService/Epg/EpgGrabber.cs b/TvEngine3/TVLibrary/TvService/Epg/EpgGrabber.cs
index 9a5f393..bf3417c 100644
--- a/TvEngine3/TVLibrary/TvService/Epg/EpgGrabber.cs
+++ b/TvEngine3/TVLibrary/TvService/Epg/EpgGrabber.cs
@@ -285,7 +285,7 @@ namespace TvService
         {
           //get the channel
           Channel ch = TransponderList.Instance.CurrentTransponder.CurrentChannel;
-
+          ch.Refresh();
           //check if its time to grab the epg for this channel
           TimeSpan ts = DateTime.Now - TransponderList.Instance.CurrentTransponder.CurrentChannel.LastGrabTime;
           if (ts.TotalMinutes < _epgReGrabAfter)
-- 
1.8.1.msysgit.1

