Пример #1
0
        public static IWoopsaElement ByNameOrNull(this IWoopsaContainer woopsaContainer, string name)
        {
            IWoopsaElement result;

            // For performance optimization, use directly the methods of classes WoopsaObject and WoopsaContainer
            // Complexity : O(1)
            if (woopsaContainer is WoopsaObject)
            {
                WoopsaObject woopsaObject = (WoopsaObject)woopsaContainer;
                result = woopsaObject.ByNameOrNull(name);
            }
            else if (woopsaContainer is WoopsaContainer)
            {
                WoopsaContainer container = (WoopsaContainer)woopsaContainer;
                result = container.ByNameOrNull(name);
            }
            else
            {
                // The code below can manage all the cases, but is used only for elements not
                // of type WoopsaContainer or WoopsaObject
                // Complexity : O(n)
                result = woopsaContainer.Items.ByNameOrNull(name);
                if (result == null && woopsaContainer is IWoopsaObject)
                {
                    IWoopsaObject woopsaObject = (IWoopsaObject)woopsaContainer;
                    result = woopsaObject.Properties.ByNameOrNull(name);
                    if (result == null)
                    {
                        woopsaObject.Methods.ByNameOrNull(name);
                    }
                }
            }
            return(result);
        }
Пример #2
0
        private bool FindWoopsaClientAlongPath(WoopsaContainer root, string path,
                                               out WoopsaBaseClientObject client, out string relativePath)
        {
            OnBeforeWoopsaModelAccess();
            try
            {
                string[]        pathParts = path.Split(WoopsaConst.WoopsaPathSeparator);
                WoopsaContainer container = root;
                bool            found     = false;

                client       = null;
                relativePath = string.Empty;
                for (int i = 0; i < pathParts.Length; i++)
                {
                    if (container is WoopsaBaseClientObject)
                    {
                        client = (WoopsaBaseClientObject)container;
                        for (int j = i; j < pathParts.Length; j++)
                        {
                            relativePath += WoopsaConst.WoopsaPathSeparator + pathParts[j];
                        }
                        found = true;
                        break;
                    }
                    else if (container == null)
                    {
                        break;
                    }
                    else if (!string.IsNullOrEmpty(pathParts[i]))
                    {
                        container = container.ByNameOrNull(pathParts[i]) as WoopsaContainer;
                    }
                }
                return(found);
            }
            finally
            {
                OnAfterWoopsaModelAccess();
            }
        }