コード例 #1
0
        public async Task <SharedOnlineItem> ShareItemAsync(OnlineItem onlineItem)
        {
            // https://doc.owncloud.org/server/10.0/developer_manual/core/ocs-share-api.html
            var keyValuePairs = new Dictionary <string, string>
            {
                // path - (string) path to the file/folder which should be shared
                { "path", @"/" + onlineItem.LocalPath },

                // shareType - (int) 0 = user; 1 = group; 3 = public link; 6 = federated cloud share
                { "shareType", "3" },

                // permissions - (int) 1 = read; 2 = update; 4 = create; 8 = delete; 16 = share; 31 = all (default: 31, for public shares: 1)
                // { "permissions", "1" }
            };

            var response = await PostPropertiesAsync(OnlinePathBuilder.FileShareApi(_connectionSettings.StorageUri), keyValuePairs);

            // {"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":{"id":2,"url":"https://???.stackstorage.com/index.php/s/M56HdvsvIAhi37Z","token":"M56HdvsvIAhi37Z","permissions":1,"expiration":""}}}

            dynamic data = response.OCS.Data;

            return(new SharedOnlineItem(onlineItem)
            {
                ShareId = (string)data.id,
                ShareUrl = new Uri((string)data.url, UriKind.Absolute)
            });
        }
コード例 #2
0
        public async Task <OwnCloudResponse> SetPasswordAsync(SharedOnlineItem onlineItem, string password)
        {
            var keyValuePairs = new Dictionary <string, string>
            {
                { "password", password }
            };

            return(await PostPropertiesAsync(OnlinePathBuilder.FileExpirationApi(_connectionSettings.StorageUri, onlineItem), keyValuePairs, "PUT"));

            // {"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":[]}}
        }
コード例 #3
0
        public async Task <OwnCloudResponse> SetExpiryDateAsync(SharedOnlineItem onlineItem, DateTime limit)
        {
            var keyValuePairs = new Dictionary <string, string>
            {
                { "expireDate", limit.ToString("yyyy-MM-dd") }
            };

            return(await PostPropertiesAsync(OnlinePathBuilder.FileExpirationApi(_connectionSettings.StorageUri, onlineItem), keyValuePairs, "PUT"));

            // {"ocs":{"meta":{"status":"ok","statuscode":100,"message":null},"data":[]}}
        }
コード例 #4
0
        private OnlineItem UploadFile(UploadStatus status, OnlineItem folder, string filePath)
        {
            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                long length = stream.Length;

                var child = OnlinePathBuilder.CreateChild(folder, Path.GetFileName(filePath));
                var task  = _client.PutFile(child.FullPath, stream, new PutFileParameters {
                    CancellationToken = _cancellationToken
                });
                do
                {
                    status.FileProgress = (float)((double)stream.Position / length);
                } while (!task.IsFaulted && !task.IsCanceled && !task.IsCompleted && !task.Wait(100));

                return(child);
            }
        }
コード例 #5
0
        public async Task <OnlineItem> CreateFolderAsync(string relativePath, OnlineItem parent = null)
        {
            // The default relative path is just nothing.
            if (string.IsNullOrEmpty(relativePath))
            {
                throw new ArgumentException("The relative path cannot be null or empty.", nameof(relativePath));
            }
            if (relativePath.StartsWith("/") || relativePath.EndsWith("/"))
            {
                throw new ArgumentException("The relative path cannot start or end with a slash.", nameof(relativePath));
            }

            // Create a new root if it does not exist (this will be the /Share/Guid/ folder.
            if (parent == null)
            {
                parent           = new OnlineItem();
                parent.LocalPath = string.Empty;
                parent.FullPath  = OnlinePathBuilder.ConvertPathToFullUri(_connectionSettings.StorageUri, null);
            }

            OnlineItem currentChild = parent;

            var pathParts = relativePath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string pathPart in pathParts)
            {
                currentChild = OnlinePathBuilder.CreateChild(currentChild, pathPart);

                // Create the folder
                _cancellationToken.ThrowIfCancellationRequested();

                var createResponse = await _client.Mkcol(currentChild.FullPath, new MkColParameters { CancellationToken = _cancellationToken }).ConfigureAwait(false);

                if (createResponse.StatusCode != 201 && createResponse.StatusCode != 405) // 405 if maybe a tweak to not check if it exists?
                {
                    throw new Exception($"The folder is not created, code={createResponse.StatusCode}, description={createResponse.Description}");
                }
            }

            return(OnlinePathBuilder.CreateChild(parent, relativePath));
        }