Ejemplo n.º 1
0
        public int IsMemberOf(string path, uint attributes)
        {
            SyncTableManager.Reload();

            var item = SyncTableManager.GetByPath(path);

            if (item == null)
            {
                unchecked
                {
                    return((int)HRESULT.S_FALSE);
                }
            }

            try
            {
                unchecked
                {
                    return(item.State == ItemState ? (int)HRESULT.S_OK : (int)HRESULT.S_FALSE);
                }
            }
            catch
            {
                unchecked
                {
                    return((int)HRESULT.E_FAIL);
                }
            }
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
0
        protected override void DoExecute()
        {
            try
            {
                File.Delete(_path);
            }
            catch (Exception ex)
            {
                var newMsg = string.Format("Delete file, raise an exception with: {0}, Exception: {1}", _path, ex.Message);
                throw new Exception(newMsg);
            }

            SyncTableManager.RemoveAllByPath(_path);
            SyncTableManager.Save();
        }
        protected override async Task <bool> DoExecuteAsync()
        {
            try
            {
                var result = await DokuFlexService.DeleteFolderAsync(_ticket, _item.GroupId, _item.FolderId);

                SyncTableManager.RemoveAllByPath(_item.Path);
                SyncTableManager.Save();

                return(result);
            }
            catch (Exception ex)
            {
                var newMsg = string.Format("Delete online directory, raise an exception with: {0}, Exception: {1}", _item.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.º 6
0
        protected override async Task <bool> DoExecuteAsync()
        {
            var item = SyncTableManager.GetByPath(_oldFullPath);

            if (item != null)
            {
                var syncItems = SyncTableManager.GetAllByPath(_oldFullPath);

                if (syncItems != null)
                {
                    foreach (var syncItem in syncItems)
                    {
                        if (syncItem.Type == "F" &&
                            String.Compare(syncItem.FolderId, item.FolderId) == 0)
                        {
                            syncItem.Name = _newName;
                        }

                        syncItem.Path = syncItem.Path.Replace(_oldFullPath, _fullPath);
                    }
                }
                else
                {
                    item.Name = _newName;
                    item.Path = item.Path.Replace(_oldFullPath, _fullPath);
                }

                try
                {
                    return(await DokuFlexService.RenameFileFolderAsync(_ticket, item.GroupId, item.FolderId, _newName));
                }
                catch (Exception ex)
                {
                    var newMsg = string.Format("Rename directory, raise an exception with: {0}, Exception: {1}", item.Path, ex.Message);
                    throw new Exception(newMsg);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        protected override async Task <bool> DoExecuteAsync()
        {
            var item = SyncTableManager.GetByPath(_oldFullPath);

            if (item != null)
            {
                item.Name = _newName;
                item.Path = item.Path.Replace(_oldFullPath, _fullPath);
            }
            else
            {
                return(false);
            }

            try
            {
                return(await DokuFlexService.RenameFileFolderAsync(_ticket, item.GroupId, item.FileId, _newName));
            }
            catch (Exception ex)
            {
                var newMsg = string.Format("Rename file, raise an exception with: {0}, Exception: {1}", item.Path, ex.Message);
                throw new Exception(newMsg);
            }
        }
Ejemplo n.º 8
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.º 9
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);
            }
        }