public ManagerCart Clone() { var newCart = new ManagerCart(Name); foreach (var s in Slides) { newCart.Slides.Add(s.Clone()); } newCart.SetAllSlidesInactive(); return newCart; }
public ManagerCart Clone(bool clonePreviewImages) { var newCart = new ManagerCart(Name); foreach (var s in Slides) { newCart.Slides.Add(s.Clone(clonePreviewImages)); } newCart.SetAllSlidesInactive(); return(newCart); }
private void newCartButton_Click(object sender, RoutedEventArgs e) { _context = (ManagerContext)DataContext; var name = NewCartWindow.Show(this); if (!string.IsNullOrEmpty(name)) { var c = new ManagerCart(name) { CanBeDeleted = true, ShowInCartList = true }; _context.Carts.Add(c); _context.PreviewCart = c; } }
private void CartListBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { var listBox = sender as ListBox; if (listBox != null) { var cart = listBox.SelectedItem as ManagerCart; if (cart != null) { _lastSelectedCart = cart; } } } catch (Exception) { // TODO HAndle and not generic Exceltion } }
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); } }
public void LoadCarts(bool loadAll, bool cleanReload) { if (cleanReload) { // Cleanup existing Carts.Clear(); } foreach (CartConfiguration cart in _config.SlidesConfiguration.CartConfigurations) { if (loadAll || Carts.Count(x => x.Name == cart.Name) == 0) { var c = new ManagerCart(cart.Name) { CanBeDeleted = false, ShowInCartList = cart.ShowInCartList }; Carts.Add(c); foreach (SlideConfiguration s in cart.Slides) { var sl = new ManagerImageReference(_config) { Template = s.Filename, Link = s.DefaultLink, Text = s.DefaultText, RegenerateOnPublish = s.RegenerateOnPublish, ValidityPeriod = TimeSpan.FromSeconds(s.ValidityPeriodSeconds), CanRepeate = s.CanRepeat, ItemsPerSlide = s.ItemsPerSlide, Context = new DataMessage() }; c.Slides.Add(sl); } if (cart.Active) { // Set current cart as active ActiveCart = c; PreviewCart = c; } if (cart.EditorDefault) { // Set current editor cart EditorCart = c; } } } }
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 } }