From 2ef89ee8426ea27913f5ff6f061daa855fa3ef93 Mon Sep 17 00:00:00 2001
From: sebastiii <sebastiii@team-mediaportal.com>
Date: Thu, 16 Oct 2014 19:47:33 +0200
Subject: [PATCH 2/2] Master : MM patch.

---
 .../Plugins/ConflictsManager/ConflictsManager.cs   |  9 ++++---
 TvEngine3/TVLibrary/TVDatabase/Schedule.cs         | 23 ----------------
 .../TVDatabase/TvBusinessLayer/BusinessLayer.cs    | 31 +++++++++++++++++++---
 3 files changed, 32 insertions(+), 31 deletions(-)

diff --git a/TvEngine3/TVLibrary/Plugins/ConflictsManager/ConflictsManager.cs b/TvEngine3/TVLibrary/Plugins/ConflictsManager/ConflictsManager.cs
index 6c5f247..7dbe311 100644
--- a/TvEngine3/TVLibrary/Plugins/ConflictsManager/ConflictsManager.cs
+++ b/TvEngine3/TVLibrary/Plugins/ConflictsManager/ConflictsManager.cs
@@ -288,15 +288,16 @@ namespace TvEngine
           {
             // checks if any schedule assigned to this cards overlaps current parsed schedule
             bool free = true;
-            foreach (Schedule assignedShedule in cardSchedules[cardno[card.IdCard]])
+            foreach (Schedule assignedSchedule in cardSchedules[cardno[card.IdCard]])
             {
-              if (schedule.IsOverlapping(assignedShedule))
+              if (schedule.IsOverlapping(assignedSchedule))
               {
-                if (!(schedule.isSameTransponder(assignedShedule) && card.supportSubChannels))
+                bool _isSameTransponder = (cmLayer.isSameTransponder(schedule, assignedSchedule) && card.supportSubChannels);
+                if (!_isSameTransponder)
                 {
                   free = false;
                   //_overlap = true;
-                  lastOverlappingSchedule = assignedShedule;
+                  lastOverlappingSchedule = assignedSchedule;
                   lastBusyCard = card.IdCard;
                   break;
                 }
diff --git a/TvEngine3/TVLibrary/TVDatabase/Schedule.cs b/TvEngine3/TVLibrary/TVDatabase/Schedule.cs
index 7e41c52..94d894b 100644
--- a/TvEngine3/TVLibrary/TVDatabase/Schedule.cs
+++ b/TvEngine3/TVLibrary/TVDatabase/Schedule.cs
@@ -1373,29 +1373,6 @@ namespace TvDatabase
       return false;
     }
 
-    /// <summary>
-    /// checks if 2 schedules have a common Transponder
-    /// depending on tuningdetails of their respective channels
-    /// </summary>
-    /// <param name="schedule"></param>
-    /// <returns>True if a common transponder exists</returns>
-    public bool isSameTransponder(Schedule schedule)
-    {
-      IList<TuningDetail> tuningList1 = ReferencedChannel().ReferringTuningDetail();
-      IList<TuningDetail> tuningList2 = schedule.ReferencedChannel().ReferringTuningDetail();
-      foreach (TuningDetail tun1 in tuningList1)
-      {
-        foreach (TuningDetail tun2 in tuningList2)
-        {
-          if (tun1.Frequency == tun2.Frequency)
-          {
-            return true;
-          }
-        }
-      }
-      return false;
-    }
-
     public QualityType QualityType
     {
       get { return (QualityType)(quality / 10); }
diff --git a/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs b/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
index 07b002a..20736e3 100644
--- a/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
+++ b/TvEngine3/TVLibrary/TVDatabase/TvBusinessLayer/BusinessLayer.cs
@@ -2966,7 +2966,31 @@ namespace TvDatabase
       return;
     }
 
-    private static bool AssignSchedulesToCard(Schedule schedule, List<Schedule>[] cardSchedules,
+    /// <summary>
+    /// checks if 2 schedules have a common Transponder
+    /// depending on tuningdetails of their respective channels
+    /// </summary>
+    /// <param name="schedule"></param>
+    /// <returns>True if a common transponder exists</returns>
+    public bool isSameTransponder(Schedule schedule1, Schedule schedule2)
+    {
+      IList<TuningDetail> tuningDetailList1 = schedule1.ReferencedChannel().ReferringTuningDetail();
+      IList<TuningDetail> tuningDetailList2 = schedule2.ReferencedChannel().ReferringTuningDetail();
+      foreach (TuningDetail td1 in tuningDetailList1)
+      {
+        IChannel c1 = GetTuningChannel(td1);
+        foreach (TuningDetail td2 in tuningDetailList2)
+        {
+          if (!c1.IsDifferentTransponder(GetTuningChannel(td2)))
+          {
+            return true;
+          }
+        }
+      }
+      return false;
+    }
+
+    private bool AssignSchedulesToCard(Schedule schedule, List<Schedule>[] cardSchedules,
                                               out List<Schedule> overlappingSchedules, out List<Schedule> notViewabledSchedules)
     {
       overlappingSchedules = new List<Schedule>();
@@ -2989,14 +3013,13 @@ namespace TvDatabase
             bool hasOverlappingSchedule = schedule.IsOverlapping(assignedSchedule);
             if (hasOverlappingSchedule)
             {
-              bool isSameTransponder = (schedule.isSameTransponder(assignedSchedule) && card.supportSubChannels);
-              if (!isSameTransponder)
+              bool _isSameTransponder = (isSameTransponder(schedule, assignedSchedule) && card.supportSubChannels);
+              if (!_isSameTransponder)
               {
                 overlappingSchedules.Add(assignedSchedule);
                 Log.Info("AssignSchedulesToCard: overlapping with " + assignedSchedule + " on card {0}, ID = {1}", count,
                          card.IdCard);
                 free = false;
-                break;
               }
             }
           }
-- 
1.8.0.msysgit.0

