Commit 0883f181 authored by alan.f's avatar alan.f

Add project files.

parent ddada543
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Threading;
using System.Threading.Tasks;
using Dicom.Network.Client;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NLog;
namespace SendFileWebapi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SCUController : ControllerBase
{
//[HttpPost]
//public async Task<ActionResult> Post([FromForm]StudentModel std)
//{
//// Getting Name
//string name = std.Name;
//foreach (var img in std.Images)
//{
// // Getting Image
// if (img.Length > 0)
// {
// using (var fileStream = new FileStream(img.FileName, FileMode.Create))
// {
// img.CopyTo(fileStream);
// var tt = fileStream;
// }
// }
//}
//return Ok(new { status = true, message = "Student Posted Successfully" });
//}
static Logger logger = LogManager.GetCurrentClassLogger();
[HttpPost]
public async Task Post([FromForm]Models.InputsDto inputsDto)
{
var client = new DicomClient(inputsDto.ServerHost, inputsDto.Port, false, inputsDto.ServerAET, inputsDto.Aet);
client.NegotiateAsyncOps();
inputsDto.FileNames.ToObservable()
.Select(fileName => Observable.FromAsync(async () =>
{
FileStream fileStream = null;
using (var stream = new FileStream(fileName.FileName, FileMode.Create))
{
await fileName.CopyToAsync(stream);
fileStream = stream;
}
var request = new Dicom.Network.DicomCStoreRequest(fileStream.Name);
await client.AddRequestAsync(request);
await client.SendAsync();
}).Select(x => fileName.FileName).Catch<string, Exception>(exp => throw new Exception($"failed to send: {fileName}, with error:{exp.Message}")))
.Concat()
.Subscribe(
filename =>
logger.Warn($"file sent:{filename}"),
onError =>
logger.Error(onError.Message),
() => { });
}
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Dicom.Network.Client;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace SendFileWebapi.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> Get()
{
var rng = new Random();
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray();
}
[HttpPost]
public async Task<IActionResult> Post([FromForm]Models.InputsDto inputsDto)
{
var client = new DicomClient(inputsDto.ServerHost, inputsDto.Port, false, inputsDto.ServerAET, inputsDto.Aet);
foreach (var formFile in inputsDto.FileNames)
{
FileStream fs=null;
if (formFile.Length > 0)
using (var stream = new FileStream(formFile.FileName, FileMode.Create,FileAccess.Write))
{
formFile.CopyTo(stream);
fs = stream;
}
var request = new Dicom.Network.DicomCStoreRequest(fs.Name);
await client.AddRequestAsync(request);
await client.SendAsync();
}
return null;
}
}
}
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SendFileWebapi.Models
{
public class FileOpration
{
public IFormFileCollection FileNames { get; set; }
}
}
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace SendFileWebapi.Models
{
public class InputsDto
{
public string ServerHost { get; set; }
public int Port { get; set; }
public IFormFileCollection FileNames { get; set; }
public string ServerAET { get; set; }
public string Aet { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace SendFileWebapi
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:13018",
"sslPort": 44340
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"SendFileWebapi": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="fo-dicom" Version="4.0.4" />
<PackageReference Include="NLog" Version="4.7.1" />
<PackageReference Include="NLog.Config" Version="4.7.1" />
<PackageReference Include="System.Reactive" Version="4.4.1" />
</ItemGroup>
</Project>

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30001.183
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SendFileWebapi", "SendFileWebapi.csproj", "{F0316487-DEBC-48EE-9B2F-88488BB28F55}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "C-Store-SCP", "..\C-Store-SCP\C-Store-SCP.csproj", "{E5740105-19AE-405D-BFE7-11DA4AAA5603}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Debug|x86.ActiveCfg = Debug|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Debug|x86.Build.0 = Debug|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Release|Any CPU.Build.0 = Release|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Release|x86.ActiveCfg = Release|Any CPU
{F0316487-DEBC-48EE-9B2F-88488BB28F55}.Release|x86.Build.0 = Release|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Debug|x86.Build.0 = Debug|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Release|Any CPU.Build.0 = Release|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Release|x86.ActiveCfg = Release|Any CPU
{E5740105-19AE-405D-BFE7-11DA4AAA5603}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7CC2360E-A293-4888-96AD-4A6A566BB23C}
EndGlobalSection
EndGlobal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace SendFileWebapi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
}
using System;
namespace SendFileWebapi
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
}
File added
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
File added
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment