コード例 #1
0
        public bool SendPackageToApi(PerformContext context, EnvironmentSettings environment, UploadDataPackageSettings importJob, string fileContent, string executionId, string uniqueFileName)
        {
            LogDebug(context, "Package is beign uploaded to API");
            var client = new RestClient(environment.ApiUrl);

            client.Timeout = -1;
            var request = new RestRequest(Method.POST);

            request.AddHeader(environment.ApiSubscriptionKeyName, environment.ApiSubscriptionKeyValue);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", JsonConvert.SerializeObject(new
            {
                baseUrl           = environment.BaseUrl,
                clientId          = environment.ClientId,
                clientSecret      = environment.ClientSecret,
                definitionGroupId = importJob.DefinitionGroupId,
                executionId,
                fileContent,
                legalEntityId = environment.LegalEntityId,
                tenant        = environment.Tenant,
                uniqueFileName
            }), ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            LogDebug(context, $"Package uploaded to API - response received ({response.StatusCode}): {response.Content}");
            return(response.StatusCode == System.Net.HttpStatusCode.OK);
        }
コード例 #2
0
        public void ExecuteJob(PerformContext context, EnvironmentSettings environment, UploadDataPackageSettings settings)
        {
            var filesInFolder = Directory.GetFiles(settings.SourceFolder);

            foreach (var file in filesInFolder)
            {
                var fileInfo = new FileInfo(file);
                // if file is locked means it is not ready to process
                if (!fileInfo.IsFileLocked())
                {
                    var bytes          = File.ReadAllBytes(file);
                    var fileContent    = Convert.ToBase64String(bytes);
                    var executionId    = Path.GetFileNameWithoutExtension(file);
                    var uniqueFileName = Path.GetFileName(file);

                    if (SendPackageToApi(context, environment, settings, fileContent, executionId, uniqueFileName))
                    {
                        if (!fileInfo.IsFileLocked())
                        {
                            MoveFileToFolder(context, file, $"{settings.SentFolder}\\{uniqueFileName}");
                        }
                    }
                }
            }
        }