private async Task DisplayScreenModelAsync(IDisplayLane lane) { while (true) { foreach (var person in lane.People.ToList()) { if (lane.GetType() == typeof(KioskDisplayLane)) { if ((DateTime.Now >= person.NextDisplayTime)) { Debug.WriteLine($"Displaying {person} for {person.CurrentDisplayCount} in lane {lane.LaneIndex}"); await Animate(person, lane); person.CurrentDisplayCount += 1; //TODO: Refactor out RecycleCount if (person.CurrentDisplayCount >= Configuration.KioskDisplayRecycleCount) { lane.People.Remove(person); } } continue; } await Animate(person, lane); var percent = lane.People.IndexOf(person).ToDouble().PercentOf(DefaultTakeCount.ToDouble()); if (percent >= 90) { AsyncHelper.FireAndForget( () => lane.UpdateQueueAsync(_currentCount, DefaultTakeCount, WebServerUrl), e => { Console.WriteLine(@"Error updating name queue for general names"); Debug.WriteLine(e); }); _currentCount += DefaultTakeCount; } using (Canceller.Token.Register(Thread.CurrentThread.Abort)) { //NOTE: This is amount of time before next name displays and begins animation await Task.Delay(TimeSpan.FromSeconds(lane.RotationDelay), Canceller.Token); } } //TODO: If queue list is not populated continue with existing list. Notifiy issue if (!lane.Queue.Any()) { continue; } //NOTE: If current queue count less than DefaultTakeCount assume at end of database list and start over at beginning. Need to same position for next runtime. if (lane.Queue.Count < DefaultTakeCount) { _currentCount = 0; } lane.People.Clear(); lane.People.AddRange(lane.Queue); lane.Queue.Clear(); } }
//TODO: Refactor out Configuration public DisplayElement(PersonViewModel person, IDisplayLane lane, double canvasWidth, Configuration configuration, bool debugMode) { _configuration = configuration; _debugMode = debugMode; Person = person; Lane = lane; TotalCanvasWidth = canvasWidth; Label = CreateLabel(person); Border = CreateBorder(Label, lane); GetXAxis(); GetYAxis(); }
private Border CreateBorder(Label label, IDisplayLane lane) { var borderName = "border" + Guid.NewGuid().ToString("N").Substring(0, 10); var width = lane.GetType() == typeof(KioskDisplayLane) && Person.IsFirstRun ? lane.LaneWidth : label.ActualWidth; var border = new Border() { Name = borderName, Uid = borderName, Child = label, Width = width, HorizontalAlignment = HorizontalAlignment.Center }; if (!_debugMode) { return(border); } border.BorderBrush = Brushes.Red; border.BorderThickness = new Thickness(2); return(border); }
private async Task <double> Animate(PersonViewModel person, IDisplayLane lane) { var totalTime = 0.0; var width = _canvas.ActualWidth; await Dispatcher.InvokeAsync(() => { NameScope.SetNameScope(this, new NameScope()); var storyboard = new Storyboard(); var displayElement = new DisplayElement(person, lane, width, Configuration, _debugMode); List <MyAnimation> animations = displayElement.CreateAnimations(); RegisterName(displayElement.Label.Name, displayElement.Label); RegisterName(displayElement.Border.Name, displayElement.Border); var e = new AnimationEventArgs { TagName = displayElement.Border.Uid }; storyboard.Completed += (sender, args) => StoryboardOnCompleted(e); foreach (var da in animations) { Storyboard.SetTargetName(da, da.TargetName); Storyboard.SetTargetProperty(da, da.PropertyPath); storyboard.Children.Add(da); } totalTime = displayElement.TotalTime; var xPosition = displayElement.XAxis; var yPosition = displayElement.YAxis; Canvas.SetLeft(displayElement.Border, xPosition); Canvas.SetTop(displayElement.Border, yPosition); _canvas.Children.Add(displayElement.Border); _canvas.UpdateLayout(); storyboard.Begin(this); }); person.NextDisplayTime = DateTime.Now.AddSeconds(totalTime); return(totalTime); }