예제 #1
0
 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();
     }
 }
예제 #2
0
        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();
        }
예제 #3
0
        public void ExportLinks(string space, string protocol, string qvsCluster, string qvwsMachine, string category, string csvFileName)
        {
            protocol = string.IsNullOrEmpty(protocol) ? "http" : protocol;
            links    = new List <string>();
            try
            {
                if (client != null)
                {
                    ServiceInfo qvs = FindService(client, ServiceTypes.QlikViewServer, qvsCluster.Trim());
                    if (qvs == null)
                    {
                        commSupport.PrintMessage("Could not find QlikView Server", true);
                    }
                    ServiceInfo qvwsService = FindService(client, ServiceTypes.QlikViewWebServer, qvwsMachine.Trim());
                    if (qvwsService == null)
                    {
                        commSupport.PrintMessage("Could not find Qvws", true);
                    }

                    string qvwsUrl = qvwsService.Address.Scheme + "://" + qvwsService.Address.Host;

                    links.Add("Name" + delimiter + "URL" + delimiter + "Description" + delimiter + "Space" + delimiter + "Type" + delimiter + "DateCreated");
                    client.ClearQVSCache(QVSCacheObjects.UserDocumentList);
                    List <DocumentNode>   userDocs       = client.GetUserDocuments(qvs.ID);
                    List <DocumentFolder> userDocFolders = client.GetUserDocumentFolders(qvs.ID, DocumentFolderScope.All);

                    bool filterForCategories = !string.IsNullOrEmpty(category);
                    foreach (DocumentNode userDoc in userDocs)
                    {
                        DocumentFolder docFolder = userDocFolders.FirstOrDefault(x => x.ID.Equals(userDoc.FolderID));
                        string         mountName = string.Empty;
                        if (docFolder != null)
                        {
                            mountName = docFolder.General.Path.ToLower();
                        }
                        if (filterForCategories)
                        {
                            DocumentMetaData dmd = client.GetDocumentMetaData(userDoc, DocumentMetaDataScope.All);
                            if (dmd.DocumentInfo.Category.ToLower().Equals(category.ToLower()))
                            {
                                ComposeDocumentLinkUrl(mountName, userDoc.RelativePath, qvwsUrl, userDoc.Name, qvsCluster, space, "");
                            }
                        }
                        else
                        {
                            ComposeDocumentLinkUrl(mountName, userDoc.RelativePath, qvwsUrl, userDoc.Name, qvsCluster, space, "");
                        }
                    }
                    WriteToCSVFile(csvFileName);
                }
                else
                {
                    commSupport.PrintMessage("Could not create connection to QMS", true);
                }
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception when exporting links, run help command for information about usage: Exeception:" + e.Message, true);
            }
        }
예제 #4
0
        private static void RunInDocMode(string[] args)
        {
            try
            {
                foreach (var arg in args)
                {
                    string parameter      = arg.Substring(0, arg.IndexOf('='));
                    string parameterValue = arg.Substring(arg.LastIndexOf('=') + 1);

                    switch (parameter.ToLower())
                    {
                    case "-cloudurl":
                        cloudDeploymentUrl = parameterValue;
                        break;

                    case "-documentfolder":
                        mountOrRootFolder = parameterValue;
                        break;

                    case "-qvscluster":
                        qvsCluster = parameterValue;
                        break;

                    case "-api_key":
                        jwtToken = parameterValue;
                        break;

                    default:
                        break;
                    }
                }
                if (string.IsNullOrEmpty(cloudDeploymentUrl) || string.IsNullOrEmpty(qvsCluster) || string.IsNullOrEmpty(jwtToken))
                {
                    commSupport.PrintMessage("Please supply required parameters", true);
                }
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception when reading parameters." + e.Message + " Run help command for information about usage", true);
            }
            try
            {
                SetUpStartValues();
                DistributeDocuments(commSupport);
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception: " + e.Message, true);
            }
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
        /// <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);
            }
        }
예제 #7
0
        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);
            }
        }
예제 #8
0
        private static void RunInMigrateMode()
        {
            if (string.IsNullOrEmpty(cloudDeploymentUrl) || string.IsNullOrEmpty(uploadpath) || string.IsNullOrEmpty(jwtToken) || string.IsNullOrEmpty(appId))
            {
                commSupport.PrintMessage("cloudurl, uploadpath, appId and api_key are required parameters", true);
            }

            try
            {
                commSupport.PrintMessage("Ready to migrate", false);
                string result = MigrateFiles(commSupport, uploadpath, proxyname, proxyport);
                if (string.IsNullOrEmpty(result))
                {
                    commSupport.PrintMessage("Failed to migrate " + uploadpath, true);
                }
                else if (!string.IsNullOrEmpty(handledDirectory))
                {
                    CopyUploadedFileToHandledDirectory(handledDirectory, uploadpath);
                }
                commSupport.PrintMessage("Migration of " + uploadpath + " succeeded", true);
            }
            catch (Exception e)
            {
                commSupport.PrintMessage("Exception when uploading file to cloud: " + e.Message, true);
            }
        }