private void OutputUIElement(UIObject ui) { Console.WriteLine(ui); using (var writer = File.AppendText(outfile)) { writer.WriteLine(string.Format("<{0}", ui.UIElement)); if (!string.IsNullOrEmpty(ui.UIName)) writer.WriteLine(string.Format("x:Name=\"{0}\"", ui.UIName)); if (ui.UIElement != "imageview") { if (!string.IsNullOrEmpty(ui.Text)) writer.WriteLine(string.Format("Text=\"{0}\"", ui.Text)); if (!string.IsNullOrEmpty(ui.FontSize)) writer.WriteLine(string.Format("TextSize=\"{0}\"", ui.FontSize)); if (!string.IsNullOrEmpty(ui.FontStyle)) writer.WriteLine(string.Format("FontFamily=\"{0}\"", ui.FontStyle)); } else { writer.WriteLine(string.Format("Source=\"{0}\""), ui.ImageName); } writer.WriteLine(string.Format("AbsoluteLayout.LayoutBounds=\"{0},{1},{2},{3}\"", ui.UIXPos, ui.UIYPos, ui.UIWidth, ui.UIHeight)); //if (ui.UIElement != "scrollView") //{ if (!string.IsNullOrEmpty(ui.BackgroundColor)) writer.WriteLine(string.Format("BackgroundColor=\"{0}\"", ui.BackgroundColor)); if (!string.IsNullOrEmpty(ui.TextColor)) writer.WriteLine(string.Format("TextColor=\"{0}\"", ui.TextColor)); else { if (string.IsNullOrEmpty(ui.ColorA)) { if (!string.IsNullOrEmpty(ui.ColorB)) { int r = (int)(255 * double.Parse(ui.ColorR)); int g = (int)(255 * double.Parse(ui.ColorG)); int b = (int)(255 * double.Parse(ui.ColorB)); writer.WriteLine(string.Format("TextColor=\"#{0}{1}{2}\"", r.ToString("X"), g.ToString("X"), b.ToString("X"))); } } else { int a = (int)(255 * double.Parse(ui.ColorA)); int r = (int)(255 * double.Parse(ui.ColorR)); int g = (int)(255 * double.Parse(ui.ColorG)); int b = (int)(255 * double.Parse(ui.ColorB)); writer.WriteLine(string.Format("TextColor=\"#{0}{1}{2}{3}\"", a.ToString("X"), r.ToString("X"), g.ToString("X"), b.ToString("X"))); } } //} writer.WriteLine("/>"); writer.WriteLine(); } }
private void OutputUIElement(UIObject ui) { Console.WriteLine(ui); using (var writer = File.AppendText(outfile)) { writer.WriteLine(string.Format("<{0}", ui.UIElement)); if (!string.IsNullOrEmpty(ui.UIName)) { writer.WriteLine(string.Format("x:Name=\"{0}\"", ui.UIName)); } if (ui.UIElement != "imageview") { if (!string.IsNullOrEmpty(ui.Text)) { writer.WriteLine(string.Format("Text=\"{0}\"", ui.Text)); } if (!string.IsNullOrEmpty(ui.FontSize)) { writer.WriteLine(string.Format("TextSize=\"{0}\"", ui.FontSize)); } if (!string.IsNullOrEmpty(ui.FontStyle)) { writer.WriteLine(string.Format("FontFamily=\"{0}\"", ui.FontStyle)); } } else { writer.WriteLine(string.Format("Source=\"{0}\""), ui.ImageName); } writer.WriteLine(string.Format("AbsoluteLayout.LayoutBounds=\"{0},{1},{2},{3}\"", ui.UIXPos, ui.UIYPos, ui.UIWidth, ui.UIHeight)); //if (ui.UIElement != "scrollView") //{ if (!string.IsNullOrEmpty(ui.BackgroundColor)) { writer.WriteLine(string.Format("BackgroundColor=\"{0}\"", ui.BackgroundColor)); } if (!string.IsNullOrEmpty(ui.TextColor)) { writer.WriteLine(string.Format("TextColor=\"{0}\"", ui.TextColor)); } else { if (string.IsNullOrEmpty(ui.ColorA)) { if (!string.IsNullOrEmpty(ui.ColorB)) { int r = (int)(255 * double.Parse(ui.ColorR)); int g = (int)(255 * double.Parse(ui.ColorG)); int b = (int)(255 * double.Parse(ui.ColorB)); writer.WriteLine(string.Format("TextColor=\"#{0}{1}{2}\"", r.ToString("X"), g.ToString("X"), b.ToString("X"))); } } else { int a = (int)(255 * double.Parse(ui.ColorA)); int r = (int)(255 * double.Parse(ui.ColorR)); int g = (int)(255 * double.Parse(ui.ColorG)); int b = (int)(255 * double.Parse(ui.ColorB)); writer.WriteLine(string.Format("TextColor=\"#{0}{1}{2}{3}\"", a.ToString("X"), r.ToString("X"), g.ToString("X"), b.ToString("X"))); } } //} writer.WriteLine("/>"); writer.WriteLine(); } }
void ProcessNode(string node, string fullSearch) { ui = new UIObject(); var dict = ProcessMakeDict(node); var ts = fullSearch.Split('"'); try { ui.UIName = Outlets.SingleOrDefault(t => t.Value == ts[1]).Key; } catch (Exception ex) { Console.WriteLine("Cant find key for {0} : {1}-{2}", ts[1], ex.Message, ex.StackTrace); } try { var doc = XDocument.Parse(node); var docTS = doc.ToString(); Console.WriteLine("docTS = {0}\n", docTS); ui.UIElement = doc.Root.Name.LocalName; Console.WriteLine("Element = {0}", ui.UIElement); switch (ui.UIElement) { case "button": ui.UIElement = "Button"; break; case "imageView": ui.UIElement = "Image"; break; case "label": ui.UIElement = "Label"; break; case "textField": ui.UIElement = "Entry"; break; case "textView": ui.UIElement = "TextView"; break; default: ui.UIElement = string.Empty; break; } Console.WriteLine("XamForms name = {0}", ui.UIElement); if (string.IsNullOrEmpty(ui.UIElement)) { Console.WriteLine("Unknown element type"); return; } ui.UIXPos = dict.GetKeyValue("x", "0"); ui.UIYPos = dict.GetKeyValue("y", "0"); ui.UIWidth = dict.GetKeyValue("width", "0"); ui.UIHeight = dict.GetKeyValue("height", "0"); var align = dict.GetKeyValue("contentHorizontalAlignment", "Left"); ui.TextHAlign = align; align = dict.GetKeyValue("contentVerticalAlignment", "Left"); if (!string.IsNullOrEmpty(align)) ui.TextVAlign = align; ui.Opaque = doc.Root.Attribute("opaque").Value; switch (ui.UIElement) { case "Button": ProcessButton(doc); OutputUIElement(ui); ui = null; break; case "Label": ProcessLabel(doc); OutputUIElement(ui); ui = null; break; case "Image": ProcessImage(doc); OutputUIElement(ui); ui = null; break; case "Entry": ProcessEntry(doc); OutputUIElement(ui); ui = null; break; case "TextView": ProcessTextView(doc); OutputUIElement(ui); ui = null; break; } } catch (Exception e) { Console.WriteLine("Ouch! Xml not nice! - {0}::{1}", e.Message, e.InnerException); } }
void ProcessNode(string node, string fullSearch) { ui = new UIObject(); var dict = ProcessMakeDict(node); var ts = fullSearch.Split('"'); try { ui.UIName = Outlets.SingleOrDefault(t => t.Value == ts[1]).Key; } catch (Exception ex) { Console.WriteLine("Cant find key for {0} : {1}-{2}", ts[1], ex.Message, ex.StackTrace); } try { var doc = XDocument.Parse(node); var docTS = doc.ToString(); Console.WriteLine("docTS = {0}\n", docTS); ui.UIElement = doc.Root.Name.LocalName; Console.WriteLine("Element = {0}", ui.UIElement); switch (ui.UIElement) { case "button": ui.UIElement = "Button"; break; case "imageView": ui.UIElement = "Image"; break; case "label": ui.UIElement = "Label"; break; case "textField": ui.UIElement = "Entry"; break; case "textView": ui.UIElement = "TextView"; break; default: ui.UIElement = string.Empty; break; } Console.WriteLine("XamForms name = {0}", ui.UIElement); if (string.IsNullOrEmpty(ui.UIElement)) { Console.WriteLine("Unknown element type"); return; } ui.UIXPos = dict.GetKeyValue("x", "0"); ui.UIYPos = dict.GetKeyValue("y", "0"); ui.UIWidth = dict.GetKeyValue("width", "0"); ui.UIHeight = dict.GetKeyValue("height", "0"); var align = dict.GetKeyValue("contentHorizontalAlignment", "Left"); ui.TextHAlign = align; align = dict.GetKeyValue("contentVerticalAlignment", "Left"); if (!string.IsNullOrEmpty(align)) { ui.TextVAlign = align; } ui.Opaque = doc.Root.Attribute("opaque").Value; switch (ui.UIElement) { case "Button": ProcessButton(doc); OutputUIElement(ui); ui = null; break; case "Label": ProcessLabel(doc); OutputUIElement(ui); ui = null; break; case "Image": ProcessImage(doc); OutputUIElement(ui); ui = null; break; case "Entry": ProcessEntry(doc); OutputUIElement(ui); ui = null; break; case "TextView": ProcessTextView(doc); OutputUIElement(ui); ui = null; break; } } catch (Exception e) { Console.WriteLine("Ouch! Xml not nice! - {0}::{1}", e.Message, e.InnerException); } }