public GraphicController DeserializeSingle(JObject json, int depth = 0) { Graphic graphic = null; GraphicController controller = null; string type = json["type"].ToString(); switch (type) { case "Scoreboard": { graphic = new Scoreboard(Windows.Source.canvas); break; } case "SingleText": { graphic = new SingleText(Windows.Source.canvas); break; } case "DoubleText": { graphic = new DoubleText(Windows.Source.canvas); break; } case "RichText": { graphic = new RichText(Windows.Source.canvas); break; } case "ImageOnly": { graphic = new ImageOnly(Windows.Source.canvas); break; } case "Countdown": { graphic = new Countdown(Windows.Source.canvas); break; } case "Bracket": { graphic = new Bracket(Windows.Source.canvas); break; } case "Group": { graphic = new Group(Windows.Source.canvas); break; } case "SequencePlayer": { graphic = new SequencePlayer(Windows.Source.canvas); break; } case "Media": { graphic = new Media(Windows.Source.canvas); break; } case "Clock": { graphic = new Clock(Windows.Source.canvas); break; } case "ImageSwitcher": { graphic = new ImageSwitcher(Windows.Source.canvas); break; } case "ImageSlider": { graphic = new ImageSlider(Windows.Source.canvas); break; } case "WebSource": { graphic = new WebSource(Windows.Source.canvas); break; } case "Playlist": { graphic = new Playlist(Windows.Source.canvas); break; } case "Blank": { controller = new Blank(null); break; } case "Peliliiga": { controller = new Peliliiga(null); break; } case "Xerberus": { controller = new Xerberus(null); break; } } if (graphic != null) { controller = graphic.Controller; controller.name.Content = json["name"].ToString(); graphic.X = double.Parse(json["x"].ToString()); graphic.Y = double.Parse(json["y"].ToString()); graphic.GraphicWidth = double.Parse(json["width"].ToString()); graphic.GraphicHeight = double.Parse(json["height"].ToString()); JObject image = JObject.Parse(json["image"].ToString()); graphic.Image.Stretch = (Stretch)Enum.Parse(typeof(Stretch), image["stretch"].ToString()); if (image["uri"] != null) { string uri = image["uri"].ToString(); Uri tempuri; if (Uri.TryCreate(uri, UriKind.Absolute, out tempuri)) { graphic.Image.UriSource = tempuri.ToString(); } else { graphic.Image.UriSource = AppDomain.CurrentDomain.BaseDirectory + uri; } if (graphic.Image.IsSequence) { graphic.Image.SequenceFrames = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + Path.GetDirectoryName(graphic.Image.UriSource), "*" + Path.GetExtension(graphic.Image.UriSource)).ToList(); } } graphic.Image.IsSequence = bool.Parse(image["isSequence"].ToString()); JObject animationIn = JObject.Parse(json["animationIn"].ToString()); graphic.AnimationIn.Style = (GraphicAnimation.AnimationStyle)Enum.Parse(typeof(GraphicAnimation.AnimationStyle), animationIn["style"].ToString()); graphic.AnimationIn.AddFade = bool.Parse(animationIn["addFade"].ToString()); graphic.AnimationIn.Duration = double.Parse(animationIn["duration"].ToString()); graphic.AnimationIn.Delay = double.Parse(animationIn["delay"].ToString()); graphic.AnimationIn.Ease = bool.Parse(animationIn["ease"].ToString()); graphic.AnimationIn.EasePower = double.Parse(animationIn["easePower"].ToString()); JObject animationOut = JObject.Parse(json["animationOut"].ToString()); graphic.AnimationOut.Style = (GraphicAnimation.AnimationStyle)Enum.Parse(typeof(GraphicAnimation.AnimationStyle), animationOut["style"].ToString()); graphic.AnimationOut.AddFade = bool.Parse(animationOut["addFade"].ToString()); graphic.AnimationOut.Duration = double.Parse(animationOut["duration"].ToString()); graphic.AnimationOut.Delay = double.Parse(animationOut["delay"].ToString()); graphic.AnimationOut.Ease = bool.Parse(animationOut["ease"].ToString()); graphic.AnimationOut.EasePower = double.Parse(animationOut["easePower"].ToString()); if (graphic.Texts != null) { JArray texts = JArray.Parse(json["texts"].ToString()); for (int i = 0; i < texts.Count; i++) { graphic.Texts[i].Content = texts[i]["content"].ToString(); graphic.Texts[i].X = double.Parse(texts[i]["x"].ToString()); graphic.Texts[i].Y = double.Parse(texts[i]["y"].ToString()); graphic.Texts[i].Width = double.Parse(texts[i]["width"].ToString()); graphic.Texts[i].LineHeight = double.Parse(texts[i]["lineHeight"].ToString()); JObject font = JObject.Parse(texts[i]["font"].ToString()); graphic.Texts[i].FontFamily = font["family"].ToString(); graphic.Texts[i].FontSize = double.Parse(font["size"].ToString()); graphic.Texts[i].FontWeight = (FontWeight) new FontWeightConverter().ConvertFromString(font["weight"].ToString()); graphic.Texts[i].FontStyle = (FontStyle) new FontStyleConverter().ConvertFromString(font["style"].ToString()); graphic.Texts[i].FontColor = font["color"].ToString(); graphic.Texts[i].HasGlow = bool.Parse(font["hasGlow"].ToString()); graphic.Texts[i].GlowColor = font["glowColor"].ToString(); graphic.Texts[i].ContentAlign = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), font["align"].ToString()); } } if (type == "Bracket") { Bracket bracket = (Bracket)graphic; JObject jsonBracket = JObject.Parse(json["bracket"].ToString()); bracket.OriginX = double.Parse(jsonBracket["originX"].ToString()); bracket.OriginY = double.Parse(jsonBracket["originY"].ToString()); bracket.BracketWidth = double.Parse(jsonBracket["width"].ToString()); bracket.BracketHeight = double.Parse(jsonBracket["height"].ToString()); bracket.Competitors = int.Parse(jsonBracket["competitors"].ToString()); bracket.OffsetX = double.Parse(jsonBracket["offsetX"].ToString()); bracket.OffsetY = double.Parse(jsonBracket["offsetY"].ToString()); bracket.Color = new BrushConverter().ConvertFromString(jsonBracket["lineColor"].ToString()) as Brush; bracket.Thickness = double.Parse(jsonBracket["lineThickness"].ToString()); bracket.HideHorizontal = bool.Parse(jsonBracket["hideHorizontalLines"].ToString()); bracket.HideVertical = bool.Parse(jsonBracket["hideVerticalLines"].ToString()); JObject jsonBracketFont = JObject.Parse(jsonBracket["font"].ToString()); bracket.ExampleLabel.FontFamily = jsonBracketFont["family"].ToString(); bracket.ExampleLabel.FontSize = double.Parse(jsonBracketFont["size"].ToString()); bracket.ExampleLabel.FontWeight = (FontWeight) new FontWeightConverter().ConvertFromString(jsonBracketFont["weight"].ToString()); bracket.ExampleLabel.FontStyle = (FontStyle) new FontStyleConverter().ConvertFromString(jsonBracketFont["style"].ToString()); bracket.ExampleLabel.FontColor = jsonBracketFont["color"].ToString(); bracket.ExampleLabel.HasGlow = bool.Parse(jsonBracketFont["hasGlow"].ToString()); bracket.ExampleLabel.GlowColor = jsonBracketFont["glowColor"].ToString(); bracket.ExampleLabel.ContentAlign = (HorizontalAlignment)Enum.Parse(typeof(HorizontalAlignment), jsonBracketFont["align"].ToString()); JArray bracketNames = JArray.Parse(jsonBracket["names"].ToString()); for (int i = 0; i < bracketNames.Count; i++) { bracket.Names[i].Content = bracketNames[i].ToString(); } JArray bracketScores = JArray.Parse(jsonBracket["scores"].ToString()); for (int i = 0; i < bracketScores.Count; i++) { bracket.Scores[i].Content = bracketScores[i].ToString(); } bracket.Redraw(); } else if (type == "SequencePlayer") { SequencePlayer sequence = (SequencePlayer)graphic; sequence.InStartFrame = int.Parse(image["sequenceInStartFrame"].ToString()); sequence.LoopStartFrame = int.Parse(image["sequenceInStartFrame"].ToString()); sequence.OutStartFrame = int.Parse(image["sequenceInStartFrame"].ToString()); } else if (type == "ImageSwitcher") { ImageSwitcher imageSwitcher = (ImageSwitcher)graphic; JObject jsonImageSwitcher = JObject.Parse(json["imageSwitcher"].ToString()); string folder = jsonImageSwitcher["folder"].ToString(); if (folder != string.Empty) { Uri tempuri; if (Uri.TryCreate(folder, UriKind.Absolute, out tempuri)) { imageSwitcher.Folder = folder.ToString(); } else { imageSwitcher.Folder = AppDomain.CurrentDomain.BaseDirectory + folder; } } string activeImage = jsonImageSwitcher["activeImage"].ToString(); if (activeImage != string.Empty) { Uri tempuri; if (Uri.TryCreate(folder, UriKind.Absolute, out tempuri)) { imageSwitcher.ActiveImage = activeImage; } else { imageSwitcher.ActiveImage = AppDomain.CurrentDomain.BaseDirectory + activeImage; } } imageSwitcher.SwitcherImage.Stretch = (Stretch)Enum.Parse(typeof(Stretch), jsonImageSwitcher["stretch"].ToString()); } else if (type == "ImageSlider") { ImageSlider imageSlider = (ImageSlider)graphic; imageSlider.Duration = int.Parse(json["sliderDuration"].ToString()); imageSlider.ImageSources = JArray.Parse(json["images"].ToString()).ToObject <List <string> >(); } else if (type == "SingleText" || type == "DoubleText") { if (graphic is SingleText) { ((SingleText)graphic).TextStorage = JArray.Parse(json["storage"].ToString()).ToObject <string[]>(); } else { ((DoubleText)graphic).TextStorage = JArray.Parse(json["storage"].ToString()).ToObject <string[]>(); } } else if (type == "Media") { ((Media)graphic).Source = json["source"].ToString(); double duration = double.Parse(json["duration"].ToString()); if (duration > 0) { ((Media)graphic).Duration = TimeSpan.FromMilliseconds(duration); controller.info.Content = string.Format("Duration: {0:00}:{1:00}", (((Media)graphic).Duration.Hours * 60) + ((Media)graphic).Duration.Minutes, ((Media)graphic).Duration.Seconds); } ((Media)graphic).Volume = double.Parse(json["volume"].ToString()); ((Media)graphic).Loop = bool.Parse(json["loop"].ToString()); } else if (type == "WebSource") { ((WebSource)graphic).Url = json["url"].ToString(); } else if (type == "Playlist") { JArray playlistSources = JArray.Parse(json["sources"].ToString()); foreach (JObject source in playlistSources) { ((Playlist)graphic).Sources.Add(Tuple.Create(source["file"].ToString(), TimeSpan.FromMilliseconds(double.Parse(source["duration"].ToString())))); } ((Playlist)graphic).Volume = double.Parse(json["volume"].ToString()); ((Playlist)graphic).Loop = bool.Parse(json["loop"].ToString()); if (((Playlist)graphic).Sources.Count == 0) { controller.info.Content = string.Empty; } else { TimeSpan total = TimeSpan.Zero; foreach (Tuple <string, TimeSpan> source in ((Playlist)graphic).Sources) { total = total.Add(source.Item2); } controller.info.Content = string.Format("Duration: {0:00}:{1:00}", (total.Hours * 60) + total.Minutes, total.Seconds); } } } else if (controller != null) { controller.name.Content = json["name"].ToString(); if (type == "Peliliiga") { Peliliiga peliliiga = (Peliliiga)controller; peliliiga.Url = json["url"].ToString(); peliliiga.Store = json["store"].ToString(); peliliiga.Interval = double.Parse(json["interval"].ToString()); } else if (type == "Xerberus") { Xerberus xerberus = (Xerberus)controller; xerberus.Url = json["url"].ToString(); xerberus.Store = json["store"].ToString(); xerberus.Interval = double.Parse(json["interval"].ToString()); Xerberus.ClientId = json["clientId"].ToString(); Xerberus.ClientSecret = json["clientSecret"].ToString(); } } else { throw new Exception("Controller with type " + json["type"] + " not found"); } controller.Id = int.Parse(json["id"].ToString()); JArray children = (JArray)json["children"]; if (children.Count > 0) { controller.childrenVisibleArrow.Visibility = Visibility.Visible; } foreach (JObject child in children) { GraphicController childController = DeserializeSingle(child, depth + 1); childController.ControllerParent = controller; GraphicController.rootList.Remove(childController); controller.Children.Add(childController); } if (depth > 0) { controller.Expanded = false; } return(controller); }
private void AddDoubleText_Click(object sender, RoutedEventArgs e) { DoubleText doubleText = new DoubleText(Windows.Source.canvas); }