Example #1
0
 public void CreateFile(File file)
 {
     var proj = _context.Projects.FirstOrDefault(e => e.Id == file.ProjectId);
     if (proj == null)
     {
         throw new ArgumentNullException("file");
     }
     var fileCopy = GetFileCopy(proj, file);
     var dirPath = Path.GetDirectoryName(fileCopy);
     if (dirPath == null)
     {
         throw new InvalidDataException("dir path");
     }
     if (!Directory.Exists(dirPath))
     {
         Directory.CreateDirectory(dirPath);
     }
     using (var createdFile = new StreamReader(new FileStream(file.FileNameWithPath, FileMode.Open)))
     {
         using (var copyFile = new StreamWriter(new FileStream(fileCopy, FileMode.Create)))
         {
             copyFile.Write(createdFile);
             copyFile.Flush();
         }
     }
 }
Example #2
0
 public byte[] GetFileAsByteArray(File file)
 {
     if (file == null)
     {
         throw new ArgumentNullException("file");
     }
     using (var currFile = new FileStream(file.FileNameWithPath, FileMode.Open))
     {
         var fileLength = currFile.Length;
         var fileInBytes = new byte[fileLength];
         long readed = 0;
         while (readed < fileLength)
         {
             readed += currFile.Read(fileInBytes, (int) readed, (int) (fileLength - readed));
         }
         return fileInBytes;
     }
 }
Example #3
0
 public byte[] GetPatch(File file)
 {
     //List<Patch> patches;
     //string currAsString;
     try
     {
         var project = _context.Projects.FirstOrDefault(e => e.Id == file.ProjectId);
         if (project == null)
         {
             throw new ArgumentNullException("file");
         }
         byte[] curFile;
         using (var currentFile = new FileStream(file.FileNameWithPath, FileMode.Open))
         {
             var fileLength = currentFile.Length;
             curFile = new byte[currentFile.Length];
             long readed = 0;
             while (readed < fileLength)
             {
                 readed += currentFile.Read(curFile, (int) readed, (int) (fileLength - readed));
             }
         }
         using (var prevFile = new FileStream(GetFileCopy(project, file), FileMode.Create))
         {
             prevFile.Write(curFile, 0, curFile.Length);
             prevFile.Flush();
         }
         return curFile;
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Example #4
0
 public void FileRenamed(File file)
 {
 }
Example #5
0
 private string GetFileCopy(Project project, File file)
 {
     if (project == null)
     {
         throw new ArgumentNullException("project");
     }
     if (file == null)
     {
         throw new ArgumentNullException("file");
     }
     return string.Format("{0}\\{1}\\{2}", project.ProjectDirectoryPath, GH_FOLDER,
         file.Id);
 }
Example #6
0
 public void RemoveFile(File file)
 {
     try
     {
         var project = _context.Projects.FirstOrDefault(e => e.Id == file.ProjectId);
         System.IO.File.Delete(GetFileCopy(project, file));
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }