/// <summary> /// Detects the parent child loop reference. /// </summary> /// <param name="suspects">The suspects.</param> /// <returns></returns> public static IObjectWithPath detectParentChildLoopReference(this List <IObjectWithPath> suspects) { IObjectWithPath output = null; List <string> uidList = new List <string>(); foreach (IObjectWithPath item in suspects) { String uid = ""; if (item is IObjectWithUID) { IObjectWithUID item_IObjectWithUID = (IObjectWithUID)item; uid = item_IObjectWithUID.UID; } /// ovde prosiriti podrsku za jos neke objekte - za sada samo IObjectWithUID podrzava if (uidList.Contains(uid)) { // objekat sa istim uidom vec postoji znaci da je on uzrok problema return(item); } else { uidList.Add(uid); } } // ako je do ovde stigao znaci da nije nasao uzrok loopa return(output); }
public virtual Boolean update(IObjectWithPath target) { _target = target; if (_target == null) { newPath = ""; } newPath = _target.path; return(getPathChange(false)); }
/// <summary> /// Makes the XML output using simple methods /// </summary> /// <param name="xmlReport">The XML report.</param> /// <param name="lineprefix">The lineprefix.</param> /// <returns></returns> public StringBuilder makeXmlSimple(StringBuilder xmlReport = null, String lineprefix = "") { if (xmlReport == null) { xmlReport = new StringBuilder(); } String tng = this.nodeType().ToString(); // iTI.xmlTagNameForType; IObjectWithPath looper = detectParentChildLooper(); if (looper != null) { xmlReport.AppendLine("WARNING: Loop child inherence at: " + this.path); return(xmlReport); } String openLine = lineprefix + "<" + tng + " name=\"" + name + "\" sourcePath=\"" + sourcePath + "\" >"; xmlReport.AppendLine(openLine); foreach (imbTreeNode nd in Values) { if (nd == this) { xmlReport.AppendLine("WARNING: Loop child inherence at: " + this.path); } else { nd.makeXmlSimple(xmlReport, lineprefix + " "); } } if (!sourceContent.isNullOrEmptyString()) { var lns = sourceContent.SplitSmart(Environment.NewLine); foreach (String ln in lns) { xmlReport.AppendLine(lineprefix + ln); } xmlReport.AppendLine(); } xmlReport.AppendLine(lineprefix + "</" + tng + ">"); return(xmlReport); }
/// <summary> /// Gets all parents. Prevents loop inherence. /// </summary> /// <param name="source">The object to start from. Excluded from result</param> /// <param name="parentDepthLimit">The parent depth limit.</param> /// <returns> /// List of all parents until root object or until looped node. Order of objects in the result is from <c>source</c> to <c>root</c> /// </returns> /// <exception cref="Exception"></exception> /// <seealso cref="IObjectWithPath" /> /// <seealso cref="IObjectWithRoot" /> public static List <IObjectWithPath> getParentsViaExtension(this IObjectWithPath source, Int32 parentDepthLimit = 2000) { List <IObjectWithPath> output = new List <IObjectWithPath>(); IObjectWithPath head = source; IObjectWithPath last_head = source; Int32 c = 0; do { c++; if (c > parentDepthLimit) { IObjectWithPath looper = output.detectParentChildLoopReference(); if (looper == null) { //throw new aceGeneralException("Parent search reached limit [" + parentDepthLimit + "] for [" + source.name + "]"); } else { String msg = "Parent search reached limit[" + parentDepthLimit + "] for [" + source.name + "]"; msg = msg + "Looper found: " + looper.name; throw new ArgumentOutOfRangeException(nameof(source), msg); } break; } head = head.parent as IObjectWithPath; if (head == last_head) { // object is parent to it self head = null; } if (head != null) { if (output.Contains(head)) { head = null; } else { output.Add(head); } } last_head = head; } while (head != null); return(output); }
/// <summary> /// Gets the path from object - just casting trick /// </summary> /// <param name="head">The head.</param> /// <returns></returns> public static String getPathFromObject(this IObjectWithPath head) { IObjectWithPath p_head = head as IObjectWithPath; if (p_head != null) { return(p_head.path); } if (head is IObjectWithName) { IObjectWithName n_head = head as IObjectWithName; return(PATHGO_PARENT + n_head.name); } return(PATHSPLITER); }
/// <summary> /// Gets the universal ID name for specified element /// </summary> /// <param name="element">The element.</param> /// <param name="autoSet">if set to <c>true</c> [automatic set].</param> /// <param name="useRelatedObject">if set to <c>true</c> [use related object].</param> /// <returns></returns> internal string getUID(diagramElementBase element, bool autoSet = true, bool useRelatedObject = false) { string output = ""; if (element is diagramNode) { if (useRelatedObject) { if (element.relatedObject is IObjectWithPath) { IObjectWithPath element_relatedObject_IObjectWithPath = (IObjectWithPath)element.relatedObject; string ptname = element_relatedObject_IObjectWithPath.path.getCleanPropertyName(); output = nodes.makeUniqueDictionaryName(ptname, ref _lastNamingIteration, 10); } else if (element.relatedObject is IObjectWithName) { IObjectWithName withName = (IObjectWithName)element.relatedObject; output = nodes.makeUniqueDictionaryName(withName.name.getCleanPropertyName(), ref _lastNamingIteration, 100); } } if (output.isNullOrEmpty()) { output = ((long)nodeCount).DecimalToOrdinalLetterSystem(); } } else if (element is diagramLink) { if (useRelatedObject) { diagramLink link = element as diagramLink; if (link.isConnected) { output = link.from.name + "to" + link.to.name; } } if (output.isNullOrEmpty()) { output = ((long)linkCount).DecimalToOrdinalLetterSystem() + "_link"; } } if (autoSet) { element.name = output; } return(output); }
private static string _getPathForParent(object parent) { string line = ""; if (parent == null) { return(""); } #region PARENT PATH ------ //if (parent is imbApplicationProject) //{ // line.Append(imbProjectResourceBase.prefix_PROJECT_PATH); //} //else if (parent is IObjectWithPath) { IObjectWithPath input_parent_IObjectWithPath = (IObjectWithPath)parent; line = line.add(input_parent_IObjectWithPath.path); } else { if (parent is IObjectWithName) { IObjectWithName input_parent_IObjectWithName = (IObjectWithName)parent; line = line.add(input_parent_IObjectWithName.name); } //else if (parent.GetType() == typeof(imbTypeInfo)) //{ // imbTypeInfo parent_imbTypeInfo = (imbTypeInfo) parent; // if (parent_imbTypeInfo.isStatic) // { // line.Append("~" + parent_imbTypeInfo.type.Name); // } //} } #endregion PARENT PATH ------ return(line); }
/// <summary> /// Detects the parent child looper. /// </summary> /// <returns></returns> public imbTreeNode detectParentChildLooper() { List <IObjectWithPath> suspects = new List <IObjectWithPath>(); foreach (imbTreeNode nd in Values) { suspects.Add(nd as IObjectWithPath); } IObjectWithPath looper = suspects.detectParentChildLoopReference(); if (looper != null) { //String msg = "imbTreeNode - parent/child reference looper detected!"; //msg += "imbTreeNode.name [" + name + "] --- path [" + path + "]"; //logSystem.log(msg, logType.Warning); } return(looper as imbTreeNode); }
/// <summary> /// Gets the path string - including <c>source</c> at end of the path /// </summary> /// <param name="source">Object to get XPath for</param> /// <param name="useXPathFormat">if set to <c>true</c> if will return XPath format with / instead of backslash, otherwise it will use \\ as path separator member.</param> /// <returns> /// XPath string with the root backslash /// </returns> public static String getPathViaExtension(this IObjectWithPath source, Boolean useXPathFormat) { List <IObjectWithPath> parents = source.getParentsViaExtension(); String output = PATHGO_ROOT; if (useXPathFormat) { output = XPATHGO_ROOT; } parents.Reverse(); parents.Add(source); Int32 l = parents.Count(); for (int i = 0; i < l; i++) { if (output.isNullOrEmpty()) { output = output + parents[i].name; } else { if (useXPathFormat) { output = output + XPATHSPLITER + parents[i].name; } else { output = output + PATHSPLITER + parents[i].name; } } } return(output); }
/// <summary> /// New instance with initial target /// </summary> /// <param name="target">The target.</param> public ObjectPathChangeMonitor(IObjectWithPath target) { update(target); }
/// <summary> /// Gets a member from parent-chain: a) Nth parent according to limit. b) parent on <c>targetPath</c>, c) parent of <c>target</c> type or simply d) root if no more parents. /// </summary> /// <param name="source">The source - objects to start search from</param> /// <param name="target">The target Type - what type will triger return of current head</param> /// <param name="limit">The limit of depth. For -1: unlimited, For 1: it will return source.parent, For 0: it will return source, for 50: it will return 50th parent in parent-chain.</param> /// <param name="targetPath">Once head reach this path it will trigger return of head. Disabled if empty or null.</param> /// <returns>Parent in parent chain or root</returns> /// \ingroup_disabled ace_ext_path public static IObjectWithParent getParentOrRoot(this IObjectWithParent source, String targetPath = "", Type target = null, Int32 limit = 100) { IObjectWithParent head = source; Int32 c = 0; Boolean p_testOn = (!imbSciStringExtensions.isNullOrEmptyString(targetPath) || (source is IObjectWithPath)); Boolean t_testOn = (target != null); if (limit == -1) { limit = PATHSEARCH_MAX_LIMIT; } do { IObjectWithParent nhead = head.parent as IObjectWithParent; if (nhead == null) { return(head); } if (nhead == head) { throw new ArgumentException("IObjectWithParent.parent is the object it self! getParentOrRoot [" + c + "]"); // logSystem.log("tmp"); break; } else { head = nhead; } if (t_testOn) { if (head.GetType() == target) { return(head); } } if (p_testOn) { IObjectWithPath p_head = head as IObjectWithPath; if (p_head != null) { if (p_head.path == targetPath) { return(head); } } } c++; if ((c > limit) || (c > PATHSEARCH_MAX_LIMIT)) { return(head); // } } while (head.parent != null); return(head); }