Пример #1
0
            public static AppPath MakePath(string path)
            {
                var words       = path.Split(_pathSeparatorChars, StringSplitOptions.RemoveEmptyEntries).ToList();
                var result      = new List <int>();
                var typeIndex   = -1;
                var actionIndex = -1;
                var isType      = false;
                var i           = 0;

                while (i < words.Count)
                {
                    var word = words[i];
                    if (isType)
                    {
                        // remove current word and insert words of type path
                        if (word != "This")
                        {
                            var ntype = Providers.Instance.StorageSchema.NodeTypes[word];
                            if (ntype == null)
                            {
                                return(null);
                            }
                            var typeNames = ntype.NodeTypePath.Split('/');
                            words.RemoveAt(i);
                            words.InsertRange(i, typeNames);
                            word        = words[i];
                            actionIndex = i + typeNames.Length;
                        }
                        else
                        {
                            actionIndex = i + 1;
                        }
                        isType = false;
                    }
                    word = word.ToLowerInvariant();
                    if (word == AppFolderName)
                    {
                        typeIndex = i;
                        isType    = true;
                        words.RemoveAt(i);
                        continue;
                    }

                    var index = PathSegments.IndexOf(word);
                    if (index < 0)
                    {
                        index = PathSegments.Count;
                        PathSegments.Add(word);
                    }
                    result.Add(index);
                    i++;
                }
                var appPath = new AppPath {
                    Indices = result.ToArray(), TypeIndex = typeIndex, ActionIndex = actionIndex
                };

                appPath.Initialize();
                return(appPath);
            }
            public static AppPath MakePath(NodeHead head, string actionName, string[] device)
            {
                var actionNameIndex = -1;
                if (actionName != null)
                {
                    actionName = actionName.ToLowerInvariant();
                    actionNameIndex = PathSegments.IndexOf(actionName);
                    if (actionNameIndex < 0)
                        return null;
                }

                var words = head.Path.Split(_pathSeparatorChars, StringSplitOptions.RemoveEmptyEntries).ToList();
                for (int i = 0; i < words.Count; i++)
                    words[i] = words[i].ToLowerInvariant();

                var result = new List<int>();
                var typeIndex = -1;
                var actionIndex = -1;
                var isTruncated = false;
                foreach (var word in words)
                {
                    var index = PathSegments.IndexOf(word);
                    if (index < 0)
                    {
                        isTruncated = true;
                        break;
                    }
                    result.Add(index);
                }
                typeIndex = result.Count;

                var ntype = ActiveSchema.NodeTypes.GetItemById(head.NodeTypeId);
                var typeNames = ntype.NodeTypePath.Split('/');
                foreach (var typeName in typeNames)
                {
                    var index = PathSegments.IndexOf(typeName.ToLowerInvariant());
                    if (index < 0)
                        break;
                    result.Add(index);
                }

                actionIndex = result.Count;
                result.Add(actionNameIndex); // can be -1
                if (device != null)
                {
                    for (int i = device.Length - 1; i >= 0; i--)
                    {
                        var index = PathSegments.IndexOf(device[i]);
                        if (index < 0)
                            break;
                        result.Add(index);
                    }
                }

                var appPath = new AppPath { Indices = result.ToArray(), TypeIndex = typeIndex, ActionIndex = actionIndex, Truncated = isTruncated };
                appPath.Initialize();
                return appPath;
            }