/// <summary> /// Execute the stored callbacks for the given condition /// </summary> /// <param name="condition">Which call backs to execute</param> /// <param name="arg">First argument for the callback</param> /// <param name="arg2">Second argument for the callback (if applicable)</param> protected void ExecuteCallbacks(Condition condition, object arg, object arg2 = null) { foreach (var current in LinkedListOps.Enumerate(_callback)) { if ((current.Condition & condition) == condition) { switch (current.Condition) { case Condition.Always: this.Invoker(current.Delegate, null); break; case Condition.Failure: case Condition.Success: this.Invoker(current.Delegate, new object[] { arg }); break; case Condition.Progress: this.Invoker(current.Delegate, new object[] { arg, arg2 }); break; } } } }
IEnumerable <IReadOnlyAttribute> IReadOnlyElement.Attributes() { return(LinkedListOps.Enumerate(_lastAttr).OfType <IReadOnlyAttribute>()); }
/// <summary> /// Write the node to the specified <see cref="XmlWriter"/> /// </summary> /// <param name="writer"><see cref="XmlWriter"/> to write the node to</param> /// <param name="settings">Settings controlling how the node is written</param> public void ToAml(XmlWriter writer, AmlWriterSettings settings) { var name = this.Name; var i = name.IndexOf(':'); var attrs = LinkedListOps.Enumerate(_lastAttr).OfType <IReadOnlyAttribute>().ToArray(); if (attrs.Any(a => a.Name == "xml:lang" && a.Value != AmlContext.LocalizationContext.LanguageCode)) { writer.WriteStartElement("i18n", name, "http://www.aras.com/I18N"); } else if (i > 0) { var prefix = name.Substring(0, i); name = name.Substring(i + 1); var ns = ""; switch (prefix) { case "SOAP-ENV": ns = "http://schemas.xmlsoap.org/soap/envelope/"; break; case "af": ns = "http://www.aras.com/InnovatorFault"; break; default: throw new NotSupportedException(); } writer.WriteStartElement(prefix, name, ns); } else { writer.WriteStartElement(name); } foreach (var attr in attrs) { i = attr.Name.IndexOf(':'); if (i > 0) { var prefix = attr.Name.Substring(0, i); if (prefix == "xmlns") { continue; } name = attr.Name.Substring(i + 1); var ns = ""; switch (prefix) { case "xml": ns = "http://www.w3.org/XML/1998/namespace"; break; default: throw new NotSupportedException(); } writer.WriteAttributeString(prefix, name, ns, attr.Value); } else { writer.WriteAttributeString(attr.Name, attr.Value); } } var elem = _content as ILinkedElement; if (elem == null) { if (PreferCData) { writer.WriteCData(this.Value); } else { writer.WriteString(this.Value); } } else { var elems = Elements().ToArray(); var item = elems.OfType <IReadOnlyItem>().FirstOrDefault(); if (this is IReadOnlyProperty && !settings.ExpandPropertyItems && item != null && !item.Attribute("action").Exists) { writer.WriteAttributeString("type", item.TypeName()); var keyedName = item.KeyedName().Value ?? item.Property("id").KeyedName().Value; if (!string.IsNullOrEmpty(keyedName)) { writer.WriteAttributeString("keyed_name", keyedName); } writer.WriteString(item.Id()); } else { foreach (var e in elems) { e.ToAml(writer, settings); } } } writer.WriteEndElement(); }
protected virtual IEnumerable <IReadOnlyElement> ReadOnlyElements() { return(LinkedListOps.Enumerate(_content as ILinkedElement).OfType <IReadOnlyElement>()); }
/// <summary>Retrieve all attributes specified for the element</summary> public IEnumerable <IAttribute> Attributes() { return(LinkedListOps.Enumerate(_lastAttr).OfType <IAttribute>()); }
/// <summary> /// Write the node to the specified <see cref="XmlWriter"/> /// </summary> /// <param name="writer"><see cref="XmlWriter"/> to write the node to</param> /// <param name="settings">Settings controlling how the node is written</param> public void ToAml(XmlWriter writer, AmlWriterSettings settings) { var name = Name; var prefix = Prefix; var i = name.IndexOf(':'); var attrs = LinkedListOps.Enumerate(_lastAttr).OfType <IReadOnlyAttribute>().ToArray(); if (string.IsNullOrEmpty(prefix) && i > 0) { prefix = name.Substring(0, i); name = name.Substring(i + 1); } if (string.IsNullOrEmpty(prefix)) { writer.WriteStartElement(name); } else { var ns = AmlReader.NamespaceFromPrefix(prefix); writer.WriteStartElement(prefix, name, ns); } foreach (var attr in attrs) { i = attr.Name.IndexOf(':'); if (i > 0) { var attributePrefix = attr.Name.Substring(0, i); if (attributePrefix == "xmlns") { continue; } name = attr.Name.Substring(i + 1); var ns = AmlReader.NamespaceFromPrefix(attributePrefix); writer.WriteAttributeString(attributePrefix, name, ns, attr.Value); } else { writer.WriteAttributeString(attr.Name, attr.Value); } } if (!(_content is ILinkedElement)) { if (PreferCData) { writer.WriteCData(this.Value); } else { writer.WriteString(this.Value); } } else { var elems = Elements().ToArray(); var item = elems.OfType <IReadOnlyItem>().FirstOrDefault(); if (this is IReadOnlyProperty && !settings.ExpandPropertyItems && item?.Attribute("action").Exists == false) { writer.WriteAttributeString("type", item.TypeName()); var keyedName = item.KeyedName().Value ?? item.Property("id").KeyedName().Value; if (!string.IsNullOrEmpty(keyedName)) { writer.WriteAttributeString("keyed_name", keyedName); } writer.WriteString(item.Id()); } else { foreach (var e in elems) { e.ToAml(writer, settings); } } } writer.WriteEndElement(); }