internal static pathResolverResult resolvePathSegments(this object source, string path,
                                                               pathResolveFlag _flagList)
        {
            string _path = path;

            //  pathResolveFlags flags = _flagList;

            pathSegments pathSeg = new pathSegments(_path, _flagList);

            pathResolverResult output = resolvePathSegments(source, pathSeg, _flagList);

            return(output);
        }
Esempio n. 2
0
        /// <summary>
        /// Vraca sve segmente posle ovog
        /// </summary>
        /// <param name="seg">Segment od koga na dalje treba da se odsece deo</param>
        /// <returns></returns>
        public pathSegments getSegmentsAfterThis(pathSegment seg, bool includeThis)
        {
            pathSegments output = new pathSegments();

            if (Contains(seg))
            {
                int segId = IndexOf(seg);
                if (!includeThis)
                {
                    segId = segId + 1;
                }
                List <pathSegment> copy = GetRange(segId, Count - segId);
                copy.ForEach(x => output.Add(x));
            }
            return(output);
        }
        /// <summary>
        /// Pronalazi pod resurs na osnovu date putanje
        /// </summary>
        /// <param name="source"></param>
        /// <param name="path"></param>
        /// <param name="returnNullIfPathEmpty"></param>
        /// <returns></returns>
        private static object _resolvePath(this object source, string path, pathResolveFlag flagList)
        // , Boolean returnNullIfPathEmpty = true, Boolean returnPropertyInfo = false, Boolean debugMode=false
        {
            imbProjectResourceBase baseResource = null;

            if (!string.IsNullOrEmpty(path))
            {
                path = path.Replace("{", "<");
                path = path.Replace("}", ">");

                if (flagList.HasFlag(pathResolveFlag.removeTypeAndRelationFilters))
                {
                    pathFilterInstructions ins = new pathFilterInstructions(path);
                    path = ins.cleanPath;
                }
            }

            if (flagList.HasFlag(pathResolveFlag.startFromProjectRoot))
            {
                // source = imbCoreManager.managerInstance.__myProjectObject;
            }

            bool returnPropertyInfo = flagList.HasFlag(pathResolveFlag.returnPropertyInfo);

            if (path.isNullOrEmptyString())
            {
                if (flagList.HasFlag(pathResolveFlag.returnNullIfPathEmpty))
                {
                    return(null);
                }
                else
                {
                    return(source);
                }
            }

            object        head     = source;
            object        lastHead = source;
            object        result   = null;
            StringBuilder msg      = new StringBuilder();
            pathSegments  segments = path.toPathSegments();

            foreach (pathSegment seg in segments)
            {
                lastHead = head;
                result   = resourcePathSegmentResolver.resolvePathSegment(head, seg, flagList);

                if (result == null)
                {
                    msg.AppendLine("Last head: " + lastHead.GetType().Name + " on segment: " + seg.position);
                    head = null;
                    // if (msg == null) msg = new imbStringBuilder(0);
                    msg.AppendLine(
                        "Path segment: " + seg.description + " failed (returned [null]) on source [" +
                        source.toStringSafe() + "]");
                    break;
                }
                else if (result == head)
                {
                    // if (msg == null) msg = new imbStringBuilder(0);

                    //msg.AppendLine();
                }
                else
                {
                    if (flagList.HasFlag(pathResolveFlag.debugMode))
                    {
                        if (msg == null)
                        {
                            msg = new StringBuilder();
                        }
                        msg.AppendLine("Path segment: " + seg.description + " returned result [" + result.toStringSafe() +
                                       "] on current head [" + head.toStringSafe() + "]");
                    }
                    head = result;
                }
            }

            //if (msg !=null)
            //{
            msg.AppendLine("Resolving path [" + path + "] - segments count [" + segments.Count +
                           "] on source [" + source.toStringSafe() + "]");

            if (head == null)
            {
                msg.AppendLine("Resolving failed! result is null");
            }
            else
            {
                msg.AppendLine("Resolve result ok :: [" + head.toStringSafe() + "]");
            }

            if (flagList.HasFlag(pathResolveFlag.debugMode))
            {
                head = null;
            }
            else
            {
                //devNoteManager.noteStatic(new aceGeneralException(msg.ToString()), devNoteType.resourceRetrieval, msg.ToString());
            }
            //}

            if (!flagList.HasFlag(pathResolveFlag.nullIsAcceptable))
            {
                //if (head == null)
                //{
                //    msg.AppendPair("Query path: ", path);
                //    if (source is IObjectWithName)
                //    {
                //        IObjectWithName ion = source as IObjectWithName;
                //        msg.AppendPair("Source: ", ion.name);
                //    }
                //    else
                //    {
                //        msg.AppendPair("Source: ", source.toStringSafe());
                //    }

                //    IObjectWithName lastHeadWithName = lastHead as IObjectWithName;
                //    if (lastHeadWithName != null)
                //    {
                //        msg.AppendPair("Last head: ", lastHeadWithName.name);
                //    }
                //    else
                //    {
                //        msg.AppendPair("Last head: ", lastHead.toStringSafe());
                //    }

                //    if (!flagList.Contains(pathResolveFlag.disableDoomyObject))
                //    {
                //        var dbg = new debugDoomyObject();
                //        //msg.AppendLine("Path: " + path);

                //        dbg.data = new object[] {segments, head, lastHead, source, flagList};

                //        dbg.report = msg.ToString();

                //        head = dbg;
                //    }

                //  //  devNoteManager.note(source, msg.ToString(), "resourcePathResolver.resolvePath()");
                //}
            }

            return(head);
        }
        /// <summary>
        /// Izvrsava kolekciju path segmenata nad prosledjenim objektom
        /// </summary>
        /// <param name="source"></param>
        /// <param name="segments"></param>
        /// <param name="_flagList"></param>
        /// <returns></returns>
        internal static pathResolverResult resolvePathSegments(this object source, pathSegments segments,
                                                               pathResolveFlag _flagList)
        {
            pathResolveFlag flags = _flagList;

            pathResolverResult output = new pathResolverResult();

            output.parent = source as IObjectWithPath;

            output.segments = segments;
            output.path     = segments.path;

            object result     = source;
            object lastResult = source;

            output.missing = new pathSegments();

            pathSegment ps = segments.First();
            int         i  = 0;

            do
            {
                ps     = segments[i];
                result = result.resolvePathSegment(ps, flags);
                if (result == null)
                {
                    output.missing = segments.getSegmentsAfterThis(ps, true);
                    break;
                }
                else
                {
                    lastResult = result;
                }
                i++;
            } while (i < segments.Count);

            if (lastResult != null)
            {
                output.nodeFound.Add(lastResult);
            }

            //foreach (pathSegment ps in segments)
            //{
            //    if (result != null)
            //    {
            //        lastResult = result;

            //    } else
            //    {
            //        output.missing = segments.getSegmentsAfterThis(ps, true);

            //        break;
            //    }
            //}*/
            //if (result != null)
            //{
            //} else if (lastResult != null)
            //{
            //    output.nodeFound.Add(lastResult);
            //}
            return(output);
        }