private static void DistributeDocuments(CommunicationSupport commSupport) { commSupport.PrintMessage(userDocs.Count + " document(s) marked for upload", false); foreach (DocumentNode doc in userDocs) { string fullDocumentPath = GetDocumentPath(doc) + doc.Name; _ = commSupport.DistributeDocument(fullDocumentPath, cloudDeploymentUrl, doc.ID.ToString(), jwtToken).GetAwaiter().GetResult(); } }
public QlikQvExport(string[] args, CommunicationSupport commSup, IQMS qmsClient) { client = qmsClient; commSupport = commSup; try { foreach (var arg in args) { string parameter = arg.Substring(0, arg.IndexOf('=')); string parameterValue = arg.Substring(arg.LastIndexOf('=') + 1); switch (parameter.ToLower()) { case "-space": space = parameterValue; break; case "-protocol": protocol = parameterValue; break; case "-qvscluster": qvsCluster = parameterValue; break; case "-qvwsmachine": qvwsMachine = parameterValue; break; case "-category": category = parameterValue; break; case "-filename": csvFileName = parameterValue; break; default: break; } } } catch (Exception) { commSupport.PrintMessage("Exception when reading parameters. Run help command for information about usage", true); } protocol = string.IsNullOrEmpty(protocol) ? "http" : protocol; _qms = new Uri(protocol + "://localhost:4799/QMS/Service"); links = new List <string>(); ExportLinks(); }
static void Main(string[] args) { commSupport = new CommunicationSupport(); client = CreateQMSAPIClient(qms); if (args.Length == 1 && args[0].Equals("-help")) { DisplayDocUploaderHelp(); } if (args.Contains("-mode=link")) { RunInLinkMode(args); } else if (args.Contains("-mode=doc")) { RunInDocMode(args); } else { commSupport.PrintMessage("'mode' parameter missing or faulty", true); } }
/// <summary> /// Create a file at the Tus server. /// </summary> /// <param name="url">URL to the creation endpoint of the Tus server.</param> /// <param name="uploadLength">The byte size of the file which will be uploaded.</param> /// <param name="metadata">Metadata to be stored alongside the file.</param> /// <returns>The URL to the created file.</returns> /// <exception cref="Exception">Throws if the response doesn't contain the required information.</exception> public async Task <string> CreateAsync(string url, long uploadLength, CommunicationSupport commSup, string version, params (string key, string value)[] metadata)
/// <summary> /// Perform a request to the Tus server. /// </summary> /// <param name="request">The <see cref="TusHttpRequest"/> to execute.</param> /// <returns>A <see cref="TusHttpResponse"/> with the response data.</returns> /// <exception cref="TusException">Throws when the request fails.</exception> public async Task <TusHttpResponse> PerformRequestAsync(TusHttpRequest request, CommunicationSupport commSup = null) { var segment = request.BodyBytes; try { var webRequest = WebRequest.CreateHttp(request.Url); webRequest.AutomaticDecompression = DecompressionMethods.GZip; webRequest.Timeout = Timeout.Infinite; webRequest.ReadWriteTimeout = Timeout.Infinite; webRequest.Method = request.Method; webRequest.KeepAlive = false; webRequest.Proxy = Proxy; try { webRequest.ServicePoint.Expect100Continue = false; } catch (PlatformNotSupportedException) { //expected on .net core 2.0 with systemproxy //fixed by https://github.com/dotnet/corefx/commit/a9e01da6f1b3a0dfbc36d17823a2264e2ec47050 //should work in .net core 2.2 } //SEND var buffer = new byte[4096]; var totalBytesWritten = 0L; webRequest.AllowWriteStreamBuffering = false; webRequest.ContentLength = segment.Count; foreach (var header in request.Headers) { switch (header.Key) { case TusHeaderNames.ContentLength: webRequest.ContentLength = long.Parse(header.Value); break; case TusHeaderNames.ContentType: webRequest.ContentType = header.Value; break; default: webRequest.Headers.Add(header.Key, header.Value); break; } } if (request.BodyBytes.Count > 0) { var inputStream = new MemoryStream(request.BodyBytes.Array, request.BodyBytes.Offset, request.BodyBytes.Count); using (var requestStream = webRequest.GetRequestStream()) { inputStream.Seek(0, SeekOrigin.Begin); var bytesWritten = await inputStream.ReadAsync(buffer, 0, buffer.Length, request.CancelToken) .ConfigureAwait(false); request.OnUploadProgressed(0, segment.Count); while (bytesWritten > 0) { totalBytesWritten += bytesWritten; request.OnUploadProgressed(totalBytesWritten, segment.Count); await requestStream.WriteAsync(buffer, 0, bytesWritten, request.CancelToken) .ConfigureAwait(false); bytesWritten = await inputStream.ReadAsync(buffer, 0, buffer.Length, request.CancelToken) .ConfigureAwait(false); } } } var response = (HttpWebResponse)await webRequest.GetResponseAsync() .ConfigureAwait(false); //contentLength=0 for gzipped responses due to .net bug long contentLength = Math.Max(response.ContentLength, 0); buffer = new byte[16 * 1024]; var outputStream = new MemoryStream(); using (var responseStream = response.GetResponseStream()) { if (responseStream != null) { var bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length, request.CancelToken) .ConfigureAwait(false); request.OnDownloadProgressed(0, contentLength); var totalBytesRead = 0L; while (bytesRead > 0) { totalBytesRead += bytesRead; request.OnDownloadProgressed(totalBytesRead, contentLength); await outputStream.WriteAsync(buffer, 0, bytesRead, request.CancelToken) .ConfigureAwait(false); bytesRead = await responseStream.ReadAsync(buffer, 0, buffer.Length, request.CancelToken) .ConfigureAwait(false); } } } return(new TusHttpResponse( response.StatusCode, response.Headers.AllKeys .ToDictionary(headerName => headerName, headerName => response.Headers.Get(headerName)), outputStream.ToArray())); } catch (OperationCanceledException cancelEx) { throw new TusException(cancelEx); } catch (WebException ex) { if (commSup != null) { commSup.PrintMessage("WebException when posting file to TCS " + ex.Message, true); } throw new TusException(ex); } catch (Exception e) { if (commSup != null) { commSup.PrintMessage("Exception when posting file to TCS " + e.Message, true); } throw new Exception(e.Message); } }
public QlikQvExport(CommunicationSupport commSup, IQMS qmsClient) { client = qmsClient; commSupport = commSup; }
private static string MigrateFiles(CommunicationSupport commSupport, string filePath, string proxyName, string proxyPort) { return(commSupport.DistributeDocumentsOrFiles(filePath, cloudDeploymentUrl, "", jwtToken, "autoreplace", proxyName, proxyPort, appId).GetAwaiter().GetResult()); }
static void Main(string[] args) { string parameter = string.Empty; string parameterValue = string.Empty; string appDataPath = AppDomain.CurrentDomain.BaseDirectory; string logPath = Path.Combine(appDataPath, "qlik_qv_export_log.txt"); List <string> parameterList = new List <string>(); if (args.Length == 1 && args[0].Equals("-help")) { DisplayDocUploaderHelp(); } try { foreach (var arg in args) { parameter = arg.Substring(0, arg.IndexOf('=')); parameterValue = arg.Substring(arg.LastIndexOf('=') + 1); parameterList.Add(parameter.ToLower() + "=" + parameterValue); switch (parameter.ToLower()) { case "-mode": mode = parameterValue; break; case "-cloudurl": cloudDeploymentUrl = parameterValue; break; case "-uploadpath": uploadpath = parameterValue; break; case "-documentfolder": mountOrRootFolder = parameterValue; break; case "-qvscluster": qvsCluster = parameterValue; break; case "-handleddirectory": handledDirectory = parameterValue; break; case "-api_key": jwtToken = parameterValue; break; case "-proxyname": proxyname = parameterValue; break; case "-proxyport": proxyport = parameterValue; break; case "-appid": appId = parameterValue; break; case "-space": space = parameterValue; break; case "-protocol": protocol = parameterValue; break; case "-qvwsmachine": qvwsMachine = parameterValue; break; case "-category": category = parameterValue; break; case "-filename": csvFileName = parameterValue; break; default: break; } } commSupport = new CommunicationSupport(proxyname, proxyport, logPath); } catch (Exception e) { File.AppendAllText(logPath, DateTime.Now.ToString() + "\t Exception when reading parameters. Parameter: " + parameter + " Parameter value: " + parameterValue + "Exception " + e.Message + " Run help command for information about usage" + Environment.NewLine); Console.WriteLine("Exception when reading parameters. Parameter: " + parameter + " Parameter value: " + parameterValue + "Exception " + e.Message + " Run help command for information about usage", true); Console.WriteLine("Press any key to exit"); Console.ReadKey(); Environment.Exit(0); } finally { File.AppendAllText(logPath, DateTime.Now.ToString() + "\t" + "Following parameters are set: " + Environment.NewLine); parameterList.ForEach(x => File.AppendAllText(logPath, DateTime.Now.ToString() + "\t" + x + Environment.NewLine)); Console.WriteLine("Parameter log written to " + logPath, true); } if (mode.Equals("link")) { RunInLinkMode(); } else if (mode.Equals("doc")) { RunInDocMode(); } else if (mode.Equals("migrate")) { RunInMigrateMode(); } else { commSupport.PrintMessage("'mode' parameter missing or faulty. Mode parameter value: " + mode, true); } }