Ejemplo n.º 1
0
        private void MoveToTrashFolder(LocalFile localFile)
        {
            Logger.LogInfo ("Synchronizer", "Versioning: " + localFile.Name);

            if (RemoteRepo.SendToTrash (localFile))
            {
                RemoteRepo.FilesChanged.Add (localFile);
                new FileInfo(localFile.FullLocalName).Delete ();
                Logger.LogInfo("Synchronizer","Local file "+localFile.Name+" was deleted.");
            }
        }
Ejemplo n.º 2
0
        bool HandleRenameEvent(LocalFile file)
        {
            File deletedFile =  LocalRepo.Files.Where (f => f.Deleted
                                                       && f.RelativePath == file.RelativePath
                                                       && f.Name != file.Name
                                                       && f.MD5Hash == file.MD5Hash
                                                       && Math.Abs (file.TimeOfLastChange.Subtract (f.TimeOfLastChange).TotalSeconds) <= 3
                                                       ).FirstOrDefault();

            return HandleMove (file, deletedFile);
        }
Ejemplo n.º 3
0
        bool HandleCreates(string path)
        {
            if (path == null) {
                //Console.WriteLine ("Debug - HandleCreate received a null value");
                return false;
            }
            if (RemoteRepo.FilesChanged.Count > 0) {
                if (RemoteRepo.FilesChanged.Where (df => df.FullLocalName == path).Any ())
                    return true;
            }

            if (System.IO.Directory.Exists (path)) {
                CreateFolder (path);
            }
            else {
                LocalFile lf = new LocalFile (path);
                HandleDelete ();
                CreateFile (lf);
            }
            return true;
        }
Ejemplo n.º 4
0
 void HandleChanges(object sender, System.IO.FileSystemEventArgs e)
 {
     if (e==null)
         return;
     LocalFile localFile = new LocalFile (e.FullPath);
     if (localFile.IsIgnoreFile)
     {
         return;
     }
     if (BacklogSynchronizer.GetInstance ().ChangesMade.Count > 0) {
         if (BacklogSynchronizer.GetInstance ().ChangesMade.Where (f => f.FullLocalName == e.FullPath).Any ()) {
             BacklogSynchronizer.GetInstance ().ChangesMade.RemoveAll (f => f.FullLocalName == e.FullPath);
             return;
         }
     }
     switch (e.ChangeType) {
     case System.IO.WatcherChangeTypes.Created:
         triggers.Add (e.FullPath);
         LastTimeCatch = DateTime.Now;
         break;
     case System.IO.WatcherChangeTypes.Deleted:
         HandleDelete();
         break;
     case System.IO.WatcherChangeTypes.Changed:
         LocalRepo.PendingChanges.Add
             (new Change(new LocalFile(e.FullPath), e.ChangeType));
         break;
     }
 }
Ejemplo n.º 5
0
        void CreateFolder(string folder_path)
        {
            if (folder_path.Contains (".app/") || folder_path.EndsWith (".app"))
                return;
            CreateWatcher (folder_path);
            LocalFile folder = new LocalFile (folder_path);
            if (System.IO.Directory.GetFiles (folder_path).Count () == 0 && System.IO.Directory.GetDirectories (folder_path).Count () == 0)
                LocalRepo.PendingChanges.Add
                    (new Change (folder, System.IO.WatcherChangeTypes.Created));
            else {
                foreach (string fileName in System.IO.Directory.GetFiles(folder_path)) {
                    LocalFile lf = new LocalFile (fileName);
                    if (!lf.IsIgnoreFile)
                        CreateFile (lf);
                }
                foreach (string folderName in System.IO.Directory.GetDirectories(folder_path)) {
                    CreateFolder (folderName);
                }
            }

            LocalRepo.Files.Add (folder);
        }
Ejemplo n.º 6
0
        void CreateFile(LocalFile file)
        {
            bool createDeprecated = HandleMoveEvent (file);
            createDeprecated |= HandleRenameEvent (file);
            if (!createDeprecated) {
                Console.WriteLine (DateTime.Now.ToUniversalTime ()+" - Create File: "+file.FullLocalName);
                file.TimeOfLastChange = DateTime.Now;
                LocalRepo.PendingChanges.Add
                    (new Change (file, System.IO.WatcherChangeTypes.Created));
            }

            if (!LocalRepo.Files.Where (f => f.FullLocalName == file.FullLocalName && file.MD5Hash == f.MD5Hash).Any ())
                LocalRepo.Files.Add (file);
        }
Ejemplo n.º 7
0
 private void SynchronizeUploadRenameFolder(Folder folder)
 {
     // nao precisa fazer upload, pois vai mover apenas remotamente (os arquivos atuais ja estao la)
     FileInfo[] filesInFolder = new DirectoryInfo(folder.FullLocalName).GetFiles();
     if (filesInFolder.Length == 0)
         RemoteRepo.Move (folder.OldVersion, folder);
     else {
         foreach (FileInfo file in filesInFolder)
         {
             LocalFile newFile = new LocalFile (file.FullName);
             LocalFile oldFile = new LocalFile
                 (file.FullName.Replace (folder.FullLocalName, folder.OldVersion.FullLocalName));
             RemoteRepo.Move (oldFile, newFile);
         }
     }
 }
Ejemplo n.º 8
0
 private void SynchronizeUploadRenameFile(LocalFile localFile)
 {
     // renomeia o arquivo remoto
     RemoteRepo.Move (localFile.OldVersion, localFile);
 }
Ejemplo n.º 9
0
        /*      Remote          Local       Backlog
                X                           X               (foi apagado enquanto offline, envia o remoto para a lixeira)
                                X           X               (foi apagado remotamente, envia o local para a lixeira e apaga)
                X               X           X               (verifica sincronia, se dessincronizado, ver qual o mais atual e atualizar)
                                            X               (foi apagado local e remotamente, enquanto estava offline, nao faz nada)
                X                                           (foi criado enquanto offline, faz o download)
                                X                           (foi criado enquanto offline, faz o upload)
                X               X                           (backlog desatualizado, remoto ganha)
        */
        public override bool Synchronize()
        {
            Synchronized = false;
            try {
                SQ.Util.Logger.LogInfo("Synchronizer", "Sync starting from backlog");
                List<string[]> filesInBackLog = Read ();
                if (filesInBackLog != null)
                {
                    List<File> filesInLocalRepo = LocalRepo.Files;
                    List<RemoteFile> filesInRemoteRepo = RemoteRepo.Files;
                    TimeSpan diffClocks = RemoteRepo.DiffClocks;
                    List<File> alreadyAnalyzed = new List<File>();

                    foreach (RemoteFile remoteFile in filesInRemoteRepo) {
                        if(remoteFile.IsIgnoreFile)
                            continue;
                        bool backlogFile = false;
                        string date = "";
                        if(filesInBackLog != null)
                        {
                            if(filesInBackLog.Count > 0)
                            {
                                if (filesInBackLog.Where (fibl => LocalRepo.ResolveDecodingProblem(string.Format("{0}{1}",fibl [4], fibl [3])) == LocalRepo.ResolveDecodingProblem(remoteFile.AbsolutePath)).Any()){
                                    date = filesInBackLog.Where (fibl => LocalRepo.ResolveDecodingProblem(string.Format("{0}{1}",fibl [4], fibl [3])) == LocalRepo.ResolveDecodingProblem(remoteFile.AbsolutePath)).First() [2];
                                    backlogFile = true;
                                }
                            }
                        }

                        LocalFile localFile = null;
                        if (remoteFile.IsAFolder){
                            System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(remoteFile.FullLocalName);
                            if(!dir.Exists){
                                ChangesMade.Add (remoteFile);
                                dir.Create();
                            }
                            continue;
                        }
                        if (filesInLocalRepo.Where (filr => LocalRepo.ResolveDecodingProblem(filr.AbsolutePath) == LocalRepo.ResolveDecodingProblem(remoteFile.AbsolutePath)).Any ())
                        {
                            File temp = filesInLocalRepo.Where (filr => LocalRepo.ResolveDecodingProblem(filr.AbsolutePath) == LocalRepo.ResolveDecodingProblem(remoteFile.AbsolutePath)).First ();
                            localFile = new LocalFile(LocalRepo.ResolveDecodingProblem(temp.AbsolutePath), temp.TimeOfLastChange);
                        }

                        if (localFile == null && backlogFile)
                        {
                            if(RemoteRepo.SendToTrash (remoteFile))
                            {
                                ChangesMade.Add (remoteFile);
                                RemoteRepo.Delete (remoteFile);
                            }
                        }
                        else if (localFile != null && backlogFile)
                        {
                            if (!FilesIsSync (localFile, remoteFile)) {

                                DateTime localLastTime = Convert.ToDateTime (date);

                                if (localFile.TimeOfLastChange > localLastTime)
                                    localLastTime = localFile.TimeOfLastChange;

                                DateTime referencialClock = localLastTime.Subtract (diffClocks);
                                if (referencialClock.Subtract (Convert.ToDateTime (remoteFile.AsS3Object.LastModified)).TotalSeconds > 0) {
                                    Console.WriteLine ("2");
                                    if(RemoteRepo.SendToTrash (remoteFile))
                                        RemoteRepo.Upload (localFile);
                                } else {
                                    Console.WriteLine ("3");
                                    if(RemoteRepo.SendToTrash (localFile))
                                    {
                                        ChangesMade.Add (remoteFile);
                                        RemoteRepo.Download (remoteFile);
                                        LocalRepo.Files.Add (new LocalFile(remoteFile.AbsolutePath));
                                    }
                                }
                            }
                            alreadyAnalyzed.Add(localFile);
                        }
                        else if (!backlogFile)
                        {
                            Console.WriteLine ("4");
                            ChangesMade.Add (remoteFile);
                            RemoteRepo.Download (remoteFile);
                            LocalRepo.Files.Add (new LocalFile(remoteFile.AbsolutePath));
                            if(localFile != null)
                                alreadyAnalyzed.Add (localFile);
                        }
                    }

                    foreach(File localFile in filesInLocalRepo){
                        string localAbsolutePath = LocalRepo.ResolveDecodingProblem (localFile.AbsolutePath);
                        if (alreadyAnalyzed.Where (lf => LocalRepo.ResolveDecodingProblem (lf.AbsolutePath) == localAbsolutePath).Any())
                            continue;
                        if (localFile.IsAFolder)
                        {
                            continue;
                        }
                        bool backlogFile = false;
                        if(filesInBackLog!=null)
                            if(filesInBackLog.Count>0)
                                backlogFile = filesInBackLog.Where (fibl => LocalRepo.ResolveDecodingProblem (string.Format("{0}{1}",fibl [4] , fibl [3])) == localAbsolutePath).Any ();

                        if(backlogFile)
                        {
                            Console.WriteLine ("5");
                            LocalFile lf = new LocalFile(localAbsolutePath);
                            if (RemoteRepo.SendToTrash (lf))
                            {
                                ChangesMade.Add (lf);
                                System.IO.File.Delete(localFile.FullLocalName);
                            }

                        }
                        else{
                            Console.WriteLine ("6");
                            RemoteRepo.Upload (localFile);
                        }
                        alreadyAnalyzed.Add (localFile);
                    }
                }
                Write();
                Repo.LastSyncTime = DateTime.Now;
                SQ.Util.Logger.LogInfo("Synchronizer", "Backlog Sync is finished");
                Synchronized = true;
                return true;
            } catch (Exception e){
                SQ.Util.Logger.LogInfo("Backlog", e);
                return false;
            }
        }
Ejemplo n.º 10
0
        private void SyncRemoveFile(LocalFile localFile)
        {
            if (localFile.IsIgnoreFile)
                return;
            //se arquivo local nao existe no repositorio remoto

            if (!ExistsInBucket (localFile))
            {
                if (!ExistsVersion (localFile)){
                    MoveToTrashFolder (localFile);
                }
                else
                {
                    FileInfo f = new FileInfo(localFile.FullLocalName);
                    if (f.Exists)
                        f.Delete();
                }
            }
        }
Ejemplo n.º 11
0
        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++;
            }
        }
Ejemplo n.º 12
0
 public static List<File> Get(List <FileInfo> fileInfos)
 {
     List <File> localFiles = new List <File> ();
     foreach (FileInfo fileInfo in fileInfos) {
         LocalFile localFile = new LocalFile (fileInfo.FullName, fileInfo.LastWriteTime);
         if(!localFile.IsIgnoreFile)
             localFiles.Add (localFile);
     }
     return localFiles;
 }
Ejemplo n.º 13
0
 public bool FilesIsSync(LocalFile localFile, RemoteFile remoteFile)
 {
     return localFile.MD5Hash == remoteFile.MD5Hash;
 }
Ejemplo n.º 14
0
        public static bool SendToTrash(LocalFile file)
        {
            connection.UploadToTrash (file);
            Logger.LogInfo ("Connection","File "+file.Name+" was sent to trash folder.");
            UpdateTrashFolder (file);

            return RemoteRepo.TrashFiles.Where (rf => rf.TrashFullName == file.TrashFullName+"(1)").Any ();
        }