Beispiel #1
0
        private async Task <bool> SynchronizeLocalDirectoriesAsync()
        {
            var result = false;
            //Synchronize on disk directories vs file sync table items of type folder
            var directoryPaths = Directory.EnumerateDirectories(_path, "*", SearchOption.AllDirectories);

            //Detect create directories on disk
            foreach (var directoryPath in directoryPaths)
            {
                if (SyncTableManager.ContainsPath(directoryPath))
                {
                    continue;
                }

                var parentDirectory = Directory.GetParent(directoryPath);
                var parentFolder    = SyncTableManager.GetByPath(parentDirectory.FullName);

                if (parentFolder != null)
                {
                    var command = new CreateOnlineDirectoryCommand(_ticket, parentFolder.GroupId, parentFolder.FolderId, directoryPath, _path);
                    command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                    _commandProcessor.AddCommand(command);
                    result = await _commandProcessor.ExecuteCommandsAsync();
                }
            }

            return(result);
        }
Beispiel #2
0
        private async void OnRenamed(object sender, RenamedEventArgs e)
        {
            var item = SyncTableManager.GetByPath(e.OldFullPath);

            if (item != null)
            {
                var command = (Command)null;

                if (item.Type == "F")
                {
                    var folder = new DirectoryInfo(e.FullPath);

                    var ticket = await DokuFlexService.GetTicketAsync();

                    var topLevelPath = ConfigurationManager.GetValue(Resources.SyncDirectoryPathKey);

                    command = new RenameDirectoryCommand(ticket, folder.Name, e.FullPath, e.OldFullPath, topLevelPath);
                }
                else
                {
                    var file = new FileInfo(e.FullPath);

                    //check if file is open by a program
                    if (!file.IsLocked())
                    {
                        var ticket = await DokuFlexService.GetTicketAsync();

                        var topLevelPath = ConfigurationManager.GetValue(Resources.SyncDirectoryPathKey);

                        command = new RenameFileCommand(ticket, file.Name, e.FullPath, e.OldFullPath, topLevelPath);
                    }
                }

                //Attach error event handler
                command.ExecuteError += OnExecuteError;

                //Detect the synchronizer object state
                if (_syncing || _synchronizer.Paused)
                {
                    _synchronizer.Synchronize(command);
                }
                else
                {
                    await _synchronizer.SynchronizeAsync(command);
                }
            }
        }
Beispiel #3
0
        private void SynchronizeLocalFiles()
        {
            //Synchronize file sync table items of type file vs on disk files
            var files = SyncTableManager.GetFiles();

            foreach (var file in files)
            {
                if (File.Exists(file.Path))
                {
                    var fileInfo = new FileInfo(file.Path);

                    if (!fileInfo.IsLocked())
                    {
                        //if on disk file is more new that file table item then... upload
                        if (fileInfo.LastWriteTime.ToFileTime() > file.LastWriteTime)
                        {
                            SyncTableManager.ChangeSyncStatusToPending(file.Path);
                            var command = new UploadFileCommand(_ticket, file.GroupId, file.FolderId, file.FileId, fileInfo, _path);
                            command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                            _commandProcessor.AddCommand(command);
                        }
                    }
                }
                else
                {
                    SyncTableManager.ChangeSyncStatusToPending(file.Path);
                    //Delete file from file sync table and dokuflex
                    var command = new DeleteOnlineFileCommand(_ticket, file);
                    command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                    _commandProcessor.AddCommand(command);
                }
            }

            //Synchronize on disk files vs file sync table items of type file
            var filePaths = Directory.EnumerateFiles(_path, "*", SearchOption.AllDirectories);

            foreach (var filePath in filePaths)
            {
                if (filePath.Contains("~"))
                {
                    continue;
                }
                if (filePath.Contains("Thumbs."))
                {
                    continue;
                }

                //Detect new files and upload
                if (!files.Any(f => f.Path.Equals(filePath)))
                {
                    var fileInfo = new FileInfo(filePath);

                    if (fileInfo.Length == 0)
                    {
                        continue;
                    }
                    if (fileInfo.IsLocked())
                    {
                        continue;
                    }

                    var parentDirectory = Directory.GetParent(filePath);
                    var parentFolder    = SyncTableManager.GetByPath(parentDirectory.FullName);

                    if (parentFolder != null)
                    {
                        // Add item as pending
                        var item = new SyncTableItem
                        {
                            Name          = fileInfo.Name,
                            Path          = fileInfo.FullName,
                            LastWriteTime = 0,
                            Type          = "C",
                            GroupId       = parentFolder.GroupId,
                            FolderId      = parentFolder.FolderId,
                            FileId        = string.Empty,
                            ModifiedTime  = 0,
                            SyncFolder    = false,
                            SyncStatus    = SyncTableItemStatus.Pending
                        };

                        SyncTableManager.Add(item);

                        var command = new UploadFileCommand(_ticket, parentFolder.GroupId, parentFolder.FolderId, String.Empty, fileInfo, _path);
                        command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                        _commandProcessor.AddCommand(command);
                    }
                }
            }
        }