private void loadDynamicAssemblies(List <PluginAssemblyContainer> pluginAssemblies, string baseFolder, string currentFolder) { foreach (string fileName in Directory.GetFiles(currentFolder).Where(f => SupportedFileExtensions.Contains(Path.GetExtension(f)))) { pluginAssemblies.Add(compileAssembly("~" + fileName.Replace(baseFolder, "").Replace("\\", "/"), null)); } foreach (string directoryName in Directory.GetDirectories(currentFolder)) { loadDynamicAssemblies(pluginAssemblies, baseFolder, directoryName); } }
public static string ReadFile(string filepath, bool isEncrypted = false, string userPassword = null) { SupportedFileExtensions fileExtension; try { SupportedFileExtensions.TryParse(Path.GetExtension(filepath).TrimStart('.'), true, out fileExtension); } catch (Exception) { Console.WriteLine("File fileExtension not supported"); throw new ArgumentException($"File Extension not supported : {Path.GetFileName(filepath)}"); } //Encryption var text = isEncrypted ? Decrypt(File.ReadAllText(filepath)) : File.ReadAllText(filepath); //Access Rights var isAdmin = !string.IsNullOrWhiteSpace(userPassword) && userPassword == _adminPassword; if (_adminRestrictedFiles.Contains(Path.GetFileNameWithoutExtension(filepath)) && !isAdmin) { return("Insufficient permissions"); } switch (fileExtension) { case SupportedFileExtensions.txt: return(text); case SupportedFileExtensions.xml: return(ReadXml(text)); case SupportedFileExtensions.json: return(ReadJson(text)); default: throw new ArgumentOutOfRangeException(); } }
public void ExportCurrentSelection() { if (string.IsNullOrEmpty(OpenedFileName)) { return; } FFMpegExporter exporter = new FFMpegExporter(); string targetFileName = exporter.GenerateFileName(OpenedFileName, ExportFilePath); SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = $"Video files |{string.Join("; ", SupportedFileExtensions.Select(ext => $"*.{ ext}"))}|All files |*.*", FileName = targetFileName, DefaultExt = Path.GetExtension(targetFileName), }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { IsExporting = true; Task exportTask = exporter.ExportAsync(OpenedFileName, saveFileDialog.FileName, SliceStart, SliceEnd, CancellationToken.None, this); exportTask.ContinueWith((task) => { IsExporting = false; ExportProgress = 0; // Reset the progress bar if (task.IsFaulted) { App.DisplayUnexpectedError(task.Exception); MessageBox.Show(task.Exception.ToString(), (string)System.Windows.Application.Current.Resources["ErrorDialogTitle"]); } }, TaskScheduler.FromCurrentSynchronizationContext()); ExportFilePath = Path.GetDirectoryName(saveFileDialog.FileName); } }
// moved method to a separate class since overriding [Authorize] attribute of base class was not working? // [AllowAnonymous] // [HttpGet] // [Route("download")] // public IActionResult DownloadFile(int id) { // Filespec ent = Logic.GetById(id, true); // string mimeType = GetMimeTypeByFilename(ent.Filename); // return File(ent.Filecontent, mimeType); // } #region helper // private string GetMimeTypeByFilename(string fileName) // { // var provider = new FileExtensionContentTypeProvider(); // string contentType; // if(!provider.TryGetContentType(fileName, out contentType)) // { // contentType = "application/octet-stream"; // } // return contentType; // } private bool FileIsSupported(string fileName) { string ext = Path.GetExtension(fileName).TrimStart('.'); return(SupportedFileExtensions.Contains(ext)); }
/// <summary> /// 是否为支持的文件扩展名。 /// </summary> /// <param name="extension">给定的文件扩展名。</param> /// <returns>返回布尔值。</returns> public bool IsSupportedFileExtension(string extension) #pragma warning disable CS8629 // 可为 null 的值类型可为 null。 => (bool)SupportedFileExtensions?.Split(',').Contains(extension);