コード例 #1
0
        public void OnReceive(DataMessage message)
        {
            if (_config.DataConfiguration.DataFlowTypes.Split(';').Contains(message.DataType))
            {
                // TODO Generalize Message creation
                // Add the message to the data flow
                var d = new DataFlowItem()
                {
                    DataMessage = message,
                    Name = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).NamePath),
                    Category = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).CategoryPath),
                    Type = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).TypePath),
                    Short = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).ShortPath),
                    Priority = DataFlowPriority.Neglectable,
                    Timestamp = DateTime.Now
                };
                if (!string.IsNullOrEmpty(_config.DataConfiguration.GetPathByDataType(message.DataType).UrlPath))
                {
                    // Set Url if available
                    d.Url = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).UrlPath);
                }
                SetFlowItemPriority(d);
                DataFlowItems.Add(d);

                // Cleanup
                while (DataFlowItems.Count > 300)
                {
                    DataFlowItems.RemoveAt(0);
                }

                // Handle auto
                if (DataDoesAutoOnAirCart(d) && AllowOverride)
                {
                    // Create the cart
                    // CreateCartForDataFlowItem(d, false);
                    // Put cart on air
                    // ActiveCart = PreviewCart;
                    // ReloadPreview();

                    // IsInOverrideCart = true;
                    // OverrideProgress = 1.0;
                    // OverrideSlideCountDown = ActiveCart.Slides.Count * OverrideRotationCount;

                    var autoCart = Carts.FirstOrDefault(x => x.Name == "AUTO");
                    if (autoCart == null)
                    {
                        autoCart = new ManagerCart("AUTO");
                        Carts.Insert(0, autoCart);
                    }

                    // TODO NEW HANDLING
                    if (Config.DataConfiguration.AutoCartClearTypes.Split(';').Contains(d.DataMessage.DataType))
                    {
                        // Need to clear the current active cart
                        autoCart.Slides.Clear();
                    }
                    if (Config.DataConfiguration.AutoCartAppendTypes.Split(';').Contains(d.DataMessage.DataType))
                    {
                        // Need to append to current active cart
                        CreateCartForDataFlowItem(d, autoCart);
                    }
                    if (Config.DataConfiguration.AutoCartGenerationTypes.Split(';').Contains(d.DataMessage.DataType))
                    {
                        // Need to create a new cart
                        CreateCartForDataFlowItem(d, autoCart);
                    }
                    if (Config.DataConfiguration.AutoEditorTypes.Split(';').Contains(d.DataMessage.DataType))
                    {
                        // Need to update the editor's template
                        if (Config.DataConfiguration.DataFlowLeftActions.Split(';').Contains("Template"))
                        {
                            // Load template to editor
                            // Find appropriate template
                            var conf = Config.DataConfiguration.DataItemConfigurations.Cast<DataItemConfiguration>().FirstOrDefault(c => c.DataType == d.DataMessage.DataType);
                            // Load corresponding template
                            if (conf != null)
                            {
                                var newTemplate = new ManagerImageReference(Config)
                                {
                                    Template = conf.DefaultTemplate,
                                    Link = Config.SlidesConfiguration.DefaultLink,
                                    CanRepeate = false
                                };

                                EditorImage = newTemplate;
                            }
                        }
                        if (Config.DataConfiguration.DataFlowLeftActions.Split(';').Contains("BackgroundUrl"))
                        {
                            // Set the background Uri
                            EditorImage.Background = d.Url;
                        }
                        if (Config.DataConfiguration.DataFlowLeftActions.Split(';').Contains("Context"))
                        {
                            // Set the context
                            EditorImage.Context = d.DataMessage;
                            EditorImage.ReRender(GlobalData);
                        }
                        EditorImage.ReRender(true);
                        EditorImage = EditorImage;
                    }
                }
            }
            if (_config.DataConfiguration.ImageFlowTypes.Split(';').Contains(message.DataType) ||
                (string.IsNullOrEmpty(_config.DataConfiguration.ImageFlowTypes) && message.DataType.CompareTo("IMAGE") == 0))
            {
                // Add the message to the image flow
                var d = new DataFlowItem()
                {
                    DataMessage = message,
                    Name = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).NamePath),
                    Category = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).CategoryPath),
                    Type = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).TypePath),
                    Short = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).ShortPath),
                    Url = message.GetValue(_config.DataConfiguration.GetPathByDataType(message.DataType).UrlPath),
                    Priority = DataFlowPriority.Neglectable,
                    Timestamp = DateTime.Now
                };

                // Handle dupplicates in http
                if (ImageFlowItems.Any(x => x.Timestamp > DateTime.Now.AddMinutes(-1) && x.Url == d.Url))
                {
                    // We already have it since less than a minute thus return and ignore it
                    return;
                }
                // Handle empty names
                if (string.IsNullOrEmpty(d.Name))
                {
                    //Generate random name
                    d.Name = Guid.NewGuid().ToString() + ".jpg";
                }
                if (d.Name.StartsWith("INSTAGRAM"))
                {
                    d.Name = Guid.NewGuid().ToString() + "_instagram.jpg";
                }
                // Save the image to local folder
                if (d.Url.StartsWith("http"))
                {
                    var filepath = Path.Combine(_config.DataConfiguration.IncomingPictureFolder, d.Name);
                    var dli = new Thread(() => DownloadImageToLocal(d.Url, filepath));
                    dli.Start();
                }

                // Set the priority according to config
                SetFlowItemPriority(d);

                // Add element to the list
                ImageFlowItems.Add(d);

                // Cleanup, keep the last 200 images only
                while (ImageFlowItems.Count > 200)
                {
                    ImageFlowItems.RemoveAt(0);
                }
            }

            if (_config.DataConfiguration.DataBaseTypes.Split(';').Contains(message.DataType))
            {
                // Add the message to the database
                UpdateDataBase(message);
            }
        }
コード例 #2
0
        public void DummyData()
        {
            // Dummy Data
            //EventFlow e0 = new EventFlow() { Name = "General" };
            //EventFlow e1 = new EventFlow() { Name = "100M Men" };
            //EventFlow e2 = new EventFlow() { Name = "High Jump Women" };
            //EventFlow e3 = new EventFlow() { Name = "4x100m Relay Women" };
            //EventFlow e4 = new EventFlow() { Name = "400m Hurdles Men" };

            //RunningEvents.Add(e0);
            //RunningEvents.Add(e1);
            //RunningEvents.Add(e2);
            //RunningEvents.Add(e3);
            //RunningEvents.Add(e4);

            DataFlowItem d1 = new DataFlowItem() { Name = "Data 15", Category = "100M", Type = "Results", Short = "Short text describing this", Priority = DataFlowPriority.High };
            DataFlowItem d2 = new DataFlowItem() { Name = "Data 25", Category = "ABC", Type = "Results", Short = "Short text describing this", Priority = DataFlowPriority.Medium };
            DataFlowItem d3 = new DataFlowItem() { Name = "Data 35", Category = "DDC", Type = "StartList", Short = "Short text describing this", Priority = DataFlowPriority.Low };
            DataFlowItem d4 = new DataFlowItem() { Name = "Data 45", Category = "DDC", Type = "Results", Short = "Short text describing this", Priority = DataFlowPriority.Neglectable };
            DataFlowItem d5 = new DataFlowItem() { Name = "Data 55", Category = "DDC", Type = "Official Results", Short = "Short text describing this", Priority = DataFlowPriority.Medium };
            DataFlowItem d6 = new DataFlowItem() { Name = "Data 65", Category = "DDC", Type = "Results", Short = "Short text describing this", Priority = DataFlowPriority.Neglectable };
            DataFlowItem d7 = new DataFlowItem() { Name = "Data 65", Category = "WEATHER", Type = "WEATHER", Short = "Stadium", Priority = DataFlowPriority.Neglectable };

            DataFlowItems.Add(d1);
            DataFlowItems.Add(d2);
            DataFlowItems.Add(d3);
            DataFlowItems.Add(d4);
            DataFlowItems.Add(d5);
            DataFlowItems.Add(d6);
            DataFlowItems.Add(d7);

            DataFlowItem i1 = new DataFlowItem()
            {
                Name = "Image 1",
                Category = "Getty",
                Type = "Image",
                Short = "Short text describing this",
                Priority = DataFlowPriority.High,
                Url = @"Z:\mh On My Mac\EBU\Assets\GETTY Images Day 1 Braunschweig\450987746.jpg"
            };
            DataFlowItem i2 = new DataFlowItem()
            {
                Name = "Image 2",
                Category = "Getty",
                Type = "Image",
                Short = "Short text describing this",
                Priority = DataFlowPriority.Medium,
                Url = @"Z:\mh On My Mac\EBU\Assets\GETTY Images Day 1 Braunschweig\450987748.jpg"
            };
            DataFlowItem i3 = new DataFlowItem()
            {
                Name = "Image 3",
                Category = "Getty",
                Type = "Image",
                Short = "Short text describing this",
                Priority = DataFlowPriority.Low,
                Url = @"Z:\mh On My Mac\EBU\Assets\GETTY Images Day 1 Braunschweig\450987750.jpg"
            };

            ImageFlowItems.Add(i1);
            ImageFlowItems.Add(i2);
            ImageFlowItems.Add(i3);
        }
コード例 #3
0
 private void SetFlowItemPriority(DataFlowItem item)
 {
     foreach (DataPriorityConfiguration prioconf in _config.DataConfiguration.DataPriorityConfigurations)
     {
         var value = item.DataMessage.GetValue(prioconf.DataPath);
         switch (prioconf.Operator.ToLower())
         {
             case "equals":
                 if (String.Compare(value, prioconf.ExpectedValue, StringComparison.Ordinal) == 0)
                 {
                     item.Priority = StringToDataFlowPriority(prioconf.Priority);
                 }
                 break;
             case "startswith":
                 if (value.StartsWith(prioconf.ExpectedValue))
                 {
                     item.Priority = StringToDataFlowPriority(prioconf.Priority);
                 }
                 break;
             case "endswith":
                 if (value.EndsWith(prioconf.ExpectedValue))
                 {
                     item.Priority = StringToDataFlowPriority(prioconf.Priority);
                 }
                 break;
             case "contains":
                 if (value.Contains(prioconf.ExpectedValue))
                 {
                     item.Priority = StringToDataFlowPriority(prioconf.Priority);
                 }
                 break;
         }
     }
 }
コード例 #4
0
        public void CreateCartForDataFlowItem(DataFlowItem m, ManagerCart appentToThisCart)
        {
            var conf = Config.DataConfiguration.DataItemConfigurations.Cast<DataItemConfiguration>().FirstOrDefault(c => c.DataType == m.DataMessage.DataType);

            // Configure which DataTypes generate Carts
            //var cartName = "";
            //var types = _config.DataConfiguration.AutoCartGenerationTypes.Split(';');
            //if (types.Contains(m.DataMessage.DataType))
            //    cartName = m.DataMessage.DataType;
            if (conf != null)
            {
                var existingCart = Carts.FirstOrDefault(x => x.Name.ToUpper() == conf.DefaultCartName.ToUpper());
                if (existingCart != null)
                {
                    // TODO ASK IF Switch Cart or add to cart

                    var newCart = existingCart.Clone();
                    newCart.Name = newCart.Name + " - " + m.DataMessage.GetValue("EVENTNAME");
                    if (newCart.Slides.Count == 1 && newCart.Slides.First().CanRepeate)
                    {
                        if (conf.DefaultCartName.ToUpper() == "STARTLIST")
                        {
                            // We might need to repeate the slide due to data and slit the context
                            // We assume 4 line per slide
                            // TODO This needs to be generic !
                            var context = m.DataMessage.Clone();

                            var ath = context.Data.FirstOrDefault(x => x.Key == "STARTPOSITIONS");

                            // Sort the list first try by int then by alpha num
                            bool ordered = false;
                            try
                            {
                                if (ath != null)
                                {
                                    ath.Data =
                                        ath.Data.OrderBy(s => string.IsNullOrWhiteSpace(s.Key))
                                            .ThenBy(x => Convert.ToInt32("0" + x.Key))
                                            .ToList();
                                    ordered = true;
                                }
                            }
                            catch (Exception)
                            {
                                // TODO Log
                            }
                            if (!ordered)
                            {
                                // Try alpha order
                                try
                                {
                                    if (ath != null)
                                    {
                                        ath.Data =
                                            ath.Data.OrderBy(s => string.IsNullOrWhiteSpace(s.Key))
                                                .ThenBy(x => x.Key)
                                                .ToList();
                                    }
                                }
                                catch (Exception)
                                {
                                    // TODO Log
                                }
                            }

                            newCart.Slides.First().Context = context;
                            newCart.Slides.First().ReRender(GlobalData);

                            var itemsPerSlide = newCart.Slides.First().ItemsPerSlide;
                            var offset = itemsPerSlide;
                            while (ath != null && ath.Data.Count > itemsPerSlide)
                            {
                                var clone = ath.Clone();
                                clone.Data.RemoveRange(0, itemsPerSlide);
                                ath.Data.RemoveRange(itemsPerSlide, ath.Data.Count - itemsPerSlide);
                                var newSlide = newCart.Slides.First().Clone();
                                newSlide.IndexOffset = offset;
                                var contextClone = context.Clone();
                                contextClone.Data.First(x => x.Key == "STARTPOSITIONS").Data = clone.Data;
                                newSlide.Context = contextClone;
                                newSlide.ReRender(GlobalData);
                                newCart.Slides.Add(newSlide);
                                ath = clone;
                                offset = offset + itemsPerSlide;
                            }
                        }
                        else if (conf.DefaultCartName.ToUpper() == "RESULTLIST")
                        {
                            // We might need to repeate the slide due to data and slit the context
                            // We assume 4 line per slide
                            // TODO This needs to be generic !
                            var context = m.DataMessage.Clone();

                            var ath = context.Data.FirstOrDefault(x => x.Key == "RESULTS");

                            // Sort the list first try by int then by alpha num
                            bool ordered = false;
                            try
                            {
                                if (ath != null)
                                {
                                    ath.Data =
                                        ath.Data.OrderBy(s => string.IsNullOrWhiteSpace(s.Key))
                                            .ThenBy(x => Convert.ToInt32("0" + x.Key))
                                            .ToList();

                                    ordered = true;
                                }
                            }
                            catch (Exception)
                            {
                                // TODO Log
                            }
                            if (!ordered)
                            {
                                // Try alpha order
                                try
                                {
                                    if (ath != null)
                                    {
                                        ath.Data =
                                            ath.Data.OrderBy(s => string.IsNullOrWhiteSpace(s.Key))
                                                .ThenBy(x => x.Key)
                                                .ToList();
                                    }
                                }
                                catch (Exception)
                                {
                                    // TODO Log
                                }
                            }

                            newCart.Slides.First().Context = context;
                            newCart.Slides.First().ReRender(GlobalData);
                            var itemsPerSlide = newCart.Slides.First().ItemsPerSlide;
                            var offset = itemsPerSlide;
                            while (ath != null && ath.Data.Count > itemsPerSlide)
                            {
                                var clone = ath.Clone();
                                clone.Data.RemoveRange(0, itemsPerSlide);
                                ath.Data.RemoveRange(itemsPerSlide, ath.Data.Count - itemsPerSlide);
                                var newSlide = newCart.Slides.First().Clone();
                                newSlide.IndexOffset = offset;
                                var contextCLone = context.Clone();
                                contextCLone.Data.First(x => x.Key == "RESULTS").Data = clone.Data;
                                newSlide.Context = contextCLone;
                                newSlide.ReRender(GlobalData);
                                newCart.Slides.Add(newSlide);
                                ath = clone;
                                offset = offset + itemsPerSlide;
                            }
                        }
                        else
                        {
                            // Set Context for all slides
                            var context = m.DataMessage.Clone();
                            foreach (var s in newCart.Slides)
                            {
                                s.Context = context;
                                s.ReRender(GlobalData);
                            }
                        }
                    }
                    else
                    {
                        foreach (var s in newCart.Slides)
                        {
                            // Set the context on all slides
                            s.Context = m.DataMessage;
                            s.ReRender(GlobalData);
                        }
                    }

                    if (appentToThisCart != null)
                    {
                        // Append i.e. merge to current
                        foreach (var s in newCart.Slides)
                        {
                            // Add to open cart (not the currently active one)
                            appentToThisCart.Slides.Add(s);
                        }
                    }
                    else
                    {
                        // Generate new cart otherwise
                        Carts.Add(newCart);
                        PreviewCart = newCart;
                    }
                }
                else
                {
                    // No Cart, try with template only
                    if (!string.IsNullOrEmpty(conf.DefaultTemplate))
                    {
                        // Create new ImageRef
                        var newImgRef = new ManagerImageReference(Config)
                        {
                            Template = conf.DefaultTemplate,
                            Link = Config.SlidesConfiguration.DefaultLink,
                            Context = m.DataMessage,
                            CanRepeate = false
                        };
                        // Handle
                        if (appentToThisCart != null)
                        {
                            // Add to open cart (not the currently active one)
                            appentToThisCart.Slides.Add(newImgRef);
                        }
                        else
                        {
                            var newCart = new ManagerCart("TEMP " + conf.DataType);
                            newCart.Slides.Add(newImgRef);
                            Carts.Add(newCart);
                            PreviewCart = newCart;
                        }
                    }
                }
            }
            else
            {
                // No cart defined for that event type
            }
        }
コード例 #5
0
        private bool DataDoesAutoOnAirCart(DataFlowItem item)
        {
            foreach (OnAirCartAutoCondition cond in _config.DataConfiguration.OnAirCartAutoConfiguration)
            {
                var value = item.DataMessage.GetValue(cond.DataPath);
                switch (cond.Operator.ToLower())
                {
                    case "equals":
                        if (String.Compare(value, cond.ExpectedValue, StringComparison.Ordinal) == 0) return true;
                        break;
                    case "startswith":
                        if (value.StartsWith(cond.ExpectedValue)) return true;
                        break;
                    case "endswith":
                        if (value.EndsWith(cond.ExpectedValue)) return true;
                        break;
                    case "contains":
                        if (value.Contains(cond.ExpectedValue)) return true;
                        break;
                }
            }

            // If we ended up here, item corresponds to all conditions
            return false;
        }