Exemple #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);
        }
Exemple #2
0
 private void OnPopup(object sender, EventArgs e)
 {
     _contextMenu.MenuItems[3].Enabled = !_syncing;
     _contextMenu.MenuItems[4].Enabled = _contextMenu.MenuItems[4].Visible = !_synchronizer.Paused;
     _contextMenu.MenuItems[5].Enabled = _contextMenu.MenuItems[5].Visible = _synchronizer.Paused;
     _contextMenu.MenuItems[6].Enabled = SyncTableManager.ContainsFolders();
 }
 public void StopSyncing(string id)
 {
     try
     {
         lock (thisLock)
         {
             SyncTableManager.RemoveAllByGroupId(id);
             SyncTableManager.Save();
         }
     }
     catch
     {
         //Silent exception...
     }
 }
Exemple #4
0
        private void LoadNotSyncItems()
        {
            var items = SyncTableManager.GetNotSyncItems();

            foreach (var item in items)
            {
                var listViewItem = new ListViewItem()
                {
                    Text = item.Name
                };

                listViewItem.SubItems.Add(item.Path);
                listViewItem.SubItems.Add(item.SyncStatusText);
                listView1.Items.Add(listViewItem);
            }
        }
Exemple #5
0
        private void SynchronizeDeletedDirectories()
        {
            //Synchronize file sync table items of type folder vs on disk directories
            var folders = SyncTableManager.GetFolders();

            //Detect delete directories from disk
            foreach (var folder in folders)
            {
                if (!Directory.Exists(folder.Path))
                {
                    var command = new DeleteOnlineDirectoryCommand(_ticket, folder);
                    command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                    _commandProcessor.AddCommand(command);
                }
            }
        }
Exemple #6
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);
                }
            }
        }
        private void lkStoreLocation_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (SyncTableManager.ContainsFolders())
            {
                return;
            }

            using (var folderDlg = new FolderBrowserDialog())
            {
                folderDlg.SelectedPath = _presenter.SyncDirectory;

                if (folderDlg.ShowDialog() == DialogResult.OK)
                {
                    _presenter.SyncDirectory = folderDlg.SelectedPath;
                    lkStoreLocation.Text     = folderDlg.SelectedPath;
                }
            }
        }
 public IList <SyncTableItem> GetSyncFolders()
 {
     return(SyncTableManager.GetSyncFolders());
 }
Exemple #9
0
        private async Task SynchronizeOnlineFilesFolders()
        {
            var folders = SyncTableManager.GetFolders();

            foreach (var folder in folders)
            {
                try
                {
                    var filesFolders = await DokuFlexService.GetFilesFoldersAsync(_ticket, folder.GroupId, folder.FolderId);

                    foreach (var fileFolder in filesFolders)
                    {
                        if (fileFolder.type == "C")
                        {
                            //Check if file exists in sync table
                            var file = SyncTableManager.GetByFileId(fileFolder.id);

                            if (file != null)
                            {
                                if (fileFolder.modifiedTime > file.ModifiedTime)
                                {
                                    SyncTableManager.ChangeSyncStatusToPending(file.Path);
                                    var command = new DownloadFileCommand(_ticket, folder.GroupId, folder.FolderId, fileFolder, file.Path, _path);
                                    command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                                    _commandProcessor.AddCommand(command);
                                }
                            }
                            else
                            {
                                var path = string.Format("{0}\\{1}", folder.Path, fileFolder.name);

                                //Add item as pending
                                var item = new SyncTableItem
                                {
                                    Name          = fileFolder.name,
                                    Path          = path,
                                    LastWriteTime = 0,
                                    Type          = "C",
                                    GroupId       = folder.GroupId,
                                    FolderId      = folder.FolderId,
                                    FileId        = string.Empty,
                                    ModifiedTime  = 0,
                                    SyncFolder    = false,
                                    SyncStatus    = SyncTableItemStatus.Pending
                                };

                                SyncTableManager.Add(item);

                                var command = new DownloadFileCommand(_ticket, folder.GroupId, folder.FolderId, fileFolder, path, _path);
                                command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                                _commandProcessor.AddCommand(command);
                            }
                        }
                        else
                        {
                            //Check if folder exists
                            if (!folders.Any(f => f.FolderId.Equals(fileFolder.id) && f.Type == "F"))
                            {
                                var path    = String.Format("{0}\\{1}", folder.Path, fileFolder.name);
                                var command = new CreateDirectoryCommand(folder.GroupId, fileFolder, path);
                                command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                                _commandProcessor.AddCommand(command);
                            }
                        }
                    }

                    var files = SyncTableManager.GetFiles(folder.FolderId);

                    foreach (var file in files)
                    {
                        if (!filesFolders.Any(f => f.id.Equals(file.FileId)))
                        {
                            SyncTableManager.ChangeSyncStatusToPending(file.Path);
                            var command = new DeleteFileCommand(file.Path);
                            command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                            _commandProcessor.AddCommand(command);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Check is folder doesn't exists
                    if (ex is RestResponseException)
                    {
                        var exception = ex as RestResponseException;

                        //Folder doesn't exists
                        if (exception.ErrorCode == 1)
                        {
                            var command = new DeleteDirectoryCommand(folder.Path);
                            command.ExecuteError += new ExecuteErrorEventHandler(OnExecuteError);
                            _commandProcessor.AddCommand(command);
                        }
                    }
                }
            }
        }
Exemple #10
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);
                    }
                }
            }
        }
Exemple #11
0
        public async Task SyncANewUserGroupAsync(string p1, string p2, string p3)
        {
            var ticket = Session.GetTikect();

            if (string.IsNullOrWhiteSpace(ticket))
            {
                return;
            }

            var group = new UserGroup()
            {
                id = p1, name = p2
            };
            var syncDirectory = ConfigurationManager.GetValue(Resources.SyncDirectoryPathKey);

            if (string.IsNullOrWhiteSpace(syncDirectory))
            {
                using (var syncNewUserGroup = new SyncNewUserGroupView(ticket, group))
                {
                    if (syncNewUserGroup.ShowDialog() == DialogResult.OK)
                    {
                        syncDirectory = syncNewUserGroup.SyncDirectory;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (SyncTableManager.GetByGroupId(p3) != null)
            {
                return;
            }

            var directory          = string.Format("{0}\\{1}", syncDirectory, group.name);
            var fileFolderInfoList = new List <FileFolderInfo>();
            var fileFolderInfo     = new FileFolderInfo()
            {
                GroupId    = group.id,
                Path       = directory,
                SyncFolder = true
            };

            fileFolderInfoList.Add(fileFolderInfo);

            using (var syncProgress = new SyncProgressView())
            {
                if (syncProgress.SyncNewUserGroup(ticket, directory, group))
                {
                    fileFolderInfoList.AddRange(syncProgress.FileFolderList);
                }
            }

            //Detect the synchronizer object state
            if (_syncing || _synchronizer.Paused)
            {
                _synchronizer.Synchronize(fileFolderInfoList);
            }
            else
            {
                await _synchronizer.SynchronizeAsync(ticket, directory, fileFolderInfoList);
            }

            WatchingPath(syncDirectory);
        }