public RingUpdater(MMSender senderToWorkFor, RingMetaData ring, DateTime todayDate) { SenderToWorkFor = senderToWorkFor; Ring = ring; TodayDate = todayDate; Init(); }
/// <summary> /// Generates a complete new ring into the provided <paramref name="ring" /> dataset. This should produce a complete 24 hour active ring which has no /// other logic then playing the right things at the right time, independet of the past. /// </summary> /// <param name="server">The source database</param> /// <param name="computerName">The name of the computer this ring is generated for.</param> /// <param name="ring">The target ring where all the generated data should be inserted at.</param> /// <remarks> /// Things which need to be done: /// <para>Set <see cref="RingMetaData.SenderId" /> to the targeting sender id.</para> /// <para>Generate <see cref="PageGroup" />s inside the database.</para> /// <para> /// Generate <see cref="Page" />s with the associated content (<see cref="Text" />, <see cref="Image" /> <see cref="Video" />, /// <see cref="DoubleTransition" />). /// </para> /// <para> /// Generate <see cref="PageSchedule" />s. <see cref="PageSchedule" />s in sequence which belongs to the same <see cref="PageGroup" /> needs to /// have the same <see cref="PageSchedule.PageGroupScheduleId" />. /// </para> /// </remarks> public void Generate(IServer server, string computerName, RingMetaData ring) { //if (DateTime.Now - server.Load<DateTime>("LastRefresh") > TimeSpan.FromDays(1)) // server.Save(StorageEnum.MultiMedia, null); //server.Save(StorageEnum.MultiMedia, null); //TODO Clears the current multimedia db MultiMedia db = GetMultiMedia(server); MMSender sender = GetMMSenderFromSenderOrComputerName(db, computerName); ring.Occasion = sender.NameId; ring.SenderId = sender.Id; sender.DataSet.SetHasBeenLoaded(); DistributionRoot DistributionRootInstance = new DistributionRoot(db,ring.TargetDate); DistributionRootInstance.PreloadAllForAllTodayAndTomorrowMMunitsIfNotHasBeenLoaded(); BalancerUsage balancerUsage = new BalancerUsage(sender, ring, ring.TargetDate) { TodaysActiveMMUnitsPerMMSlot = DistributionRootInstance.TodayActiveMMUnitsPerMMSlot }; balancerUsage.LoadActuallBalancers(sender); RingGenerator ringGenerator = new RingGenerator(sender, ring, ring.TargetDate) { DistributionRootInstance = DistributionRootInstance, TodaysBalancers = (balancerUsage.TodaysBalancersPerSender.ContainsKey(sender)) ? balancerUsage.TodaysBalancersPerSender[sender] : null }; ringGenerator.Generate(); }
public RingGenerator(MMSender targetSender, RingMetaData targetRing, DateTime targetDate) { SourceSender = targetSender; TargetRing = targetRing; TargetDate = targetDate; Init(); }
public void Update(MultiMedia db, string computerName, RingMetaData ring) { MMSender sender = GetMMSenderFromSenderOrComputerName(db, computerName); ring.SenderId = sender.Id; DistributionRoot DistributionRootInstance = new DistributionRoot(sender.DataSet, ring); DistributionRootInstance.PreloadAllForAllTodayAndTomorrowMMunitsIfNotHasBeenLoaded(); }
public BalancerUsage(MMSender sender, RingMetaData ring, DateTime targetDate) { Sender = sender; this.MultiMediaDb = sender.DataSet; Ring = ring; PlayerDb = Ring.DataSet; TodaysDate = targetDate; TomorrowsDate = TodaysDate.AddDays(1); }
/// <summary> /// Generates a complete new ring into the provided <paramref name="ring" /> dataset. This should produce a complete 24 hour active ring which has no /// other logic then playing the right things at the right time, independet of the past. /// </summary> /// <param name="db">The source database</param> /// <param name="computerName">The name of the computer this ring is generated for.</param> /// <param name="ring">The target ring where all the generated data should be inserted at.</param> /// <remarks> /// Things which need to be done: /// <para>Set <see cref="RingMetaData.SenderId" /> to the targeting sender id.</para> /// <para>Generate <see cref="PageGroup" />s inside the database.</para> /// <para> /// Generate <see cref="Page" />s with the associated content (<see cref="Text" />, <see cref="Image" /> <see cref="Video" />, /// <see cref="DoubleTransition" />). /// </para> /// <para> /// Generate <see cref="PageSchedule" />s. <see cref="PageSchedule" />s in sequence which belongs to the same <see cref="PageGroup" /> needs to /// have the same <see cref="PageSchedule.PageGroupScheduleId" />. /// </para> /// </remarks> public void Generate(MultiMedia db, string computerName, RingMetaData ring) { MMSender sender = GetMMSenderFromSenderOrComputerName(db, computerName); ring.SenderId = sender.Id; sender.DataSet.SetHasBeenLoaded(); DistributionRoot DistributionRootInstance = new DistributionRoot(db, ring); DistributionRootInstance.PreloadAllForAllTodayAndTomorrowMMunitsIfNotHasBeenLoaded(); DistributionRootInstance.LoadActuallBalancers(sender); RingGenerator ringGenerator = new RingGenerator(sender, ring, DateTime.Now); ringGenerator.Generate(); }
public void Update(IServer server, string computerName, RingMetaData ring) { MultiMedia db = GetMultiMedia(server); MMSender sender = GetMMSenderFromSenderOrComputerName(db, computerName); ring.SenderId = sender.Id; sender.DataSet.SetHasBeenLoaded(); DistributionRoot DistributionRootInstance = new DistributionRoot(db, ring.TargetDate); DistributionRootInstance.PreloadAllForAllTodayAndTomorrowMMunitsIfNotHasBeenLoaded(); BalancerUsage balancerUsage = new BalancerUsage(sender, ring, ring.TargetDate) { TodaysActiveMMUnitsPerMMSlot = DistributionRootInstance.TodayActiveMMUnitsPerMMSlot, TomorrowsActiveMMUnitsPerMMSlot = DistributionRootInstance.TomorrowActiveMMUnitsPerMMSlot }; balancerUsage.LoadActuallBalancers(sender); RingUpdater ringUpdater = new RingUpdater(sender, ring, ring.TargetDate) { DistributionRootInstance = DistributionRootInstance, TodaysBalancers = (balancerUsage.TodaysBalancersPerSender.ContainsKey(sender)) ? balancerUsage.TodaysBalancersPerSender[sender] : null, TomorrowsBalancers = (balancerUsage.TomorrowsBalancersPerSender.ContainsKey(sender)) ? balancerUsage.TodaysBalancersPerSender[sender] : null, }; ringUpdater.Update(); }
public PageGroup GeneratePageGroup(IServer server, Guid mmUnitId, RingMetaData ring) { MultiMedia db = GetMultiMedia(server); MMUnit mmUnit = db.MMUnits.FindOrLoad(mmUnitId); PageGroupGenerator pageGroupGenerator = new PageGroupGenerator(mmUnit, ring.DataSet); return pageGroupGenerator.Generate(); }
double AddPlayerScreenGroupToPlayList(RingMetaData ringMetaData, Guid slotId, MMUnit mmUnit, double relativeStartSecond, ref List<PageSchedule> lastInsertedSchedules) { PageGroup pageGroup = ActualRing.DataSet.PageGroups.Find(mmUnit.Id); if (pageGroup == null) { pageGroup = new PageGroupGenerator(mmUnit, ActualRing.DataSet).Generate(); if (pageGroup.DurationInSeconds == 0) throw new Exception($"screenGroup.DurationInSeconds == 0 bei {pageGroup.Name} ({pageGroup.Id})"); } //Debug.WriteLine($"PlayListTime = {playList.RelativeStartSeconds} CurentStartTime = {currentStartTime.TotalSeconds}"); Guid pageGroupScheduledId = Guid.NewGuid(); TimeSpan currentStartTime = TimeSpan.FromSeconds(relativeStartSecond); Page[] pages = pageGroup.Pages.OrderBy(x=>x.SortOrder).ToArray(); for (int i = 0; i < pages.Length; i++) { Page page = pages[i]; if (currentStartTime > TimeSpan.FromDays(1)) continue; PageSchedule pageSchedule = pageGroup.DataSet.PageSchedules.NewRow(); pageSchedule.Id = Guid.NewGuid(); pageSchedule.StartTime = DateTime.Now.Date.Add(currentStartTime); pageSchedule.DiagnosticText = $"{pageGroup.Name} Seite {i+1}"; pageSchedule.PageGroupScheduleId = pageGroupScheduledId; pageSchedule.Page = page; pageSchedule.RingMetaData = ringMetaData; pageSchedule.SlotId = slotId; currentStartTime = currentStartTime.Add(TimeSpan.FromSeconds((double)pageSchedule.Page.ExpectedDuration)); pageSchedule.Table.Rows.Add(pageSchedule); if (lastInsertedSchedules != null) lastInsertedSchedules.Add(pageSchedule); } if (pageGroup.DurationInSeconds == 0) Debug.WriteLine($"Duration = 0 Beitrag SchreenGroup {pageGroup.Name} ({pageGroup.Id})"); return currentStartTime.TotalSeconds; }
int FillProgrammBlock(MMSender sender, RingMetaData ringMetaData, MMProgrammBlock programmBlock, Dictionary<MMSlot, Dictionary<MMUnit, List<MMUnitTiming>>> activeMMUnitsPerMMSlotAndDateTime, Dictionary<MMSlot, DbEntities.CustomClasses.StandardModelle.StatisticalBalancer<MMUnit>> actuallBalancers, DateTime programmDate, double runningStartSecond, double runningEndSeconds) { double blockStartSecond = ((DateTime)programmBlock.MMProgrammBlockTimings .FirstOrDefault().TimeA).TimeOfDay.TotalSeconds; double blockEndSecond = ((DateTime)programmBlock.MMProgrammBlockTimings .FirstOrDefault().TimeB).TimeOfDay.TotalSeconds - 5; if (runningStartSecond > blockEndSecond) return 0; if (runningStartSecond < blockStartSecond) return 0; if (runningStartSecond < 0) runningStartSecond = blockStartSecond; if (runningEndSeconds > blockEndSecond) runningEndSeconds = blockEndSecond; int numberOfPlaylistEntries = -1; while ((runningStartSecond < blockEndSecond) && (numberOfPlaylistEntries != 0)) { if (numberOfPlaylistEntries == -1) numberOfPlaylistEntries = 0; // Debug.WriteLine($"\t{programmBlock.NameId}"); foreach (MMProgrammBlockToMMSlot mmProgrammBlockToMMSlot in programmBlock.Get_MMSlotsZuMMProgrammBlockOrdered) { //Debug.WriteLine($"\t\t{mmProgrammBlockToMMSlot.MMSlot.NameId} (MMSlot), Typ = {mmProgrammBlockToMMSlot.MMProgrammBlockToMMSlotsPlayingTyp.TypNameId}"); if (!activeMMUnitsPerMMSlotAndDateTime.ContainsKey(mmProgrammBlockToMMSlot.MMSlot)) { // Debug.WriteLine($"\t\t\t-------- nothing to Play ------------------"); continue; } List<PageSchedule> slotPageSchedules = new List<PageSchedule>(); switch (mmProgrammBlockToMMSlot.MMProgrammBlockToMMSlotsPlayingTyp.TypNameId) { case "Balanced": { //if (DistributionRootInstance.TodaysBalancersPerSender.Keys.Count == 0) // DistributionRootInstance.LoadActuallBalancers(SourceSender); double timeLimit = runningStartSecond + (double)mmProgrammBlockToMMSlot.MaximalDurationInSeconds; List<PageSchedule> balancedPageSchedules = new List<PageSchedule>(); while ((runningStartSecond < blockEndSecond) && (runningStartSecond < timeLimit)) { TimeSpan RemainingToBlockEnd = (blockEndSecond < timeLimit) ? TimeSpan.FromSeconds(blockEndSecond - runningStartSecond) : TimeSpan.FromSeconds(timeLimit - runningStartSecond); runningStartSecond = AddPlayerScreenGroupToPlayList(ringMetaData, mmProgrammBlockToMMSlot.Id, actuallBalancers[mmProgrammBlockToMMSlot.MMSlot].GetNextItem(RemainingToBlockEnd), runningStartSecond, ref balancedPageSchedules); } break; } case "Standard": foreach (MMUnit toPlay in activeMMUnitsPerMMSlotAndDateTime[mmProgrammBlockToMMSlot.MMSlot].Keys) { //Debug.WriteLine($"\t\t\t{toPlay.NameId} - aus {toPlay.TableName}"); if (runningStartSecond > blockEndSecond) break; runningStartSecond = AddPlayerScreenGroupToPlayList(ringMetaData, mmProgrammBlockToMMSlot.Id, toPlay, runningStartSecond, ref slotPageSchedules); numberOfPlaylistEntries++; } break; case "TimeLimited": break; default: throw new Exception($"Playing Typ {mmProgrammBlockToMMSlot.MMProgrammBlockToMMSlotsPlayingTyp.TypNameId} ist fehlerhaft"); } if (runningStartSecond >= blockEndSecond) break; // Debug.WriteLine($""); } } return numberOfPlaylistEntries; }
public int CreateActuallProgrammForSender(MMSender mmSender, RingMetaData ringMetaData, Dictionary<MMSlot, Dictionary<MMUnit, List<MMUnitTiming>>> activeMMUnitsPerMMSlot, bool isToday, double runningStartSeconds, double runningEndSeconds) { int numberOfPlaylistEntries = 0; Dictionary<MMSlot, DbEntities.CustomClasses.StandardModelle.StatisticalBalancer<MMUnit>> balancersToUse = null; if (isToday) { if (BalancerUsageInstance.TodaysBalancersPerSender.Keys.Contains(mmSender)) balancersToUse = BalancerUsageInstance.TodaysBalancersPerSender[mmSender]; } else { if (BalancerUsageInstance.TomorrowsBalancersPerSender.Keys.Contains(mmSender)) balancersToUse = BalancerUsageInstance.TomorrowsBalancersPerSender[mmSender]; } foreach (MMProgrammBlock programmBlock in mmSender.Get_OrderedProgrammBloecke) { numberOfPlaylistEntries += FillProgrammBlock(mmSender, ringMetaData, programmBlock, activeMMUnitsPerMMSlot, balancersToUse, (isToday) ? dataContext.DefaultRangeFrom : dataContext.DefaultRangeTo, runningStartSeconds, runningEndSeconds); } Debug.WriteLine($"Für den Sender {mmSender.NameId} wurden {numberOfPlaylistEntries} erzeugt"); return numberOfPlaylistEntries; }
public PageGroup GeneratePageGroup(MMUnit mmUnit, RingMetaData ring) { return PageGroupGenerator.GetOrCreatePageGroup(mmUnit, ring.DataSet); }