public CustomTagTemplate(string tag, string markup, OffsetItem thisOffset, RootElementMaster master) : this(tag) { this.MyRootMaster = master; MyOffset = thisOffset; LoadTag(markup); }
/// <summary> /// Loads a new root level offset into the <c>MyOffset</c>property /// </summary> /// <param name="offset"></param> protected virtual void LoadOffset(OffsetItem offset) { if (MyOffset != offset) { MyOffset = offset; } }
/// <summary> /// Extracts the raw markup block based on the passed in OffsetItems /// </summary> /// <param name="item"></param> /// <param name="nextSibling"></param> /// <returns></returns> protected string GetRawBlock(OffsetItem item, OffsetItem nextSibling) { string rawBlock; int startIndex = item.GetAbsolutePosition(); int closeIndex = item.GetAbsoluteEndPosition(); if (item.EndPosition > 0) { closeIndex = item.GetAbsoluteEndPosition(); } else { if (nextSibling != null) { closeIndex = item.GetAbsoluteEndPosition(nextSibling.Position); } else { closeIndex = RawTag.Length - 1; } } rawBlock = RawTag.Substring(startIndex, closeIndex - startIndex); return(rawBlock); }
/// <summary> /// Assigns a default OffsetItem to MyOffset if one is not set. /// Does not overwrite an existing offset. /// </summary> protected virtual void ConfirmDefaultOffset() { if (null == MyOffset) { MyOffset = new OffsetItem(0, ControlFactory.RESERVEDKEY_LITERAL); } }
/// <summary> /// Tests to see if two OffsetItems are equal. /// Disregards ParentOffset. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (!(obj is OffsetItem)) { return(false); } OffsetItem other = (OffsetItem)obj; return(this.Position == other.Position && this.EndPosition == other.EndPosition && this.OffsetKey == other.OffsetKey); }
/// <summary> /// Creates and resolves an OSML control and adds it to the control tree. /// Override this method to allow for special logic - ex: custom tags /// </summary> /// <param name="offsetItem"></param> /// <param name="markup"></param> /// <returns></returns> protected virtual BaseGadgetControl AddResolveControlTag(OffsetItem offsetItem, string markup) { if (ControlFactory.RESERVEDKEY_CUSTOM_TAG == offsetItem.OffsetKey) { string customTagName = GetBlobTagName(markup); CustomTag tagInstance = MyCustomTagFactory.CreateTagInstance(customTagName, markup, this.MyRootMaster); return(this.AddControl(tagInstance)); } else { return(this.AddControl(MyControlFactory.CreateControl(offsetItem, markup, MyControlFactory.GetChildControlContextGroup(this.GetType(), this.MyParseContext), MyRootMaster))); } }
protected void Dispose(bool disposing) { if (disposing) { if (null != ParentOffset) { ParentOffset = null; } if (HasChildList()) { ChildOffsets.Dispose(); } } }
public RootElementMaster(string gadgetXml, OffsetItem masterOffsets, string controlFactoryKey) : this() { this.MyControlFactory = ControlFactory.GetControlFactory(controlFactoryKey); this.MyOffset = masterOffsets; //trim whitespace if (!string.IsNullOrEmpty(gadgetXml) && (gadgetXml.StartsWith(" ", StringComparison.InvariantCulture) || gadgetXml.StartsWith("\t", StringComparison.InvariantCulture) || gadgetXml.StartsWith("\r\n", StringComparison.InvariantCulture) || gadgetXml.StartsWith("\n", StringComparison.InvariantCulture))) { gadgetXml = gadgetXml.Trim(); } LoadTag(gadgetXml); }
/// <summary> /// Calculate the end position of the current tag's markup. /// This is used when the end position may not be specified. /// In that case, the next item's start position is used. /// </summary> /// <param name="offsets"></param> /// <param name="currentItem"></param> /// <returns></returns> protected int GetMarkupEndPosition(OffsetList offsets, int currentItem) { OffsetItem item = offsets[currentItem]; //assuming since this is internal we're not beyond list if (item.EndPosition > 0) { return(item.EndPosition); } else { if (currentItem + 1 >= offsets.Count) { return(0); } else { return(offsets[currentItem + 1].Position); } } }
/// <summary> /// Calculates absolute position within root parent markup of a given local index /// </summary> /// <param name="relativePosition"></param> /// <returns></returns> private int GetAbsolutePosition(int relativePosition) { int pos = relativePosition; //look upward to find local offset int breakoutMax = 1000; int loopCount = 0; int diff = 0; OffsetItem oi = this; if (null != oi.ParentOffset) { while (null != oi.ParentOffset && oi != oi.ParentOffset && ++loopCount < breakoutMax) { oi = oi.ParentOffset; diff += oi.Position; } } return(pos + diff); }
/// <summary> /// Performs a deep clone of the item. /// </summary> /// <returns></returns> public object Clone() { OffsetItem newItem = new OffsetItem(this.ToString()); return(newItem); }