예제 #1
0
 public static BackupRestore Find(string Root, string Product, string Id)
 {
     var Result = default(BackupRestore);
     var Dir = Path.Combine(Root, BackupDirectory);
     var FullId = GetFullId(Product, Id);
     if (Directory.Exists(Dir))
     {
         var DirList = new List<DirectoryTag>();
         foreach (var DateItem in Directory.GetDirectories(Dir))
         {
             DateTime date;
             var DateName = new DirectoryInfo(DateItem).Name;
             if (DateTime.TryParseExact(DateName, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
             {
                 foreach (var VersionItem in Directory.GetDirectories(DateItem))
                 {
                     var VersionName = new DirectoryInfo(VersionItem).Name;
                     if (VersionName.StartsWith(FullId, StringComparison.InvariantCultureIgnoreCase))
                     {
                         Version BckpVersion;
                         var StrVersion = VersionName.Substring(FullId.Length);
                         if (Version.TryParse(StrVersion, out BckpVersion))
                             DirList.Add(new DirectoryTag { Name = VersionItem, Date = date, Version = BckpVersion });
                     }
                 }
             }
         }
         var ByVersion = from i in DirList where i.Version == (from v in DirList select v.Version).Max() select i;
         var ByDate = from i in ByVersion where i.Date == (from v in ByVersion select v.Date).Max() select i;
         var SrcTag = ByDate.First();
         Result = new BackupRestore { Id = Id, Root = GetComponentRoot(SrcTag, Id), BackupFile = Path.Combine(SrcTag.Name, AppZip), BackupMainConfigFile = GetMainConfig(SrcTag) };
     }
     return Result;
 }
예제 #2
0
        public static BackupRestore Find(string Root, string Product, string Id)
        {
            var Result = default(BackupRestore);
            var Dir    = Path.Combine(Root, BackupDirectory);
            var FullId = GetFullId(Product, Id);

            if (Directory.Exists(Dir))
            {
                var DirList = new List <DirectoryTag>();
                foreach (var DateItem in Directory.GetDirectories(Dir))
                {
                    DateTime date;
                    var      DateName = new DirectoryInfo(DateItem).Name;
                    if (DateTime.TryParseExact(DateName, DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out date))
                    {
                        foreach (var VersionItem in Directory.GetDirectories(DateItem))
                        {
                            var VersionName = new DirectoryInfo(VersionItem).Name;
                            if (VersionName.StartsWith(FullId, StringComparison.InvariantCultureIgnoreCase))
                            {
                                Version BckpVersion;
                                var     StrVersion = VersionName.Substring(FullId.Length);
                                if (Version.TryParse(StrVersion, out BckpVersion))
                                {
                                    DirList.Add(new DirectoryTag {
                                        Name = VersionItem, Date = date, Version = BckpVersion
                                    });
                                }
                            }
                        }
                    }
                }
                var ByVersion = from i in DirList where i.Version == (from v in DirList select v.Version).Max() select i;
                var ByDate    = from i in ByVersion where i.Date == (from v in ByVersion select v.Date).Max() select i;
                var SrcTag    = ByDate.First();
                Result = new BackupRestore {
                    Id = Id, Root = GetComponentRoot(SrcTag, Id), BackupFile = Path.Combine(SrcTag.Name, AppZip), BackupMainConfigFile = GetMainConfig(SrcTag)
                };
            }
            return(Result);
        }