private async Task <CollectionEntity> CreateEngineItem(EngineDoc doc, string jwtToken, string multiCloudMachineName, string docName) { CollectionEntity result = null; try { result = await GetItem(jwtToken, multiCloudMachineName, doc.Attributes.AppId, "qvapp"); if (result != null && result.Id != null) { return(result); } string additionalUri = "items"; string jsonRequest = SetupJson(doc, docName); using (HttpResponseMessage createItemResponse = await SetupAndSendRequest(HttpMethod.Post, multiCloudMachineName + additionalUri, jsonRequest, jwtToken)) { if (createItemResponse != null && createItemResponse.StatusCode == HttpStatusCode.NotFound) { PrintMessage("Failure - Document could not be created. StatusCode= " + createItemResponse.StatusCode + ", reason= " + createItemResponse.ReasonPhrase, false); } var responseContent = await createItemResponse.Content.ReadAsStringAsync() ?? "{}"; result = JsonConvert.DeserializeObject <CollectionEntity>(responseContent); } } catch (Exception e) { PrintMessage("Failure - Could not create item for doc upload. Exception= " + e.Message, false); } return(result); }
public async Task <string> DistributeDocumentsOrFiles(string fileNameAndPath, string cloudDeploymentResourceUrl, string sourceDocumentId, string jwtToken, string mode, string proxyName, string proxyPort, string appId = null) { PrintMessage("Deployment Name: " + cloudDeploymentResourceUrl, false); string multiCloudMachineName = cloudDeploymentResourceUrl.TrimEnd('/') + "/api/v1/"; string responseContent; try { Assembly assembly = Assembly.GetExecutingAssembly(); string version = assembly.GetName().Version.ToString(); var tusClient = new TusClient(version); tusClient.AdditionalHeaders.Add("Authorization", "Bearer " + jwtToken); string url; using (var l_FileStream = new FileStream(fileNameAndPath, FileMode.Open, FileAccess.Read)) { url = await tusClient.CreateAsync(multiCloudMachineName + "temp-contents/files", l_FileStream.Length, this, proxyName, proxyPort); int cloudChunkSize = 300; PrintMessage("Upload file to Cloud - Chunk size set to " + cloudChunkSize, false); await tusClient.UploadAsync(url, l_FileStream, cloudChunkSize, this, proxyName, proxyPort); } responseContent = await ImportApp(jwtToken, multiCloudMachineName, sourceDocumentId, fileNameAndPath, url, mode, appId, version); if (string.IsNullOrEmpty(responseContent)) { return(string.Empty); } EngineDoc result = JsonConvert.DeserializeObject <EngineDoc>(responseContent); CollectionEntity engineItem = await CreateEngineItem(result, jwtToken, multiCloudMachineName, Path.GetFileNameWithoutExtension(fileNameAndPath), version); if (engineItem == null) { return(string.Empty); } } catch (HttpAppSizeException) { throw; } catch (WorkflowException) { throw; } catch (TaskCanceledException e) { PrintMessage("Failure - Could not upload document to engine, Connection timeout. Message =" + e.Message, false); throw new AppUploadTimeoutException("Client connection timeout."); } catch (Exception) { throw; } return(responseContent); }