Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
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);
     }
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
        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;
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
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);
            }
        }
Ejemplo n.º 8
0
 public void ChangeMachineDetails(Credentials c, MachineContents newM,
                                  MachineContents oldM)
 {
     throw new Exception("not implemented");
 }
Ejemplo n.º 9
0
 private MachineContents getMachine()
 {
     MachineContents m = new MachineContents(this.MachineName.Text,
         this.MachineDescription.Text);
     return m;
 }
Ejemplo n.º 10
0
 public DirectoryContents GetDirectoryWithFiles(Credentials c, MachineContents m, DirectoryIdentity d)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public bool AddMachine(Credentials c, MachineContents m)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
0
        private void buttonSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            try {
                //MessageBox.Show(String.Format("old: {0} new: {1} {2}", machine.Identity.ToString(),
                //	MachineName, MachineDesc), "Erroren");

                var newMachine = new MachineContents(MachineName, MachineDesc);

                if (connection.ChangeMachineDetails(credentials, newMachine, machine)) {
                    machine.Name = MachineName;
                    machine.Description = MachineDesc;
                    new SystemMessage("FileSync", "Changes saved",
                        "Machine metadata was successfully updated.", MemeType.FuckYea).ShowDialog();
                } else
                    new SystemMessage("FileSync", "Error", "bool WCF function returned false").ShowDialog();

            } catch (ActionException ex) {
                MessageBox.Show(ex.Message, ex.Title);
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 16
0
 public void GetDirList(Credentials c, MachineContents m)
 {
     throw new Exception("not implemented");
 }
Ejemplo n.º 17
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);
            }
        }
Ejemplo n.º 18
0
        public FileContents GetFileWithContent(Credentials c, MachineContents m,
				DirectoryContents d, FileIdentity fid)
        {
            var cl = new Ref.FileSyncModelClient();
            try {
                FileContents f = null;
                f = cl.GetFileWithContent(c, m, d, f);
                cl.Close();
                if (f == null)
                    throw new ActionException("Received a null object.", ActionType.User);
                return f;
            } catch (Exception ex) {
                cl.Abort();
                throw new ActionException("Error while downloading file contents from database.",
                    ActionType.File, MemeType.Fuuuuu, ex);
            }
        }
Ejemplo n.º 19
0
 public System.Collections.Generic.List<FileContents> GetFileList(Credentials c, MachineContents m, DirectoryContents d)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 20
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);
            }
        }
Ejemplo n.º 21
0
 public void AddDirectory(Credentials c, MachineContents m, DirectoryContents d)
 {
     throw new Exception("not implemented");
 }
Ejemplo n.º 22
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;
            }
        }
Ejemplo n.º 23
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;
 }
Ejemplo n.º 24
0
        private void buttonLogout_Click(object sender, RoutedEventArgs e)
        {
            LoggedIn = false;

            credentials = null;
            user = null;
            machine = null;
        }
Ejemplo n.º 25
0
        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;
        }
Ejemplo n.º 26
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();
     }
 }
Ejemplo n.º 27
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;
            }
        }
Ejemplo n.º 28
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;
            }
        }
Ejemplo n.º 29
0
 public FileContents GetFileWithContent(Credentials c, MachineContents m, DirectoryContents d, FileIdentity f)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 public void GetFileContent(Credentials c, MachineContents m, DirectoryContents d,
                            FileContents f)
 {
     throw new Exception("not implemented");
 }
Ejemplo n.º 31
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;
        }
Ejemplo n.º 32
0
 public MachineContents(MachineContents mc)
     : this(mc.Name, mc.Description, mc.Directories)
 {
     //nothing needed here
 }
Ejemplo n.º 33
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;
        }
Ejemplo n.º 34
0
 public bool SaveMachine(MachineContents m)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 35
0
 public System.Collections.Generic.List <FileContents> GetFileList(Credentials c, MachineContents m, DirectoryContents d)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 36
0
        public bool UpdateMachine(IFileSyncModel connection, Credentials c, MachineContents newM,
				MachineContents oldM)
        {
            throw new NotImplementedException();
        }
Ejemplo n.º 37
0
 public bool ChangeMachineDetails(Credentials c, MachineContents newM, MachineContents oldM)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 38
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);
     }
 }
Ejemplo n.º 39
0
 public bool AddFile(Credentials c, MachineContents m, DirectoryContents d, FileContents f)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 40
0
 public bool EraseMachine(MachineContents d)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 41
0
 public MachineContents(MachineContents mc)
     : this(mc.Name, mc.Description, mc.Directories)
 {
     //nothing needed here
 }
Ejemplo n.º 42
0
 public void AddMachine(Credentials c, MachineContents m)
 {
     throw new Exception("not implemented");
 }