Example #1
0
        /// <summary>Gets checksum for resource if it exists.</summary>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="checksumAlgorithm">The checksum algorithm to use.</param>
        /// <returns>Checksum for resource or empty byte array if the resource does not exist.</returns>
        public static byte[] TryGetChecksum(
            ResourceKey resourceKey,
            ChecksumAlgorithm checksumAlgorithm)
        {
            var algName = GetChecksumName(checksumAlgorithm);

            using (var s = resourceKey.TryGetResourceStream())
            {
                if (s == null)
                {
                    return(Array <byte> .Empty);
                }

                using (var h = HashAlgorithm.Create(algName))
                {
                    // ReSharper disable once PossibleNullReferenceException
                    return(h.ComputeHash(s));
                }
            }
        }
        public static XDocument TryParseXmlAnnotationDoc(
            ResourceKey annotationResourceKey,
            [NotNull] IMessageLogger messageLogger)
        {
            Code.NotNull(messageLogger, nameof(messageLogger));
            Code.BugIf(annotationResourceKey.Assembly == null, "annotationResourceKey.Assembly == null");

            var assembly     = annotationResourceKey.Assembly;
            var resourceName = annotationResourceKey.ResourceName;

            using (var resourceStream = annotationResourceKey.TryGetResourceStream())
            {
                if (resourceStream == null)
                {
                    messageLogger.WriteSetupErrorMessage(
                        $"XML annotation resource stream '{resourceName}' not found. Assembly {assembly.FullName}.");

                    return(null);
                }

                return(TryParseXmlAnnotationDoc(resourceStream, $"Resource '{resourceName}'", messageLogger));
            }
        }