From 9019f39edea68cb5a9020df3070cd53f35871ba3 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 12 Mar 2018 23:49:05 +0100 Subject: [PATCH] refabrique : une librairie serveur --- Yavsc.Abstract/project.json | 4 +- Yavsc.Abstract/project.lock.json | 27 ++-- Yavsc.Server/Helpers/FileUploadHelpers.cs | 137 ++++++++++++++++++ .../Helpers/SimpleJsonPostMethod.cs | 2 +- Yavsc.Server/Model/FormFile.cs | 26 ++++ Yavsc.Server/project.json | 48 ++++++ Yavsc.Server/project.lock.json | 115 +++++++++++++++ .../ApiControllers/FileSystemApiController.cs | 16 +- Yavsc/Helpers/FileSystemHelpers.cs | 3 +- Yavsc/Helpers/GoogleHelpers.cs | 2 + Yavsc/Services/GoogleApis/CalendarManager.cs | 9 +- Yavsc/Services/GoogleApis/MapTracks.cs | 2 +- Yavsc/Services/MessageServices.cs | 2 +- Yavsc/project.json | 7 +- app/YaDaemon/Program.cs | 9 -- app/YaDaemon/YaDaemon.csproj | 8 - app/YaDaemon/global.json | 5 - global.json | 2 +- testOauthClient/Controllers/HomeController.cs | 47 +++++- testOauthClient/Startup.cs | 15 +- testOauthClient/Views/Home/Contact.cshtml | 11 +- testOauthClient/Views/Home/Index.cshtml | 6 +- testOauthClient/package.json | 22 +-- testOauthClient/project.json | 12 +- yavsc.code-workspace | 6 + 25 files changed, 457 insertions(+), 86 deletions(-) create mode 100644 Yavsc.Server/Helpers/FileUploadHelpers.cs rename {Yavsc.Abstract => Yavsc.Server}/Helpers/SimpleJsonPostMethod.cs (99%) create mode 100644 Yavsc.Server/Model/FormFile.cs create mode 100644 Yavsc.Server/project.json create mode 100644 Yavsc.Server/project.lock.json delete mode 100644 app/YaDaemon/Program.cs delete mode 100755 app/YaDaemon/YaDaemon.csproj delete mode 100644 app/YaDaemon/global.json diff --git a/Yavsc.Abstract/project.json b/Yavsc.Abstract/project.json index 03bbb525..a7d028b3 100644 --- a/Yavsc.Abstract/project.json +++ b/Yavsc.Abstract/project.json @@ -23,13 +23,11 @@ "Chat" ] }, - "projectUrl": "", - "licenseUrl": "", "tooling": { "defaultNamespace": "Yavsc" }, "dependencies": { - "Newtonsoft.Json": "10.0.2" + "Newtonsoft.Json": "9.0.1" }, "frameworks": { "net451": { diff --git a/Yavsc.Abstract/project.lock.json b/Yavsc.Abstract/project.lock.json index 038d1cdc..5a5800ef 100644 --- a/Yavsc.Abstract/project.lock.json +++ b/Yavsc.Abstract/project.lock.json @@ -3,7 +3,7 @@ "version": 2, "targets": { ".NETFramework,Version=v4.5.1": { - "Newtonsoft.Json/10.0.2": { + "Newtonsoft.Json/9.0.1": { "type": "package", "compile": { "lib/net45/Newtonsoft.Json.dll": {} @@ -14,7 +14,7 @@ } }, ".NETFramework,Version=v4.5.1/debian.9-x86": { - "Newtonsoft.Json/10.0.2": { + "Newtonsoft.Json/9.0.1": { "type": "package", "compile": { "lib/net45/Newtonsoft.Json.dll": {} @@ -25,7 +25,7 @@ } }, ".NETFramework,Version=v4.5.1/debian.9-x64": { - "Newtonsoft.Json/10.0.2": { + "Newtonsoft.Json/9.0.1": { "type": "package", "compile": { "lib/net45/Newtonsoft.Json.dll": {} @@ -37,9 +37,9 @@ } }, "libraries": { - "Newtonsoft.Json/10.0.2": { + "Newtonsoft.Json/9.0.1": { "type": "package", - "sha512": "iwElSU2IXmwGvytJsezyDML2ZWDkG2JzTYzlU/BNlmzMdlmRvbnwITsGGY74gwVEpDli1UdOLkMT7/3jxWvXzA==", + "sha512": "U82mHQSKaIk+lpSVCbWYKNavmNH1i5xrExDEquU1i6I5pV6UMOqRnJRSlKO3cMPfcpp0RgDY+8jUXHdQ4IfXvw==", "files": [ "lib/net20/Newtonsoft.Json.dll", "lib/net20/Newtonsoft.Json.xml", @@ -51,15 +51,12 @@ "lib/net45/Newtonsoft.Json.xml", "lib/netstandard1.0/Newtonsoft.Json.dll", "lib/netstandard1.0/Newtonsoft.Json.xml", - "lib/netstandard1.3/Newtonsoft.Json.dll", - "lib/netstandard1.3/Newtonsoft.Json.xml", - "lib/portable-net40+sl5+win8+wpa81+wp8/Newtonsoft.Json.dll", - "lib/portable-net40+sl5+win8+wpa81+wp8/Newtonsoft.Json.xml", - "lib/portable-net45+win8+wpa81+wp8/Newtonsoft.Json.dll", - "lib/portable-net45+win8+wpa81+wp8/Newtonsoft.Json.xml", - "LICENSE.md", - "Newtonsoft.Json.10.0.2.nupkg", - "Newtonsoft.Json.10.0.2.nupkg.sha512", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.xml", + "Newtonsoft.Json.9.0.1.nupkg", + "Newtonsoft.Json.9.0.1.nupkg.sha512", "Newtonsoft.Json.nuspec", "tools/install.ps1" ] @@ -67,7 +64,7 @@ }, "projectFileDependencyGroups": { "": [ - "Newtonsoft.Json >= 10.0.2" + "Newtonsoft.Json >= 9.0.1" ], ".NETFramework,Version=v4.5.1": [ "fx/System.ComponentModel.DataAnnotations >= 4.0.0", diff --git a/Yavsc.Server/Helpers/FileUploadHelpers.cs b/Yavsc.Server/Helpers/FileUploadHelpers.cs new file mode 100644 index 00000000..1b088029 --- /dev/null +++ b/Yavsc.Server/Helpers/FileUploadHelpers.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Yavsc.Server.Model; + +namespace Yavsc.Server.Helpers +{ + /// + /// Thanks to Stefan @ Stackoverflow + /// + public class RequestHelper + { + string WRPostMultipart(string url, Dictionary parameters, string authorizationHeader = null) + { + + string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); + byte[] boundaryBytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n"); + + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + request.ContentType = "multipart/form-data; boundary=" + boundary; + request.Method = "POST"; + request.KeepAlive = true; + request.Credentials = System.Net.CredentialCache.DefaultCredentials; + if (authorizationHeader != null) + request.Headers["Authorization"] = authorizationHeader; + if (parameters != null && parameters.Count > 0) + { + + using (Stream requestStream = request.GetRequestStream()) + { + using (WebResponse response = request.GetResponse()) + { + + + foreach (KeyValuePair pair in parameters) + { + + requestStream.Write(boundaryBytes, 0, boundaryBytes.Length); + if (pair.Value is FormFile) + { + FormFile file = pair.Value as FormFile; + string header = "Content-Disposition: form-data; name=\"" + pair.Key + "\"; filename=\"" + file.Name + "\"\r\nContent-Type: " + file.ContentType + "\r\n\r\n"; + byte[] bytes = System.Text.Encoding.UTF8.GetBytes(header); + requestStream.Write(bytes, 0, bytes.Length); + byte[] buffer = new byte[32768]; + int bytesRead; + if (file.Stream == null) + { + // upload from file + using (FileStream fileStream = File.OpenRead(file.FilePath)) + { + while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) + requestStream.Write(buffer, 0, bytesRead); + fileStream.Close(); + } + } + else + { + // upload from given stream + while ((bytesRead = file.Stream.Read(buffer, 0, buffer.Length)) != 0) + requestStream.Write(buffer, 0, bytesRead); + } + } + else + { + string data = "Content-Disposition: form-data; name=\"" + pair.Key + "\"\r\n\r\n" + pair.Value; + byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data); + requestStream.Write(bytes, 0, bytes.Length); + } + + } + + byte[] trailer = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n"); + requestStream.Write(trailer, 0, trailer.Length); + requestStream.Close(); + + using (Stream responseStream = response.GetResponseStream()) + using (StreamReader reader = new StreamReader(responseStream)) + { + return reader.ReadToEnd(); + } + } // end WebResponse response + + } // end using requestStream + + } + else throw new ArgumentOutOfRangeException("no parameter found "); + + } + + public static async Task PostMultipart(string url, FormFile[] formFiles, string access_token = null) + { + + if (formFiles != null && formFiles.Length > 0) + { + var client = new HttpClient(); + var formData = new MultipartFormDataContent(); + + if (access_token != null) + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", access_token); + foreach (var formFile in formFiles) + { + HttpContent fileStreamContent = new StreamContent(formFile.Stream); + if (formFile.ContentType!=null) + fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue(formFile.ContentType); + else fileStreamContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); + + // fileStreamContent.Headers.ContentDisposition = formFile.ContentDisposition!=null? new ContentDispositionHeaderValue( + // formFile.ContentDisposition) : new ContentDispositionHeaderValue("form-data; name=\"file\"; filename=\"" + formFile.Name + "\""); + fileStreamContent.Headers.Add("Content-Disposition", formFile.ContentDisposition); + fileStreamContent.Headers.Add("Content-Length", formFile.Stream.Length.ToString()); + + //fileStreamContent.Headers.Add("FilePath", formFile.FilePath); + + formData.Add(fileStreamContent, "file", formFile.Name); + + } + + var response = client.PostAsync(url, formData).Result; + if (!response.IsSuccessStatusCode) + { + return null; + } + return await response.Content.ReadAsStringAsync(); + } // end if formFiles != null + + return null; + } + + } + + +} diff --git a/Yavsc.Abstract/Helpers/SimpleJsonPostMethod.cs b/Yavsc.Server/Helpers/SimpleJsonPostMethod.cs similarity index 99% rename from Yavsc.Abstract/Helpers/SimpleJsonPostMethod.cs rename to Yavsc.Server/Helpers/SimpleJsonPostMethod.cs index 9f7b4004..5003bf96 100644 --- a/Yavsc.Abstract/Helpers/SimpleJsonPostMethod.cs +++ b/Yavsc.Server/Helpers/SimpleJsonPostMethod.cs @@ -25,7 +25,7 @@ using Newtonsoft.Json; using System; using System.Json; -namespace Yavsc.Helpers +namespace Yavsc.Server.Helpers { /// /// Simple json post method. diff --git a/Yavsc.Server/Model/FormFile.cs b/Yavsc.Server/Model/FormFile.cs new file mode 100644 index 00000000..9bac0ae4 --- /dev/null +++ b/Yavsc.Server/Model/FormFile.cs @@ -0,0 +1,26 @@ + +using System.IO; +using System.Net.Mime; + +namespace Yavsc.Server.Model +{ +public class FormFile + { + public string Name { get; set; } + + string contentDispositionString; + public string ContentDisposition { get { + return contentDispositionString; + } set { + ContentDisposition contentDisposition = new ContentDisposition(value); + Name = contentDisposition.FileName; + contentDispositionString = value; + } } + + public string ContentType { get; set; } + + public string FilePath { get; set; } + + public Stream Stream { get; set; } + } +} \ No newline at end of file diff --git a/Yavsc.Server/project.json b/Yavsc.Server/project.json new file mode 100644 index 00000000..6223d6eb --- /dev/null +++ b/Yavsc.Server/project.json @@ -0,0 +1,48 @@ +{ + "version": "1.0.0-*", + "description": "Yavsc server common library", + "authors": [ + "Paul Schneider " + ], + "packOptions": { + "repository": { + "type": "git", + "url": "https://github.com/pazof/yavsc" + }, + "licenseUrl": "https://github.com/pazof/yavsc/blob/vnext/LICENSE", + "requireLicenseAcceptance": true, + "owners": [ + "Paul Schneider " + ], + "summary": "Yet another very small company", + "projectUrl": "http://yavsc.pschneider.fr", + "tags": [ + "Blog", + "Blog", + "PoS", + "Chat" + ] + }, + "tooling": { + "defaultNamespace": "Yavsc" + }, + "dependencies": { + "Newtonsoft.Json": "9.0.1", + "Yavsc.Abstract": { + "target": "project", + "type": "build" + } + }, + "frameworks": { + "net451": { + "frameworkAssemblies": { + "System.ComponentModel.DataAnnotations": "4.0.0", + "System.Json": "4.0.0", + "System.Net": "4.0.0.0", + "System.Net.Http": "4.0.0.0", + "System.Xml": "4.0.0.0", + "System": "4.0.0.0" + } + } + } +} \ No newline at end of file diff --git a/Yavsc.Server/project.lock.json b/Yavsc.Server/project.lock.json new file mode 100644 index 00000000..b04cea72 --- /dev/null +++ b/Yavsc.Server/project.lock.json @@ -0,0 +1,115 @@ +{ + "locked": false, + "version": 2, + "targets": { + ".NETFramework,Version=v4.5.1": { + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "Yavsc.Abstract/1.0.5": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1", + "dependencies": { + "Newtonsoft.Json": "9.0.1" + }, + "frameworkAssemblies": [ + "System.ComponentModel.DataAnnotations", + "System.Json" + ] + } + }, + ".NETFramework,Version=v4.5.1/debian.9-x86": { + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "Yavsc.Abstract/1.0.5": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1", + "dependencies": { + "Newtonsoft.Json": "9.0.1" + }, + "frameworkAssemblies": [ + "System.ComponentModel.DataAnnotations", + "System.Json" + ] + } + }, + ".NETFramework,Version=v4.5.1/debian.9-x64": { + "Newtonsoft.Json/9.0.1": { + "type": "package", + "compile": { + "lib/net45/Newtonsoft.Json.dll": {} + }, + "runtime": { + "lib/net45/Newtonsoft.Json.dll": {} + } + }, + "Yavsc.Abstract/1.0.5": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.1", + "dependencies": { + "Newtonsoft.Json": "9.0.1" + }, + "frameworkAssemblies": [ + "System.ComponentModel.DataAnnotations", + "System.Json" + ] + } + } + }, + "libraries": { + "Yavsc.Abstract/1.0.5": { + "type": "project", + "path": "../Yavsc.Abstract/project.json" + }, + "Newtonsoft.Json/9.0.1": { + "type": "package", + "sha512": "U82mHQSKaIk+lpSVCbWYKNavmNH1i5xrExDEquU1i6I5pV6UMOqRnJRSlKO3cMPfcpp0RgDY+8jUXHdQ4IfXvw==", + "files": [ + "lib/net20/Newtonsoft.Json.dll", + "lib/net20/Newtonsoft.Json.xml", + "lib/net35/Newtonsoft.Json.dll", + "lib/net35/Newtonsoft.Json.xml", + "lib/net40/Newtonsoft.Json.dll", + "lib/net40/Newtonsoft.Json.xml", + "lib/net45/Newtonsoft.Json.dll", + "lib/net45/Newtonsoft.Json.xml", + "lib/netstandard1.0/Newtonsoft.Json.dll", + "lib/netstandard1.0/Newtonsoft.Json.xml", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.dll", + "lib/portable-net45+wp80+win8+wpa81/Newtonsoft.Json.xml", + "Newtonsoft.Json.9.0.1.nupkg", + "Newtonsoft.Json.9.0.1.nupkg.sha512", + "Newtonsoft.Json.nuspec", + "tools/install.ps1" + ] + } + }, + "projectFileDependencyGroups": { + "": [ + "Newtonsoft.Json >= 9.0.1", + "Yavsc.Abstract " + ], + ".NETFramework,Version=v4.5.1": [ + "fx/System.ComponentModel.DataAnnotations >= 4.0.0", + "fx/System.Json >= 4.0.0", + "fx/System.Net >= 4.0.0", + "fx/System.Xml >= 4.0.0", + "fx/System >= 4.0.0" + ] + } +} \ No newline at end of file diff --git a/Yavsc/ApiControllers/FileSystemApiController.cs b/Yavsc/ApiControllers/FileSystemApiController.cs index 0e3b5115..3ed0f0db 100644 --- a/Yavsc/ApiControllers/FileSystemApiController.cs +++ b/Yavsc/ApiControllers/FileSystemApiController.cs @@ -52,18 +52,18 @@ namespace Yavsc.ApiControllers return Ok(files); } - [HttpPost] - public IActionResult Post(string subdir="", string names = null) + [HttpPost("{subdir}")] + public IActionResult Post(string subdir="") { - string root = null; - string [] destinationFileNames = names?.Split('/'); + string destDir = null; List received = new List(); InvalidPathException pathex = null; try { - root = User.InitPostToFileSystem(subdir); + destDir = User.InitPostToFileSystem(subdir); } catch (InvalidPathException ex) { pathex = ex; } + logger.LogInformation($"Recieving files, saved in '{destDir}' (specified ad '{subdir}')."); if (pathex!=null) return new BadRequestObjectResult(pathex); var uid = User.GetUserId(); @@ -72,11 +72,11 @@ namespace Yavsc.ApiControllers ); int i=0; logger.LogInformation($"Recieving {Request.Form.Files.Count} files."); + foreach (var f in Request.Form.Files) { - var destFileName = destinationFileNames?.Length >i ? destinationFileNames[i] : null; - - var item = user.ReceiveUserFile(root, f, destFileName); + + var item = user.ReceiveUserFile(destDir, f); dbContext.SaveChanges(User.GetUserId()); received.Add(item); logger.LogInformation($"Recieved '{item.FileName}'."); diff --git a/Yavsc/Helpers/FileSystemHelpers.cs b/Yavsc/Helpers/FileSystemHelpers.cs index 631793bb..d704ec54 100644 --- a/Yavsc/Helpers/FileSystemHelpers.cs +++ b/Yavsc/Helpers/FileSystemHelpers.cs @@ -46,7 +46,7 @@ namespace Yavsc.Helpers } var di = new DirectoryInfo(root); if (!di.Exists) di.Create(); - return root; + return di.FullName; } public static void DeleteUserFile(this ApplicationUser user, string fileName) @@ -66,6 +66,7 @@ namespace Yavsc.Helpers ContentDisposition contentDisposition = new ContentDisposition(f.ContentDisposition); item.FileName = Yavsc.Abstract.FileSystem.FileSystemHelpers.FilterFileName (destFileName ?? contentDisposition.FileName); item.MimeType = contentDisposition.DispositionType; + item.DestDir = root; var fi = new FileInfo(Path.Combine(root, item.FileName)); if (fi.Exists) { diff --git a/Yavsc/Helpers/GoogleHelpers.cs b/Yavsc/Helpers/GoogleHelpers.cs index 83326a7d..7f2ab3b8 100644 --- a/Yavsc/Helpers/GoogleHelpers.cs +++ b/Yavsc/Helpers/GoogleHelpers.cs @@ -39,6 +39,8 @@ namespace Yavsc.Helpers using Models; using Models.Calendar; using Services; + using Server.Helpers; + /// /// Google helpers. diff --git a/Yavsc/Services/GoogleApis/CalendarManager.cs b/Yavsc/Services/GoogleApis/CalendarManager.cs index ef9fbaab..45cc4887 100644 --- a/Yavsc/Services/GoogleApis/CalendarManager.cs +++ b/Yavsc/Services/GoogleApis/CalendarManager.cs @@ -31,16 +31,17 @@ using Google.Apis.Calendar.v3.Data; using System.Collections.Generic; using System.Linq; using Google.Apis.Services; +using System.Threading; +using Google.Apis.Auth.OAuth2.Flows; +using Google.Apis.Auth.OAuth2.Responses; +using Google.Apis.Util; namespace Yavsc.Services { - using System.Threading; - using Google.Apis.Auth.OAuth2.Flows; - using Google.Apis.Auth.OAuth2.Responses; - using Google.Apis.Util; using Yavsc.Helpers; using Yavsc.Models; using Yavsc.Models.Calendar; + using Yavsc.Server.Helpers; using Yavsc.ViewModels.Calendar; /// diff --git a/Yavsc/Services/GoogleApis/MapTracks.cs b/Yavsc/Services/GoogleApis/MapTracks.cs index cc563103..230bee9a 100644 --- a/Yavsc/Services/GoogleApis/MapTracks.cs +++ b/Yavsc/Services/GoogleApis/MapTracks.cs @@ -19,8 +19,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . using System.Threading.Tasks; -using Yavsc.Helpers; using Yavsc.Models.Google; +using Yavsc.Server.Helpers; namespace Yavsc.GoogleApis { diff --git a/Yavsc/Services/MessageServices.cs b/Yavsc/Services/MessageServices.cs index aa490280..cb3d6498 100755 --- a/Yavsc/Services/MessageServices.cs +++ b/Yavsc/Services/MessageServices.cs @@ -5,7 +5,6 @@ using MimeKit; using MailKit.Security; using System; using Yavsc.Models.Messaging; -using Yavsc.Helpers; using Microsoft.AspNet.Identity; using Yavsc.Models; using Yavsc.Models.Google.Messaging; @@ -15,6 +14,7 @@ using Yavsc.Interfaces.Workflow; using System.Linq; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Yavsc.Server.Helpers; namespace Yavsc.Services { diff --git a/Yavsc/project.json b/Yavsc/project.json index f8fdb14c..fdaf13e6 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -122,6 +122,11 @@ "Microsoft.AspNet.OWin": "1.0.0-rc1-final", "System.Json": "4.0.20126.16343", "Yavsc.Abstract": { + "target": "project", + "type": "build" + }, + "Yavsc.Server": { + "target": "project", "type": "build" }, "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final", @@ -163,4 +168,4 @@ "prepublish": "gulp min" }, "embed": "Views/**/*.cshtml" -} +} \ No newline at end of file diff --git a/app/YaDaemon/Program.cs b/app/YaDaemon/Program.cs deleted file mode 100644 index 0f051baa..00000000 --- a/app/YaDaemon/Program.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -class YaDaemon -{ - static void Main(string[] args) - { - Console.WriteLine("Hello World!"); - } -} diff --git a/app/YaDaemon/YaDaemon.csproj b/app/YaDaemon/YaDaemon.csproj deleted file mode 100755 index a5f81a8c..00000000 --- a/app/YaDaemon/YaDaemon.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - Exe - netcoreapp1.0 - - - diff --git a/app/YaDaemon/global.json b/app/YaDaemon/global.json deleted file mode 100644 index 9bead993..00000000 --- a/app/YaDaemon/global.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "sdk": { - "version": "1.0.0-rc4-004771" - } -} diff --git a/global.json b/global.json index 5d2357a2..86dc811e 100644 --- a/global.json +++ b/global.json @@ -2,7 +2,7 @@ "projects": [ "Yavsc", "Yavsc.Abstract", - "YaTask", + "Yavsc.Server", "testOauthClient" ], "sdk": { diff --git a/testOauthClient/Controllers/HomeController.cs b/testOauthClient/Controllers/HomeController.cs index b9f94e15..4e5e4d62 100755 --- a/testOauthClient/Controllers/HomeController.cs +++ b/testOauthClient/Controllers/HomeController.cs @@ -1,18 +1,24 @@ using System; +using System.Collections.Generic; +using System.IO; using System.Json; +using System.Linq; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNet.Mvc; using Microsoft.Extensions.Logging; -using Yavsc.Helpers; +using Yavsc.Server.Helpers; +using Yavsc.Server.Model; namespace testOauthClient.Controllers { public class HomeController : Controller { ILogger _logger; + public HomeController(ILoggerFactory loggerFactory) { _logger=loggerFactory.CreateLogger(); @@ -39,6 +45,45 @@ namespace testOauthClient.Controllers } + [HttpPost] + public async Task PostFiles(string subdir) + { + string results = null; + _logger.LogInformation($"{Request.Form.Files.Count} file(s) to send"); + + // TODO better uri construction in production environment + List args = new List(); + foreach (var formFile in Request.Form.Files) + { + _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."); + + return View("Index", model: results); + + } + [HttpPost] public async Task PostDeviceInfo(CancellationToken cancellationToken) { diff --git a/testOauthClient/Startup.cs b/testOauthClient/Startup.cs index 5f84a922..0e29a10d 100755 --- a/testOauthClient/Startup.cs +++ b/testOauthClient/Startup.cs @@ -112,12 +112,15 @@ namespace testOauthClient string email = null; if (emails !=null) email = emails.First?.Value(); - context.Identity.AddClaim( - new Claim( ClaimTypes.NameIdentifier,identifier)); - context.Identity.AddClaim( - new Claim( ClaimTypes.Name,givenName)); - context.Identity.AddClaim( - new Claim( ClaimTypes.Email,email)); + if (identifier!=null) + context.Identity.AddClaim( + new Claim( ClaimTypes.NameIdentifier,identifier)); + if (givenName!=null) + context.Identity.AddClaim( + new Claim( ClaimTypes.Name,givenName)); + if (email!=null) + context.Identity.AddClaim( + new Claim( ClaimTypes.Email,email)); // TODO add all emails and roles } diff --git a/testOauthClient/Views/Home/Contact.cshtml b/testOauthClient/Views/Home/Contact.cshtml index cddb37e1..cecd5aa2 100755 --- a/testOauthClient/Views/Home/Contact.cshtml +++ b/testOauthClient/Views/Home/Contact.cshtml @@ -5,13 +5,12 @@

@ViewData["Message"]

- One Microsoft Way
- Redmond, WA 98052-6399
- P: - 425.555.0100 + Paul Schneider
+ A: Boulevard Aristide Briand - 92150 Suresnes + M: 336 51 14 15 64
- Support: Support@example.com
- Marketing: Marketing@example.com + Support: contact@pschneider.fr
+ Marketing: paul@pschneider.fr
diff --git a/testOauthClient/Views/Home/Index.cshtml b/testOauthClient/Views/Home/Index.cshtml index 4b319c1a..04f4b47b 100755 --- a/testOauthClient/Views/Home/Index.cshtml +++ b/testOauthClient/Views/Home/Index.cshtml @@ -12,7 +12,7 @@ }

- if (!string.IsNullOrEmpty(Model)) { + if (Model!=null) {

Message received from the resource controller: @Model

} @@ -22,6 +22,10 @@
+
+ Envoyer vers le dossier "test" + +
Sign out } diff --git a/testOauthClient/package.json b/testOauthClient/package.json index c61e8c38..e49ea7ae 100755 --- a/testOauthClient/package.json +++ b/testOauthClient/package.json @@ -1,12 +1,12 @@ { - "licence": "GNU GPL", - "name": "testOauthClient", - "version": "0.0.0", - "devDependencies": { - "gulp": "^3.9.0", - "gulp-concat": "2.5.2", - "gulp-cssmin": "0.1.7", - "gulp-uglify": "1.2.0", - "rimraf": "2.2.8" - } -} + "licence": "GNU GPL v3", + "name": "test-oauth-client", + "version": "0.0.0", + "devDependencies": { + "gulp": "^3.9.1", + "gulp-concat": "^2.6.1", + "gulp-cssmin": "^0.2.0", + "gulp-uglify": "^3.0.0", + "rimraf": "^2.6.2" + } +} \ No newline at end of file diff --git a/testOauthClient/project.json b/testOauthClient/project.json index 79453190..11dbe0a5 100755 --- a/testOauthClient/project.json +++ b/testOauthClient/project.json @@ -8,6 +8,11 @@ }, "dependencies": { "Yavsc.Abstract": { + "target": "project", + "type": "build" + }, + "Yavsc.Server": { + "target": "project", "type": "build" }, "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final", @@ -32,9 +37,10 @@ "frameworks": { "dnx451": { "dependencies": { - "System.Json": "4.0.0" + "System.Json": "4.0.20126.16343" } - } + }, + "net451": {} }, "exclude": [ "wwwroot", @@ -56,4 +62,4 @@ "gulp min" ] } -} \ No newline at end of file +} diff --git a/yavsc.code-workspace b/yavsc.code-workspace index 6ef10fd4..1839ca0e 100644 --- a/yavsc.code-workspace +++ b/yavsc.code-workspace @@ -8,6 +8,12 @@ }, { "path": "cli" + }, + { + "path": "testOauthClient" + }, + { + "path": "Yavsc.Server" } ], "settings": {