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 void CreateAccountTest() { Credentials c = new Credentials("testUserLogin", Security.ComputeHash("testUserPass")); UserContents uc = new UserContents(c, "Test User", "*****@*****.**"); guiConn.AddUser(uc); Assert.AreEqual(guiConn.GetUser(c), uc); }
public MachineWindow(MainWindow mw) : this() { this.parentWindow = mw; this.credentials = parentWindow.credentials; RefreshMachinesList(); }
public bool AddDirectory(Credentials c, MachineContents m, DirectoryContents d) { var cl = new Ref.FileSyncModelClient(); try { bool result = false; result = cl.AddDirectory(c, m, d); cl.Close(); return result; } catch (Exception ex) { cl.Abort(); throw new ActionException("Unable to create a new directory in the database.", ActionType.Directory, MemeType.Fuuuuu, ex); } }
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 AddMachine(Credentials c, MachineContents m) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (MachineNameExists(context, m.Name)) { //throw new Exception("machine with given name already exists"); return false; } else { int user_id = LoginToId(context, c.Login); Machine m1 = Machine.CreateMachine(1, user_id, m.Name); m1.machine_description = m.Description; context.Machines.AddObject(m1); context.SaveChanges(); } } return true; }
public bool AddMachine(Credentials c, MachineContents m) { var cl = new Ref.FileSyncModelClient(); try { if (c == null) throw new ArgumentNullException("cr", "user credentials must be provided"); if (m == null) throw new ArgumentNullException("m", "machine contents were null"); bool result = false; result = cl.AddMachine(c, m); cl.Close(); return result; } catch (Exception ex) { cl.Abort(); throw new ActionException("Failed to create a new machine.", ActionType.Machine, MemeType.Fuuuuu, ex); } }
public bool AddDirectory(Credentials c, MachineContents m, DirectoryContents d) { m.Directories=GetDirList(c, 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 { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { d.Owner = LoginToId(context, c.Login); } AddDir(d); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { m.Id = MachineNameToId(context, m.Name); } AddMachDir(m, d); } return true; }
public MachineContents DownloadMachine(IFileSyncModel connection, Credentials c, MachineIdentity mid) { var m = connection.GetMachineWithDirs(c, mid); if (m == null) return null; List<DirectoryContents> directories = new List<DirectoryContents>(); foreach (DirectoryIdentity did in m.Directories) { var d = connection.GetDirectoryWithFiles(c, m, did); List<FileContents> files = new List<FileContents>(); foreach (FileIdentity fid in d.Files) { var f = connection.GetFileWithContent(c, m, d, fid); files.Add(f); } d.Files = files; directories.Add(d); } m.Directories = directories; return m; }
public bool ChangeMachineDetails(Credentials c, MachineContents newM, MachineContents oldM) { var cl = new Ref.FileSyncModelClient(); try { if (c == null) throw new ArgumentNullException("c", "user credentials must be provided"); if (newM == null) throw new ArgumentNullException("newM", "new machine identity must be provided"); if (oldM == null) throw new ArgumentNullException("oldM", "old machine identity must be provided"); bool result = false; result = cl.ChangeMachineDetails(c, newM, oldM); cl.Close(); return result; } catch (Exception ex) { cl.Abort(); throw new ActionException("Error while updating machine details.", ActionType.Machine, MemeType.Fuuuuu, ex); } }
private Credentials getCredentials() { var cr = new Credentials(this.getLogin(), Security.ComputeHash(this.UserPassword.Password)); return cr; }
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 Authenticate(filesyncEntitiesNew context, Credentials c) { try { //User u1 = (from u in context.Users // where c.Equals(u.user_login, u.user_pass) // select u).Single(); User u1 = (from u in context.Users where c.Login == u.user_login && c.Password == u.user_pass select u).Single(); } catch { return false; } return true; }
public bool Login(Credentials c) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { //try { //User u1 = (from u in context.Users // where c.Equals(u.user_login, u.user_pass) // select u).Single(); User u1 = context.Users.Where(u => u.user_login == c.Login).SingleOrDefault(); if (u1 == null) { return false; } //(from u in context.Users // where c.Login == u.user_login && c.Password == u.user_pass // select u).Single(); if (!c.Equals(u1.user_login, u1.user_pass)) return false; UpdateLastLogin(context, LoginToId(context, c.Login)); //} catch (Exception ex) { //if (ex.GetType().Equals(typeof(Exception))) // throw ex; //throw new Exception("wrong credentials", ex); //} return true; } }
public UserIdentity GetUser(Credentials c) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (LoginExists(context, c.Login)) { if (Authenticate(context, c)) { int id = LoginToId(context, c.Login); User u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); UserIdentity u = new UserContents(u1.user_login, u1.user_pass, u1.user_fullname, u1.user_email); u.LastLogin = (DateTime)u1.user_lastlogin; u.Id = u1.user_id; return u; } else { //throw new Exception("wrong password"); return null; } } else { //throw new Exception("no such user"); return null; } } }
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) { 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 UploadDirectory(IFileSyncModel connection, Credentials c, MachineIdentity m, DirectoryContents d) { //add dir if it does not exist if (!connection.AddDirectory(c, new MachineContents(m), d)) return false; foreach (FileContents f in d.Files) { try { FileContents fUp = null; if (f.Size == 0) fUp = ReadFileContents(f, d); else fUp = f; if (!UploadFile(connection, c, m, d, f)) return false; } catch (ActionException ex) { throw new ActionException("Couldn't upload the directory contents.", ActionType.Directory, ex); } catch (Exception ex) { throw new ActionException("Error while uploading a directory.", ActionType.Directory, ex); } } return true; }
public bool UpdateMachine(IFileSyncModel connection, Credentials c, MachineContents newM, MachineContents oldM) { throw new NotImplementedException(); }
public void AddMachine(Credentials c, MachineContents m) { throw new Exception("not implemented"); }
public void ChangeMachineDetails(Credentials c, MachineContents newM, MachineContents oldM) { throw new Exception("not implemented"); }
public void GetDirList(Credentials c, MachineContents m) { throw new Exception("not implemented"); }
public void AddDirectory(Credentials c, MachineContents m, DirectoryContents d) { throw new Exception("not implemented"); }
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 void DelUser(Credentials c) { throw new Exception("not implemented"); }
public bool UploadMachine(IFileSyncModel connection, Credentials c, MachineContents m) { try { foreach (DirectoryContents d in m.Directories) { if (!UploadDirectory(connection, c, m, d)) return false; } return true; } catch (ActionException ex) { throw new ActionException("Couldn't upload the machine contents." , ActionType.Machine, ex); } catch (Exception ex) { throw new ActionException("Error while uploading a whole machine.", ActionType.Machine, ex); } }
public List<FileContents> GetFileList(Credentials c, MachineContents m, DirectoryContents d) { List<FileContents> filelist = new List<FileContents>(); m.Directories=GetDirList(c, m); d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single(); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { 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 })) { FileIdentity file = new FileIdentity(x.f.file_name, x.f.file_modified, x.f.file_uploaded, FileType.PlainText, x.f.file_size, x.f.file_hash); file.Content = x.f.content_id; file.Id = x.f.file_id; filelist.Add(new FileContents(file)); } } //d.Files = filelist; return filelist; }
public FileContents DownloadFile(IFileSyncModel connection, Credentials c, MachineIdentity m, DirectoryIdentity d, FileIdentity f) { throw new NotImplementedException(); }
public MachineContents GetMachineWithDirs(Credentials c, MachineIdentity m) { MachineContents mc = new MachineContents(m); using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { int mach_id = MachineNameToId(context, m.Name); if (mach_id == -1) return null; mc.Id = mach_id; List<DirectoryContents> dirlist = new List<DirectoryContents>(); 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 })) { var dir = new DirectoryContents(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); } mc.Directories = dirlist; return mc; } }
public void Login(Credentials c) { throw new Exception("not implemented"); }
public UserContents GetUserWithMachines(Credentials c) { UserContents u =(UserContents) GetUser(c); List<Machine> ml; List<MachineContents> machinelist; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (!Authenticate(context, c)) return null; //throw new Exception("unauthorized access detected"); machinelist = new List<MachineContents>(); u.Id = LoginToId(context, u.Login); ml = (from o in context.Machines where o.user_id == u.Id select o).ToList(); } foreach (Machine m in ml) { MachineContents m1 = new MachineContents(m.machine_name, m.machine_description); m1.Id = m.machine_id; m1.User = m.user_id; machinelist.Add(m1); } u.Machines = machinelist; return u; }
public bool ChangeMachineDetails(Credentials c, MachineContents newM, MachineContents oldM) { using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { oldM.Id = MachineNameToId(context, oldM.Name); Machine m1 = (from o in context.Machines where o.machine_id == oldM.Id select o).SingleOrDefault(); if (m1 == null) return false; m1.machine_name = newM.Name; m1.machine_description = newM.Description; context.SaveChanges(); return true; } }
public void GetMachineList(Credentials c, UserContents u) { throw new Exception("not implemented"); }
public bool DelFile(Credentials c, MachineIdentity m, DirectoryIdentity d, FileIdentity f) { throw new NotImplementedException(); }
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; }
public bool DelMachine(Credentials c, MachineIdentity m) { throw new NotImplementedException(); }
public UserContents GetUser(Credentials c) { throw new Exception("not implemented"); }
public bool DelUser(Credentials c) { UserContents u =(UserContents) GetUser(c); bool result = false; using (filesyncEntitiesNew context = new filesyncEntitiesNew()) { if (!Authenticate(context, c)) return result; int id = LoginToId(context, u.Login); var u1 = (from o in context.Users where o.user_id == id select o).SingleOrDefault(); if (u1 != null) { context.Users.DeleteObject(u1); context.SaveChanges(); result = true; } } return result; }
public void AddUser(Credentials c, UserContents u) { throw new Exception("not implemented"); }
public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d, FileContents f) { throw new Exception("not implemented"); }