Exemple #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);
        }
Exemple #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));
        }
Exemple #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));
        }