From 2c9aa980d5ef229f2a886e02df7faa155ff8c08e Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 3 Jul 2017 20:30:00 +0200 Subject: [PATCH] Set appData env var --- Yavsc/Settings/SiteSettings.cs | 2 + Yavsc/Startup/Startup.SanityChecks.cs | 20 ++ Yavsc/Startup/Startup.cs | 2 + Yavsc/project.json | 326 +++++++++++++------------- 4 files changed, 187 insertions(+), 163 deletions(-) diff --git a/Yavsc/Settings/SiteSettings.cs b/Yavsc/Settings/SiteSettings.cs index 5c91481c..48aaedf1 100644 --- a/Yavsc/Settings/SiteSettings.cs +++ b/Yavsc/Settings/SiteSettings.cs @@ -28,6 +28,8 @@ namespace Yavsc /// /// public Contact Admin { get; set; } + + public string DataDir { get; set; } /// /// User's files directory /// diff --git a/Yavsc/Startup/Startup.SanityChecks.cs b/Yavsc/Startup/Startup.SanityChecks.cs index c49347ad..85f50970 100644 --- a/Yavsc/Startup/Startup.SanityChecks.cs +++ b/Yavsc/Startup/Startup.SanityChecks.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using Google.Apis.Auth.OAuth2; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Hosting; @@ -21,8 +22,27 @@ namespace Yavsc ILoggerFactory loggerFactory ) { + var logger = loggerFactory.CreateLogger(); + var appData = Environment.GetEnvironmentVariable("APPDATA"); + if (appData == null) + { + if (SiteSetup.DataDir == null) { + SiteSetup.DataDir = "AppData"; + } else logger.LogWarning("existing setting: "+SiteSetup.DataDir); + DirectoryInfo di = new DirectoryInfo(SiteSetup.DataDir); + if (!di.Exists) + { + di.Create(); + logger.LogWarning("Created dir : "+di.FullName); + } else logger.LogWarning("existing: "+di.Name); + SiteSetup.DataDir = Path.Combine(Directory.GetCurrentDirectory(),di.Name); + Environment.SetEnvironmentVariable("APPDATA", SiteSetup.DataDir); + logger.LogWarning("AppData was not found in env vars, it has been set to : "+ + Environment.GetEnvironmentVariable("APPDATA")); + } + var creds = GoogleSettings?.Account?.private_key; if (creds==null) throw new InvalidOperationException("No Google API credential"); diff --git a/Yavsc/Startup/Startup.cs b/Yavsc/Startup/Startup.cs index a31772de..f08bba71 100755 --- a/Yavsc/Startup/Startup.cs +++ b/Yavsc/Startup/Startup.cs @@ -67,6 +67,7 @@ namespace Yavsc builder.AddEnvironmentVariables(); Configuration = builder.Build(); ConnectionString = Configuration["Data:DefaultConnection:ConnectionString"]; + } public static GoogleAuthSettings GoogleSettings { get; set; } public IConfigurationRoot Configuration { get; set; } @@ -264,6 +265,7 @@ namespace Yavsc Startup.UserBillsDirName = new DirectoryInfo(siteSettings.Value.UserFiles.Bills).FullName; Startup.Temp = siteSettings.Value.TempDir; PayPalSettings = payPalSettings.Value; + // TODO implement an installation & upgrade procedure // Create required directories foreach (string dir in new string[] { UserFilesDirName, UserBillsDirName, SiteSetup.TempDir }) diff --git a/Yavsc/project.json b/Yavsc/project.json index 31dee38d..7849cdb2 100755 --- a/Yavsc/project.json +++ b/Yavsc/project.json @@ -1,167 +1,167 @@ { - "version": "1.0.0-*", - "authors": [ - "Paul Schneider" - ], - "tags": [ - "Blog", - "PoS", - "Chat" - ], - "projectUrl": "http://yavsc.pschneider.fr", - "licenseUrl": "", - "userSecretsId": "aspnet5-YavscWeb-a0dadd21-2ced-43d3-96f9-7e504345102f", - "compilationOptions": { - "emitEntryPoint": true, - "debugType": "portable", - "outputName": "Yavsc" - }, - "buildOptions": { - "debugType": "portable", - "emitEntryPoint": true - }, - "compile": [ - "*.cs" - ], - "resource": [ - "Resources/**/*.resx" - ], - "namedResource": {}, - "configurations": { - "Debug": { - "compilationOptions": { + "version": "1.0.0-*", + "authors": [ + "Paul Schneider" + ], + "tags": [ + "Blog", + "PoS", + "Chat" + ], + "projectUrl": "http://yavsc.pschneider.fr", + "licenseUrl": "", + "userSecretsId": "aspnet5-YavscWeb-a0dadd21-2ced-43d3-96f9-7e504345102f", + "compilationOptions": { "emitEntryPoint": true, - "define": [ - "DEBUG", - "TRACE" - ], - "optimize": false, - "debugType": "portable" - } + "debugType": "portable", + "outputName": "Yavsc" }, - "Release": { - "compilationOptions": { - "define": [ - "RELEASE", - "TRACE" - ], - "optimize": true - } - } - }, - "webroot": "wwwroot", - "tooling": { - "defaultNamespace": "Yavsc" - }, - "dependencies": { - "EntityFramework.Commands": "7.0.0-rc1-final", - "EntityFramework.Core": "7.0.0-rc1-final", - "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", - "EntityFramework.Relational": "7.0.0-rc1-final", - "EntityFramework7.Npgsql": "3.1.0-rc1-3", - "EntityFramework7.Npgsql.Design": "3.1.0-rc1-5", - "MailKit": "1.12.0", - "MarkdownDeep-av.NET": "1.5.6", - "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final", - "Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final", - "Microsoft.AspNet.Authentication.Twitter": "1.0.0-rc1-final", - "Microsoft.AspNet.Authorization": "1.0.0-rc1-final", - "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final", - "Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final", - "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*", - "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-*", - "Microsoft.AspNet.Localization": "1.0.0-rc1-final", - "Microsoft.AspNet.Mvc": "6.0.0-rc1-*", - "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-*", - "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", - "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final", - "Microsoft.AspNet.SignalR.Core": "2.2.1", - "Microsoft.AspNet.SignalR.JS": "2.2.1", - "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-*", - "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-*", - "Microsoft.AspNet.WebSockets.Server": "1.0.0-rc1-*", - "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final", - "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final", - "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", - "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final", - "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", - "Microsoft.Extensions.Logging.TraceSource": "1.0.0-rc1-final", - "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final", - "Microsoft.Extensions.Globalization.CultureInfoCache": "1.0.0-rc1-final", - "Microsoft.Extensions.Localization": "1.0.0-rc1-final", - "Microsoft.Extensions.Localization.Abstractions": "1.0.0-rc1-final", - "Microsoft.Extensions.CodeGeneration": "1.0.0-rc1-final", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final", - "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final", - "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", - "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8", - "Microsoft.Framework.Configuration.Binder": "1.0.0-beta8", - "Microsoft.Framework.Configuration.Json": "1.0.0-beta8", - "Microsoft.AspNet.Session": "1.0.0-rc1-final", - "Microsoft.AspNet.Web.Optimization": "1.1.3", - "Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final", - "Microsoft.Extensions.Options": "0.0.1-alpha", - "Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final", - "Microsoft.AspNet.DataProtection": "1.0.0-rc1-final", - "Microsoft.AspNet.DataProtection.SystemWeb": "1.0.0-rc1-final", - "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final", - "Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final", - "Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", - "Microsoft.AspNet.OWin": "1.0.0-rc1-final", - "System.Json": "4.0.20126.16343", - "Yavsc.Abstract": { - "type": "build", - "version": "1.0.0" + "buildOptions": { + "debugType": "portable", + "emitEntryPoint": true }, - "Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713", - "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final", - "Microsoft.DiaSymReader.Native": "1.5.0", - "PayPalMerchant-net451": "2.7.109" - }, - "commands": { - "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", - "coiffure": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:88", - "lua": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:85", - "luatest": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5001", - "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", - "zicmoove": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:87", - "yavsc": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:86", - "yavscpre": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:84", - "ef": "EntityFramework.Commands", - "gen": "Microsoft.Extensions.CodeGeneration" - }, - "frameworks": { - "dnx451": { - "frameworkAssemblies": { - "System.Drawing": "4.0.0.0", - "System.Net": "4.0.0.0", - "System.Xml": "4.0.0.0", - "System": "4.0.0.0" - } - } - }, - "exclude": [ - "wwwroot", - "node_modules", - "bower_components", - "contrib" - ], - "publishExclude": [ - "**.user", - "**.vspscc", - "contrib/**/*.*" - ], - "scripts": { - "prebuild": "echo before building", - "postbuild": "echo after building", - "prepack": "gulp min", - "postpack": "echo after packing", - "prerestore": "echo before restoring packages", - "postrestore": "echo after restoring packages", - "prepublish": "gulp min", - "postpublish": "echo after publish" - }, - "embed": "Views/**/*.cshtml" -} + "compile": [ + "*.cs" + ], + "resource": [ + "Resources/**/*.resx" + ], + "namedResource": {}, + "configurations": { + "Debug": { + "compilationOptions": { + "emitEntryPoint": true, + "define": [ + "DEBUG", + "TRACE" + ], + "optimize": false, + "debugType": "portable" + } + }, + "Release": { + "compilationOptions": { + "define": [ + "RELEASE", + "TRACE" + ], + "optimize": true + } + } + }, + "webroot": "wwwroot", + "tooling": { + "defaultNamespace": "Yavsc" + }, + "dependencies": { + "EntityFramework.Commands": "7.0.0-rc1-final", + "EntityFramework.Core": "7.0.0-rc1-final", + "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final", + "EntityFramework.Relational": "7.0.0-rc1-final", + "EntityFramework7.Npgsql": "3.1.0-rc1-3", + "EntityFramework7.Npgsql.Design": "3.1.0-rc1-5", + "MailKit": "1.12.0", + "MarkdownDeep-av.NET": "1.5.6", + "Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final", + "Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final", + "Microsoft.AspNet.Authentication.Twitter": "1.0.0-rc1-final", + "Microsoft.AspNet.Authorization": "1.0.0-rc1-final", + "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final", + "Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final", + "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-*", + "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-*", + "Microsoft.AspNet.Localization": "1.0.0-rc1-final", + "Microsoft.AspNet.Mvc": "6.0.0-rc1-*", + "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-*", + "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final", + "Microsoft.AspNet.Server.WebListener": "1.0.0-rc1-final", + "Microsoft.AspNet.SignalR.Core": "2.2.1", + "Microsoft.AspNet.SignalR.JS": "2.2.1", + "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-*", + "Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-*", + "Microsoft.AspNet.WebSockets.Server": "1.0.0-rc1-*", + "Microsoft.Extensions.Configuration.Abstractions": "1.0.0-rc1-final", + "Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final", + "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final", + "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final", + "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", + "Microsoft.Extensions.Logging.TraceSource": "1.0.0-rc1-final", + "Microsoft.Extensions.DependencyInjection.Abstractions": "1.0.0-rc1-final", + "Microsoft.Extensions.Globalization.CultureInfoCache": "1.0.0-rc1-final", + "Microsoft.Extensions.Localization": "1.0.0-rc1-final", + "Microsoft.Extensions.Localization.Abstractions": "1.0.0-rc1-final", + "Microsoft.Extensions.CodeGeneration": "1.0.0-rc1-final", + "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final", + "Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final", + "Microsoft.Framework.ConfigurationModel.Json": "1.0.0-beta4", + "Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta8", + "Microsoft.Framework.Configuration.Binder": "1.0.0-beta8", + "Microsoft.Framework.Configuration.Json": "1.0.0-beta8", + "Microsoft.AspNet.Session": "1.0.0-rc1-final", + "Microsoft.AspNet.Web.Optimization": "1.1.3", + "Microsoft.Extensions.WebEncoders.Core": "1.0.0-rc1-final", + "Microsoft.Extensions.Options": "0.0.1-alpha", + "Microsoft.Extensions.WebEncoders": "1.0.0-rc1-final", + "Microsoft.AspNet.DataProtection": "1.0.0-rc1-final", + "Microsoft.AspNet.DataProtection.SystemWeb": "1.0.0-rc1-final", + "Microsoft.AspNet.Authentication.JwtBearer": "1.0.0-rc1-final", + "Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final", + "Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final", + "Microsoft.AspNet.OWin": "1.0.0-rc1-final", + "System.Json": "4.0.20126.16343", + "Yavsc.Abstract": { + "type": "build", + "version": "1.0.0" + }, + "Extensions.AspNet.Authentication.Instagram": "1.0.0-t150809211713", + "Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final", + "Microsoft.DiaSymReader.Native": "1.5.0", + "PayPalMerchant-net451": "2.7.109" + }, + "commands": { + "web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", + "coiffure": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:88", + "lua": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:85", + "luatest": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5001", + "kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000", + "zicmoove": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:87", + "yavsc": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:86", + "yavscpre": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://*:84", + "ef": "EntityFramework.Commands", + "gen": "Microsoft.Extensions.CodeGeneration" + }, + "frameworks": { + "dnx451": { + "frameworkAssemblies": { + "System.Drawing": "4.0.0.0", + "System.Net": "4.0.0.0", + "System.Xml": "4.0.0.0", + "System": "4.0.0.0" + } + } + }, + "exclude": [ + "wwwroot", + "node_modules", + "bower_components", + "contrib" + ], + "publishExclude": [ + "**.user", + "**.vspscc", + "contrib/**/*.*" + ], + "scripts": { + "prebuild": "echo before building", + "postbuild": "echo after building", + "prepack": "gulp min", + "postpack": "echo after packing", + "prerestore": "echo before restoring packages", + "postrestore": "echo after restoring packages", + "prepublish": "gulp min", + "postpublish": "echo after publish" + }, + "embed": "Views/**/*.cshtml" +} \ No newline at end of file