コード例 #1
0
ファイル: ManifestHelper.cs プロジェクト: Rychard/Manifesto
        /// <summary>
        /// Creates a new manifest entry.
        /// </summary>
        /// <param name="rootDirectory">The directory that the file's path will be stored relative to.</param>
        /// <param name="relativeFilepath">The path to the file, relative to the <paramref name="rootDirectory" /></param>
        /// <param name="remoteLocation">A remote location where the file can be obtained from.</param>
        /// <param name="hashAlgorithm">A valid parameter for the <seealso cref="System.Security.Cryptography.HashAlgorithm"/>.<seealso cref="System.Security.Cryptography.HashAlgorithm.Create(string)"/> method.</param>
        public static ManifestEntry CreateManifestEntry(String rootDirectory, String relativeFilepath, String remoteLocation = null, String hashAlgorithm = null)
        {
            String absolutePath;
            if (String.IsNullOrWhiteSpace(rootDirectory))
            {
                absolutePath = relativeFilepath;
            }
            else
            {
                absolutePath = Path.Combine(rootDirectory, relativeFilepath);
            }
            
            if (!File.Exists(absolutePath)) { return null; }

            FileInfo fi = new FileInfo(absolutePath);
            var size = fi.Length;
            String hash = String.Empty;

            if (hashAlgorithm != null)
            {
                var hashTask = ManifestHelper.GetHashAsync(hashAlgorithm, absolutePath);
                hashTask.Wait();
                hash = hashTask.Result;
            }

            String webLocation = remoteLocation;
            var entry = new ManifestEntry(hash, size, relativeFilepath, webLocation);
            return entry;
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ManifestValidatorResult"/> class.
 /// </summary>
 /// <param name="manifestEntry">The manifest entry that was validated.</param>
 /// <param name="isValidHash">If the hash of the file is valid, <c>true</c>.  Otherwise, <c>false</c>.</param>
 /// <param name="fileLocation">The absolute path to the validated file.</param>
 public ManifestValidatorResult(ManifestEntry manifestEntry, Boolean isValidHash, String fileLocation)
 {
     this.ManifestEntry = manifestEntry;
     this.IsValidHash = isValidHash;
     this.FileLocation = fileLocation;
 }