Esempio n. 1
0
 public static UserModel GetUser(CredentialsLib c)
 {
     if (LoginExists(c.Login))
     {
         if (Authenticate(c))
         {
             using (filesyncEntities context = new filesyncEntities())
             {
                 int  id = LoginToId(c.Login);
                 User u1 = (from o in context.Users
                            where o.user_id == id
                            select o).Single();
                 UserModel u = new UserModel(u1.user_login, u1.user_pass, u1.user_fullname, u1.user_email);
                 u.Lastlogin = (DateTime)u1.user_lastlogin;
                 u.Id        = u1.user_id;
                 return(u);
             }
         }
         else
         {
             throw new Exception("wrong password");
         }
     }
     else
     {
         throw new Exception("no such user");
     }
 }
Esempio n. 2
0
 public static void GetFileContent(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
 {
     GetFileContentId(m, d, f);
     using (filesyncEntities context = new filesyncEntities())
     {
         Content c1 = (from o in context.Contents
                       where o.content_id == f.Content
                       select o).Single();
         f.Data = c1.content_data;
     }
 }
Esempio n. 3
0
        public static bool LoginIn(CredentialsLib c)
        {
            //var c2 = new RemoteCredentialsLib();
            //c2.Login = c.Login;
            //c2.Pass = c.Pass;

            var cl  = new FileSyncServiceClient();
            var res = cl.LoginIn(c);

            cl.Close();

            return(res);
        }
Esempio n. 4
0
        public static UserModel GetUser(CredentialsLib c)
        {
            var c2 = new RemoteCredentialsLib();

            c2.Login = c.Login;
            c2.Pass  = c.Pass;

            var cl  = new FileSyncServiceClient();
            var res = cl.GetUser(c2);

            cl.Close();

            return(res);
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
0
        public static UserModel GetUser(CredentialsLib c)
        {
            //var c2 = new RemoteCredentialsLib();
            //c2.Login = c.Login;
            //c2.Pass = c.Pass;

            var cl = new FileSyncServiceClient();
            var u  = cl.GetUser(c);

            cl.Close();

            var res = new UserModel(u.Login, u.Pass, u.Fullname, u.Email);

            return(res);
        }
Esempio n. 7
0
        public static void AddDirectory(CredentialsLib c, MachineModel m, DirModel d)
        {
            GetDirList(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 = UserManipulator.LoginToId(c.Login);
                AddDir(d);
                m.Id = MachManipulator.MachineNameToId(m.Name);
                AddMachDir(m, d);
            }
        }
Esempio n. 8
0
        public static bool Authenticate(CredentialsLib c)
        {
            using (filesyncEntities context = new filesyncEntities())
            {
                User u1;
                try
                {
                    u1 = (from u in context.Users
                          where u.user_login == c.Login && u.user_pass == c.Pass
                          select u).Single();
                }
                catch
                {
                    return(false);
                }

                return(true);
            }
        }
Esempio n. 9
0
        public static void AddMachine(CredentialsLib c, MachineModel m)
        {
            if (MachineNameExists(m.Name))
            {
                throw new Exception("machine with given name already exists");
            }
            else
            {
                int     user_id = UserManipulator.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();
                }
            }
        }
Esempio n. 10
0
        public static void DelUser(CredentialsLib c)
        {
            UserModel 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");
                }
            }
        }
Esempio n. 11
0
        public static void GetFileList(CredentialsLib c, MachineModel m, DirModel d)
        {
            List <FileModel> filelist = new List <FileModel>();

            DirManipulator.GetDirList(m);
            d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
            using (filesyncEntities context = new filesyncEntities())
            {
                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 }))
                {
                    FileModel file = new FileModel(x.f.file_name, x.f.file_size,
                                                   x.f.file_hash, x.type_name, x.f.file_uploaded, x.f.file_modified);
                    file.Content = x.f.content_id;
                    file.Id      = x.f.file_id;
                    filelist.Add(file);
                }
            }
            d.Files = filelist;
        }
Esempio n. 12
0
        public static void AddFile(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
        {
            DirManipulator.GetDirList(m);
            f.Dir = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
            if (!CheckFileExistence(m, d, f))
            {
                AddFileContent(f);
                TypeManipulator.TypeToId(f);
                File f1 = File.CreateFile(1, f.Dir, f.Type, 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(m, d, f);
                GetFileContentId(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();
                }
            }
        }
Esempio n. 13
0
 public static void AddDirectory(CredentialsLib c, MachineModel m, DirModel d)
 {
     //
 }
Esempio n. 14
0
 public static void AddMachine(CredentialsLib c, MachineModel m)
 {
     //
 }
Esempio n. 15
0
 public static void GetFileContent(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
 {
     //
 }
Esempio n. 16
0
 public static void GetFileList(CredentialsLib c, MachineModel m, DirModel d)
 {
     //es= filelist;
 }
Esempio n. 17
0
 public static void AddFile(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
 {
     //
 }
Esempio n. 18
0
 public CredentialsLib(CredentialsLib c)
 {
     c.Login = Login;
     c.Pass  = Pass;
 }
Esempio n. 19
0
 public static void ChangeMachineDetails(CredentialsLib c, MachineModel newMachine, MachineModel oldMachine)
 {
     //
 }