Ejemplo n.º 1
0
        public static void Add(SyncTableItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            //Check is item exist
            if (_syncTable.IndexOf(item) > 0)
            {
                return;
            }

            _syncTable.Add(item);
        }
Ejemplo n.º 2
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);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public static void Remove(SyncTableItem item)
 {
     _syncTable.Remove(item);
 }
Ejemplo n.º 4
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);
                    }
                }
            }
        }