public static void AddDirectory(CredentialsLib c, MachineModel m, DirModel d) { GetDirList(m); int NoSuchNameYet = (from o in m.Directories where o.Name == d.Name select o).Count(); if (NoSuchNameYet != 0) { // throw new Exception("directory with given name already exists"); //no action needed } else { d.Owner = UserManipulator.LoginToId(c.Login); AddDir(d); m.Id = MachManipulator.MachineNameToId(m.Name); AddMachDir(m, d); } }
private static bool CheckFileExistence(MachineModel m, DirModel d, FileModel f) { DirManipulator.GetDirList(m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); try { using (filesyncEntities context = new filesyncEntities()) { (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); }
public static void AddMachine(CredentialsLib c, MachineModel m) { if (MachineNameExists(m.Name)) { throw new Exception("machine with given name already exists"); } else { int user_id = UserManipulator.LoginToId(c.Login); Machine m1 = Machine.CreateMachine(1, user_id, m.Name); m1.machine_description = m.Description; using (filesyncEntities context = new filesyncEntities()) { context.Machines.AddObject(m1); context.SaveChanges(); } } }
public static void GetMachineList(UserModel user) { List <MachineModel> machinelist = new List <MachineModel>(); user.Id = UserManipulator.LoginToId(user.Login); using (filesyncEntities context = new filesyncEntities()) { List <Machine> ml = (from o in context.Machines where o.user_id == user.Id select o).ToList(); foreach (Machine m in ml) { MachineModel m1 = new MachineModel(m.machine_name, m.machine_description); m1.Id = m.machine_id; m1.User = m.user_id; machinelist.Add(m1); } user.Machines = machinelist; } }
public static void GetDirList(MachineModel m) { int mach_id = MachManipulator.MachineNameToId(m.Name); List <DirModel> dirlist = new List <DirModel>(); using (filesyncEntities context = new filesyncEntities()) { foreach (var x in (from md in context.MachineDirs join d in context.Dirs on md.dir_id equals d.dir_id where md.machine_id == mach_id select new { md.dir_realpath, d })) { DirModel dir = new DirModel(x.d.dir_name, x.d.dir_description, x.dir_realpath); dir.Id = x.d.dir_id; dir.Owner = x.d.user_ownerid; dirlist.Add(dir); } m.Directories = dirlist; } }
public static void GetFileList(CredentialsLib c, MachineModel m, DirModel d) { List <FileModel> filelist = new List <FileModel>(); DirManipulator.GetDirList(m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); using (filesyncEntities context = new filesyncEntities()) { foreach (var x in (from f in context.Files join t in context.Types on f.type_id equals t.type_id where f.dir_id == d.Id select new { f, t.type_name })) { FileModel file = new FileModel(x.f.file_name, x.f.file_size, x.f.file_hash, x.type_name, x.f.file_uploaded, x.f.file_modified); file.Content = x.f.content_id; file.Id = x.f.file_id; filelist.Add(file); } } d.Files = filelist; }
public static void AddFile(CredentialsLib c, MachineModel m, DirModel d, FileModel f) { DirManipulator.GetDirList(m); f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); if (!CheckFileExistence(m, d, f)) { AddFileContent(f); TypeManipulator.TypeToId(f); File f1 = File.CreateFile(1, f.Dir, f.Type, f.Content, f.Name, f.Size, f.Hash, f.Uploaded, f.Modified); using (filesyncEntities context = new filesyncEntities()) { context.Files.AddObject(f1); context.SaveChanges(); } } else { GetFileId(m, d, f); GetFileContentId(m, d, f); UpdateFileContent(f); TypeManipulator.TypeToId(f); using (filesyncEntities context = new filesyncEntities()) { 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(); } } }
public static void ChangeMachineDetails(CredentialsLib c, MachineModel newMachine, MachineModel oldMachine) { oldMachine.Id = MachineNameToId(oldMachine.Name); using (filesyncEntities context = new filesyncEntities()) { Machine m1 = (from o in context.Machines where o.machine_id == oldMachine.Id select o).Single(); m1.machine_name = newMachine.Name; m1.machine_description = newMachine.Description; context.SaveChanges(); } }
public static void AddMachine(CredentialsLib c, MachineModel m) { // }
public static void GetFileContent(CredentialsLib c, MachineModel m, DirModel d, FileModel f) { // }
public static void GetFileList(CredentialsLib c, MachineModel m, DirModel d) { //es= filelist; }
public static void AddFile(CredentialsLib c, MachineModel m, DirModel d, FileModel f) { // }
public static void ChangeMachineDetails(CredentialsLib c, MachineModel newMachine, MachineModel oldMachine) { // }
public static void GetDirList(MachineModel m) { // }
public static void AddDirectory(CredentialsLib c, MachineModel m, DirModel d) { // }