Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
send-file-api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alan Farhadi
send-file-api
Commits
b2d025f5
Commit
b2d025f5
authored
May 17, 2020
by
alan.f
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean-code
parent
ed89adb7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
30 deletions
+40
-30
SCUController.cs
Controllers/SCUController.cs
+19
-9
WeatherForecastController.cs
Controllers/WeatherForecastController.cs
+19
-19
FilesPackage.cs
Models/FilesPackage.cs
+2
-2
No files found.
Controllers/SCUController.cs
View file @
b2d025f5
...
...
@@ -23,19 +23,29 @@ namespace SendFileWebapi.Controllers
static
Logger
logger
=
LogManager
.
GetCurrentClassLogger
();
[
HttpPost
]
public
async
Task
Post
([
FromForm
]
Models
.
InputsDto
inputsDto
)
public
async
Task
Post
([
FromForm
]
Models
.
FilesPackage
inputsDto
)
{
var
clone
=
inputsDto
.
UplodedFiles
.
Select
(
f
=>
{
var
s
=
new
MemoryStream
();
f
.
CopyTo
(
s
);
s
.
Seek
(
0
,
SeekOrigin
.
Begin
);
return
new
{
f
.
FileName
,
s
};
}).
ToArray
();
var
client
=
new
DicomClient
(
inputsDto
.
ServerHost
,
inputsDto
.
Port
,
false
,
inputsDto
.
ServerAET
,
inputsDto
.
Aet
);
client
.
NegotiateAsyncOps
();
inputsDto
.
FileNames
.
ToObservable
()
.
Select
(
fileNam
e
=>
Observable
.
FromAsync
(
async
()
=>
clone
.
ToObservable
()
.
Select
(
uploadedFil
e
=>
Observable
.
FromAsync
(
async
()
=>
{
var
stream
=
fileName
.
OpenReadStream
();
var
request
=
new
Dicom
.
Network
.
DicomCStoreRequest
(
await
DicomFile
.
OpenAsync
(
stream
,
FileReadOption
.
ReadAll
));
await
client
.
AddRequestAsync
(
request
);
await
client
.
SendAsync
();
stream
.
Dispose
();
}).
Select
(
x
=>
fileName
.
FileName
).
Catch
<
string
,
Exception
>(
exp
=>
throw
new
Exception
(
$"failed to send:
{
fileName
}
, with error:
{
exp
.
Message
}
"
)))
using
(
var
stream
=
uploadedFile
.
s
)
{
var
request
=
new
Dicom
.
Network
.
DicomCStoreRequest
(
await
DicomFile
.
OpenAsync
(
stream
));
await
client
.
AddRequestAsync
(
request
);
await
client
.
SendAsync
();
}
}).
Select
(
x
=>
uploadedFile
.
FileName
).
Catch
<
string
,
Exception
>(
exp
=>
throw
new
Exception
(
$"failed to send:
{
uploadedFile
}
, with error:
{
exp
.
Message
}
"
)))
.
Concat
()
.
Subscribe
(
filename
=>
...
...
Controllers/WeatherForecastController.cs
View file @
b2d025f5
...
...
@@ -38,26 +38,26 @@ namespace SendFileWebapi.Controllers
.
ToArray
();
}
[
HttpPost
]
public
async
Task
<
IActionResult
>
Post
([
FromForm
]
Models
.
InputsDto
inputsDto
)
{
//
[HttpPost]
//
public async Task<IActionResult> Post([FromForm]Models.InputsDto inputsDto)
//
{
var
client
=
new
DicomClient
(
inputsDto
.
ServerHost
,
inputsDto
.
Port
,
false
,
inputsDto
.
ServerAET
,
inputsDto
.
Aet
);
//
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
;
}
//
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;
//
}
}
}
Models/
InputsDto
.cs
→
Models/
FilesPackage
.cs
View file @
b2d025f5
...
...
@@ -6,11 +6,11 @@ using System.Threading.Tasks;
namespace
SendFileWebapi.Models
{
public
class
InputsDto
public
class
FilesPackage
{
public
string
ServerHost
{
get
;
set
;
}
public
int
Port
{
get
;
set
;
}
public
IFormFileCollection
FileNam
es
{
get
;
set
;
}
public
IFormFileCollection
UplodedFil
es
{
get
;
set
;
}
public
string
ServerAET
{
get
;
set
;
}
public
string
Aet
{
get
;
set
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment