Exemplo n.º 1
0
        public static Either <Exception, ProcessId> TryParse(string path)
        {
            if (path == null || path.Length == 0)
            {
                return(new InvalidProcessIdException());
            }
            if (path[0] == '@')
            {
                return(ParseRegisteredProcess(path.Substring(1)));
            }

            if (path[0] != Sep)
            {
                return(new InvalidProcessIdException());
            }

            ProcessName[] parts = null;
            ProcessName   name;
            string        finalPath = null;

            if (path.Length == 1)
            {
                parts = new ProcessName[0];
            }
            else
            {
                try
                {
                    parts = SplitOnSep(path).ToArray();
                }
                catch (InvalidProcessNameException)
                {
                    return(new InvalidProcessIdException());
                }
            }

            finalPath = parts == null
                ? ""
                : parts.Length == 0
                    ? Sep.ToString()
                    : Sep + String.Join(Sep.ToString(), parts);

            if (path != Sep.ToString())
            {
                name = parts == null
                    ? ""
                    : parts.Length == 0
                        ? Sep.ToString()
                        : parts.Last();
            }
            else
            {
                name = "$";
            }

            return(new ProcessId(parts, name, finalPath));
        }
        public string GetScoresString()
        {
            string scoresString = "";

            foreach (var score in ScoresList)
            {
                scoresString += Sep.ToString() + score.ToString();
            }
            return(scoresString);
        }
Exemplo n.º 3
0
        public ProcessId(string path)
        {
            if (path == null || path.Length == 0)
            {
                throw new InvalidProcessIdException();
            }
            if (path[0] == '@')
            {
                var regd = ParseRegisteredProcess(path.Substring(1));
                parts = regd.parts;
                name  = regd.name;
                Path  = regd.Path;
                return;
            }

            if (path[0] != Sep)
            {
                throw new InvalidProcessIdException();
            }
            if (path.Length == 1)
            {
                parts = new ProcessName[0];
            }
            else
            {
                try
                {
                    parts = SplitOnSep(path).ToArray();
                }
                catch (InvalidProcessNameException)
                {
                    throw new InvalidProcessIdException();
                }
            }

            Path = parts == null
                ? ""
                : parts.Length == 0
                    ? Sep.ToString()
                    : Sep + String.Join(Sep.ToString(), parts);

            if (path != Sep.ToString())
            {
                name = parts == null
                    ? ""
                    : parts.Length == 0
                        ? Sep.ToString()
                        : parts.Last();
            }
            else
            {
                name = "$";
            }
        }
Exemplo n.º 4
0
        public ProcessId(string path)
        {
            if (path == null || path.Length == 0)
            {
                throw new InvalidProcessIdException();
            }
            if (path[0] != Sep)
            {
                throw new InvalidProcessIdException();
            }
            if (path.Length == 1)
            {
                parts = new ProcessName[0];
            }
            else
            {
                try
                {
                    parts = path.Substring(1)
                            .Split(Sep)
                            .Select(p => new ProcessName(p))
                            .ToArray();
                }
                catch (InvalidProcessNameException)
                {
                    throw new InvalidProcessIdException();
                }
            }

            Path = parts == null
                ? ""
                : parts.Length == 0
                    ? Sep.ToString()
                    : Sep + String.Join(Sep.ToString(), parts);

            if (path != Sep.ToString())
            {
                name = parts == null
                    ? ""
                    : parts.Length == 0
                        ? Sep.ToString()
                        : parts.Last();
            }
            else
            {
                name = "$";
            }
        }
Exemplo n.º 5
0
        public static Either <Exception, ProcessId> TryParse(string path)
        {
            if (path == null || path.Length == 0)
            {
                return(new InvalidProcessIdException());
            }

            var system = "";

            if (path.StartsWith("//"))
            {
                var end = path.IndexOf('/', 2);
                end = end == -1
                    ? path.IndexOf("@", 2)
                    : end;

                if (end == -1)
                {
                    return(new InvalidProcessIdException($"Invalid ProcessId ({path}), nothing following the system specifier"));
                }

                system = path.Substring(2, end - 2);
                path   = path.Substring(end);
            }

            if (path[0] == '@')
            {
                return(ParseRegisteredProcess(path.Substring(1)));
            }

            if (path[0] != Sep)
            {
                return(new InvalidProcessIdException());
            }

            ProcessName[] parts = null;
            ProcessName   name;
            string        finalPath = null;

            if (path.Length == 1)
            {
                parts = new ProcessName[0];
            }
            else
            {
                try
                {
                    parts = SplitOnSep(path).ToArray();
                }
                catch (InvalidProcessNameException)
                {
                    return(new InvalidProcessIdException());
                }
            }

            finalPath = parts == null
                ? ""
                : parts.Length == 0
                    ? Sep.ToString()
                    : Sep + String.Join(Sep.ToString(), parts);

            if (path != Sep.ToString())
            {
                name = parts == null
                    ? ""
                    : parts.Length == 0
                        ? Sep.ToString()
                        : parts.Last();
            }
            else
            {
                name = "$";
            }

            return(new ProcessId(parts, system == "" ? default(SystemName) : system, name, finalPath));
        }
 public string Output()
 {
     return(string.Join(Sep.ToString(), GetLine()));
 }