public bool AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { m.Directories = GetDirList(c, m); f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); if (!CheckFileExistence(c, m, d, f)) { AddFileContent(f); //TypeManipulator.TypeToId(f); File f1 = File.CreateFile(1, f.Dir, 1, f.Content, f.Name, f.Size, f.Hash, f.Uploaded, f.Modified); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Files.AddObject(f1); context.SaveChanges(); } } else { GetFileId(c, m, d, f); GetFileContentId(c, m, d, f); UpdateFileContent(f); //TypeManipulator.TypeToId(f); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { File f1 = (from o in context.Files where o.file_id == f.Id select o).Single(); f1.file_hash = f.Hash; f1.file_modified = f.Modified; f1.file_size = f.Size; f1.file_uploaded = f.Uploaded; context.SaveChanges(); } } return true; }
public bool AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { var cl = new Ref.FileSyncModelClient(); try { bool result = false; result = cl.AddFile(c, m, d, f); cl.Close(); return result; } catch (Exception ex) { cl.Abort(); throw new ActionException("Error occurred while file was uploaded.", ActionType.File, MemeType.Fuuuuu, ex); } }
public bool AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { throw new NotImplementedException(); }
private void GetFileId(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { GetDirList(c, m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { int file_id = (from o in context.Files where (o.file_name == f.Name) && (o.dir_id == d.Id) select o.file_id).Single(); f.Id = file_id; } }
private bool CheckFileExistence(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { GetDirList(c, m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); try { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { (from o in context.Files where (o.file_name == f.Name) && (o.dir_id == d.Id) select o.file_id).Single(); } } catch { return false; } return true; }
private void AddFileContent(FileContents f) { int AddedContentId; Content f1 = Content.CreateContent(1, f.Data); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { context.Contents.AddObject(f1); context.SaveChanges(); AddedContentId = (from c in context.Contents select c).ToList().Last().content_id; } f.Content = AddedContentId; }
private static void UpdateFileContent(FileContents f) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); c1.content_data = f.Data; context.SaveChanges(); } }
private static int FileComparison(FileContents x, FileContents y) { int nameComparison = x.Name.CompareTo(y.Name); if (nameComparison != 0) return nameComparison; int modifiedComparison = x.Modified.CompareTo(y.Modified); if (modifiedComparison != 0) return modifiedComparison; int sizeComparison = x.Size.CompareTo(y.Size); if (sizeComparison != 0) return sizeComparison * (-1); int hashComparison = x.Hash.CompareTo(y.Hash); if (hashComparison != 0) return hashComparison; return 0; }
public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { f.Id = GetFileContentId(c, m, d, f); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); f.Data = c1.content_data; } }
public bool SaveFile(FileContents f, DirectoryIdentity d) { throw new NotImplementedException(); }
public bool UploadFile(IFileSyncModel connection, Credentials c, MachineIdentity m, DirectoryIdentity d, FileContents f) { return connection.AddFile(c, new MachineContents(m), new DirectoryContents(d), f); }
public bool SaveFile(FileContents f, string localPath) { throw new NotImplementedException(); }
public MachineContents ReadMachineContents(MachineContents m, bool addFilesContents = false) { if (m.Directories == null || m.Directories.Count == 0) return m; foreach (DirectoryContents d in m.Directories) { if (d.LocalPath == null || d.LocalPath.Equals(EmptyLocalPath)) return null; string[] filePaths = Directory.GetFiles(d.LocalPath); if (filePaths == null || filePaths.Length == 0) return null; if (d.Files == null) d.Files = new List<FileContents>(); foreach (string path in filePaths) { FileContents file; if (addFilesContents) file = ReadFileContents(path); else file = new FileContents(ReadFileMetadata(path)); d.Files.Add(file); } RemoveDuplicateFiles(d); } return m; }
public FileContents ReadFileContents(string localPath) { if (localPath == null) throw new ActionException("No file path was provided.", ActionType.File, MemeType.Fuuuuu); FileIdentity fid = ReadFileMetadata(localPath); string contents = String.Empty; try { StreamReader reader = new StreamReader(localPath); contents = reader.ReadToEnd(); reader.Close(); } catch (Exception ex) { throw new ActionException("Error while reading file data from disk. " + "File path was: '" + localPath + "'.", ActionType.File, ex); } FileContents f = new FileContents(fid, contents); return f; }
public FileContents(FileContents fc) : this(fc.Name, fc.Modified, fc.Contents, fc.Uploaded, fc.Type, fc.Size, fc.Hash) { //nothing needed here }
public FileContents GetFileWithContent(Credentials c, MachineContents m, DirectoryContents d, FileIdentity f) { var fc = new FileContents(f); GetFileContentId(c, m, d, fc); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { Content c1 = (from o in context.Contents where o.content_id == f.Content select o).Single(); fc.Data = c1.content_data; } return fc; }
public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { throw new Exception("not implemented"); }