예제 #1
0
파일: Main.cs 프로젝트: dokuflex/Dokuflex
        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);
                }
            }
        }