public FileOutput Read(string fileKey) { var file = _repository.GetAll(e => e.FileKey == fileKey).FirstOrDefault(); if (file == null) { throw new EntityNotFoundException <string>("fileKey", typeof(File)); } var fileOutput = file.MapTo <FileOutput>(); fileOutput.Stream = _fileOperation.Read(file.Id); return(fileOutput); }
static void FileSystemExample() { /* * Let's assume some path and file: */ var path = "C:/Temp/FSTest"; var file = "test.txt"; if (Directory.Exists(path)) { Directory.Delete(path, true); Directory.CreateDirectory(path); } /* * Let's check that FileOperation works properly */ Console.WriteLine("Firstly we check the FileOperation class"); FS = new FileOperation(); Console.WriteLine("\tIs File Removed: {0}", FS.IsRemoved(path, file)); FS.Create(path, file); FS.Append(path, file, new List <string>() { "Top-Level: Foo", "Top-Level: Bar" }); Console.WriteLine("\tContents of FileOperation FS file:"); foreach (var line in FS.Read(path, file)) { Console.WriteLine("\t\t{0}", line); } Console.WriteLine("Press enter to continue:"); Console.ReadLine(); /* * Now let's check the Proxy on the layer some_layer */ Console.WriteLine("Now let's check the Proxy on the layer some_layer"); FSProxy = new ProxyFileOperation(new FileOperation(), "some_layer"); FSProxy.Create(path, file); FSProxy.Append(path, file, new List <string>() { "SOME_LAYER - Yup" }); Console.WriteLine("\tContents of ProxyOperation FS file (some_layer):"); foreach (var line in FSProxy.Read(path, file)) { Console.WriteLine("\t\t{0}", line); } Console.WriteLine("Press enter to continue:"); Console.ReadLine(); /* * Now let's check the Proxy on the layer layer */ Console.WriteLine("Now let's check the Proxy on the layer mindfcuk"); FSProxy = new ProxyFileOperation(new FileOperation(), "mindfcuk"); FSProxy.Create(path, file); FSProxy.Append(path, file, new List <string>() { "mindfcuk - ORly?" }); Console.WriteLine("\tContents of ProxyOperation FS file (mindfcuk):"); foreach (var line in FSProxy.Read(path, file)) { Console.WriteLine("\t\t{0}", line); } Console.WriteLine("Should we delete the file (1) or not (0)"); var input = Console.ReadLine(); if ("1".Equals(input)) { FSProxy.Delete(path, file); } Console.WriteLine("And now let's delete the contents of file. Is it removed: {0}", FSProxy.IsRemoved(path, file)); Console.WriteLine("Press enter to continue:"); Console.ReadLine(); /* * Absurd level */ Console.WriteLine("Absurd level: Proxy of Proxy:"); FSProxy = new ProxyFileOperation(new ProxyFileOperation(new FileOperation(), "mindfcuk"), "inception"); FSProxy.Append(path, file, new List <string>() { "Inception - How is it possible", "Inception - Seriously?" }); Console.WriteLine("\tContents of ProxyProxy FS file (inception)"); foreach (var line in FSProxy.Read(path, file)) { Console.WriteLine("\t\t{0}", line); } }