public static async Task <string> GetPreviousVersionGuid(string branch, string versionGuid, bool retry = true)
        {
            StudioDeployLogs deployLogs = await GetDeployLogs(branch);

            if (deployLogs.LookupFromGuid.ContainsKey(versionGuid))
            {
                StudioDeployLog currentLog      = deployLogs.LookupFromGuid[versionGuid];
                int             previousVersion = currentLog.Version - 1;

                if (deployLogs.LookupFromVersion.ContainsKey(previousVersion))
                {
                    StudioDeployLog previousLog = deployLogs.LookupFromVersion[previousVersion];
                    return(previousLog.VersionGuid);
                }
                else
                {
                    throw new Exception("Could not resolve previous version.");
                }
            }
            else if (retry)
            {
                // The cache might be invalid now? Try rebuilding it.
                Logs.Remove(branch);
                return(await GetPreviousVersionGuid(branch, versionGuid, false));
            }
            else
            {
                throw new Exception("Unknown version guid: " + versionGuid);
            }
        }
        private void Add(StudioDeployLog deployLog)
        {
            // Add by version guid
            if (!LookupFromGuid.ContainsKey(deployLog.VersionGuid))
            {
                LookupFromGuid.Add(deployLog.VersionGuid, deployLog);
            }

            // Add by version info
            if (!LookupFromVersion.ContainsKey(deployLog.Version) && deployLog.Patch == 0)
            {
                LookupFromVersion.Add(deployLog.Version, deployLog);
            }
        }
        private void InitializeLogs(string deployHistory)
        {
            MatchCollection matches = Regex.Matches(deployHistory, MatchLog);

            foreach (Match match in matches)
            {
                string[] data = match.Groups.Cast <Group>()
                                .Select(group => group.Value)
                                .Where(value => value.Length != 0)
                                .ToArray();

                StudioDeployLog deployLog = new StudioDeployLog();
                deployLog.VersionGuid = data[1];

                int.TryParse(data[2], out deployLog.MajorRev);
                int.TryParse(data[3], out deployLog.Version);
                int.TryParse(data[4], out deployLog.Patch);
                int.TryParse(data[5], out deployLog.Changelist);

                Add(deployLog);
            }
        }