51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Configuration;
|
|||
|
using System.Diagnostics;
|
|||
|
using System.IO;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Web.Hosting;
|
|||
|
|
|||
|
namespace TrainInfomationProviderService
|
|||
|
{
|
|||
|
class RunTimeContext
|
|||
|
{
|
|||
|
public static string ServiceRoot { get; private set; }
|
|||
|
|
|||
|
public static string DataStorageRoot { get; private set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 是否是web环境
|
|||
|
/// </summary>
|
|||
|
public static bool IsWeb { get; private set; }
|
|||
|
|
|||
|
|
|||
|
static RunTimeContext()
|
|||
|
{
|
|||
|
Trace.TraceInformation("[CONTEXT] 正在初始化上下文");
|
|||
|
|
|||
|
IsWeb = System.Web.Hosting.HostingEnvironment.IsHosted;
|
|||
|
Trace.TraceInformation("[CONTEXT] WEB模式:{0}", IsWeb);
|
|||
|
|
|||
|
if (IsWeb)
|
|||
|
{
|
|||
|
ServiceRoot = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;
|
|||
|
DataStorageRoot = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["dataStoragePath"]);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ServiceRoot = System.Reflection.Assembly.GetEntryAssembly().GetLocation();
|
|||
|
DataStorageRoot = ConfigurationManager.AppSettings["dataStoragePath"];
|
|||
|
if (!Path.IsPathRooted(DataStorageRoot))
|
|||
|
DataStorageRoot = PathUtility.Combine(ServiceRoot, DataStorageRoot);
|
|||
|
}
|
|||
|
Directory.CreateDirectory(DataStorageRoot);
|
|||
|
|
|||
|
Trace.TraceInformation("[CONTEXT] 服务根目录:{0}", ServiceRoot);
|
|||
|
Trace.TraceInformation("[CONTEXT] 数据根目录:{0}", DataStorageRoot);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|