Light12306/TrainInfomationProviderService/RunTimeContext.cs
2014-11-21 20:32:36 +08:00

51 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}