principalement du format de code

This commit is contained in:
2020-09-12 01:11:30 +01:00
parent 3a6f16e3bb
commit 2cd531c242
87 changed files with 510 additions and 550 deletions

View File

@ -15,25 +15,26 @@ namespace testOauthClient.Controllers
public class HomeController : Controller
{
readonly ILogger _logger;
public class GCMRegistrationRecord {
public string GCMRegistrationId { get; set; } = "testGoogleRegistrationIdValue";
public string DeviceId { get; set; }= "TestDeviceId";
public string Model { get; set; }= "TestModel";
public string Platform { get; set; }= "External Web";
public string Version { get; set; }= "0.0.1-rc1";
}
public class GCMRegistrationRecord
{
public string GCMRegistrationId { get; set; } = "testGoogleRegistrationIdValue";
public string DeviceId { get; set; } = "TestDeviceId";
public string Model { get; set; } = "TestModel";
public string Platform { get; set; } = "External Web";
public string Version { get; set; } = "0.0.1-rc1";
}
public HomeController(ILoggerFactory loggerFactory)
{
_logger=loggerFactory.CreateLogger<HomeController>();
_logger = loggerFactory.CreateLogger<HomeController>();
}
[HttpGet]
public IActionResult Index()
{
return View();
}
[HttpPost]
public async Task<IActionResult> GetUserInfo(CancellationToken cancellationToken)
{
@ -54,38 +55,41 @@ namespace testOauthClient.Controllers
[HttpPost]
public async Task<IActionResult> PostFiles(string subdir)
{
string results = null;
string results;
_logger.LogInformation($"{Request.Form.Files.Count} file(s) to send");
// TODO better uri construction in production environment
List<FormFile> args = new List<FormFile>();
foreach (var formFile in Request.Form.Files)
// TODO better uri construction in production environment
List<FormFile> args = new List<FormFile>();
foreach (var formFile in Request.Form.Files)
{
_logger.LogWarning($"Treating {formFile.ContentDisposition}");
MemoryStream memStream = new MemoryStream();
const int sz = 1024 * 64;
byte[] buffer = new byte[sz];
using (var innerStream = formFile.OpenReadStream())
{
int szRead = 0;
do
{
_logger.LogWarning($"Treating {formFile.ContentDisposition}");
var memStream = new MemoryStream();
const int sz = 1024*64;
byte [] buffer = new byte[sz];
using (var innerStream = formFile.OpenReadStream()) {
int szRead = 0;
do {
szRead = innerStream.Read(buffer,0,sz);
memStream.Write(buffer,0,szRead);
} while (szRead>0);
}
memStream.Seek(0,SeekOrigin.Begin);
args.Add(
new FormFile {
ContentDisposition = formFile.ContentDisposition,
ContentType = formFile.ContentType,
Stream = memStream
});
}
string uri = "http://dev.pschneider.fr/api/fs/"+System.Uri.EscapeDataString(subdir);
_logger.LogInformation($"Posting data to '{uri}'...");
results = await RequestHelper.PostMultipart(uri, args.ToArray(), AccessToken);
_logger.LogInformation("Data posted.");
szRead = innerStream.Read(buffer, 0, sz);
memStream.Write(buffer, 0, szRead);
} while (szRead > 0);
}
memStream.Seek(0, SeekOrigin.Begin);
args.Add(
new FormFile
{
ContentDisposition = formFile.ContentDisposition,
ContentType = formFile.ContentType,
Stream = memStream
});
}
string uri = "http://dev.pschneider.fr/api/fs/" + System.Uri.EscapeDataString(subdir);
_logger.LogInformation($"Posting data to '{uri}'...");
results = await RequestHelper.PostMultipart(uri, args.ToArray(), AccessToken);
_logger.LogInformation("Data posted.");
return View("Index", model: results);
}
@ -109,14 +113,16 @@ namespace testOauthClient.Controllers
GCMRegistrationRecord result = null;
var authHeader = $"Bearer {AccessToken}";
_logger.LogWarning($"using authorization Header {authHeader}");
try {
try
{
using (var request = new SimpleJsonPostMethod(
"http://dev.pschneider.fr/api/gcm/register", authHeader))
{
result = await request.Invoke<GCMRegistrationRecord>(new
GCMRegistrationRecord {
GCMRegistrationRecord
{
GCMRegistrationId = "testGoogleRegistrationIdValue",
DeviceId = "TestDeviceId",
Model = "TestModel",
@ -125,8 +131,9 @@ namespace testOauthClient.Controllers
});
}
}
catch (Exception ex) {
return View("Index", model: new { error = ex.Message });
catch (Exception ex)
{
return View("Index", model: new { error = ex.Message });
}
return View("Index", model: result?.ToString());
}

View File

@ -29,7 +29,7 @@
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Newtonsoft.Json": "6.0.1-beta1"
"Newtonsoft.Json": "7.0.1"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls=http://*:5002"