/// <summary>
        /// 2014 Maj> Univerzalni alat za resavanje putanje - uzima project kao source i poziva resolvePathSegment() metod - podrzava sve vrste linkova
        /// </summary>
        /// <param name="path">Univerzalni path - podrzava sve specijalne prefikse: / # . : # _ @</param>
        /// <param name="returnPropertyInfo">Da li da vrati imbPropertyInfo umesto vrednosti - vazi za> @ $ . : ,</param>
        /// <returns>Objekat koji se nalazi na putanji</returns>
        /// <remarks>
        /// <para>Upit preko stringa - bez korenskog objekta -- koristi ga debugTools i providerCase</para>
        /// </remarks>
        public static object resolvePath(this string path, pathResolveFlag flags)
        {
            // imbCoreManager.managerInstance.__myProjectObject
            object source = null;

            // prepravljeno 2014. 18. sept
            return(resolvePath(source, path, flags));
        }
        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);
        }
        /// <summary>
        /// Najčešće korišćen metod za upit nad putanjom i objektom
        /// </summary>
        /// <param name="source"></param>
        /// <param name="path"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static object resolvePath(this object source, string path, pathResolveFlag flags)
        // , Boolean returnNullIfPathEmpty = true, Boolean returnPropertyInfo = false, Boolean debugMode=false
        {
            pathResolveFlag _flags = flags;

            object obj = resolvePath(source, path, _flags);

            if (obj == null)
            {
                if (!_flags.HasFlag(pathResolveFlag.nullIsAcceptable))
                {
                    Exception ex = new ArgumentOutOfRangeException("Resource retrieved from path [" + path + "] is null ", nameof(path));
                    throw ex;
                }
            }
            else
            {
            }

            return(obj);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="path"></param>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static T resolvePath <T>(this object source, string path, pathResolveFlag flags)
            where T : imbProjectResourceBase
        {
            object obj = _resolvePath(source, path, flags);

            if (obj is T)
            {
                return(obj as T);
            }
            else if (obj == null)
            {
                Exception ex = new ArgumentOutOfRangeException("Resource retrieved from path [" + path + "] is null ", nameof(path));
                throw ex;
            }
            else
            {
                Exception ex = new ArgumentOutOfRangeException("Resource retrieved from path [" + path + "] is nor null and [" +
                                                               typeof(T).Name +
                                                               "]", nameof(path));
                throw ex;
            }
            return(obj as T);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Na osnovu dobijenog stringa pravi konstruise kolekciju
        /// </summary>
        /// <param name="__path"></param>
        public void deployPath(string __path, pathResolveFlag _flags)
        {
            Clear();
            pathResolveFlag flags = _flags;

            //if (flags == null) flags = new pathSegmentsFlags();

            path = __path;

            string workPath = __path;

            if (flags.HasFlag(pathResolveFlag.autorenameCollectionIndexer))
            {
                workPath = _select_CollectionIndexer.Replace(workPath, _replace_CollectionIndexer);
            }

            MatchCollection __segmentMatches = resourcePathResolver.regex_pathToSegments.Matches(workPath);

            if (__segmentMatches.Count == 0)
            {
                if (!path.isNullOrEmptyString())
                {
                    Add(pathSegment.create(imbProjectResourceBase.prefix_PROPERTY_PATH, workPath, Count));
                }
            }
            else
            {
                foreach (Match __smatch in __segmentMatches)
                {
                    Add(pathSegment.create(__smatch.Groups[2].Value, __smatch.Groups[1].Value, Count));
                }
            }
            if (Count > 0)
            {
                lastSegment = this.Last();
            }
        }
Exemplo n.º 6
0
        ///// <summary>
        ///// Konstruktor koji u isto vreme pravi kolekciju
        ///// </summary>
        ///// <param name="__path"></param>
        //public pathSegments(string __path)
        //{
        //    deployPath(__path);
        //}

        /// <summary>
        /// Konstruktor koji u isto vreme pravi kolekciju
        /// </summary>
        /// <param name="__path"></param>
        public pathSegments(string __path, pathResolveFlag _flagList)
        {
            deployPath(__path, _flagList);
        }
Exemplo n.º 7
0
        public pathResolverResult resolvePath(String path, pathResolveFlag flags)
        {
            pathResolverResult output = this.resolvePathSegments(path, flags);

            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);
        }
        /// <summary>
        /// 2014> resava kompleksne putanje
        /// </summary>
        /// <param name="source">Izvorni objekat. Moze biti imbTypeInfo - onda ce uvek vracati imbPropertyInfo</param>
        /// <param name="pathSegment">Putanja ili deo putanje koji treba da se resi</param>
        /// <param name="returnPropertyInfo">Vraca imbPropertyInfo umesto vrednosti - vazi za> @ $ . : , </param>
        /// <returns></returns>
        internal static object resolvePathSegment(this object source, pathSegment segment, pathResolveFlag flagList)
        {
            object output = null;

            //imbPropertyInfo iPI = null;

            //imbTypeInfo iTI = null;

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

            //if (source is Type)
            //{
            //    Type st = source as Type;

            //    source = st.getTypology();
            //}
            //if (source is imbTypeInfo)
            //{
            //    iTI = source as imbTypeInfo;
            //}
            //else if (source is imbPropertyInfo)
            //{
            //    iPI = source as imbPropertyInfo;
            //    iTI = iPI.propertyTypeInfo;
            //}
            //else
            //{
            //    iTI = source.getTypology();
            //}

            //if (iTI == null)
            //{
            //}

            //imbProjectResource resource = null;

            //if (source is imbProjectResource)
            //{
            //    resource = source as imbProjectResource;
            //}

            switch (segment.prefix)
            {
            case imbProjectResourceBase.prefix_PROPERTYINFO:
                returnPropertyInfo = true;
                break;

            case imbProjectResourceBase.prefix_PROPERTY_OF_GENERIC:
                //returnPropertyInfo = true;

                //var gen = iTI.deepGenericSubTypeSearch(true);
                //if (gen.Any())
                //{
                //    iTI = gen.First().getTypology();
                //}

                break;
            }

            if (!segment.isPrefixSupported)
            {
                throw new ArgumentOutOfRangeException("Path segment prefix not supported !!! [" + segment.prefix +
                                                      "] - returning source object");
                return(source);
            }

            switch (segment.prefix)
            {
            default:

                break;

            case imbProjectResourceBase.prefix_CHILD_PATH:
                //if (resource != null)
                //{
                //    return resource.children.First(x => x.title == segment.needle);
                //}
                //else
                //{
                //    if (source is IImbCollections)
                //    {
                //        // IImbCollections _col = source as IImbCollections;
                //        output = executeCollectionQuery(source, segment.needle);
                //    }
                //}
                break;

            case imbProjectResourceBase.prefix_TYPEBYNAME:

                //if (source == null)
                //{
                //    //output = new settingsEntriesForObject(); //imbTypology.getTypology(segment.needle);
                //}
                //else
                //{
                //    if (string.IsNullOrEmpty(segment.needle))
                //    {
                //        output = source.GetType();
                //    }
                //    else
                //    {
                //        Type t = iTI.type.GetNestedType(segment.needle);
                //        if (t != null) output = t.getTypology();
                //    }
                //}
                break;

            case imbProjectResourceBase.prefix_OPERATIONENUM:

                //#region OPERATION ENUMERATION

                //if (source == null)
                //{
                //    output = imbCoreManager.enumerations.getElementSafe(segment.needle);
                //    //   if (output != null) output = output.getTypology();
                //}
                //else
                //{
                //    if (string.IsNullOrEmpty(segment.needle))
                //    {
                //        if (source is imbEnumMemberInfo)
                //        {
                //            imbEnumMemberInfo iEM = source as imbEnumMemberInfo;
                //            iEM.executeOperation(null, null, null);
                //            output = iEM;
                //        }
                //    }
                //    else
                //    {
                //        if (source is imbTypeInfo)
                //        {
                //            if (iTI.isEnum)
                //            {
                //                imbEnumMemberInfo iEM = iTI.findEnumerationMember(segment.needle);
                //                if (iEM != null)
                //                {
                //                    iEM.executeOperation(null, null, null);
                //                }
                //                output = iEM;
                //            }
                //            else
                //            {
                //                Type t = iTI.type.GetNestedType(segment.needle);
                //                if (t != null) output = t.getTypology();
                //            }
                //        }
                //        else
                //        {
                //            imbEnumMemberInfo iEM = null;
                //            foreach (var et in iTI.operationEnumTypes)
                //            {
                //                foreach (var etm in et.enumMembers)
                //                {
                //                    if (etm.name == segment.needle)
                //                    {
                //                        iEM = etm;
                //                        break;
                //                    }
                //                }
                //                if (iEM != null)
                //                {
                //                    break;
                //                }
                //            }
                //            if (iEM != null) iEM.executeOperation(source, null, null);
                //            output = iEM;
                //        }
                //    }
                //}

                //#endregion

                break;

            case imbProjectResourceBase.prefix_COLLECTION_INDEX_ACCESS:
                output = executeCollectionQuery(source, segment.needle);
                break;

            case imbProjectResourceBase.prefix_COLLECTION_QUERY:
                output = executeCollectionQuery(source, segment.needle);
                break;

            case imbProjectResourceBase.prefix_NOPARENT_PATH:
                output = source;
                break;

            case imbProjectResourceBase.prefix_GLOBAL_RESOURCE:

                // output = globalResources.resolveGlobalResourcePath(segment.needle);
                break;

            case imbProjectResourceBase.prefix_STRING_LIST:
                // output = segment.needle.convertPresetListToTree(segment.needle, "big05b");
                break;

            case imbProjectResourceBase.prefix_LINKED_PROPERTY_PATH:
                //if (resource != null)
                //{
                //    resource.imbResourceLib.finalDeploy();
                //    iPI = iTI.linkedResource.imbFirstSafe(x => (x.propertyRealName == segment.needle));
                //    if (returnPropertyInfo)
                //    {
                //        output = iPI;
                //    }
                //    else
                //    {
                //        if (iPI != null) output = source.imbGetPropertySafe(iPI, null);
                //    }
                //}
                //else
                //{
                //    throw new aceGeneralException(
                //        "Prefix for linked property path is supported only for imbProjectResource objects! This object is: " +
                //        source.getTypeSignature());
                //}

                break;

            case imbProjectResourceBase.prefix_PROJECT_PATH:
                //  output = imbCoreManager.managerInstance.__myProjectObject;
                break;

            case imbProjectResourceBase.prefix_INTEGRATED_PATH:

                //#region INTEGRATED resource $

                //var props = iTI.getPropertyInfoByRelationTypes(resourceRelationTypes.integratedResource,
                //                                               resourceRelationTypes.integratedEntityCollection);
                //if (props.Any())
                //{
                //    iPI = props.imbFirstSafe(x => x.propertyRealName == segment.needle);

                //    if (returnPropertyInfo)
                //    {
                //        output = iPI;
                //    }
                //    else
                //    {
                //        if (iPI == null)
                //        {
                //            // nije pronadjen property -- pokusati preko object name-a
                //            var _values = source.getPropertyValues(props);
                //            foreach (var r in _values)
                //            {
                //                if (r.Value is IObjectWithName)
                //                {
                //                    IObjectWithName r_IObjectWithName = (IObjectWithName) r.Value;
                //                    if (segment.needle.compareStrings(r_IObjectWithName.name,
                //                                                      stringMatchPolicy.similar))
                //                    {
                //                        output = r_IObjectWithName;
                //                        break;
                //                    }
                //                }
                //                else if (r.Key.compareStrings(segment.needle, stringMatchPolicy.similar))
                //                {
                //                    output = r.Value;
                //                    break;
                //                }
                //            }
                //        }
                //        else
                //        {
                //            output = source.imbGetPropertySafe(iPI);
                //        }
                //    }
                //}

                //#endregion

                break;

            case imbProjectResourceBase.prefix_PROPERTYINFO:
            case imbProjectResourceBase.prefix_PROPERTY_OF_GENERIC:
            case imbProjectResourceBase.prefix_PROPERTY_PATH:
                //if (iTI != null)
                //{
                //    if (iTI.isEnum)
                //    {
                //        output = iTI.findEnumerationMember(segment.needle);
                //    }
                //    else
                //    {
                //        iPI = iTI.searchForProperty(segment.needle);
                //        if (iPI != null)
                //        {
                //            if (returnPropertyInfo)
                //            {
                //                output = iPI;
                //            }
                //            else
                //            {
                //                output = source.imbGetPropertySafe(iPI, null);
                //            }
                //        }
                //    }
                //}
                break;
            }
            return(output);
        }