public void Configuration(IAppBuilder app) { InitialzieContainer(); InitializeEFConfiguration(); var env = GlobalContainer.GetService <IApplicationEnvironment>(); if (env.IsProduction()) { GlobalContainer.AddSingleton(typeof(ISuitablePathResolver), typeof(MinimizedPathResolver)); } if (!IsWindowsAuthentication()) { Authentication.ConfigureAuth(app); } UseRedirectWhenDirectAccess(app); app.UseCors(CorsOptions.AllowAll); app.UseServiceUnit( ServiceUnitSettings.Create().SetContextCreatedHandler(OnServiceUnitContextCreated), new ServiceUnitApi(), new ServiceUnitForm(), new ServiceUnitResource() { JavaScriptFormatter = (text, culture, resourceName) => { return(";(function(){ App.culture(\"" + culture.Name + "\",{ \"text\": { " + resourceName + ":" + text + "}} );})();"); } }); UseDefaultPage(app); }
private JObject LoadConfig(string path, string env, bool createEmpty = true) { //HostingEnvironment var dir = GlobalContainer.GetService <IApplicationEnvironment>().MapPath(path); JObject envConfig = null; if (!string.IsNullOrEmpty(env)) { var configFileName = System.IO.Path.Combine(dir, string.Format(EnvConfigFileNameFormat, env)); if (File.Exists(configFileName)) { envConfig = JObject.Parse(File.ReadAllText(configFileName)); } else { if (createEmpty) { envConfig = JObject.Parse("{}"); } } } var config = LoadConfig(path, createEmpty); if (envConfig != null && config != null) { config.Merge(envConfig); } if (config == null && envConfig != null) { config = envConfig; } return(config); }
public static HttpResponseMessage CreateFileDownloadErrorResponse(this HttpRequestMessage request, HttpStatusCode statusCode, string message, string detail) { HttpResponseMessage response = request.CreateResponse(statusCode); var env = GlobalContainer.GetService <IApplicationEnvironment>(); var uri = env.ApplicationRoot + "/Shared/V1/Users/page/DownloadError?Message=" + message + "&Detail=" + detail; response.Headers.Location = new Uri(uri, UriKind.RelativeOrAbsolute); return(response); }
public static string ResolveSuitableFileUrl(this Control source, string path) { var resolvedPath = source.ResolveUrl(path); var resolver = GlobalContainer.GetService <ISuitablePathResolver>(); if (resolver == null) { return(resolvedPath); } return(resolver.Resolve(resolvedPath)); }
public FileOutputMailSender(SmtpMailConfiguration smtpConfig) { Contract.NotNull(smtpConfig, "smtpConfig"); Contract.NotNull(smtpConfig.FileOutputDir, "FileOutputDir"); outputDirectory = GlobalContainer.GetService <IApplicationEnvironment>().MapPath(smtpConfig.FileOutputDir); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } this.smtpConfig = smtpConfig; }
private JObject LoadConfig(string path, bool createEmpty = true) { //HostingEnvironment var dir = GlobalContainer.GetService <IApplicationEnvironment>().MapPath(path); var configFileName = System.IO.Path.Combine(dir, ConfigFileName); if (File.Exists(configFileName)) { return(JObject.Parse(File.ReadAllText(configFileName))); } if (createEmpty) { return(JObject.Parse("{}")); } return(null); }
void IMiddlewareRegisterSetting.Use(global::Owin.IAppBuilder builder) { ITypePath typePath = GlobalContainer.GetService <ITypePath>(); List <TypePathItem> items = typePath.Items.Where(i => i.TargetType.IsSubclassOf(typeof(ServiceUnitPersistentConnection))).ToList(); foreach (TypePathItem item in items) { PathMapResult pathconvert = PathMapper.Convert( item.Path, "/{ServiceUnitName}/{Version}/{Role}/Socket/{Name}Socket", "/{ServiceUnitName}/{Version}/{Role}/socket/{Name}"); if (pathconvert.Success) { builder.MapSignalR(pathconvert.MappedPath, item.TargetType, new ConnectionConfiguration()); } } }
/// <summary> /// 指定されたルート相対パスをもとに縮小化されたファイルがある場合は、そのパスを返し、ない場合は指定されたルート相対パスを返します。 /// </summary> /// <param name="rootRelativePath">ルート相対パス</param> /// <returns>縮小化されたファイルのパス</returns> public string Resolve(string rootRelativePath) { var env = GlobalContainer.GetService <IApplicationEnvironment>(); var fileName = env.MapPath(rootRelativePath); var withOut = fileName.Remove(fileName.Length - NPath.GetExtension(fileName).Length); if (!withOut.EndsWith(".min", StringComparison.InvariantCultureIgnoreCase)) { if (File.Exists(withOut + ".min" + NPath.GetExtension(fileName))) { fileName = withOut + ".min" + NPath.GetExtension(fileName); } } var appRoot = env.ApplicationRoot; return((appRoot.EndsWith("/") ? appRoot : (appRoot + "/")) + fileName.Replace(env.RootDir, string.Empty).Replace('\\', '/')); }
public static ServiceConfiguration Load() { ServiceConfiguration config = null; var key = CreateKey(null, null, null); if (configurationPool.TryGetValue(key, out config)) { return(config); } var env = GlobalContainer.GetService <IApplicationEnvironment>().EnvironmentName; var dic = JObject.Parse("{}").Extend(LoadRoot(env), LoadServiceUnitRoot(env)).ToObject <Dictionary <string, JToken> >(); config = new ServiceConfiguration(dic, ""); configurationPool.AddOrUpdate(key, config, (k, old) => config); return(config); }
public static JToken LoadTreeJson(string[] roles) { var cacheKey = string.Join(",", roles); JToken result; if (treeConfigurationPool.TryGetValue(cacheKey, out result)) { return(result); } var environment = GlobalContainer.GetService <IApplicationEnvironment>(); var rootDir = new DirectoryInfo(environment.MapPath(ServiceUnitDir)); var env = environment.EnvironmentName; var rootConfig = ServiceConfigurationLoader.Load(); var rootJson = LoadConfig(ServiceUnitDir, env, false); if (rootJson == null) { result = JObject.Parse("{}"); treeConfigurationPool.AddOrUpdate(cacheKey, result, (k, old) => result); return(result); } AddItemsProperty(rootJson); //service unit foreach (var suDir in rootDir.GetDirectories()) { var suJson = LoadServiceUnit(suDir.Name, env, false); if (suJson == null) { continue; } AddItemsProperty(suJson); AddServicePath(((JArray)suJson["items"]), suDir.Name); AddServicePath(suJson); ((JArray)rootJson["items"]).Add(suJson); //version foreach (var vDir in suDir.GetDirectories()) { var vJson = LoadVersion(suDir.Name, vDir.Name, env, false); if (vJson == null) { continue; } AddItemsProperty(vJson); AddServicePath(((JArray)vJson["items"]), suDir.Name, vDir.Name); AddServicePath(vJson, suDir.Name); ((JArray)suJson["items"]).Add(vJson); //role foreach (var roleDir in vDir.GetDirectories()) { if (!rootConfig.AvailableRoles.Any(r => r == roleDir.Name)) { continue; } var roleJson = LoadRole(suDir.Name, vDir.Name, roleDir.Name, env, false); if (roleJson == null) { continue; } if (roles.Length != 0 && !roles.Contains(roleDir.Name)) { continue; } AddItemsProperty(roleJson); AddServicePath(((JArray)roleJson["items"]), suDir.Name, vDir.Name, roleDir.Name); AddServicePath(roleJson, suDir.Name, vDir.Name); ((JArray)vJson["items"]).Add(roleJson); } } } treeConfigurationPool.AddOrUpdate(cacheKey, rootJson, (k, old) => rootJson); return(rootJson); }