/// <summary> /// Map from source ControlType to SourceType. /// </summary> internal static ContentSourceType MapControlTypeToSourceType(ControlType controlType) { ContentSourceType sourceType = ContentSourceType.None; switch (controlType) { case ControlType.RadioButton: sourceType = ContentSourceType.RadioButton; break; case ControlType.Checkbox: sourceType = ContentSourceType.Checkbox; break; case ControlType.TextEntry: sourceType = ContentSourceType.TextEntry; break; case ControlType.StaticText: sourceType = ContentSourceType.StaticText; break; case ControlType.PhotoList: sourceType = ContentSourceType.PhotoList; break; case ControlType.MultiSelect: sourceType = ContentSourceType.MultiSelect; break; case ControlType.SingleSelect: sourceType = ContentSourceType.SingleSelect; break; case ControlType.Photo: sourceType = ContentSourceType.Photo; break; case ControlType.Form: sourceType = ContentSourceType.Form; break; case ControlType.Section: sourceType = ContentSourceType.Section; break; case ControlType.CalculationList: sourceType = ContentSourceType.CalculationList; break; case ControlType.Calculation: sourceType = ContentSourceType.Calculation; break; case ControlType.CalculationVariable: sourceType = ContentSourceType.CalculationVariable; break; } return(sourceType); }
/// <exception cref="PathException"></exception> private static ContentSourceType ParseTypeName(string text, ref int pos) { ContentSourceType type = ContentSourceType.None; int start = pos; // Find the colon separator between the type name and the object id int end = start; while ((end < text.Length) && (text[end] != ':')) { ++end; } string typeName = text.Substring(start, end - start); bool ok = System.Enum.TryParse <ContentSourceType>(typeName, out type); if (!ok) { throw new PathException($"Invalid type name at position {start}."); } pos = end; return(type); }
/// <summary> /// Get all immediate children of the given parent. See /// the document file specification for the rules governing what types can /// be children of what other types. The returned list is sorted by ordinal. /// </summary> public List <Reference> GetChildren(Reference parent) { _tracer("{0}", 1, parent); List <Reference> children = new List <Reference>(); List <DocumentItem> childItems = null; try { childItems = _document.GetChildren(parent.Id); } catch (NotFoundException ex) { ex.Reference = parent.ToString(); throw; //TODO: See the comment in Path.Resolve relating to throw } foreach (DocumentItem item in childItems) { ContentSourceType sourceType = (ContentSourceType)item.ObjectType; Reference child = Reference.Create(sourceType, item.ObjectId, true); children.Add(child); } _tracer("Found {0} children:", 1, children.Count); foreach (Reference reference in children) { _tracer("{0}", 1, reference); } return(children); }
/// <summary> /// Get the immediate parent or container of the given child object. The child object /// reference must already be resolved to a concrete object reference. See /// the document file specification for the rules governing what types can /// be parents of what other types. /// </summary> public Reference GetParent(Reference child) { _tracer("{0}", 1, child); DocumentItem parentItem = null; try { // Every concrete object must have exactly one parent. The only // possible exception is the document root, and that should // never be passed in here. parentItem = _document.GetParent(child.Id); } catch (NotFoundException ex) { ex.Reference = child.ToString(); throw; //TODO: See the comment in Path.Resolve relating to throw } ContentSourceType sourceType = (ContentSourceType)parentItem.ObjectType; Reference parentRef = Reference.Create(sourceType, parentItem.ObjectId, true); _tracer("Found parent {0}", 1, parentRef); return(parentRef); }
public Path(ContentSourceType targetType, string targetId, int lineNumber, int linePosition) { _lineNumber = lineNumber; _linePosition = linePosition; string path = $"{targetType}:{targetId}"; Parse(path); }
/// <exception cref="PathException"></exception> internal static Reference Parse(string text, ref int pos) { ContentSourceType type = ParseTypeName(text, ref pos); if (text[pos] != ':') { throw new PathException($"Expected ':' at position {pos}."); } ++pos; string id = ParseObjectId(text, ref pos); return(Create(type, id, false)); }
public static Reference Create(ContentSourceType type, string id, bool resolved) { // If the type:id matches any of our const values then return // that const, otherwise return a new reference. It's because // we want to do this const-matching that we don't expose a // public constructor. if (type == ContentSourceType.None) { if (resolved && id == _empty.Id) { return(_empty); } else if (!resolved && id == _null.Id) { return(_null); } } return(new Reference(type, id, resolved)); }
public Reference(Reference other) { _type = other._type; _id = other._id; _isResolved = other._isResolved; }
private Reference(ContentSourceType type, string id, bool resolved) { _type = type; _id = id; _isResolved = resolved; }