public TimeSpan CalculateDiffClocks() { try { SQ.Repository.File clockFile = new RemoteFile (Constant.CLOCK_TIME); PutObjectRequest putObject = new PutObjectRequest () { BucketName = bucketName, Key = clockFile.Name, ContentBody = string.Empty }; DateTime localClock; using (S3Response response = Connect ().PutObject (putObject)){ localClock = DateTime.Now; response.Dispose (); } ListObjectsResponse files = Connect ().ListObjects (new ListObjectsRequest ().WithBucketName (bucketName)); S3Object remotefile = files.S3Objects.Where (o => o.Key == clockFile.Name).FirstOrDefault(); string sRemoteclock = remotefile.LastModified; Delete(clockFile); DateTime remoteClock = Convert.ToDateTime (sRemoteclock); return localClock.Subtract(remoteClock); } catch(Exception e) { return new TimeSpan(0); Logger.LogInfo ("Connection","Fail to determinate a remote clock: "+e.Message +" \n"); } }
void AddDownloadFile(RemoteFile remoteFile) { remoteFile.TimeOfLastChange = DateTime.Now; RemoteRepo.FilesChanged.Add (remoteFile); }
private void SyncFile(RemoteFile remoteFile) { LocalFile localFile = new LocalFile (remoteFile.FullLocalName); if (localFile.IsFileLocked) return; if (remoteFile.InTrash || remoteFile.IsIgnoreFile) return; Logger.LogInfo ("Synchronizer","Synchronizing: "+remoteFile.Name); if (localFile.ExistsInLocalRepo) { if ( !FilesIsSync (localFile, remoteFile)) { Console.WriteLine ("Not sync "+localFile.MD5Hash+" "+remoteFile.MD5Hash); // nao estando sincronizado // faz upload do arquivo local para o trash com referencia ao arquivo remoto //localFile.RecentVersion = remoteFile; MoveToTrashFolder (localFile); // baixa arquivo remoto //Changes.Add (connection.Download (remoteFile)); AddDownloadFile (remoteFile); RemoteRepo.Download (remoteFile); } } else { // se nao existe, baixa AddDownloadFile(remoteFile); RemoteRepo.Download (remoteFile); countOperation++; } }
public bool FilesIsSync(LocalFile localFile, RemoteFile remoteFile) { return localFile.MD5Hash == remoteFile.MD5Hash; }
public static void Download(RemoteFile remoteFile) { //TODO observar aqui if (!RemoteRepo.IsTrashFile (remoteFile) && !LocalRepo.PendingChanges.Where (c => c.File.FullLocalName == remoteFile.FullLocalName && c.Event == System.IO.WatcherChangeTypes.Deleted).Any()) connection.Download (remoteFile); }
public static void Delete(RemoteFile file) { connection.Delete (file); }
public static bool SendToTrash(RemoteFile remoteFile) { connection.CopyToTrash (remoteFile); bool copySucessfull = RemoteRepo.TrashFiles.Where (rm => remoteFile.AbsolutePath+"(0)" == rm.AbsolutePath).Any(); if (copySucessfull) UpdateTrashFolder (remoteFile); return copySucessfull; }
public static bool IsTrashFile(RemoteFile file) { return file.InTrash; }