示例#1
0
        //если файл есть в папке телефона и есть в бд
        public void UpdateIfInDbPhone(string fileComp, string pathComp, string pathComInPhon,
                                        PhoneModel findFileFromPhone,
                                            ComputerModel findFileFromComp)
        {
            var context = new SynchronContext();
            var nameComp = fileComp;
            var createComp = File.GetCreationTime(pathComp);
            var modificComp = File.GetLastWriteTime(pathComp);
            var namePhone = fileComp;
            var createPhone = File.GetCreationTime(pathComInPhon);
            var modificPhone = File.GetLastWriteTime(pathComInPhon);
            if (modificComp > modificPhone)
            {
                File.Delete(pathComInPhon);
                File.Copy(pathComp, pathComInPhon);
                findFileFromPhone.ModificationDate = modificComp;
            }
            else if (modificPhone > modificComp)
            {
                File.Delete(pathComp);
                File.Copy(pathComInPhon, pathComp);

                findFileFromComp.ModificationDate = modificPhone;

            }
            context.SaveChanges();
        }
示例#2
0
 public void InsertInDbComp(string pathComp, string fileNameAndFolderComp)
 {
     var db = new SynchronContext();
     var nameComp = fileNameAndFolderComp;
     var createComp = File.GetCreationTime(pathComp);
     var modificComp = File.GetLastWriteTime(pathComp);
     var comp = new ComputerModel
     {
         Name = nameComp,
         CreateDate = createComp,
         ModificationDate = modificComp
     };
     db.ComputerModels.Add(comp);
     db.SaveChanges();
 }
示例#3
0
 public void InsertFileIfNotInDbComp(string fileNameAndFolderPhone, string pathPhone, string pathPhInCom)
 {
     var db = new SynchronContext();
     var nameComp = fileNameAndFolderPhone;
     var createComp = File.GetCreationTime(pathPhone);
     var modificComp = File.GetLastWriteTime(pathPhone);
     var comp = new ComputerModel
     {
         Name = nameComp,
         CreateDate = createComp,
         ModificationDate = modificComp
     };
     db.ComputerModels.Add(comp);
     try { File.Copy(pathPhone, pathPhInCom); }
     catch { }
     db.SaveChanges();
 }
示例#4
0
        public void Delete(string pathComp, string pathCompInPhone, ComputerModel findFileFromComp,PhoneModel findFileFromPhone)
        {
            var context = new SynchronContext();
            var modific = File.GetLastWriteTime(pathComp);
            if (modific > findFileFromComp.ModificationDate)
            {
                findFileFromComp.ModificationDate = modific;
                File.Copy(pathComp, pathCompInPhone);
                findFileFromPhone.ModificationDate = modific;
            }
            else if (modific < findFileFromComp.ModificationDate)
            {
                var com = new ComputerModel { IdComp = findFileFromComp.IdComp, };
                context.Entry(com).State = System.Data.Entity.EntityState.Deleted;

                var phon = new PhoneModel { IdPhone = findFileFromPhone.IdPhone };
                context.Entry(phon).State = System.Data.Entity.EntityState.Deleted;

                File.Delete(pathComp);
            }
            context.SaveChanges();
        }
示例#5
0
 //если файл есть в папке компьютера, но нет в бд
 public void UpdateIfNotInDbComp(string filePhon, string pathPhone, string pathPhInCom)
 {
     var context = new SynchronContext();
     var namePhone = filePhon;
     var createPhone = File.GetCreationTime(pathPhone);
     var modificPhone = File.GetLastWriteTime(pathPhone);
     var nameComp = filePhon;
     var createComp = File.GetCreationTime(pathPhInCom);
     var modificComp = File.GetLastWriteTime(pathPhInCom);
     if (modificPhone > modificComp)
     {
         var comp = new ComputerModel
         {
             Name = nameComp,
             CreateDate = createComp,
             ModificationDate = modificPhone
         };
         context.ComputerModels.Add(comp);
         File.Delete(pathPhInCom);
         File.Copy(pathPhone, pathPhInCom);
     }
     else if (modificComp > modificPhone)
     {
         var comp = new ComputerModel
         {
             Name = nameComp,
             CreateDate = createComp,
             ModificationDate = modificComp
         };
         context.ComputerModels.Add(comp);
     }
     context.SaveChanges();
 }