Ejemplo n.º 1
0
        protected override async Task <bool> DoExecuteAsync()
        {
            try
            {
                //Create the target file to download
                File.Create(_filePath).Close();

                var item = SyncTableManager.GetByPath(_filePath);

                if (item == null)
                {
                    //Add to file sync table
                    item = new SyncTableItem()
                    {
                        Name          = string.Empty,
                        Path          = _filePath,
                        LastWriteTime = 0,
                        Type          = _fileFolder.type,
                        GroupId       = _groupId,
                        FolderId      = _folderId,
                        FileId        = _fileFolder.id,
                        ModifiedTime  = _fileFolder.modifiedTime,
                        SyncFolder    = false
                    };

                    SyncTableManager.Add(item);
                }
                else
                {
                    item.FileId       = _fileFolder.id;
                    item.ModifiedTime = _fileFolder.modifiedTime;
                    item.SyncStatus   = SyncTableItemStatus.SyncInProgress;
                }

                var result = await DokuFlexService.DownloadFileAsync(_ticket, _fileFolder.id, _filePath);

                var fileInfo = new FileInfo(_filePath);

                item.Name          = fileInfo.Name;
                item.LastWriteTime = fileInfo.LastWriteTime.ToFileTime();
                item.SyncStatus    = SyncTableItemStatus.InSync;

                SyncTableManager.Save();

                return(result);
            }
            catch (Exception ex)
            {
                if (File.Exists(_filePath))
                {
                    var fileInfo = new FileInfo(_filePath);
                    var item     = SyncTableManager.GetByPath(_filePath);
                    item.Name          = fileInfo.Name;
                    item.LastWriteTime = fileInfo.LastWriteTime.ToFileTime();
                    item.SyncStatus    = SyncTableItemStatus.ErrorConflict;
                    SyncTableManager.Save();
                }
                else
                {
                    var newMsg = string.Format("Download file, raise an exception with: {0}, Exception: {1}", _filePath, ex.Message);
                    throw new Exception(newMsg);
                }
            }

            return(false);
        }