Ejemplo n.º 1
0
        protected override void DoExecute()
        {
            try
            {
                var directoryInfo = Directory.Exists(_path) ? new DirectoryInfo(_path) : Directory.CreateDirectory(_path);
                //Add to sync table
                var item = new SyncTableItem()
                {
                    Name          = directoryInfo.Name,
                    Path          = directoryInfo.FullName,
                    LastWriteTime = directoryInfo.LastWriteTime.ToFileTime(),
                    Type          = _type,
                    GroupId       = _groupId,
                    SyncFolder    = _synFolder
                };

                if (string.Compare("F", _type) == 0)
                {
                    item.FolderId     = _fileFolder.id;
                    item.ModifiedTime = _fileFolder.modifiedTime;
                }

                SyncTableManager.Add(item);
                SyncTableManager.Save();
            }
            catch (Exception ex)
            {
                var newMsg = string.Format("Create directory, raise an exception with: {0}, Exception: {1}", _path, ex.Message);
                throw new Exception(newMsg);
            }
        }
        protected override async Task <bool> DoExecuteAsync()
        {
            var directory = new DirectoryInfo(_path);

            //Add item to SyncTable and set the SyncProgress state
            var item = new SyncTableItem()
            {
                Name          = directory.Name,
                Path          = _path,
                LastWriteTime = directory.LastWriteTimeUtc.ToFileTimeUtc(),
                Type          = "F",
                GroupId       = _groupId,
                FolderId      = String.Empty,
                FileId        = String.Empty,
                ModifiedTime  = 0,
                SyncFolder    = false,
            };

            SyncTableManager.Add(item);
            SyncTableManager.Save();

            try
            {
                var nodeId = await DokuFlexService.CreateFolderAsync(_ticket, _groupId, _parentFolderId, directory.Name);

                //Set nodeId property
                item.FolderId = nodeId;
                SyncTableManager.Save();

                return(!String.IsNullOrWhiteSpace(nodeId));
            }
            catch (Exception ex)
            {
                //Rollback the Add item action
                SyncTableManager.Remove(item);
                SyncTableManager.Save();

                var newMsg = string.Format("Create online directory, raise an exception with: {0}, Exception: {1}", _path, ex.Message);
                throw new Exception(newMsg);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        protected override async Task <bool> DoExecuteAsync()
        {
            var sourcePath = Command.SourcePath;
            var targetPath = _fileInfo.FullName;

            //remove this code when possible.
            if (string.Equals(sourcePath, targetPath))
            {
                var newMsg = string.Format("The source file was already processed in a previous call. File: {0}", sourcePath);
                throw new Exception(newMsg);
            }

            var item = SyncTableManager.GetByPath(_fileInfo.FullName);

            if (item == null)
            {
                item = new SyncTableItem()
                {
                    Name          = _fileInfo.Name,
                    Path          = _fileInfo.FullName,
                    LastWriteTime = 0,
                    Type          = "C",
                    GroupId       = _groupId,
                    FolderId      = _folderId,
                    FileId        = _fileId,
                    ModifiedTime  = 0,
                    SyncFolder    = false
                };

                SyncTableManager.Add(item);
            }
            else
            {
                item.SyncStatus = SyncTableItemStatus.SyncInProgress;
            }

            try
            {
                var uploadInfo = await DokuFlexService.UploadFileAsync(_ticket, _groupId, _folderId, _fileId, _fileInfo, true);

                //Set additional attributes
                item.LastWriteTime = _fileInfo.LastWriteTime.ToFileTimeUtc();
                item.FileId        = uploadInfo.nodeId;
                item.ModifiedTime  = uploadInfo.modifiedTime;
                item.SyncStatus    = SyncTableItemStatus.InSync;

                SyncTableManager.Save();

                //This too!
                Command.SourcePath = _fileInfo.FullName;
                return(uploadInfo != null);
            }
            catch (Exception ex)
            {
                var newMsg = string.Format("File: {0}, Exception: {1}", _fileInfo.FullName, ex.Message);
                item.LastWriteTime = 0; //Enable this file to by uploaded again in some point of the time
                item.SyncStatus    = SyncTableItemStatus.ErrorConflict;

                throw new Exception(newMsg);
            }
        }