Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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();
                }
            }
        }