コード例 #1
0
        private void buttonCreateSubmit_Click(object sender, RoutedEventArgs e)
        {
            Credentials     c = this.getCredentials();
            MachineContents m = this.getMachine();

            try {
                Ref.AddUser(c, this.getUser());

                this.DialogResult = true;
                //MessageBox.Show("User was created!");

                Ref.Login(c);
                Ref.AddMachine(c, m);

                parentWindow.credentials = c;
                Ref.GetDirList(c, m);
                //parentWindow.machine = new MachineContents(c, id, false, false, true);
                Ref.AddLocalDirs(m);
                //MachineActions.GetContets(c, id);

                //MessageBox.Show("Machine was created!");
                this.Close();
            } catch (ActionException ex) {
                new SystemMessage(ex).ShowDialog();
            }
        }
コード例 #2
0
        public void AddLocalDirs(MachineContents m, bool addLocalFiles = true)
        {
            if (addLocalFiles)
            {
                foreach (DirectoryContents d in m.Directories)
                {
                    if (d.LocalPath == null || d.LocalPath.Equals(EmptyLocalPath))
                    {
                        return;
                    }

                    string[] filePaths = Directory.GetFiles(d.LocalPath);

                    if (filePaths == null || filePaths.Length == 0)
                    {
                        return;
                    }

                    if (d.Files == null)
                    {
                        d.Files = new List <FileContents>();
                    }

                    foreach (string path in filePaths)
                    {
                        d.Files.Add(GetLocalFileContent(path));
                    }
                }
            }
        }
コード例 #3
0
        public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m,
                                                       DirectoryIdentity did)
        {
            var cl = new Ref.FileSyncModelClient();

            try {
                DirectoryContents newD = new DirectoryContents(did);
                newD.Files = cl.GetFileList(c, m, newD);
                cl.Close();
                if (newD == null)
                {
                    throw new ActionException("Received a null object.", ActionType.User);
                }
                return(newD);

                //DirectoryContents d = null;
                //d = cl.GetDirectoryWithFiles(c, m, did);
                //cl.Close();
                //return d;
            } catch (ActionException ex) {
                cl.Abort();
                throw new ActionException("Unable to download directory contents.",
                                          ActionType.Directory, MemeType.Fuuuuu, ex);
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Error while downloading directory contents.",
                                          ActionType.Directory, MemeType.Fuuuuu, ex);
            }
        }
コード例 #4
0
        private void optionDownloadMachine_Click(object sender, RoutedEventArgs e)
        {
            try {
                machine = new MachineContents(credentials, machine, true, true, true);
                //MachineActions.GetContets(credentials, machine.Identity);

                RefreshDisplayedMachineInfo();

                if (machine.SaveToDisk())
                {
                    new SystemMessage("FileSync", "File sync complete.",
                                      "All directories defined in this machine were downloaded and restored.",
                                      MemeType.FuckYea).ShowDialog();
                }

                //foreach (DirIdentity did in machine.Directories) {
                //    var files = DirActions.Download(credentials, machine.Identity, did);
                //    foreach (FileContents f in files)
                //        f.SaveToDisk(did);
                //}

                //MessageBox.Show("Directories restored.", "FileSync",
                //    MessageBoxButton.OK, MessageBoxImage.Information);
            } catch (ActionException ex) {
                new SystemMessage(ex).ShowDialog();
                //MessageBox.Show(ex.Message, ex.Title);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
ファイル: LoginWindow.xaml.cs プロジェクト: mbdevpl/FileSync
        private MachineContents getMachine()
        {
            MachineContents m = new MachineContents(this.MachineName.Text,
                                                    this.MachineDescription.Text);

            return(m);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m, DirectoryIdentity 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();
            var dc = new DirectoryContents(d);

            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));
                }
            }
            dc.Files = filelist;
            return(dc);
        }
コード例 #9
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);
            }
        }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        public void AddFile(Credentials c, MachineContents m, DirectoryContents d,
                            FileContents f)
        {
            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 (filesyncEntities context = new filesyncEntities()) {
                    context.Files.AddObject(f1);
                    context.SaveChanges();
                }
            }
            else
            {
                GetFileId(c, m, d, f);
                GetFileContentId(c, 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();
                }
            }
        }
コード例 #12
0
        private void buttonLogout_Click(object sender, RoutedEventArgs e)
        {
            LoggedIn = false;

            credentials = null;
            user        = null;
            machine     = null;
        }
コード例 #13
0
        private MachineContents getMachine()
        {
            MachineContents m = new MachineContents();

            m.Name        = this.MachineName.Text;
            m.Description = this.MachineDescription.Text;
            return(m);
        }
コード例 #14
0
        private static void AddMachDir(MachineContents m, DirectoryContents d)
        {
            MachineDir md1 = MachineDir.CreateMachineDir(m.Id, d.Id, d.LocalPath);

            using (filesyncEntitiesNew context = new filesyncEntitiesNew()) {
                context.MachineDirs.AddObject(md1);
                context.SaveChanges();
            }
        }
コード例 #15
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;
     }
 }
コード例 #16
0
 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;
     }
 }
コード例 #17
0
 public void ChangeMachineDetails(Credentials c, MachineContents newM,
                                  MachineContents oldM)
 {
     oldM.Id = MachineNameToId(oldM.Name);
     using (filesyncEntities context = new filesyncEntities()) {
         Machine m1 = (from o in context.Machines
                       where o.machine_id == oldM.Id
                       select o).Single();
         m1.machine_name        = newM.Name;
         m1.machine_description = newM.Description;
         context.SaveChanges();
     }
 }
コード例 #18
0
 private int GetFileContentId(Credentials c, MachineContents m, DirectoryContents d,
                              FileContents f)
 {
     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()) {
         int content_id = (from o in context.Files
                           where (o.file_name == f.Name) && (o.dir_id == d.Id)
                           select o.content_id).Single();
         f.Content = content_id;
     }
     return(f.Content);
 }
コード例 #19
0
        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);
            }
        }
コード例 #20
0
        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);
        }
コード例 #21
0
        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);
            }
        }
コード例 #22
0
 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);
 }
コード例 #23
0
ファイル: MainWindow.xaml.cs プロジェクト: mbdevpl/FileSync
        private void buttonCreateSelectMachine_Click(object sender, RoutedEventArgs e)
        {
            if (!LoggedIn)
            {
                return;
            }

            //temporary
            UserContents user = connection.GetUserWithMachines(credentials);

            //new UserContents(credentials, true).Machines;
            // UserActions.GetContents(this.credentials).Machines;
            this.machine = connection.GetMachineWithDirs(credentials, user.Machines[0]);
            //this.machine = user.Machines[0];
            //new MachineContents(credentials, machines[0], true, false, true);
            //MachineActions.GetContets(credentials, machines[0]);
            RefreshDisplayedMachineInfo();
            if (machine != null)
            {
                return;
            }
            //end of temporary

            if (new MachineWindow(this).ShowDialog() == false)
            {
                return;
            }

            if (this.machine == null)
            {
                LoggedInAndChosenMachine = false;
                return;
            }

            RefreshDisplayedMachineInfo();

            try {
                //foreach (DirContents dc in MachineActions.GetDirsContents(credentials, machine))
                //	directories.Add(dc);
                //if (PropertyChanged != null)
                //    PropertyChanged(this, new PropertyChangedEventArgs("Directories"));
            } catch (ActionException ex) {
                MessageBox.Show(ex.Message, ex.Title);
            }

            RefreshDisplayedDirectories();
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        public void AddMachine(Credentials c, MachineContents m)
        {
            if (MachineNameExists(m.Name))
            {
                throw new Exception("machine with given name already exists");
            }
            else
            {
                int     user_id = 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();
                }
            }
        }
コード例 #26
0
        public void AddDirectory(Credentials c, MachineContents m, DirectoryContents d)
        {
            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
            {
                d.Owner = LoginToId(c.Login);
                AddDir(d);
                m.Id = MachineNameToId(m.Name);
                AddMachDir(m, d);
            }
        }
コード例 #27
0
 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);
     }
 }
コード例 #28
0
        public void GetDirList(Credentials c, MachineContents m)
        {
            int mach_id = MachineNameToId(m.Name);
            List <DirectoryContents> dirlist = new List <DirectoryContents>();

            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 }))
                {
                    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);
                }
                m.Directories = dirlist;
            }
        }
コード例 #29
0
        public void GetMachineList(Credentials c, UserContents u)
        {
            List <MachineContents> machinelist = new List <MachineContents>();

            u.Id = LoginToId(u.Login);
            using (filesyncEntities context = new filesyncEntities()) {
                List <Machine> 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;
            }
        }
コード例 #30
0
 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);
     }
 }