コード例 #1
0
ファイル: Representation.cs プロジェクト: el2iot2/metafolder
 public abstract Uri Identify(IRepository repository, Stream content, ITypedContent typedContent);
コード例 #2
0
        public override Uri Identify(IRepository repository, Stream originalContentStream, ITypedContent typedContent)
        {
            Stream contentStream = originalContentStream;
            string fileExtension = null;

            if (typedContent != null)
            {
                fileExtension = typedContent.FileExtension;
                Func <Stream, Stream> streamPreprocessorFunc;
                if (_StreamIdentifierPreprocessorFuncs.TryGetValue(typedContent.ContentType, out streamPreprocessorFunc))
                {
                    contentStream = streamPreprocessorFunc(originalContentStream);
                }
            }

            byte[] hash        = _HashAlgorithm.ComputeHash(contentStream);
            string relativeUri = string.Concat(
                _Encoding
                .Encode(
                    BitConverter.ToUInt64(hash, 0),
                    false)
                .ToLower(),
                "-",
                _Encoding
                .Encode(
                    BitConverter.ToUInt64(hash, 8),
                    false)
                .ToLower());

            for (int i = _FolderDepth; i > 0; i--)
            {
                relativeUri = relativeUri.Insert(i, Path.DirectorySeparatorChar.ToString());
            }

            if (fileExtension != null)
            {
                relativeUri = Path.ChangeExtension(relativeUri, fileExtension);
            }

            return(new Uri(repository.Uri, relativeUri));
        }