示例#1
0
        private bool Validate(Stream stream, string fileName)
        {
            var info = SupportedFileManager.GetSupportedFileInfo(ClassType);

            if (info == null)
            {
                return(false);
            }

            bool valid = true;

            try
            {
                try
                {
                    info.Instantiator(stream, true, fileName);
                }
                catch (Exception)
                {
                    valid = false;
                }
            }
            finally
            {
                stream.Position = 0;
            }

            return(valid);
        }
示例#2
0
        public static IResourceWrapper GetResourceWrapper(string text, Stream stream, int supportedFileIndex, string filePath = null)
        {
            if (supportedFileIndex == -1)
            {
                return(new BinaryFileWrapper(text, new BinaryFile(stream)));
            }

            var supportedFileInfo = SupportedFileManager.GetSupportedFileInfo(supportedFileIndex);
            var resource          = supportedFileInfo.Instantiator(stream, false, filePath);

            return(GetResourceWrapper(text, resource));
        }
示例#3
0
        public static IResourceWrapper GetResourceWrapper(string text, Stream stream, int supportedFileIndex, string filePath = null)
        {
            if (stream is FileStream fileStream)
            {
                if (filePath == null)
                {
                    filePath = fileStream.Name;
                }

                stream = fileStream.ToMemoryStream(leaveOpen: false);
            }

            if (supportedFileIndex == -1)
            {
                return(new BinaryFileWrapper(text, new BinaryFile(stream)));
            }

            var supportedFileInfo = SupportedFileManager.GetSupportedFileInfo(supportedFileIndex);
            var resource          = supportedFileInfo.Instantiator(stream, false, filePath);

            return(GetResourceWrapper(text, resource));
        }
示例#4
0
 public static IResourceWrapper GetResourceWrapper(string text, Stream stream, string filePath = null)
 {
     return(GetResourceWrapper(text, stream, SupportedFileManager.GetSupportedFileIndex(text, stream), filePath ?? text));
 }