IsValidPath() public static method

Determines whether the specified path is valid.
public static IsValidPath ( string path ) : PathResult
path string The path.
return PathResult
        private static string GetMessage(string msg)
        {
            int id;

            if (int.TryParse(msg, out id) || (RepositoryPath.IsValidPath(msg) == RepositoryPath.PathResult.Correct))
            {
                return("Content not found: " + msg);
            }
            return(msg);
        }
Example #2
0
        /// <summary>
        /// Gets a new node identifier based on the provided value.
        /// </summary>
        /// <param name="identifier">Can be a path or an id.</param>
        public static NodeIdentifier Get(object identifier)
        {
            if (identifier == null)
            {
                return(null);
            }

            var nid = new NodeIdentifier();

            var idAsText = identifier as string;

            if (idAsText != null)
            {
                // We received a string, that can be a path or an id as well.
                int id;

                if (RepositoryPath.IsValidPath(idAsText) == RepositoryPath.PathResult.Correct)
                {
                    nid.Path = idAsText;
                }
                else if (int.TryParse(idAsText, out id))
                {
                    nid.Id = id;
                }
                else
                {
                    throw new SnNotSupportedException("An identifier should be either a path or an id. Invalid value: " + idAsText);
                }
            }
            else
            {
                if (!(identifier is int || identifier is short || identifier is long))
                {
                    throw new SnNotSupportedException("An identifier should be either a path or an id. Invalid value: " + identifier);
                }

                nid.Id = Convert.ToInt32(identifier);
            }

            return(nid);
        }