//если файл есть в папке телефона и есть в бд 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(); }
public void InsertInDbPhone(string pathPhone, string fileNameAndFolderPhone) { var db = new SynchronContext(); var namePhone = fileNameAndFolderPhone; var createPhone = File.GetCreationTime(pathPhone); var modificPhone = File.GetLastWriteTime(pathPhone); var phone = new PhoneModel { Name = namePhone, CreateDate = createPhone, ModificationDate = modificPhone }; db.PhoneModels.Add(phone); db.SaveChanges(); }
public void InsertFileIfNotInDbPhone(string fileNameAndFolderComp, string pathComp, string pathComInPhon) { var context = new SynchronContext(); var namePhone = fileNameAndFolderComp; var createPhone = File.GetCreationTime(pathComp); var modificPhone = File.GetLastWriteTime(pathComp); var phone = new PhoneModel { Name = namePhone, CreateDate = createPhone, ModificationDate = modificPhone }; context.PhoneModels.Add(phone); try { File.Copy(pathComp, pathComInPhon); } catch { } context.SaveChanges(); }
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(); }
//если файл есть в папке телефона, но нет в бд public void UpdateIfNotInDbPhone(string fileComp, string pathComp, string pathComInPhon) { 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) { var phone = new PhoneModel { Name = namePhone, CreateDate = createPhone, ModificationDate = modificComp }; context.PhoneModels.Add(phone); File.Delete(pathComInPhon); File.Copy(pathComp, pathComInPhon); } else if (modificPhone > modificComp) { var phone = new PhoneModel { Name = namePhone, CreateDate = createPhone, ModificationDate = modificPhone }; context.PhoneModels.Add(phone); } context.SaveChanges(); }