/// <summary>
        /// This creates the YAML file in the specified dir and uploads it
        /// </summary>
        /// <param name="result"></param>
        private void UploadYamlFileToResources(ParseSqlResult result)
        {
            File.WriteAllText(_yamlFullFilePath, result.Yaml);

            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                ResourceFileRequest rfRequest = new ResourceFileRequest();

                rfRequest.FullFilePath = _yamlFullFilePath;
                rfRequest.AppGuid      = new Guid(DefaultAppGuid);
                rfRequest.FileName     = Path.GetFileName(_yamlFullFilePath);

                try
                {
                    rsapiClient.PushResourceFiles(rsapiClient.APIOptions, new List <ResourceFileRequest>()
                    {
                        rfRequest
                    });
                    Console.WriteLine($"{nameof(UploadYamlFileToResources)} - Local YAML file ({_yamlFullFilePath}) - was uploaded successfully");
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{nameof(UploadYamlFileToResources)} - Could not upload ({_yamlFullFilePath}) - Exception: {ex.Message}");
                }
            }
        }
示例#2
0
        public async Task <ActionResult> AddBookData([FromForm] ResourceFileRequest bookDataRequest)
        {
            Stream stream = null;

            try
            {
                Request.Headers.TryGetValue("auth_key", out var authKey);
                if (bookDataRequest.JsonFile.Length > 0 && await _tokenManagerService.ValidateToken(authKey))
                {
                    stream = bookDataRequest.JsonFile.OpenReadStream();
                    using (var streamReader = new StreamReader(stream))
                    {
                        var fileContent = streamReader.ReadToEnd();
                        await _s3FileProcessorService.AddBookData(bookDataRequest.Name, fileContent);
                    }
                    return(StatusCode(StatusCodes.Status200OK, new { Status = "Data from the file successfully processed" }));
                }
                return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Bad request" }));
            }
            catch (Exception exception)
            {
                _logger.LogError($"Error while processing data from the file: {exception.Message}");
                return(StatusCode(StatusCodes.Status500InternalServerError, new { Status = "Error while process data from the file", exception.Message }));
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
        static void UploadYamlFileToResources()
        {
            using (IRSAPIClient rsapiClient = CreateRsapiClient())
            {
                ResourceFileRequest rfRequest = new ResourceFileRequest();

                rfRequest.FullFilePath = yamlFullFilePath;
                rfRequest.AppGuid      = new Guid(Constants.Guids.Default);
                rfRequest.FileName     = Path.GetFileName(yamlFullFilePath);

                try
                {
                    rsapiClient.PushResourceFiles(rsapiClient.APIOptions, new List <ResourceFileRequest>()
                    {
                        rfRequest
                    });
                    System.Console.WriteLine($"Local YAML file ({yamlFullFilePath}) - was uploaded successfully");
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine($"Could not upload ({yamlFullFilePath}) - Exception: {ex.Message}");
                }
            }
        }