Esempio n. 1
0
        public void convert(string filepath)
        {
            Mime   mime     = new Mime();
            string mimeType = mime.Lookup(filepath);

            string mp3path = filepath.Replace(".wav", ".mp3");

            Debug.WriteLine(mp3path);

            try {
                byte[] wavFile = File.ReadAllBytes(filepath);

                using (MemoryStream memoryStream = new MemoryStream())
                    using (MemoryStream WaveMemoryStream = new MemoryStream(wavFile))
                        using (WaveFileReader WaveFileReader = new WaveFileReader(WaveMemoryStream))
                            using (LameMP3FileWriter mp3Writer = new LameMP3FileWriter(memoryStream, WaveFileReader.WaveFormat, 128)) {
                                WaveFileReader.CopyTo(mp3Writer);
                                try {
                                    File.WriteAllBytes(mp3path, memoryStream.ToArray());
                                } catch (Exception e) {
                                    // error writing file
                                    Debug.WriteLine(e);
                                }
                            }
            } catch (Exception e) {
                Debug.WriteLine(e);
            }
        }
Esempio n. 2
0
        public void convert(string filepath)
        {
            Mime   mime     = new Mime();
            string mimeType = mime.Lookup(filepath);

            Console.WriteLine(mimeType);
            if (mimeType == "audio/mpeg")
            {
                string wavfile = filepath.Replace(".mp3", ".wav");
                string wavpath = wavfile;

                int    index   = wavfile.LastIndexOf("\\");
                string wavname = wavfile.Substring(index + 1, wavfile.Length - index - 1);
                index = filepath.LastIndexOf("\\");
                string mp3name = filepath.Substring(index + 1, filepath.Length - index - 1);
                Console.Out.WriteLine("Converting {0} to {1}", mp3name, wavname);
                try {
                    using (Mp3FileReader reader = new Mp3FileReader(filepath)) {
                        using (WaveStream wavestream = WaveFormatConversionStream.CreatePcmStream(reader)) {
                            WaveFileWriter.CreateWaveFile(wavfile, wavestream);
                        }
                    }
                } catch (Exception e) {
                    // Exception when there is a wrong filetype
                    Console.Out.WriteLine("Exception occured: " + e);
                }
            }
        }
        public void supports_making_multiple_lookups()
        {
            var firstResult  = Mime.Lookup("test.html");
            var secondResult = Mime.Lookup("test.pdf");

            firstResult.Should().NotBeNullOrEmpty();
            secondResult.Should().NotBeNullOrEmpty();
        }
Esempio n. 4
0
 public override string GetMimeTypeFromPath(string path)
 {
     if (_mime == null)
     {
         _mime = new Mime();
     }
     return(_mime.Lookup(path));
 }
Esempio n. 5
0
 public Request <T> SetFile(string filePath, string fileParameterName)
 {
     _filePath          = filePath;
     _fileParameterName = fileParameterName;
     _fileName          = filePath.Split('/').Last();
     _fileContentType   = Mime.Lookup(_fileName);
     return(this);
 }
        public FileResult FileDownloadD(string Cvv)
        {
            string Extention = Path.GetExtension(Cvv);
            Mime   Omine     = new Mime();
            string FileType  = Omine.Lookup(Extention);

            return(File(Cvv, FileType));
        }
Esempio n. 7
0
        public void SupportsMakingMultipleLookups()
        {
            var firstResult  = Mime.Lookup("test.html");
            var secondResult = Mime.Lookup("test.pdf");

            Assert.NotNull(firstResult);
            Assert.NotEmpty(firstResult);
            Assert.NotNull(secondResult);
            Assert.NotEmpty(secondResult);
        }
        public void htm_extension_is_correctly_identified()
        {
            var result = Mime.Lookup("test.htm");

            result.Should().Be("text/html");
        }
        public void html_extension_should_have_correct_mime_type()
        {
            var result = Mime.Lookup("test.html");

            result.Should().Be("text/html");
        }
        public void HtmExtensionIsCorrectlyIdentified()
        {
            var result = Mime.Lookup("test.htm");

            Assert.Equal("text/html", result);
        }
        public void HtmlExtensionShouldHaveCorrectMimeType()
        {
            var result = Mime.Lookup("test.html");

            Assert.Equal("text/html", result);
        }
Esempio n. 12
0
        public async Task ImportAsync()
        {
            FileInfo existingFile = new FileInfo(caseFile);

            using (var fileReader = new StreamReader(existingFile.OpenRead()))
            {
                using (var csvReader = new CsvReader(fileReader))
                {
                    List <string> headers = null;
                    if (csvReader.ReadHeader())
                    {
                        headers = csvReader.FieldHeaders.ToList();
                    }
                    else
                    {
                        Console.WriteLine("Could not read headers. Exiting");
                        return;
                    }

                    var headerCount = headers.Count();
                    while (csvReader.Read())
                    {
                        var record = csvReader.CurrentRecord;

                        var fogBugzCase = new Dictionary <String, String>(headers.Zip(record, (k, v) => new KeyValuePair <String, String>(k, v))
                                                                          .Where(kp => !String.IsNullOrWhiteSpace((kp.Value))));

                        if (fogBugzCase.TryGetValue("ixPersonAssignedTo", out var assignee))
                        {
                            if (!int.TryParse(assignee, out var _))
                            {
                                fogBugzCase.Remove("ixPersonAssignedTo");
                                string personId = driver.GetPersonId(assignee);
                                if (!string.IsNullOrEmpty(personId))
                                {
                                    fogBugzCase.Add("ixPersonAssignedTo", personId);
                                }
                                else
                                {
                                    Console.WriteLine($"Unable to look up personId for {assignee}");
                                }
                            }
                        }

                        if (fogBugzCase.TryGetValue("ixPersonEditedBy", out var reporter))
                        {
                            if (!int.TryParse(reporter, out var _))
                            {
                                fogBugzCase.Remove("ixPersonEditedBy");
                                string personId = driver.GetPersonId(reporter);
                                if (!string.IsNullOrEmpty(personId))
                                {
                                    fogBugzCase.Add("ixPersonEditedBy", personId);
                                }
                                else
                                {
                                    Console.WriteLine($"Unable to look up personId for {reporter}");
                                }
                            }
                        }

                        List <Dictionary <string, byte[]> > attachmentData = null;
                        if (fogBugzCase.TryGetValue("attachments", out var attachments))
                        {
                            fogBugzCase.Remove("attachments");
                            List <Attachment> files    = GetAttachments(attachments);
                            ASCIIEncoding     encoding = new ASCIIEncoding();

                            if (files.Count > 0)
                            {
                                attachmentData = new List <Dictionary <string, byte[]> >(files.Count);
                                for (int i = 0; i < files.Count; i++)
                                {
                                    attachmentData[i]                = new Dictionary <string, byte[]>();
                                    attachmentData[i]["name"]        = encoding.GetBytes("File" + (i + 1).ToString());
                                    attachmentData[i]["filename"]    = encoding.GetBytes(files[i].name);
                                    attachmentData[i]["contenttype"] = encoding.GetBytes(mimeDetector.Lookup(files[i].name));
                                    using (FileStream fs = new FileStream(Path.Combine(attachmentDirectory, files[i].nameOnDisk), FileMode.Open))
                                    {
                                        BinaryReader br = new BinaryReader(fs);
                                        attachmentData[i]["data"] = br.ReadBytes((int)fs.Length);
                                    }
                                }
                                fogBugzCase.Add("nFileCount", files.Count.ToString());
                            }
                        }

                        await driver.ExecuteCommandAsync(fogBugzCase, attachmentData);
                    }
                }
            }
        }
Esempio n. 13
0
        public static MFilesDocument UpdateSlave(DocumentsContext ctx, MFilesDocument masterDoc, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, string thumbnailsUrlPattern)
        {
            if (sourceDoc.Guid != masterDoc.Guid)
            {
                targetDoc.Guid         = sourceDoc.Guid;
                targetDoc.ModifiedDate = sourceDoc.ModifiedDate;
                targetDoc.CreatedDate  = sourceDoc.CreatedDate;
            }
            else
            {
                targetDoc = masterDoc;
            }

            var doc = masterDoc.Document;

            Debug.Assert(doc != null);

            string languageCode;

            // TODO: should be in configuration or don't use CultureUtils
            // or we need to update language in M-Files
            if (sourceDoc.Language == "Portugese")
            {
                languageCode = "pt";
            }
            else if (sourceDoc.Language == "Azeri")
            {
                languageCode = "az";
            }
            else
            {
                languageCode = CultureUtils.GetLangTwoLetterCode(sourceDoc.Language);
            }

            if (languageCode == null)
            {
                ClassLogger.Warn(
                    $"Could not find language code for  {sourceDoc.Language} (Document {sourceDoc.UnNumber})");
                return(null);
            }

            var title = doc.Titles.FirstOrDefault(t => t.Language == languageCode && t.Document == doc);

            if (title == null || title.MFilesDocument == targetDoc)
            {
                if (title == null)
                {
                    title = new Title {
                        MFilesDocument = targetDoc
                    };
                    doc.Titles.Add(title);
                }

                title.Document       = doc;
                title.Language       = languageCode;
                title.LanguageFull   = sourceDoc.Language;
                title.MFilesDocument = targetDoc;
                title.Value          = sourceDoc.Title;
            }

            var descirpiton = doc.Descriptions.FirstOrDefault(t => t.Language == languageCode && t.Document == doc);

            if (descirpiton == null || descirpiton.MFilesDocument == targetDoc)
            {
                if (descirpiton == null)
                {
                    descirpiton = new Description();
                    doc.Descriptions.Add(descirpiton);
                }
                descirpiton.Document       = doc;
                descirpiton.Language       = languageCode;
                descirpiton.LanguageFull   = sourceDoc.Language;
                descirpiton.MFilesDocument = targetDoc;
                descirpiton.Value          = sourceDoc.Description;
            }


            var file          = sourceDoc.File;
            var repositoryUrl = vaultDetails[sourceDoc.VaultName].Url ?? "";


            var targetFile = ctx.Files.FirstOrDefault(f => f.FileId == targetDoc.Guid);

            if (targetFile == null)
            {
                targetFile = new File();
                doc.Files.Add(targetFile);
            }
            targetFile.Document       = doc;
            targetFile.MFilesDocument = targetDoc;
            targetFile.Language       = languageCode;
            targetFile.LanguageFull   = sourceDoc.Language;
            targetFile.Name           = file.Name;
            targetFile.Extension      = file.Extension.ToLower();
            targetFile.Size           = file.Size;
            targetFile.MimeType       = Mime.Lookup(file.Name + "." + file.Extension.ToLower());
            targetFile.Url            = file.GetUrl(repositoryUrl);
            targetFile.ThumbnailUrl   = thumbnailsUrlPattern.Replace("{vault}", sourceDoc.VaultName)
                                        .Replace("{file}", $"{targetFile.Name}.{targetFile.Extension}");


            using (var trans = ctx.Database.BeginTransaction())
            {
                try
                {
                    ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    ClassLogger.Error(ex);
                    throw;
                }
            }

            return(targetDoc);
        }