private XElement ResolveRenderComponent(string path, XElement current, IScope scope) { var uri = new Uri(path); var name = (uri.Host + "." + uri.AbsolutePath).Replace("/", ".").Replace("..", "."); if (name.EndsWith(".")) { name = name.Substring(0, name.Length - 1); } IXmlComponent component = null; if (ComponentCache.ContainsKey(name)) { component = ComponentCache[name]; } else { if (null == Container) { throw new Exception("components can be used only with Container setup " + path); } component = Container.Get <IXmlComponent>(name); } var componentResult = component.Create(path, current, scope); return(componentResult); }
static Control AddControlToLayout(String name, IXmlComponent com, XmlDocument xDoc, XmlNode comNode, Panel targetPanel, Dictionary <String, IXmlComponent> IdList, String Namespace = null) { Control control = com as Control; com.LoadXml(xDoc, comNode); //String name = name;// XmlGetter.Attribute(comNode, "Name"); if (name.Length == 0) { name = (comNode.Name); } string newName = name; int count = 0; while (IdList.Keys.Contains(newName)) { newName = name + count; count++; } if (Namespace != null && Namespace.Length > 0) { newName = Namespace + GlobalVars.Seperator + newName; } IdList.Add(newName, com); control.Name = newName; targetPanel.Controls.Add(control); return(control); }
/// <summary> /// Serializes the IXmlComponent object to the dependency dependency file. /// </summary> /// <param name="component">The component.</param> /// <param name="path">The path.</param> internal void StoreDependencyFile(IXmlComponent component, string path) { if (null == component) { throw new ArgumentNullException("component"); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } Logger.Instance().Log(TraceLevel.Info, string.Format("Writing dependency definition file {0} ...", path)); var serializer = CreateDependencyXmlSerializer(); if (File.Exists(path)) { // make sure we write a fresh file to prevent partial writes/remaining fragments from previous versions File.Delete(path); } using (var sw = File.OpenWrite(path)) { serializer.Serialize(sw, component); } Logger.Instance().Log(TraceLevel.Info, string.Format("Writing information to dependency definition file finished successfully")); }
/// <summary> /// Constructor checks argument and saves xml component. /// </summary> /// <param name="xmlComponent">Xml component</param> public XmlComponentViewModel(IXmlComponent xmlComponent) { if (xmlComponent == null) { throw new ArgumentNullException("xmlComponent"); } _xmlComponent = xmlComponent; }
public static IXmlComponent GetComponentByName(String name, IXmlComponent baseComponent) { String baseComName = (baseComponent as Control).Name; baseComName = baseComName.Replace("\\", "/"); string ns = baseComName.Substring(0, baseComName.LastIndexOf("/")); return(GetComponentByName(name, ns)); }
public void StoreXmlComponent(IXmlComponent component, string path, ILogger log) { if (String.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } var parser = new ParserXml(); parser.StoreDependencyFile(component, path); }
public override bool GetCondition() { if (_values.Count == 0) { return(true); } if (_values.Count < 2) { throw new Exception(((XmlConditionTypes)_conditionType).ToString() + " 요소에는 반드시 Value 요소가 2개이상 들어가야 합니다."); } IXmlComponent loadingComponent = XmlComponent.NowLoading; for (int i = 1; i < _values.Count; i++) { String value1 = (_values[i].IsVariable) ? GetValue(_values[i].Value).ToString() : _values[i].Value; String value2 = (_values[i - 1].IsVariable) ? GetValue(_values[i - 1].Value).ToString() : _values[i - 1].Value; value1 = (_values[i].IsComponent) ? GetComponentValue(_values[i].Value) : _values[i].Value; value2 = (_values[i - 1].IsComponent) ? GetComponentValue(_values[i - 1].Value) : _values[i - 1].Value; String value1Type = _values[i].TypeName; String value2Type = _values[i - 1].TypeName; switch (_conditionType) { case XmlConditionTypes.Equal: if (value1.Trim().Equals(value2.Trim("\t \n\r".ToCharArray())) == false) { return(false); } break; case XmlConditionTypes.More: if (DataComparer.Minus(value1Type, value1, value2Type, value2) <= 0) { return(false); } break; case XmlConditionTypes.MoreOrEqual: if (DataComparer.Minus(value1Type, value1, value2Type, value2) < 0) { return(false); } break; default: break; } } return(true); }
public void SaveXmlComponent(IXmlComponent component, TargetsFileData targetsFileData) { if (DependencyService == null) { return; } if (Logger == null) { return; } DependencyService.StoreXmlComponent(component, targetsFileData.LocalPath, Logger); }
public override void OnImportsSatisfied() { // create the component view model try { _xmlComponent = XmlComponentRepository.GetXmlComponent(TargetsFileData); if (_xmlComponent == null) { var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0}!", TargetsFileData.LocalPath))); EventPublisher.Publish(initErrorEvent); } } catch (XmlException xe) { var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0} (Error while parsing XML: {1})!", TargetsFileData.LocalPath, xe.Message))); EventPublisher.Publish(initErrorEvent); } catch (DependencyServiceException dse) { var initErrorEvent = new InitializationErrorEvent(new Exception(String.Format("Error while loading local file {0} ({1})!", TargetsFileData.LocalPath, dse.Message))); EventPublisher.Publish(initErrorEvent); } _xmlComponentViewModel = new XmlComponentViewModel(_xmlComponent); // initialize the list of available Xml dependencies in the current targets file var dependencies = _xmlComponentViewModel.GetDependencies(); foreach (var xmlDependencyViewModel in dependencies) { XmlDependencies.Add(xmlDependencyViewModel); } // add special view model for creation var createXmlDependencyViewModel = new CreateXmlDependencyViewModel(); createXmlDependencyViewModel.XmlDependencyCreationRequest += CreateXmlDependencyViewModel_XmlDependencyCreationRequest; XmlDependencies.Add(createXmlDependencyViewModel); // hook events ChangeTrackingService.HasChangesChanged += ChangeTrackingService_HasChangesChanged; var saveAllChangesEvent = EventPublisher.GetEvent <SaveAllChangesEvent>(); saveAllChangesEvent.Subscribe(o => Save(o.FileName)); }
public XmlNode GetXml(XmlDocument xDoc, XmlNode parent = null) { XmlNode xLayout = XmlAdder.Element(xDoc, "Tab", parent); if (_layoutPanel is FlowLayoutPanel) { XmlNode flow = XmlAdder.Element(xDoc, "Flow", xLayout); for (int i = 0; i < _layoutPanel.Controls.Count; i++) { XmlNode com = XmlAdder.Element(xDoc, "Component", flow); Control control = _layoutPanel.Controls[i]; XmlAdder.Attribute(xDoc, "Width", control.Width.ToString(), com); XmlAdder.Attribute(xDoc, "Height", control.Height.ToString(), com); IXmlComponent xRealCom = control as IXmlComponent; if (xRealCom != null) { xRealCom.GetXml(xDoc, com); } } } else //Panel { XmlNode panel = XmlAdder.Element(xDoc, "Panel", xLayout); for (int i = 0; i < _layoutPanel.Controls.Count; i++) { XmlNode com = XmlAdder.Element(xDoc, "Component", panel); Control control = _layoutPanel.Controls[i]; XmlAdder.Attribute(xDoc, "Width", control.Width.ToString(), com); XmlAdder.Attribute(xDoc, "Height", control.Height.ToString(), com); XmlAdder.Attribute(xDoc, "X", control.Location.X.ToString(), com); XmlAdder.Attribute(xDoc, "Y", control.Location.Y.ToString(), com); IXmlComponent xRealCom = control as IXmlComponent; if (xRealCom != null) { xRealCom.GetXml(xDoc, com); } } } return(xLayout); }
public virtual void LoadXml(XmlDocument xDoc, XmlNode rootNode, Boolean refLoad = false) { if (rootNode == null) { return; } _xDoc = xDoc; XmlControlHandler.GetDefaultXmlItemAttributes(rootNode, xDoc, this); _sendingParser = XmlGetter.Attribute(rootNode, "SendingParser"); _args = ValueParser.getArgs(XmlGetter.Attribute(rootNode, "Args")); _format = new XmlMatchFormat(); //초기값. foreach (XmlNode child in rootNode.ChildNodes) { if (child.Name.Equals("Format")) { XmlNode xFormat = child; _format = new XmlMatchFormat(); if (xFormat != null) { _format.LoadXml(xDoc, xFormat, refLoad); } } else { String comName = child.Name; string recentName = null; if (_recentTarget.ContainsKey(comName)) { recentName = _recentTarget[comName]; } if (comName.Equals("ScenarioTable")) { String targetName = XmlGetter.Attribute(child, "TargetName"); if (targetName.Length == 0) { if (recentName != null) { targetName = recentName; } else { throw new Exception("ScenarioTable 을 위한 TargetName이 정의되지 않았습니다."); } } IXmlComponent com = XmlControlHandler.GetComponentByName(targetName); //같은 타입에서는 여러번 TargetName을 쓰지 않아도 인식하도록.. if (com != null) { XmlScenarioTable table = com as XmlScenarioTable; if (table != null) { if (targetName.Length > 0) { _recentTarget[comName] = targetName;//모든 속성이 맞으면 등록.. } XmlTableMatchInfo info = new XmlTableMatchInfo(targetName, table); info.LoadXml(xDoc, child); _matchInfoItems.Add(info); _targetComponents.Add(com); String column = XmlGetter.Attribute(child, "ColumnName"); if (column.Length > 0) { if (table.ColumnNames.Contains(column)) { table.Columns(column).RelativeObject["XmlMatchData"] = XmlMatchData.NowLoading; } else { throw new Exception("XmlMatchComponent: Table[" + table.Name + "]에 Column[" + column + "] 이 없습니다."); } } } else { throw new Exception("targetName [" + targetName + "]은 ScenarioTable 이 아닙니다."); } } else { throw new Exception("TargetName [" + targetName + "] 은 배치되지 않았습니다."); } } } } }
public XmlTableMatchInfo(String targetName, IXmlComponent component) { _targetName = targetName; _component = component; }
public void LoadXml(XmlDocument xDoc, XmlNode rootNode, bool refLoad = false) { if (rootNode == null) { return; } string refPath = XmlGetter.Attribute(rootNode, "Ref"); bool refExist = refPath.Length > 0; XmlNode comNode; if (refExist) { if (XmlLayoutCollection.NowLoadingPath.Length > 0) { refPath = XmlLayoutCollection.NowLoadingPath + XmlLayoutCollection.PathSeperator + refPath; } comNode = XmlGetter.RootNode(out _xDoc, refPath, null, XmlSchemaValidation); _filePath = refPath; } else { if (rootNode.ChildNodes.Count == 0) { throw new Exception("Component 태그의 정의가 완전하지 않습니다. Ref로 xml파일을 불러오거나 직접 내부에 정의해야 합니다.\r\n name:" + XmlGetter.Attribute(rootNode, "Name")); } comNode = rootNode.ChildNodes[0]; } string nameText; nameText = XmlGetter.Attribute(rootNode, "Name"); XmlControlHandler.LoadInterface(this, rootNode, xDoc); Control control = XmlControlHandler.AddControl(nameText, xDoc, comNode, _panel, _idList, _namespace);; _realComponent = control; NowLoading = control as IXmlComponent; //if (txt.Length > 0) control.Name = txt; if (XmlGetter.Attribute(rootNode, "Margin").Length > 0) { control.Margin = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Margin")); } if (XmlGetter.Attribute(rootNode, "Padding").Length > 0) { control.Padding = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Padding")); } if (XmlGetter.Attribute(rootNode, "Enabled").Length > 0) { control.Enabled = (XmlGetter.Attribute(rootNode, "Enabled").Equals("false") == false); } String hgt = XmlGetter.Attribute(rootNode, "Height"); if (hgt.Length != 0) { control.Height = int.Parse(hgt); } String wid = XmlGetter.Attribute(rootNode, "Width"); if (wid.Length != 0) { control.Width = int.Parse(wid); } if (_panel is FlowLayoutPanel) { } else if (_panel is Panel) { String x = XmlGetter.Attribute(rootNode, "X"); Point location = new Point(); if (x.Length != 0) { location.X = int.Parse(x); } String y = XmlGetter.Attribute(rootNode, "Y"); if (y.Length != 0) { location.Y = int.Parse(y); } control.Location = location; } }
public XmlNode GetXml(XmlDocument xDoc, XmlNode parent = null) { XmlNode xLayout = XmlAdder.Element(xDoc, "Layout", parent); XmlAdder.Attribute(xDoc, "Dock", this.Dock.ToString(), xLayout); switch (this.Dock) { case DockStyle.Fill: break; case DockStyle.Left: case DockStyle.Right: XmlAdder.Attribute(xDoc, "Width", this.Width.ToString(), xLayout); break; case DockStyle.Top: case DockStyle.Bottom: XmlAdder.Attribute(xDoc, "Height", this.Height.ToString(), xLayout); break; case DockStyle.None: XmlAdder.Attribute(xDoc, "Width", this.Width.ToString(), xLayout); XmlAdder.Attribute(xDoc, "Height", this.Height.ToString(), xLayout); XmlAdder.Attribute(xDoc, "X", this.Location.X.ToString(), xLayout); XmlAdder.Attribute(xDoc, "Y", this.Location.Y.ToString(), xLayout); break; } if (this.BackgroundImage != null) { XmlAdder.Attribute(xDoc, "Background-Image", _backgroundImage_Path, xLayout); } if (this.BackColor.Equals(Color.Transparent) == false) { XmlAdder.Attribute(xDoc, "Background-Color", this.BackColor.ToString(), xLayout); } if (_layoutPanel is FlowLayoutPanel) { XmlNode flow = XmlAdder.Element(xDoc, "Flow", xLayout); for (int i = 0; i < _layoutPanel.Controls.Count; i++) { //XmlComponent xCom = new XmlComponent(_layoutPanel, _idList, _namespace); XmlNode com = XmlAdder.Element(xDoc, "Component", flow); Control control = _layoutPanel.Controls[i]; XmlAdder.Attribute(xDoc, "Width", control.Width.ToString(), com); XmlAdder.Attribute(xDoc, "Height", control.Height.ToString(), com); XmlAdder.Attribute(xDoc, "Name", control.Name, com); XmlAdder.Attribute(xDoc, "Name", control.Name, com); IXmlComponent xRealCom = control as IXmlComponent; if (xRealCom != null) { xRealCom.GetXml(xDoc, com); } } } else //Panel { XmlNode panel = XmlAdder.Element(xDoc, "Panel", xLayout); for (int i = 0; i < _layoutPanel.Controls.Count; i++) { XmlNode com = XmlAdder.Element(xDoc, "Component", panel); Control control = _layoutPanel.Controls[i]; XmlAdder.Attribute(xDoc, "Width", control.Width.ToString(), com); XmlAdder.Attribute(xDoc, "Height", control.Height.ToString(), com); XmlAdder.Attribute(xDoc, "X", control.Location.X.ToString(), com); XmlAdder.Attribute(xDoc, "Y", control.Location.Y.ToString(), com); IXmlComponent xRealCom = control as IXmlComponent; if (xRealCom != null) { xRealCom.GetXml(xDoc, com); } } } return(xLayout); }
public static Control AddControl(string name, XmlDocument xDoc, XmlNode comNode, Panel targetPanel, Dictionary <String, IXmlComponent> idList, String Namespace = null) { Control control = null; String controlName = comNode.Name; switch (comNode.Name) { case "Label": control = AddControlToLayout(name, new XmlLabel(), xDoc, comNode, targetPanel, idList, Namespace); break; case "TextBox": control = AddControlToLayout(name, new XmlTextBox(), xDoc, comNode, targetPanel, idList, Namespace); break; case "Button": control = AddControlToLayout(name, new XmlButton(), xDoc, comNode, targetPanel, idList, Namespace); break; case "ImageButton": control = AddControlToLayout(name, new XmlImageButton(), xDoc, comNode, targetPanel, idList, Namespace); break; case "Led": control = AddControlToLayout(name, new XmlImageLed(), xDoc, comNode, targetPanel, idList, Namespace); break; case "TextArea": control = AddControlToLayout(name, new XmlTextArea(), xDoc, comNode, targetPanel, idList, Namespace); break; case "Layout": control = AddControlToLayout(name, new XmlLayout(idList, Namespace), xDoc, comNode, targetPanel, idList, Namespace); break; case "TabControl": control = AddControlToLayout(name, new XmlTabControl(idList, Namespace), xDoc, comNode, targetPanel, idList, Namespace); break; case "CustomControl": if (GetCustomXmlComponent != null) { controlName = XmlGetter.Attribute(comNode, "ControlName"); if (controlName.Length == 0) { controlName = name; } IXmlComponent compon = GetCustomXmlComponent(controlName, Namespace, idList); if (compon != null) { control = AddControlToLayout(name, compon, xDoc, comNode, targetPanel, idList, Namespace); } } break; default: if (GetCustomXmlComponent != null) { IXmlComponent compon = GetCustomXmlComponent(comNode.Name, Namespace, idList); if (compon != null) { control = AddControlToLayout(name, compon, xDoc, comNode, targetPanel, idList, Namespace); } } break; } if (control == null) { throw new Exception(controlName + "은 유효한 컴포넌트명이 아닙니다. Namespace:" + Namespace); } return(control); }
public static void GetTextAttributes(XmlNode rootNode, IXmlComponent xmlComponent) { Button b = new Button(); }
public static void GetDefaultControlAttributes( XmlNode rootNode, XmlDocument document, IXmlComponent xmlComponent, bool refLoad = false, XmlItemInterface.GetRealTimeArgsFunc argFunc = null, XmlItemInterface.GetComponentValueFunc comValueFunc = null) { xmlComponent.Interface = new XmlItemInterface(rootNode, document, xmlComponent); xmlComponent.Interface.GetRealTimeArgCallback = argFunc; xmlComponent.Interface.GetComponentValueFuncCallBack = comValueFunc; if (refLoad == false) { String refPath = XmlGetter.Attribute(rootNode, "Ref"); if (refPath.Length > 0) { xmlComponent.LoadXml(refPath, true); } } Control targetControl = xmlComponent as Control; if (XmlGetter.Attribute(rootNode, "Margin").Length > 0) { targetControl.Margin = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Margin")); } if (XmlGetter.Attribute(rootNode, "Padding").Length > 0) { targetControl.Padding = ValueParser.Padding(XmlGetter.Attribute(rootNode, "Padding")); } if (XmlGetter.Attribute(rootNode, "Enabled").Length > 0) { targetControl.Enabled = (XmlGetter.Attribute(rootNode, "Enabled").Equals("false") == false); } DockStyle dock = ValueParser.GetDockStyle(XmlGetter.Attribute(rootNode, "Dock")); switch (dock) { case DockStyle.Bottom: case DockStyle.Top: { String hgt = XmlGetter.Attribute(rootNode, "Height"); if (hgt.Length != 0) { targetControl.Height = int.Parse(hgt); } break; } case DockStyle.Left: case DockStyle.Right: { String wid = XmlGetter.Attribute(rootNode, "Width"); if (wid.Length != 0) { targetControl.Width = int.Parse(wid); } break; } case DockStyle.Fill: //필요없음.. break; case DockStyle.None: { String hgt = XmlGetter.Attribute(rootNode, "Height"); if (hgt.Length != 0) { targetControl.Height = int.Parse(hgt); } String wid = XmlGetter.Attribute(rootNode, "Width"); if (wid.Length != 0) { targetControl.Width = int.Parse(wid); } String x = XmlGetter.Attribute(rootNode, "X"); Point location = new Point(); if (x.Length != 0) { location.X = int.Parse(x); } String y = XmlGetter.Attribute(rootNode, "Y"); if (y.Length != 0) { location.Y = int.Parse(y); } targetControl.Location = location; break; } } targetControl.Dock = dock; //이 control이 붙을 parent에 docking하는 모드임.. if (dock != DockStyle.Fill) { targetControl.Anchor = ValueParser.GetAnchorStyles(XmlGetter.Attribute(rootNode, "Anchor")); } string txt; txt = XmlGetter.Attribute(rootNode, "Name"); if (txt.Length > 0) { targetControl.Name = txt; } txt = XmlGetter.Attribute(rootNode, "Text"); // attr.Value; if (txt.Length > 0) { targetControl.Text = txt; } string color = XmlGetter.Attribute(rootNode, "TextColor"); if (color.Length > 0) { targetControl.ForeColor = ValueParser.StringToColor(color); } color = XmlGetter.Attribute(rootNode, "BackColor"); if (color.Length == 0) { color = XmlGetter.Attribute(rootNode, "Background-Color"); } try { if (color.Length > 0) { targetControl.BackColor = ValueParser.StringToColor(color); } } catch (Exception e) { if (color.Length > 0) { if (color.Equals("Transparent")) { if (targetControl.Parent != null) { targetControl.BackColor = targetControl.Parent.BackColor; } else { targetControl.BackColor = Color.FromKnownColor(KnownColor.Control); } } else { throw new Exception("XmlControlHandler: 색 변환 중 에러.. color:" + color + "\r\n" + e.Message); } } } LoadInterface(xmlComponent, rootNode, document); }
public IXmlMatchInfoBase(String targetName, IXmlComponent component) { _targetName = targetName; _component = component; }
public static void RegisterEvent(IXmlComponent obj) { Control control = obj as Control; }