예제 #1
0
 private bool TryGetFileAttributeFromLast(string pathFromWorkingFolder, out FileAttributeItem item)
 {
     item = null;
     if (!CanVersionIncremental)
     {
         return(false);
     }
     if (_parameters.Changes == null)
     {
         return(false);
     }
     if (_parameters.Changes.ContainsKey(pathFromWorkingFolder) && _parameters.Changes[pathFromWorkingFolder] != ChangeKindWithDependency.None)
     {
         return(false);
     }
     if (LastBuildVersionInfo == null)
     {
         return(false);
     }
     if (!LastBuildVersionInfo.Attributes.TryGetValue(pathFromWorkingFolder, out item))
     {
         return(false);
     }
     return(true);
 }
예제 #2
0
        public void UpdateBuildVersionInfoPerDependencyGraph()
        {
            if (CurrentBuildVersionInfo.Dependency == null)
            {
                return;
            }
            var fileAttributes = CurrentBuildVersionInfo.Attributes;
            var nodesToUpdate  = CurrentBuildVersionInfo.Dependency.GetAllDependentNodes().Except(fileAttributes.Keys, FilePathComparer.OSPlatformSensitiveStringComparer);

            foreach (var node in nodesToUpdate)
            {
                RelativePath path = RelativePath.TryParse(node);
                if (path == null)
                {
                    continue;
                }
                string fullPath = Path.Combine(EnvironmentContext.BaseDirectory, path.RemoveWorkingFolder());
                if (File.Exists(fullPath))
                {
                    fileAttributes[node] = new FileAttributeItem
                    {
                        File             = node,
                        LastModifiedTime = File.GetLastWriteTimeUtc(fullPath),
                        MD5 = StringExtension.GetMd5String(File.ReadAllText(fullPath)),
                    };
                }
            }
        }
예제 #3
0
 public void InitFileAttributes()
 {
     using (new LoggerPhaseScope("InitFileAttributes", LogLevel.Verbose))
     {
         var fileAttributes = CurrentBuildVersionInfo.Attributes;
         foreach (var f in GetFilesToCalculateAttributes())
         {
             string key = f.PathFromWorkingFolder;
             if (fileAttributes.ContainsKey(key))
             {
                 continue;
             }
             FileAttributeItem item;
             if (!TryGetFileAttributeFromLast(key, out item))
             {
                 string md5;
                 using (var fs = File.OpenRead(f.FullPath))
                 {
                     md5 = Convert.ToBase64String(MD5.Create().ComputeHash(fs));
                 }
                 fileAttributes[key] = new FileAttributeItem
                 {
                     File             = key,
                     LastModifiedTime = File.GetLastWriteTimeUtc(f.FullPath),
                     MD5          = md5,
                     IsFromSource = f.IsFromSource,
                 };
             }
             else
             {
                 fileAttributes[key] = new FileAttributeItem
                 {
                     File             = item.File,
                     LastModifiedTime = item.LastModifiedTime,
                     MD5          = item.MD5,
                     IsFromSource = f.IsFromSource,
                 };
             }
         }
     }
 }
예제 #4
0
 public void InitFileAttributes()
 {
     using (new LoggerPhaseScope("InitFileAttributes", LogLevel.Verbose))
     {
         var fileAttributes = CurrentBuildVersionInfo.Attributes;
         foreach (var f in GetFilesToCalculateAttributes())
         {
             string key = f.PathFromWorkingFolder;
             if (fileAttributes.ContainsKey(key))
             {
                 continue;
             }
             if (!TryGetFileAttributeFromLast(key, out FileAttributeItem item))
             {
                 string hash;
                 using (var fs = File.OpenRead(f.FullPath))
                 {
                     hash = HashUtility.GetSha256HashString(fs);
                 }
                 fileAttributes[key] = new FileAttributeItem
                 {
                     File             = key,
                     LastModifiedTime = File.GetLastWriteTimeUtc(f.FullPath),
                     Hash             = hash,
                     IsFromSource     = f.IsFromSource,
                 };
             }
             else
             {
                 fileAttributes[key] = new FileAttributeItem
                 {
                     File             = item.File,
                     LastModifiedTime = item.LastModifiedTime,
                     Hash             = item.Hash,
                     IsFromSource     = f.IsFromSource,
                 };
             }
         }
     }
 }
예제 #5
0
 public void InitFileAttributes()
 {
     using (new LoggerPhaseScope("InitFileAttributes", false))
         using (new PerformanceScope("InitFileAttributes", LogLevel.Verbose))
         {
             var fileAttributes = CurrentBuildVersionInfo.Attributes;
             foreach (var f in GetFilesToCalculateAttributes())
             {
                 string key = f.PathFromWorkingFolder;
                 if (fileAttributes.ContainsKey(key))
                 {
                     continue;
                 }
                 FileAttributeItem item;
                 if (!TryGetFileAttributeFromLast(key, out item))
                 {
                     fileAttributes[key] = new FileAttributeItem
                     {
                         File             = key,
                         LastModifiedTime = File.GetLastWriteTimeUtc(f.FullPath),
                         MD5          = StringExtension.GetMd5String(File.ReadAllText(f.FullPath)),
                         IsFromSource = f.IsFromSource,
                     };
                 }
                 else
                 {
                     fileAttributes[key] = new FileAttributeItem
                     {
                         File             = item.File,
                         LastModifiedTime = item.LastModifiedTime,
                         MD5          = item.MD5,
                         IsFromSource = f.IsFromSource,
                     };
                 }
             }
         }
 }
예제 #6
0
 public void UpdateBuildVersionInfoPerDependencyGraph()
 {
     if (CurrentBuildVersionInfo.Dependency == null)
     {
         return;
     }
     var fileAttributes = CurrentBuildVersionInfo.Attributes;
     var nodesToUpdate = CurrentBuildVersionInfo.Dependency.GetAllDependentNodes().Except(fileAttributes.Keys);
     foreach (var node in nodesToUpdate)
     {
         string fullPath = Path.Combine(EnvironmentContext.BaseDirectory, ((RelativePath)node).RemoveWorkingFolder());
         if (File.Exists(fullPath))
         {
             fileAttributes[node] = new FileAttributeItem
             {
                 File = node,
                 LastModifiedTime = File.GetLastWriteTimeUtc(fullPath),
                 MD5 = StringExtension.GetMd5String(File.ReadAllText(fullPath)),
             };
         }
     }
 }