예제 #1
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();
            }
        }
예제 #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;
     }
 }
예제 #3
0
        private static void GetFileId(MachineModel m, DirModel d, FileModel f)
        {
            DirManipulator.GetDirList(m);
            d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
            using (filesyncEntities context = new filesyncEntities())
            {
                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;
            }
        }
예제 #4
0
        private static void AddDir(DirModel 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;
        }
예제 #5
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);
            }
        }
예제 #6
0
 private static bool CheckFileExistence(MachineModel m, DirModel d, FileModel f)
 {
     DirManipulator.GetDirList(m);
     d.Id = (from o in m.Directories where o.Name == d.Name select o.Id).Single();
     try
     {
         using (filesyncEntities context = new filesyncEntities())
         {
             (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);
 }
예제 #7
0
        public static void GetDirList(MachineModel m)
        {
            int             mach_id = MachManipulator.MachineNameToId(m.Name);
            List <DirModel> dirlist = new List <DirModel>();

            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 }))
                {
                    DirModel dir = new DirModel(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;
            }
        }
예제 #8
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;
        }
예제 #9
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();
                }
            }
        }
예제 #10
0
 public static void GetFileContent(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
 {
     //
 }
예제 #11
0
 public static void GetFileList(CredentialsLib c, MachineModel m, DirModel d)
 {
     //es= filelist;
 }
예제 #12
0
 public static void AddFile(CredentialsLib c, MachineModel m, DirModel d, FileModel f)
 {
     //
 }
예제 #13
0
 public static void AddDirectory(CredentialsLib c, MachineModel m, DirModel d)
 {
     //
 }