private static void ProcessLiteralPaths(SessionState session, IEnumerable <string> paths, ICollection <PscxPathInfo> pathInfos, bool shouldExist) { // store as unresolved (literal) foreach (string path in paths) { PscxPathInfo pscxPath; // NOTE: IsValid only checks for syntactical validity, not existance if (session.Path.IsValid(path)) { // is existance required? if (shouldExist) { if (Exists(path, true)) { // valid pscxPath = new UnresolvedPscxPathImpl(path, session); } else { // does not exist pscxPath = new InvalidPscxPathImpl(path) { _state = PscxPathState.NotExist }; } } else { // valid pscxPath = new UnresolvedPscxPathImpl(path, session); } } else { // invalid path pscxPath = new InvalidPscxPathImpl(path) { _state = PscxPathState.InvalidSyntax }; } pathInfos.Add(pscxPath); } }
private static void ProcessResolvablePaths(SessionState session, IEnumerable <string> paths, ICollection <PscxPathInfo> pathInfos, bool shouldExist) { // handle wildcard resolving etc foreach (string path in paths) { try { Collection <PathInfo> resolvedPaths = session.Path.GetResolvedPSPathFromPSPath(path); foreach (PathInfo resolvedPath in resolvedPaths) { // save resolved path along with original input path var pscxPath = new ResolvedPscxPathImpl(resolvedPath, path); pathInfos.Add(pscxPath); } } catch (ItemNotFoundException ex) { PscxPathInfo pscxPath; // check if input contains wildcards or should exist = true if (WildcardPattern.ContainsWildcardCharacters(ex.ItemName) || shouldExist) { // save qualifed/resolved failed path as invalid. // must be invalid because an unresolved wildcard // can never be a valid path. pscxPath = new InvalidPscxPathImpl(ex.ItemName) { _state = PscxPathState.Unresolved }; } else { // path is not wildcard but nonetheless does not exist. // pass back as a literal path. pscxPath = new UnresolvedPscxPathImpl(ex.ItemName, session) { _state = PscxPathState.NotExist }; } pathInfos.Add(pscxPath); } } }
private static void ProcessResolvablePaths(SessionState session, IEnumerable<string> paths, ICollection<PscxPathInfo> pathInfos, bool shouldExist) { // handle wildcard resolving etc foreach (string path in paths) { try { Collection<PathInfo> resolvedPaths = session.Path.GetResolvedPSPathFromPSPath(path); foreach (PathInfo resolvedPath in resolvedPaths) { // save resolved path along with original input path var pscxPath = new ResolvedPscxPathImpl(resolvedPath, path); pathInfos.Add(pscxPath); } } catch (ItemNotFoundException ex) { PscxPathInfo pscxPath; // check if input contains wildcards or should exist = true if (WildcardPattern.ContainsWildcardCharacters(ex.ItemName) || shouldExist) { // save qualifed/resolved failed path as invalid. // must be invalid because an unresolved wildcard // can never be a valid path. pscxPath = new InvalidPscxPathImpl(ex.ItemName) { _state = PscxPathState.Unresolved }; } else { // path is not wildcard but nonetheless does not exist. // pass back as a literal path. pscxPath = new UnresolvedPscxPathImpl(ex.ItemName, session) { _state = PscxPathState.NotExist }; } pathInfos.Add(pscxPath); } } }
private static void ProcessLiteralPaths(SessionState session, IEnumerable<string> paths, ICollection<PscxPathInfo> pathInfos, bool shouldExist) { // store as unresolved (literal) foreach (string path in paths) { PscxPathInfo pscxPath; // NOTE: IsValid only checks for syntactical validity, not existance if (session.Path.IsValid(path)) { // is existance required? if (shouldExist) { if (Exists(path, true)) { // valid pscxPath = new UnresolvedPscxPathImpl(path, session); } else { // does not exist pscxPath = new InvalidPscxPathImpl(path) { _state = PscxPathState.NotExist }; } } else { // valid pscxPath = new UnresolvedPscxPathImpl(path, session); } } else { // invalid path pscxPath = new InvalidPscxPathImpl(path) { _state = PscxPathState.InvalidSyntax }; } pathInfos.Add(pscxPath); } }