Exemple #1
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();
                }
            }
        }
Exemple #2
0
        private static void AddMachDir(MachineContents m, DirectoryContents d)
        {
            MachineDir md1 = MachineDir.CreateMachineDir(m.Id, d.Id, d.LocalPath);

            using (filesyncEntities context = new filesyncEntities()) {
                context.MachineDirs.AddObject(md1);
                context.SaveChanges();
            }
        }
Exemple #3
0
        private static void AddMachDir(MachineModel m, DirModel d)
        {
            MachineDir md1 = MachineDir.CreateMachineDir(m.Id, d.Id, d.Path);

            using (filesyncEntities context = new filesyncEntities())
            {
                context.MachineDirs.AddObject(md1);
                context.SaveChanges();
            }
        }
Exemple #4
0
 private static void UpdateFileContent(FileContents f)
 {
     using (filesyncEntities context = new filesyncEntities()) {
         Content c1 = (from o in context.Contents
                       where o.content_id == f.Content
                       select o).Single();
         c1.content_data = f.Data;
         context.SaveChanges();
     }
 }
        public static void Add(MachdirModel md)
        {
            MachineDir md1 = MachineDir.CreateMachineDir(1, md.Dir, md.Path);

            using (filesyncEntities context = new filesyncEntities())
            {
                context.MachineDirs.AddObject(md1);
                context.SaveChanges();
            }
        }
Exemple #6
0
        private void AddFileContent(FileContents f)
        {
            int     AddedContentId;
            Content f1 = Content.CreateContent(1, f.Data);

            using (filesyncEntities context = new filesyncEntities()) {
                context.Contents.AddObject(f1);
                context.SaveChanges();
                AddedContentId = (from c in context.Contents select c).ToList().Last().content_id;
            }
            f.Content = AddedContentId;
        }
Exemple #7
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();
     }
 }
Exemple #8
0
        public static void ChangeMachineDetails(CredentialsLib c, MachineModel newMachine, MachineModel oldMachine)
        {
            oldMachine.Id = MachineNameToId(oldMachine.Name);

            using (filesyncEntities context = new filesyncEntities())
            {
                Machine m1 = (from o in context.Machines
                              where o.machine_id == oldMachine.Id
                              select o).Single();
                m1.machine_name        = newMachine.Name;
                m1.machine_description = newMachine.Description;
                context.SaveChanges();
            }
        }
Exemple #9
0
 private void UpdateLastLogin(int id)
 {
     using (filesyncEntities context = new filesyncEntities()) {
         try {
             var u1 = (from o in context.Users
                       where o.user_id == id
                       select o).Single();
             u1.user_lastlogin = DateTime.Now;
             context.SaveChanges();
         } catch {
             throw new Exception("no such user");
         }
     }
 }
Exemple #10
0
        private static void AddDir(DirectoryContents d)
        {
            int AddedDirId;
            Dir d1 = Dir.CreateDir(1, d.Name, d.Owner);

            d1.dir_description = d.Description;

            using (filesyncEntities context = new filesyncEntities()) {
                context.Dirs.AddObject(d1);
                context.SaveChanges();
                AddedDirId = (from z in context.Dirs select z).ToList().Last().dir_id;
            }

            d.Id = AddedDirId;
        }
Exemple #11
0
        public void DelUser(Credentials c)
        {
            UserContents u = GetUser(c);

            using (filesyncEntities context = new filesyncEntities()) {
                try {
                    int id = LoginToId(u.Login);
                    var u1 = (from o in context.Users
                              where o.user_id == id
                              select o).Single();
                    context.Users.DeleteObject(u1);
                    context.SaveChanges();
                } catch {
                    throw new Exception("no such user");
                }
            }
        }
Exemple #12
0
        public static void AddType(FileModel f)
        {
            if (TypeNameExists(f.Typename))
            {
                throw new Exception("type with given name already exists");
            }
            else
            {
                Type t = Type.CreateType(1, f.Typename);

                using (filesyncEntities context = new filesyncEntities())
                {
                    context.Types.AddObject(t);
                    context.SaveChanges();
                }
            }
        }
Exemple #13
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();
                }
            }
        }
Exemple #14
0
 public void AddUser(Credentials c, UserContents u)
 {
     if (LoginExists(u.Login))
     {
         throw new Exception("user already exists");
     }
     else
     {
         //TODO: don't use password directly
         User u1 = User.CreateUser(1, u.Login, u.Password);
         u1.user_email     = u.Email;
         u1.user_fullname  = u.Name;
         u1.user_lastlogin = DateTime.Now;
         using (filesyncEntities context = new filesyncEntities()) {
             context.Users.AddObject(u1);
             context.SaveChanges();
         }
     }
 }
Exemple #15
0
 public static void Add(UserModel u)
 {
     if (LoginExists(u.Login))
     {
         throw new Exception("user already exists");
     }
     else
     {
         User u1 = User.CreateUser(1, u.Login, u.Pass);
         u1.user_email     = u.Email;
         u1.user_fullname  = u.Fullname;
         u1.user_lastlogin = DateTime.Now;
         using (filesyncEntities context = new filesyncEntities())
         {
             context.Users.AddObject(u1);
             context.SaveChanges();
         }
     }
 }