IReadOnlyProperty IReadOnlyItem.Property(string name, string lang) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(name); } if (string.IsNullOrEmpty(lang)) { return(((IReadOnlyItem)this).Property(name)); } if (Exists) { var elem = _content as ILinkedElement; if (elem != null) { var prop = LinkedListOps.FindAll(elem, name) .OfType <IReadOnlyProperty>() .FirstOrDefault(p => p.Attribute("xml:lang").Value == lang); if (prop != null) { return(prop); } } var result = new Property(this, name, new Attribute("xml:lang", lang)); return(result); } return(Innovator.Client.Property.NullProp); }
/// <summary> /// Callback to be executed when the reported progress changes /// </summary> /// <param name="callback">Callback to be executed with the progress [0, 100] and the message</param> /// <returns> /// The current instance for chaining additional calls /// </returns> public IPromise <T> Progress(Action <int, string> callback) { if (_status == Status.Pending) { LinkedListOps.Add(ref _callback, new Callback(callback, Condition.Progress)); } return(this); }
IReadOnlyProperty IReadOnlyItem.Property(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(name); } if (Exists || _parent != AmlElement.NullElem) { var elem = _content as ILinkedElement; if (elem != null) { var prop = LinkedListOps.Find(elem, name) as IReadOnlyProperty; // The first one should be in the user's language if multiple languages // exist if (prop != null && prop.Attribute("xml:lang").Exists) { prop = LinkedListOps.FindAll(elem, name) .OfType <IReadOnlyProperty>() .FirstOrDefault(p => p.Attribute("xml:lang").Value == AmlContext.LocalizationContext.LanguageCode); } if (prop != null) { return(prop); } } if (name == "generation" && (_attr & ElementAttributes.ItemDefaultGeneration) > 0) { return(Client.Property.DefaultGeneration); } if (name == "is_current" && (_attr & ElementAttributes.ItemDefaultIsCurrent) > 0) { return(Client.Property.DefaultIsCurrent); } if (name == "is_released" && (_attr & ElementAttributes.ItemDefaultIsReleased) > 0) { return(Client.Property.DefaultIsReleased); } if (name == "major_rev" && (_attr & ElementAttributes.ItemDefaultMajorRev) > 0) { return(Client.Property.DefaultMajorRev); } if (name == "new_version" && (_attr & ElementAttributes.ItemDefaultNewVersion) > 0) { return(Client.Property.DefaultNewVersion); } if (name == "not_lockable" && (_attr & ElementAttributes.ItemDefaultNotLockable) > 0) { return(Client.Property.DefaultNotLockable); } return(new Property(this, name)); } return(Innovator.Client.Property.NullProp); }
internal void RemoveNode(ILinkedElement elem) { AssertModifiable(); var lastElem = _content as ILinkedElement; if (lastElem == null) { return; } _content = LinkedListOps.Remove(lastElem, elem); }
IPromise IPromise.Done(Action <object> callback) { if (_status == Status.Resolved) { callback.Invoke(_arg); } else { LinkedListOps.Add(ref _callback, new Callback(callback, Condition.Success)); } return(this); }
/// <summary> /// Callback to be executed when the promise encounters an error /// </summary> /// <param name="callback">Callback to be executed with the exception of the promise</param> /// <returns>The current instance for chaining additional calls</returns> public IPromise <T> Fail(Action <Exception> callback) { if (_status == Status.Rejected) { callback.Invoke((Exception)_arg); } else { LinkedListOps.Add(ref _callback, new Callback(callback, Condition.Failure)); } return(this); }
/// <summary> /// Callback to be executed when the promise completes regardless of whether an error occurred /// </summary> /// <param name="callback">Callback to be executed</param> /// <returns>The current instance for chaining additional calls</returns> public IPromise <T> Always(Action callback) { if (_status != Status.Pending) { callback.Invoke(); } else { LinkedListOps.Add(ref _callback, new Callback(callback, Condition.Always)); } return(this); }
internal Element ElementByName(string name) { var elem = _content as ILinkedElement; if (elem != null) { var result = (LinkedListOps.Find(elem, name) as Element); if (result != null) { return(result); } } return(Elements().OfType <Element>().FirstOrDefault(e => e.Name == name) ?? new AmlElement(this, name)); }
internal Element ElementByName(string name, string prefix = "") { if (_content is ILinkedElement elem) { var result = LinkedListOps.FindAll(elem, name) .Cast <Element>() .FirstOrDefault(e => e.Prefix == prefix); if (result != null) { return(result); } } return(Elements().OfType <Element>().FirstOrDefault(e => e.Name == name && e.Prefix == prefix) ?? new AmlElement(this, name)); }
/// <summary>Returns the set of relationships associated with this item</summary> public IRelationships Relationships() { if (Exists) { var elem = _content as ILinkedElement; if (elem != null) { var rel = LinkedListOps.FindAll(elem, "Relationships") .OfType <Relationships>() .OrderByDescending(r => r.Elements().OfType <IReadOnlyItem>().Count()) .FirstOrDefault(); if (rel != null) { return(rel); } } } return(new Relationships(this)); }
IReadOnlyProperty IReadOnlyItem.Property(string name, string lang) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(name); } if (string.IsNullOrEmpty(lang)) { return(((IReadOnlyItem)this).Property(name)); } if (Exists) { if (_content is ILinkedElement elem) { /* Current IOM functionality (This is the desired functionality): * Return the i18n element for the requested language * Do not fall back the non-i18n element * Note: An attempt was made to fall back to the non-i18n element * However this breaks when setting a corporate language (en) value when on a non-corporate connection (de). * This would result in the en value being saved as a de value */ var propsOfSameName = LinkedListOps.FindAll(elem, name) .OfType <IReadOnlyProperty>(); var prop = propsOfSameName .FirstOrDefault(p => p.Prefix == "i18n" && string.Equals(p.Attribute("xml:lang").Value, lang, StringComparison.OrdinalIgnoreCase)); if (prop != null) { return(prop); } } // Force the i18n namespace return(new Property(this, "i18n:" + name, new Attribute("xml:lang", lang))); } return(Innovator.Client.Property.NullProp); }
/// <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>()); }
IReadOnlyAttribute IReadOnlyElement.Attribute(string name) { return((LinkedListOps.Find(_lastAttr, name) as IReadOnlyAttribute) ?? new Attribute(this, name)); }
/// <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(); }
/// <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(); }
internal void RemoveAttribute(Attribute attr) { AssertModifiable(); LinkedListOps.Remove(ref _lastAttr, attr); }
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>()); }
internal void QuickAddAttribute(ILinkedAnnotation attr) { LinkedListOps.Add(ref _lastAttr, attr); }
internal void QuickAddElement(ILinkedElement elem) { _content = LinkedListOps.Add(_content as ILinkedElement, elem); }
IReadOnlyProperty IReadOnlyItem.Property(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(name); } if (Exists || _parent != AmlElement.NullElem) { if (_content is ILinkedElement elem) { /* Current IOM functionality: * Return the non-i18n element regardless of any xml:lang attribute * Desired functionality: * Return the non-i18n element regardless of any xml:lang attribute * If not found: * Return the i18n element that matches your current language */ var propsOfSameName = LinkedListOps.FindAll(elem, name) .OfType <IReadOnlyProperty>(); var prop = propsOfSameName.FirstOrDefault(p => string.IsNullOrEmpty(p.Prefix)); if (prop == null) { prop = propsOfSameName .FirstOrDefault(p => p.Prefix == "i18n" && string.Equals(p.Attribute("xml:lang").Value, AmlContext.LocalizationContext.LanguageCode, StringComparison.OrdinalIgnoreCase)); } if (prop != null) { return(prop); } } if (name == "generation" && (_attr & ElementAttributes.ItemDefaultGeneration) > 0) { return(Client.Property.DefaultGeneration); } if (name == "is_current" && (_attr & ElementAttributes.ItemDefaultIsCurrent) > 0) { return(Client.Property.DefaultIsCurrent); } if (name == "is_released" && (_attr & ElementAttributes.ItemDefaultIsReleased) > 0) { return(Client.Property.DefaultIsReleased); } if (name == "major_rev" && (_attr & ElementAttributes.ItemDefaultMajorRev) > 0) { return(Client.Property.DefaultMajorRev); } if (name == "new_version" && (_attr & ElementAttributes.ItemDefaultNewVersion) > 0) { return(Client.Property.DefaultNewVersion); } if (name == "not_lockable" && (_attr & ElementAttributes.ItemDefaultNotLockable) > 0) { return(Client.Property.DefaultNotLockable); } return(new Property(this, name)); } return(Innovator.Client.Property.NullProp); }