A class that stores a relative path string
Inheritance: IFormattable
示例#1
0
        /// <summary>
        /// Parses a string representing a relative path.
        /// </summary>
        /// <remarks>
        /// Parses a string representing a relative path.
        /// </remarks>
        /// <exception cref="ServiceResultException">Thrown if any errors occur during parsing</exception>
        public static RelativePathFormatter Parse(string textToParse)
        {
            if (String.IsNullOrEmpty(textToParse))
            {
                return(new RelativePathFormatter());
            }

            RelativePathFormatter path = new RelativePathFormatter();

            try
            {
                StringReader reader = new StringReader(textToParse);

                while (reader.Peek() != -1)
                {
                    Element element = Element.Parse(reader);
                    path.m_elements.Add(element);
                }
            }
            catch (Exception e)
            {
                throw new ServiceResultException(
                          StatusCodes.BadIndexRangeInvalid,
                          Utils.Format("Cannot parse relative path: '{0}'.", textToParse),
                          e);
            }

            return(path);
        }
示例#2
0
        /// <summary>
        /// Parses a relative path formatted as a string.
        /// </summary>
        public static RelativePath Parse(string browsePath, ITypeTable typeTree)
        {
            if (typeTree == null)
            {
                throw new ArgumentNullException("typeTree");
            }

            // parse the string.
            RelativePathFormatter formatter = RelativePathFormatter.Parse(browsePath);

            // convert the browse names to node ids.
            RelativePath relativePath = new RelativePath();

            foreach (RelativePathFormatter.Element element in formatter.Elements)
            {
                RelativePathElement parsedElement = new RelativePathElement();

                parsedElement.ReferenceTypeId = null;
                parsedElement.IsInverse       = false;
                parsedElement.IncludeSubtypes = element.IncludeSubtypes;
                parsedElement.TargetName      = element.TargetName;

                switch (element.ElementType)
                {
                case RelativePathFormatter.ElementType.AnyHierarchical: {
                    parsedElement.ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences;
                    break;
                }

                case RelativePathFormatter.ElementType.AnyComponent: {
                    parsedElement.ReferenceTypeId = ReferenceTypeIds.Aggregates;
                    break;
                }

                case RelativePathFormatter.ElementType.ForwardReference: {
                    parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                    break;
                }

                case RelativePathFormatter.ElementType.InverseReference: {
                    parsedElement.ReferenceTypeId = typeTree.FindReferenceType(element.ReferenceTypeName);
                    parsedElement.IsInverse       = true;
                    break;
                }
                }

                if (NodeId.IsNull(parsedElement.ReferenceTypeId))
                {
                    throw ServiceResultException.Create(
                              StatusCodes.BadSyntaxError,
                              "Could not convert BrowseName to a ReferenceTypeId: {0}",
                              element.ReferenceTypeName);
                }

                relativePath.Elements.Add(parsedElement);
            }

            return(relativePath);
        }
示例#3
0
        /// <summary>
        /// Returns true if the relative path does not specify any elements.
        /// </summary>
        public static bool IsEmpty(RelativePathFormatter relativePath)
        {
            if (relativePath != null)
            {
                return(relativePath.Elements.Count == 0);
            }

            return(true);
        }
示例#4
0
        /// <summary>
        /// Parses a string representing a relative path and translates the namespace indexes.
        /// </summary>
        /// <remarks>
        /// Parses a string representing a relative path.
        /// </remarks>
        /// <exception cref="ServiceResultException">Thrown if any errors occur during parsing</exception>
        public static RelativePathFormatter Parse(string textToParse, NamespaceTable currentTable, NamespaceTable targetTable)
        {
            RelativePathFormatter path = Parse(textToParse);

            if (path != null)
            {
                path.TranslateNamespaceIndexes(currentTable, targetTable);
            }

            return(path);
        }
示例#5
0
        /// <summary>
        /// Formats the relative path as a string.
        /// </summary>
        public string Format(ITypeTable typeTree)
        {
            RelativePathFormatter formatter = new RelativePathFormatter(this, typeTree);

            return(formatter.ToString());
        }
 /// <summary>
 /// Formats the relative path as a string.
 /// </summary>
 public string Format(ITypeTable typeTree)
 {
     RelativePathFormatter formatter = new RelativePathFormatter(this, typeTree);
     return formatter.ToString();
 }
        /// <summary>
        /// Parses a string representing a relative path.
        /// </summary>
        /// <remarks>
        /// Parses a string representing a relative path.
        /// </remarks>
        /// <exception cref="ServiceResultException">Thrown if any errors occur during parsing</exception>
        public static RelativePathFormatter Parse(string textToParse)
        {
            if (String.IsNullOrEmpty(textToParse))
            {
                return new RelativePathFormatter();
            }

            RelativePathFormatter path = new RelativePathFormatter();

            try
            {
                StringReader reader = new StringReader(textToParse);

                while (reader.Peek() != -1)
                {
                    Element element = Element.Parse(reader);
                    path.m_elements.Add(element);
                }
            }
            catch (Exception e)
            {
                throw new ServiceResultException(
                    StatusCodes.BadIndexRangeInvalid,
                    Utils.Format("Cannot parse relative path: '{0}'.", textToParse),
                    e);
            }

            return path;
        }
        /// <summary>
        /// Returns true if the relative path does not specify any elements.
        /// </summary>
        public static bool IsEmpty(RelativePathFormatter relativePath)
        {
            if (relativePath != null)
            {
                return relativePath.Elements.Count == 0;
            }

            return true;
        }