private static string FindLatestVersionDirPath(IDirectoryAdapter directoryAdapter, string baseDirPath)
        {
            Guard.NotNull(directoryAdapter, "directoryAdapter");
            Guard.NotNullNorEmpty(baseDirPath, "baseDirPath");

            string[] subDirs =
                directoryAdapter.GetDirectories(baseDirPath, "*.*", SearchOption.TopDirectoryOnly);

            var versionedFolders = new List <Tuple <VersionedFolder, string> >();

            foreach (string subDirPath in subDirs)
            {
                string subDir = Path.GetFileName(subDirPath) ?? "";
                Match  match  = _VersionedFoldeRegex.Match(subDir);

                if (!match.Success)
                {
                    continue;
                }

                string majorStr    = match.Groups["Major"].Value;
                string minorStr    = match.Groups["Minor"].Value;
                string revisionStr = match.Groups["Revision"].Value;
                string buildStr    = match.Groups["Build"].Value;
                string customStr   = match.Groups["Custom"].Value;
                string markerStr   = match.Groups["Marker"].Value;

                var versionedFolder =
                    new VersionedFolder(
                        int.Parse(majorStr),
                        int.Parse(minorStr),
                        int.Parse(revisionStr),
                        int.Parse(buildStr),
                        customStr,
                        !string.IsNullOrEmpty(markerStr) ? int.Parse(markerStr) : 0);

                versionedFolders.Add(new Tuple <VersionedFolder, string>(versionedFolder, subDirPath));
            }

            versionedFolders.Sort(
                (folder, otherFolder) =>
                Equals(folder.Item1, otherFolder.Item1)
          ? 0
          : folder.Item1.IsSmallerThan(otherFolder.Item1)
              ? 1
              : -1);

            Tuple <VersionedFolder, string> latestVersionedFolder =
                versionedFolders.FirstOrDefault();

            return
                (latestVersionedFolder != null
          ? latestVersionedFolder.Item2
          : null);
        }
            public bool IsSmallerThan(VersionedFolder other)
            {
                Guard.NotNull(other, "other");

                return(Major < other.Major ||
                       (Major == other.Major && Minor < other.Minor) ||
                       (Minor == other.Minor && Revision < other.Revision) ||
                       (Revision == other.Revision && Build < other.Build) ||
                       (Build == other.Build && !Marker.HasValue && other.Marker.HasValue) ||
                       (Build == other.Build && Marker.HasValue && other.Marker.HasValue && Marker.Value < other.Marker.Value));
            }
 private bool Equals(VersionedFolder other)
 {
     return(Major == other.Major && Minor == other.Minor && Revision == other.Revision && Build == other.Build && string.Equals(Custom, other.Custom) && Marker == other.Marker);
 }
 private bool Equals(VersionedFolder other)
 {
     return Major == other.Major && Minor == other.Minor && Revision == other.Revision && Build == other.Build && string.Equals(Custom, other.Custom) && Marker == other.Marker;
 }
            public bool IsSmallerThan(VersionedFolder other)
            {
                Guard.NotNull(other, "other");

                return Major < other.Major
                || (Major == other.Major && Minor < other.Minor)
                || (Minor == other.Minor && Revision < other.Revision)
                || (Revision == other.Revision && Build < other.Build)
                || (Build == other.Build && !Marker.HasValue && other.Marker.HasValue)
                || (Build == other.Build && Marker.HasValue && other.Marker.HasValue && Marker.Value < other.Marker.Value);
            }
        private static string FindLatestVersionDirPath(IDirectoryAdapter directoryAdapter, string baseDirPath)
        {
            Guard.NotNull(directoryAdapter, "directoryAdapter");
              Guard.NotNullNorEmpty(baseDirPath, "baseDirPath");

              string[] subDirs =
            directoryAdapter.GetDirectories(baseDirPath, "*.*", SearchOption.TopDirectoryOnly);

              var versionedFolders = new List<Tuple<VersionedFolder, string>>();

              foreach (string subDirPath in subDirs)
              {
            string subDir = Path.GetFileName(subDirPath) ?? "";
            Match match = _VersionedFoldeRegex.Match(subDir);

            if (!match.Success)
            {
              continue;
            }

            string majorStr = match.Groups["Major"].Value;
            string minorStr = match.Groups["Minor"].Value;
            string revisionStr = match.Groups["Revision"].Value;
            string buildStr = match.Groups["Build"].Value;
            string customStr = match.Groups["Custom"].Value;
            string markerStr = match.Groups["Marker"].Value;

            var versionedFolder =
              new VersionedFolder(
            int.Parse(majorStr),
            int.Parse(minorStr),
            int.Parse(revisionStr),
            int.Parse(buildStr),
            customStr,
            !string.IsNullOrEmpty(markerStr) ? int.Parse(markerStr) : 0);

            versionedFolders.Add(new Tuple<VersionedFolder, string>(versionedFolder, subDirPath));
              }

              versionedFolders.Sort(
            (folder, otherFolder) =>
            Equals(folder.Item1, otherFolder.Item1)
              ? 0
              : folder.Item1.IsSmallerThan(otherFolder.Item1)
              ? 1
              : -1);

              Tuple<VersionedFolder, string> latestVersionedFolder =
            versionedFolders.FirstOrDefault();

              return
            latestVersionedFolder != null
              ? latestVersionedFolder.Item2
              : null;
        }