示例#1
0
        public ContentInfo GetParent()
        {
            byte[] buf = null;
            switch (Document.Extension)
            {
            case PathUtil.EXTENSIONP7M:
                var p7k = P7kLoadFromBuf();
                if (p7k.Equals(0))
                {
                    return(null);
                }
                buf = P7kContentReadToBuf(p7k);
                P7kFree(p7k);
                break;

            case PathUtil.EXTENSIONPDF:
                return(null);

            default:
                var p7x = P7xLoadFromBuf();
                if (p7x.Equals(0))
                {
                    return(null);
                }
                buf = P7xContentReadToBuf(p7x);
                P7xFree(p7x);
                break;
            }

            if (buf.IsNullOrEmpty())
            {
                return(null);
            }

            string resolved = Document.FileName.ToPath().GetFileNameResolveChain();

            if (this.Document.Extension.EqualsIgnoreCase(PathUtil.EXTENSIONP7M))
            {
                var contentType = new DigitalSignViewer().GetContentTypeBuf(buf, this.Document.FileName);
                if (contentType.EqualsIgnoreCase(PathUtil.EXTENSIONP7M))
                {
                    resolved = resolved + contentType;
                    return(new ContentInfo(resolved, buf));
                }
            }

            if (!resolved.ToPath().HasExtension())
            {
                var contentType = new DigitalSignViewer().GetContentTypeBuf(buf, this.Document.FileName);
                resolved = resolved.ToPath().ChangeExtension(contentType);
            }
            return(new ContentInfo(resolved, buf));
        }
        public static string GetContentTypeBuf(this DigitalSignViewer source, byte[] buf)
        {
            enumContentTypeEx docType;
            string            pDocExt = null;

            source.GetContentTypeBuf(buf, out docType, out pDocExt);
            if (pDocExt.IsNullOrWhiteSpace())
            {
                throw new InvalidOperationException("Non è stato possibile identificare il contenuto.");
            }
            return(pDocExt);
        }
 /// <summary>
 /// Recupera la corretta estensione del file dall'array di byte.
 /// Se non si riesce a identificare l'estensione corretta, prima rimuovo le estensioni ".P7M" e in seguito vado a verificare il nome del file.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="buf">buffer di dati</param>
 /// <param name="filename">nome del file</param>
 /// <returns></returns>
 public static string GetContentTypeBuf(this DigitalSignViewer source, byte[] buf, string filename)
 {
     try
     {
         return(GetContentTypeBuf(source, buf));
     }
     catch (Exception)
     {
         try
         {
             return(ExtensionFileByMagicNumbers.GetExtension(buf).ToString());
         }
         catch (Exception)
         {
             return(ExtensionFile.none.ToString());
         }
     }
 }
 public static string GetContentTypeBuf(this DigitalSignViewer source, IContent contentInfo)
 {
     return(source.GetContentTypeBuf(contentInfo.Content));
 }