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 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 Task <PasswordGeneratedEventArgs> GeneratePasswordAsTask() { Trace.WriteLine("Ran"); var tcs = RegisterAsTask <PasswordGeneratedEventArgs>(ref OnNewPasswordGenerated); var childTask = Task <PasswordGeneratedEventArgs> .Factory.StartNew(() => { Provider.ServerMachine.Identity = MachineIdentity.GetCurrentIdentity(); Provider.ServerMachine.Password = AlphaNumericGenerator.Generate(2, GeneratorOptions.Numeric); Provider.ServerMachine.PasswordHash = HashUtil.ComputeHash(Provider.ServerMachine.Password, HashType.SHA512); var newPasswordEventArgs = new PasswordGeneratedEventArgs { NewPassword = Provider.ServerMachine.Password }; if (OnNewPasswordGenerated != null) { OnNewPasswordGenerated(this, newPasswordEventArgs); } return(newPasswordEventArgs); }, TaskCreationOptions.AttachedToParent); return(tcs.Task); }
public bool DelDirectory(Credentials c, MachineIdentity mid, DirectoryIdentity did) { var cl = new Ref.FileSyncModelClient(); cl.Abort(); throw new NotImplementedException(); }
public MachineContents GetMachineWithDirs(Credentials c, MachineIdentity mid) { var cl = new Ref.FileSyncModelClient(); try { if (c == null) { throw new ArgumentNullException("c", "user credentials must be provided"); } if (mid == null) { throw new ArgumentNullException("mid", "machine identity was null"); } MachineContents newM = new MachineContents(mid); newM.Directories = cl.GetDirList(c, newM); cl.Close(); if (newM == null) { throw new ActionException("Received a null object.", ActionType.User); } return(newM); //MachineContents m = null; //m = cl.GetMachineWithDirs(c, mid); //cl.Close(); //return m; } catch (Exception ex) { cl.Abort(); throw new ActionException("Unable to get list of directories belonging " + "to the machine.", ActionType.Machine, ex); } }
// TODO: Redo this public Task <IntroducerIntroductionCompletedEventArgs> RequestIntroductionAsTask(string novaId, string password) { var tcs = RegisterAsTask <IntroducerIntroductionCompletedEventArgs>(ref OnIntroductionCompleted); var childTask = Task.Factory.StartNew(() => { var clientMachine = new Machine { Identity = MachineIdentity.GetCurrentIdentity(), PrivateEndPoint = Network.GetInternalEndPoint() }; var serverMachine = new Machine { NovaId = novaId, PasswordHash = HashUtil.ComputeHash(password, HashType.SHA512) }; Network.SendUnconnectedMessage(new RequestIntroducerIntroductionMessage { ClientMachine = clientMachine, ServerMachine = serverMachine }, Config.GetIPEndPoint("IntroducerEndPoint")); }, TaskCreationOptions.AttachedToParent); return(tcs.Task); }
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 DelFile(Credentials c, MachineIdentity m, DirectoryIdentity d, FileIdentity f) { throw new NotImplementedException(); }
public bool DelMachine(Credentials c, MachineIdentity m) { throw new NotImplementedException(); }
public FileContents DownloadFile(IFileSyncModel connection, Credentials c, MachineIdentity m, DirectoryIdentity d, FileIdentity f) { 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)); }