private void Init() { this.exportEntities = new Multimap <string, ExportEntity>(); this.dotNetLibs = new List <string>(); this.projectReferenceToGuid = new Dictionary <string, string>(); ExportEntity entity; foreach (Dictionary <string, string> instruction in this.GetResourceCopyInstructions()) { string command = instruction["TYPE"]; switch (command) { case "COPY_CODE": this.EnsureInstructionContainsAttribute(command, instruction, "target"); this.EnsureInstructionContainsAttribute(command, instruction, "value"); entity = new ExportEntity() { FileOutput = new FileOutput() { Type = FileOutputType.Text, TextContent = instruction["value"], }, }; entity.Values["target"] = instruction["target"]; this.exportEntities.Add("COPY_CODE", entity); break; case "EMBED_CODE": this.EnsureInstructionContainsAttribute(command, instruction, "value"); entity = new ExportEntity() { Value = instruction["value"], }; this.exportEntities.Add("EMBED_CODE", entity); break; case "DOTNET_LIB": this.EnsureInstructionContainsAttribute(command, instruction, "name"); string dotNetLib = instruction["name"]; this.DotNetLibs.Add(dotNetLib); break; case "DOTNET_DLL": this.EnsureInstructionContainsAttribute(command, instruction, "from"); this.EnsureInstructionContainsAttribute(command, instruction, "hintpath"); if (instruction.ContainsKey("to")) { throw new InvalidOperationException( "DOTNET_DLL resource types should not use the 'to' field. " + "The destination is automatically determined by the hintpath."); } string from = instruction["from"]; bool isExternalDllSource = from.StartsWith("LIB:"); entity = new ExportEntity(); if (isExternalDllSource) { string[] parts = from.Split(':'); if (parts.Length != 3) { throw new InvalidOperationException("DOTNET_DLL from=LIB: references must contain a library name followed by a ':' followed by the resource path in that library."); } string extLibName = parts[1].Trim(); from = parts[2]; entity.DeferredFileOutputBytesLibraryName = extLibName; entity.DeferredFileOutputBytesLibraryPath = from.Trim(); } else { entity.FileOutput = new FileOutput() { Type = FileOutputType.Binary, BinaryContent = this.library.ReadFileBytes("resources/" + from) }; } entity.Values["hintpath"] = instruction["hintpath"]; foreach (string dllAttr in new string[] { "name", "version", "culture", "token", "architecture", "specificversion" }) { if (instruction.ContainsKey(dllAttr)) { entity.Values[dllAttr] = instruction[dllAttr]; } } this.exportEntities.Add("DOTNET_DLL", entity); break; case "LIB_DLL_REF": this.EnsureInstructionContainsAttribute(command, instruction, "name"); this.EnsureInstructionContainsAttribute(command, instruction, "version"); string name = instruction["name"]; string version = instruction["version"]; projectReferenceToGuid[name] = IdGenerator.GenerateCSharpGuid(name + "|" + version, "library-project"); break; default: throw new InvalidOperationException("The command '" + command + "' is not recongized in the resource manifest of library: '" + this.library.Name + "'"); } } }
public FileResult Export() { var fileExport = new ExportEntity<Book>(_bookRepository.GetAll(), _booksdocXls); FileInfo info = new FileInfo(fileExport.SaveToPath()); return File(info.OpenRead(), "text/plain", info.Name); }
private void Init() { this.exportEntities = new Multimap <string, ExportEntity>(); ExportEntity entity; foreach (Dictionary <string, string> instruction in this.GetResourceCopyInstructions()) { string command = instruction["TYPE"]; switch (command) { case "COPY_CODE": this.EnsureInstructionContainsAttribute(command, instruction, "target"); this.EnsureInstructionContainsAttribute(command, instruction, "value"); entity = new ExportEntity() { FileOutput = new FileOutput() { Type = FileOutputType.Text, TextContent = instruction["value"], }, }; entity.Values["target"] = instruction["target"]; this.exportEntities.Add("COPY_CODE", entity); break; case "EMBED_CODE": this.EnsureInstructionContainsAttribute(command, instruction, "value"); entity = new ExportEntity() { Value = instruction["value"], }; this.exportEntities.Add("EMBED_CODE", entity); break; case "DOTNET_REF": this.EnsureInstructionContainsAttribute(command, instruction, "name"); entity = new ExportEntity() { Type = "DOTNET_REF", Value = instruction["name"], }; this.exportEntities.Add("DOTNET_REF", entity); break; case "DOTNET_DLL": this.EnsureInstructionContainsAttribute(command, instruction, "from"); this.EnsureInstructionContainsAttribute(command, instruction, "hintpath"); if (instruction.ContainsKey("to")) { throw new InvalidOperationException( "DOTNET_DLL resource types should not use the 'to' field. " + "The destination is automatically determined by the hintpath."); } string from = instruction["from"]; entity = new ExportEntity(); entity.FileOutput = new FileOutput() { Type = FileOutputType.Binary, BinaryContent = this.library.Metadata.ReadFileBytes("native/" + from) }; entity.Values["hintpath"] = instruction["hintpath"]; foreach (string dllAttr in new string[] { "name", "version", "culture", "token", "architecture", "specificversion" }) { if (instruction.ContainsKey(dllAttr)) { entity.Values[dllAttr] = instruction[dllAttr]; } } this.exportEntities.Add("DOTNET_DLL", entity); break; default: throw new InvalidOperationException("The command '" + command + "' is not recongized in the resource manifest of library: '" + this.library.Metadata.ID + "'"); } } }