public void ShouldCombineUrl() { var combiner = new UrlCombiner(); string expected = "mixerp.org/erp"; string result = combiner.Combine("mixerp.org", "erp"); Assert.Equal(expected, result); }
/// <summary> /// Performs a post request to this documents endpoint. /// </summary> /// <remarks>For more details about RESTful Document CRUD, check /// <a href="https://doc.nuxeo.com/display/NXDOC/Document+Resources+Endpoints">Nuxeo Documentation Center</a>. /// </remarks> /// <param name="entity">The <see cref="Entity"/> to be posted.</param> /// <param name="extendEndpoint">A path suffix to be apeended to the document's enpoint, including the adapter.</param> /// <returns>A <see cref="Task"/> that will return the resulting <see cref="Entity"/>.</returns> public async Task <Entity> Post(Entity entity, string extendEndpoint = "") { return(await client.Post(GenerateEndpoint(true, UrlCombiner.Combine((entity is BusinessObject ? ((BusinessObject)entity).Name : string.Empty), extendEndpoint)), null, client.Marshaller.Marshal(entity), GenerateHeaders())); }
/// <summary> /// Executes a an <see cref="UploadJob"/>. /// </summary> /// <param name="job">The <see cref="UploadJob"/> to be executed.</param> /// <returns>A new and updated <see cref="Batch"/> instance of the current batch.</returns> public async Task <Batch> Upload(UploadJob job) { if (job.IsChunked) { int readBytes, currentChunk = 0, chunkCount = (int)Math.Ceiling((double)job.Blob.File.Length / job.ChunkSize); byte[] buffer = new byte[job.ChunkSize]; Batch batch = null; using (FileStream fs = job.Blob.File.OpenRead()) { while ((readBytes = fs.Read(buffer, 0, buffer.Length)) > 0) { batch = (Batch)await client.PostBin(UrlCombiner.Combine(Endpoint, job.FileId.ToString()), null, buffer, new Dictionary <string, string>() { { "X-Upload-Type", "chunked" }, { "X-Upload-Chunk-Index", currentChunk.ToString() }, { "X-Upload-Chunk-Count", chunkCount.ToString() }, { "X-File-Name", Uri.EscapeDataString(job.Blob.Filename) }, { "X-File-Type", job.Blob.MimeType }, { "X-File-Size", job.Blob.File.Length.ToString() } }); currentChunk++; } } return(batch); } else { using (FileStream fs = job.Blob.File.OpenRead()) { return((Batch)await client.PostBin(UrlCombiner.Combine(Endpoint, job.FileId.ToString()), null, fs.ReadToEnd(), new Dictionary <string, string>() { { "X-File-Name", Uri.EscapeDataString(job.Blob.Filename) }, { "X-File-Type", job.Blob.MimeType } })); } } }
private string BuildEndpointForDoc(string doc, string extension = "", EndpointType type = EndpointType.UID, bool withAdapter = false) { List <string> segments = new List <string>(); segments.Add(client.RestPath); if (!string.IsNullOrEmpty(Repository)) { segments.Add("repo"); segments.Add(Repository); } segments.Add(type == EndpointType.UID ? "id" : "path"); segments.Add(doc); if (withAdapter && Adapter != null) { segments.Add(Adapter.GetEndpointSuffix()); } if (!string.IsNullOrEmpty(extension)) { segments.Add(extension); } return(UrlCombiner.Combine(segments.ToArray())); }
/// <summary> /// Returns the endpoint suffix to the current <see cref="Adapter"/>, to be appended to other requests. /// </summary> /// <returns>A string with the endpoint suffix.</returns> public string GetEndpointSuffix() { return("@" + UrlCombiner.Combine(Id, (Parameters != string.Empty ? (Parameters[0] != '?' ? "/" : string.Empty) + Parameters : string.Empty))); }
/// <summary> /// Initializes a new instance of <see cref="BatchOperation"/>. /// </summary> /// <param name="client">The client over which the operation is to be executed.</param> /// <param name="batch">The <see cref="Batch"/> over which the operation is to be executed.</param> /// <param name="id">The operation id.</param> public BatchOperation(Client client, Batch batch, string id) : base(client, id) { Batch = batch; Endpoint = UrlCombiner.Combine(client.RestPath, "upload/", Batch.BatchId, "execute/", Id); }
/// <summary> /// Sets the Nuxeo <see cref="Client"/> instance through which the requests for this batch will be made. /// </summary> /// <param name="client">The Nuxeo <see cref="Client"/> instance.</param> /// <returns>The current <see cref="Batch"/> instance.</returns> public Batch SetClient(Client client) { this.client = client; Endpoint = UrlCombiner.Combine(client.RestPath, "upload/", BatchId); return(this); }
/// <summary> /// Requests information about a particular uploaded file. /// </summary> /// <param name="fileIndex">The index of the uploaded file.</param> /// <returns>An instance of <see cref="BatchFile"/> containing information about the file.</returns> public async Task <BatchFile> Info(int fileIndex) { return((BatchFile)await client.Get(UrlCombiner.Combine(Endpoint, fileIndex.ToString()))); }
static UrlHelper() { Combiner = new UrlCombiner(); }