Esempio n. 1
0
        public ResponseFileInfo ConvertFile(UploadFileInfo request)
        {
            string           hash          = "";
            string           destDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "WRecords");
            Stream           sourceStream  = null;
            ResponseFileInfo fileInfo      = null;

            try
            {
                fileInfo     = new ResponseFileInfo();
                sourceStream = new MemoryStream();
                sourceStream.Write(request.ByteArray, 0, request.ByteArray.Length);
                using (MD5 md5 = MD5.Create())
                {
                    hash = Hash.GetMD5Hash(md5, request.ByteArray);
                    string destFullDirectory = Path.Combine(destDirectory, request.Email, hash);
                    string videoDirectory    = Path.Combine(destFullDirectory, "video");

                    if (!Directory.Exists(destDirectory))
                    {
                        Directory.CreateDirectory(destDirectory);
                    }

                    if (!Directory.Exists(destFullDirectory))
                    {
                        Directory.CreateDirectory(destFullDirectory);
                        Directory.CreateDirectory(videoDirectory);
                        Zip.Unzip(sourceStream, destFullDirectory);
                    }
                    sourceStream.Dispose();

                    VideoConverter converter    = new VideoConverter(destFullDirectory, videoDirectory);
                    string         archiveError = converter.CheckArchiveCorrect();
                    if (archiveError != null)
                    {
                        throw new Exception(archiveError);
                    }

                    string outFilePath = converter.Start();
                    converter.Dispose();
                    fileInfo.Path = string.Format("WRecords/{0}/{1}/video/{2}", request.Email, hash, Path.GetFileName(outFilePath));
                    fileInfo.Hash = hash;
                }
            }
            catch (Exception e)
            {
                File.WriteAllText(Path.Combine(destDirectory, hash + "__catch.txt"), e.StackTrace);
            }
            return(fileInfo);
        }