예제 #1
0
        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);
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
        }
예제 #4
0
        public bool DelDirectory(Credentials c, MachineIdentity mid, DirectoryIdentity did)
        {
            var cl = new Ref.FileSyncModelClient();

            cl.Abort();
            throw new NotImplementedException();
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        // 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);
        }
예제 #7
0
        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);
        }
예제 #8
0
 public bool DelFile(Credentials c, MachineIdentity m, DirectoryIdentity d,
                     FileIdentity f)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public bool DelMachine(Credentials c, MachineIdentity m)
 {
     throw new NotImplementedException();
 }
예제 #10
0
 public FileContents DownloadFile(IFileSyncModel connection, Credentials c,
                                  MachineIdentity m, DirectoryIdentity d, FileIdentity f)
 {
     throw new NotImplementedException();
 }
예제 #11
0
 public bool UploadFile(IFileSyncModel connection, Credentials c, MachineIdentity m,
                        DirectoryIdentity d, FileContents f)
 {
     return(connection.AddFile(c, new MachineContents(m), new DirectoryContents(d), f));
 }