initial version with inspection edition
This commit is contained in:
160
IronIntelContractor/CacheManager.cs
Normal file
160
IronIntelContractor/CacheManager.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Foresight.Cache;
|
||||
using Foresight.Cache.AspNet;
|
||||
using Foresight.Cache.Redis;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public static class CacheManager
|
||||
{
|
||||
public static void Dispose()
|
||||
{
|
||||
if (_Client != null)
|
||||
{
|
||||
_Client.Dispose();
|
||||
_Client = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient _Client = null;
|
||||
private static object _sycobj = new object();
|
||||
|
||||
private static FIRedisCacheClient CreateRedisClient(string[] servers)
|
||||
{
|
||||
if ((servers == null) || (servers.Length == 0))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<RedisNode> ls = new List<RedisNode>();
|
||||
foreach (string srv in servers)
|
||||
{
|
||||
try
|
||||
{
|
||||
RedisNode node = CreateRedisNode(srv);
|
||||
ls.Add(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", typeof(CacheManager).FullName + ".CreateRedisClient", "Create RedisNode failed: " + srv, ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
if (ls.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FIRedisCacheClient("IRONINTEL_" + ContractorHost.Instance.CustomerID.ToUpper(), ls);
|
||||
}
|
||||
}
|
||||
|
||||
private static RedisNode CreateRedisNode(string server)
|
||||
{
|
||||
string[] address = server.Split(new char[] { ':' });
|
||||
int port = -1;
|
||||
if (!int.TryParse(address[1], out port))
|
||||
{
|
||||
port = -1;
|
||||
}
|
||||
int weight = 100;
|
||||
if (!int.TryParse(address[2], out weight))
|
||||
{
|
||||
weight = 100;
|
||||
}
|
||||
RedisNode node = new RedisNode(address[0], port, weight);
|
||||
return node;
|
||||
}
|
||||
|
||||
private static void InitCacheClient()
|
||||
{
|
||||
FIRedisCacheClient fc = null;
|
||||
try
|
||||
{
|
||||
fc = CreateRedisClient(ContractorHost.Instance.RedisServersAddress);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", typeof(CacheManager).FullName + ".InitCacheClient", "Create Redis client failed", ex.ToString(),string.Empty);
|
||||
}
|
||||
if (fc != null)
|
||||
{
|
||||
_Client = fc;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Client = new AspNetCacheManager("IRONINTEL_" + ContractorHost.Instance.CustomerID.ToUpper());
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
lock (_sycobj)
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
InitCacheClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _Client;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Remove(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.Remove(key);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(string key, byte[] buffer, TimeSpan expire)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
Remove(key);
|
||||
}
|
||||
else if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.SetValue(key, buffer, expire);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetValue(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.GetValue(key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
269
IronIntelContractor/ContractorHost.cs
Normal file
269
IronIntelContractor/ContractorHost.cs
Normal file
@ -0,0 +1,269 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Configuration;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Foresight.Data;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.DataModel.Admin.Customers;
|
||||
using IronIntel.DataModel.Admin.Users;
|
||||
using IronIntel.Services;
|
||||
using Foresight.Services.Log;
|
||||
using Foresight.Services.Mail;
|
||||
using IronIntel.DataModel.Admin;
|
||||
using IronIntel.DataModel.Admin.Machines;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Ironintel contractor站点宿主。目前contractor站点仍然是每个公司一个站点
|
||||
/// </summary>
|
||||
public class ContractorHost : IIronIntelHost
|
||||
{
|
||||
public static ContractorHost Instance { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Instance = new ContractorHost();
|
||||
IronIntelHostEnvironment.InitHost(Instance);
|
||||
}
|
||||
|
||||
private const string APPNAME = "IronIntelCustomerSite";
|
||||
|
||||
private CustomerManager _CustomerManager = null;
|
||||
private LoginManager _LoginManager = null;
|
||||
private LogWriter _LogWriter = null;
|
||||
private SystemParamProvider _MasterSystemParams = null;
|
||||
private MachineClassManager _MachineClassManager = null;
|
||||
private MachineManager _MachineManager = null;
|
||||
|
||||
public string DataDbConnectionString { get; private set; }
|
||||
public string FICDbConnectionString { get; private set; }
|
||||
public CustomerInfo Customer { get; private set; }
|
||||
|
||||
public DataModel.Contractor.ContractorSystemParams ContractorSystemParams { get; private set; }
|
||||
private string AdminDbConnectionString = string.Empty;
|
||||
private string MasterDbConnectionString = string.Empty;
|
||||
private string MasterDbConnectionString2 = string.Empty;//指向新的数据库服务器
|
||||
|
||||
public string CustomerID { get; private set; }
|
||||
private string MasterServiceAddress = string.Empty;
|
||||
private string FICSysDbName = string.Empty;
|
||||
|
||||
private string ForesightServiceAppName = string.Empty;
|
||||
private string ForesightServiceAddress = string.Empty;
|
||||
public string[] RedisServersAddress { get; private set; }
|
||||
|
||||
private ContractorHost()
|
||||
{
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(ConfigurationManager.AppSettings["DbConntionString"]);
|
||||
try
|
||||
{
|
||||
sb.Password = SystemUtility.DecryptString(sb.Password);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
DataDbConnectionString = sb.ToString();
|
||||
LoadLocalParams();
|
||||
InitMasterManager();
|
||||
CreateDbObjects();
|
||||
|
||||
_MachineManager = new MachineManager(AdminDbConnectionString);
|
||||
_MachineClassManager = new MachineClassManager(AdminDbConnectionString);
|
||||
|
||||
Customer = GetCustomerInfo(CustomerID);
|
||||
ContractorSystemParams = new DataModel.Contractor.ContractorSystemParams();
|
||||
ContractorSystemParams.Init(Customer, DataDbConnectionString, FICDbConnectionString);
|
||||
MasterDbConnectionString2 = _CustomerManager.GetCustomerIronIntelDbConnectionString2(CustomerID);
|
||||
}
|
||||
|
||||
private void LoadLocalParams()
|
||||
{
|
||||
const string PARAM_MASTER_SERVICE_ADDRESS = "MasterServiceAddress";
|
||||
const string PARAM_COMPANYID = "CompanyID";
|
||||
const string PARAM_FICSYSDB = "FICSysDBName";
|
||||
|
||||
|
||||
FISqlConnection db = new FISqlConnection(DataDbConnectionString);
|
||||
DataTable tb = db.GetDataTableBySQL("select PARAMNAME,PARAMVALUE from SYSPARAMS");
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
string pname = dr["PARAMNAME"].ToString();
|
||||
string pvalue = FIDbAccess.GetFieldString(dr["PARAMVALUE"], string.Empty);
|
||||
if (string.Compare(pname, PARAM_COMPANYID, true) == 0)
|
||||
{
|
||||
CustomerID = pvalue;
|
||||
}
|
||||
else if (string.Compare(pname, PARAM_MASTER_SERVICE_ADDRESS, true) == 0)
|
||||
{
|
||||
string[] uris = pvalue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
MasterServiceAddress = uris[0];
|
||||
}
|
||||
else if (string.Compare(pname, PARAM_FICSYSDB, true) == 0)
|
||||
{
|
||||
FICSysDbName = pvalue;
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(DataDbConnectionString);
|
||||
sb.InitialCatalog = FICSysDbName;
|
||||
FICDbConnectionString = sb.ConnectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDbObjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
IronIntel.Services.Database.Contractor.ContractorDbCreator cd = new Services.Database.Contractor.ContractorDbCreator(DataDbConnectionString);
|
||||
cd.Create();
|
||||
|
||||
FI.FIC.Database.FIC.FICDbInitializer ficdb = new FI.FIC.Database.FIC.FICDbInitializer(FICDbConnectionString);
|
||||
ficdb.RunIronIntel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog(CustomerID, GetType().FullName + ".CreateDbObjects()", "Init db objects failed: " + ex.Message, ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMasterManager()
|
||||
{
|
||||
IronSysServiceClient client = new IronSysServiceClient(MasterServiceAddress);
|
||||
client.AppName = APPNAME;
|
||||
AdminDbConnectionString = client.GetAdminDbConnectionString();
|
||||
|
||||
FISqlConnection db = new FISqlConnection(AdminDbConnectionString);
|
||||
string masterdb = FIDbAccess.GetFieldString(db.GetRC1BySQL("select PARAMVALUE from SYSPARAMS where PARAMNAME='MASTER_DB_NAME'"), string.Empty);
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(AdminDbConnectionString);
|
||||
sb.InitialCatalog = masterdb;
|
||||
MasterDbConnectionString = sb.ConnectionString;
|
||||
|
||||
_CustomerManager = new CustomerManager(MasterDbConnectionString);
|
||||
_LoginManager = new LoginManager(MasterDbConnectionString);
|
||||
|
||||
_MasterSystemParams = new SystemParamProvider(MasterDbConnectionString);
|
||||
|
||||
ForesightServiceAppName = _MasterSystemParams.ForesightServiceAppName;
|
||||
ForesightServiceAddress = _MasterSystemParams.ForesightServiceAddress;
|
||||
|
||||
string str = _MasterSystemParams.RedisServersAddress;
|
||||
if(string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
RedisServersAddress = new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
RedisServersAddress = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
_LogWriter = new LogWriter(ForesightServiceAddress);
|
||||
_LogWriter.AppName = ForesightServiceAppName;
|
||||
}
|
||||
|
||||
public CustomerManager GetCustomerManager()
|
||||
{
|
||||
return _CustomerManager;
|
||||
}
|
||||
|
||||
public LoginManager GetLoginManager()
|
||||
{
|
||||
return _LoginManager;
|
||||
}
|
||||
|
||||
public long SendEmail(string customerid, MailMessage msg)
|
||||
{
|
||||
return SendEmail(customerid, APPNAME, msg);
|
||||
}
|
||||
|
||||
public long SendEmail(string customerid,string mailtype, MailMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
MailSender mail = new MailSender(ForesightServiceAddress);
|
||||
mail.AppName = ForesightServiceAppName;
|
||||
return mail.SendMail(ForesightServiceAppName, customerid, mailtype, msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog(customerid, "Error", GetType().FullName + ".SendEmail", "Add mail to mailservice failed: " + ex.Message, ex.ToString(), string.Empty);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLog(string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
_LogWriter.WriteLog(ForesightServiceAppName, CustomerInfo.FORESIGHT, SystemUtility.HostName, APPNAME, logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
public void WriteLog(string customerid, string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
_LogWriter.WriteLog(ForesightServiceAppName, customerid, SystemUtility.HostName, APPNAME, logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
public string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
return _LogWriter.GetResourceLock(ForesightServiceAppName, resourceid, locksecond);
|
||||
}
|
||||
|
||||
public void ReleaseLock(string lockid)
|
||||
{
|
||||
_LogWriter.ReleaseLock(ForesightServiceAppName, lockid);
|
||||
}
|
||||
|
||||
public CustomerInfo GetCustomerInfo(string custid)
|
||||
{
|
||||
if (Customer != null)
|
||||
{
|
||||
if (string.Compare(custid, Customer.ID, true) == 0)
|
||||
{
|
||||
return Customer;
|
||||
}
|
||||
}
|
||||
return _CustomerManager.GetCustomerByID(custid);
|
||||
}
|
||||
|
||||
public DataModel.LicenseInfo GetLicense()
|
||||
{
|
||||
return _CustomerManager.GetLicense(CustomerID);
|
||||
}
|
||||
|
||||
public string GetIronIntelDbConnectionString(string custid)
|
||||
{
|
||||
if (string.Compare(custid, CustomerID, true) == 0)
|
||||
{
|
||||
return DataDbConnectionString;
|
||||
}
|
||||
return _CustomerManager.GetCustomerIronIntelDbConnectionString(custid);
|
||||
}
|
||||
|
||||
public T GetContractorManager<T>() where T : DataModel.Contractor.ContractorBusinessBase, new()
|
||||
{
|
||||
T rst = new T();
|
||||
rst.Init(Customer, DataDbConnectionString, FICDbConnectionString);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public IronIntel.DataModel.Contractor.Users.UserManager GetUserManager()
|
||||
{
|
||||
return GetContractorManager<IronIntel.DataModel.Contractor.Users.UserManager>();
|
||||
}
|
||||
|
||||
public SystemParamProvider GetSystemParamsProvider()
|
||||
{
|
||||
return _MasterSystemParams;
|
||||
}
|
||||
|
||||
public MachineClassManager GetMachineClassManager()
|
||||
{
|
||||
return _MachineClassManager;
|
||||
}
|
||||
|
||||
public MachineManager GetMachineManager()
|
||||
{
|
||||
return _MachineManager;
|
||||
}
|
||||
}
|
||||
}
|
528
IronIntelContractor/FIC/FICHost.cs
Normal file
528
IronIntelContractor/FIC/FICHost.cs
Normal file
@ -0,0 +1,528 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using System.Net.Mail;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using Foresight.Data;
|
||||
using Foresight.Security.License;
|
||||
using System.Web;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using FI.FIC;
|
||||
using IronIntel.DataModel.Contractor.Users;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.Contractor.Site;
|
||||
|
||||
namespace IronIntel.Contractor.FIC
|
||||
{
|
||||
public class FICHost : IFICHost
|
||||
{
|
||||
static readonly Guid FIC_MODULE_ID = new Guid("1c6dfe25-347d-4889-ab75-73ade9190d27");
|
||||
const string FIC_MODULE_NAME = "Foresight Intelligence Center";
|
||||
const string FIC_MODULE_VERSION = "3.0";
|
||||
|
||||
public string FICDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return ContractorHost.Instance.FICDbConnectionString;
|
||||
}
|
||||
}
|
||||
|
||||
public string FrsDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
public bool FICInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool FRSInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
FICHostEnvironment.SetHost(new FICHost());
|
||||
}
|
||||
|
||||
public byte[] GetCacheData(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = CacheManager.GetValue(key);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Decompress(buffer);
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.FromBuffer(tmp);
|
||||
createTime = fc.CreateTime;
|
||||
return fc.Data;
|
||||
}
|
||||
|
||||
public DataTable GetCacheDataTable(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = GetCacheData(key, ignoreExpired, ref createTime);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//FIDataTable tb = new FIDataTable();
|
||||
//tb.FillFromBuffer(buffer);
|
||||
//return FIDbAccess.ConvertDataTable(tb);
|
||||
return Deserialize(buffer) as DataTable;
|
||||
}
|
||||
|
||||
public FICCompanyInfo GetCompanyInfo()
|
||||
{
|
||||
var cp = ContractorHost.Instance.Customer;
|
||||
FICCompanyInfo ficcp = new FICCompanyInfo();
|
||||
ficcp.ID = cp.ID;
|
||||
ficcp.Name = cp.Name;
|
||||
|
||||
return ficcp;
|
||||
}
|
||||
|
||||
public CompanyLic GetLicense()
|
||||
{
|
||||
var lic = ContractorHost.Instance.GetLicense();
|
||||
if (lic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CompanyLic ci = new CompanyLic();
|
||||
ci.CompanyID = ContractorHost.Instance.Customer.ID;
|
||||
ci.CompanyName = ContractorHost.Instance.Customer.Name;
|
||||
|
||||
Foresight.Security.License.LicenseInfo li = new Foresight.Security.License.LicenseInfo();
|
||||
ci.Licenses.Add(li);
|
||||
li.CompanyID = ci.CompanyID;
|
||||
li.CompanyName = ci.CompanyName;
|
||||
li.Expiration = lic.ExpireDate;
|
||||
li.ID = Guid.Empty;
|
||||
li.StartDate = lic.StartDate;
|
||||
li.ModuleID = FIC_MODULE_ID;
|
||||
li.ModuleName = FIC_MODULE_NAME;
|
||||
li.Version = FIC_MODULE_VERSION;
|
||||
|
||||
foreach (var item in lic.Items)
|
||||
{
|
||||
var prop = ConvertLicenseItem(item);
|
||||
if (prop != null)
|
||||
{
|
||||
li.AddtionalPropertes.Add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
return ci;
|
||||
}
|
||||
|
||||
private LicenseAddtionalPropertyObj ConvertLicenseItem(DataModel.LicenseItem item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
switch (item.Key)
|
||||
{
|
||||
case "ColumnLineCombChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ColumnLineCombChart", Value = item.Value, Description = item.Description };
|
||||
case "ExportChartToXPS":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ExportChartToXPS", Value = item.Value, Description = item.Description };
|
||||
case "FreeChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "FreeChart", Value = item.Value, Description = item.Description };
|
||||
case "DrilldownToURL":
|
||||
return new LicenseAddtionalPropertyObj { Key = "DrilldownToURL", Value = item.Value, Description = item.Description };
|
||||
case "MaxCharts":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxCharts", Value = item.Value, Description = item.Description };
|
||||
case "MaxDataTables":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxDataTables", Value = item.Value, Description = item.Description };
|
||||
case "PrintChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "PrintChart", Value = item.Value, Description = item.Description };
|
||||
case "ScatterChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ScatterChart", Value = item.Value, Description = item.Description };
|
||||
case "Snapshot":
|
||||
return new LicenseAddtionalPropertyObj { Key = "Snapshot", Value = item.Value, Description = item.Description };
|
||||
case "SQLGenerator":
|
||||
return new LicenseAddtionalPropertyObj { Key = "SQLGenerator", Value = item.Value, Description = item.Description };
|
||||
//case "MainStyle":
|
||||
//case "MaxAdminCount":
|
||||
//case "MaxLogins":
|
||||
//case "MaxNormalUerCount":
|
||||
//case "MaxReadOnlyUserCount":
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
return ContractorHost.Instance.GetResourceLock(resourceid, locksecond);
|
||||
}
|
||||
|
||||
private static FICUserInfo ConvertToFICUserInfo(IronIntel.DataModel.Contractor.Users.UserInfo ui)
|
||||
{
|
||||
var user = new FICUserInfo
|
||||
{
|
||||
ID = ui.ID,
|
||||
IID = ui.UID,
|
||||
Enabled = ui.Active,
|
||||
DisplayName = ui.Name,
|
||||
Mobile = ui.Mobile,
|
||||
BusinessPhone = ui.BusinessPhone,
|
||||
};
|
||||
switch (ui.UserType)
|
||||
{
|
||||
case UserTypes.Common:
|
||||
user.UserType = FICUserTypes.Common;
|
||||
break;
|
||||
case UserTypes.Admin:
|
||||
user.UserType = FICUserTypes.Admin;
|
||||
break;
|
||||
case UserTypes.Readonly:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
case UserTypes.SupperAdmin:
|
||||
user.UserType = FICUserTypes.SuperAdmin;
|
||||
break;
|
||||
default:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByIID(string useriid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
var ui = um.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByLoginSessionID(string sessionid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo ui = um.GetUserByLoginSessionID(sessionid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByUserID(string userId)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo ui = um.GetUserByID(userId);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers()
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
UserInfo[] users = um.GetSelfUsers();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public string GetUserEmail(string useriid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
UserInfo ui = um.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ui.ID;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostMessage(int category, string msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void ReleaseResourceLock(string lockid)
|
||||
{
|
||||
ContractorHost.Instance.ReleaseLock(lockid);
|
||||
}
|
||||
|
||||
public void RemoveCache(string key)
|
||||
{
|
||||
CacheManager.Remove(key);
|
||||
}
|
||||
|
||||
public void SendMail(MailMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
ContractorHost.Instance.SendEmail(ContractorHost.Instance.CustomerID, "FIC", message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", this.GetType().FullName + ".SendMail(MailMessage)", "Add fic mail to mail service failed", ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCacheData(string key, byte[] buffer, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
return;
|
||||
}
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.Data = buffer;
|
||||
fc.CreateTime = createTime;
|
||||
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Compress(fc.ToBuffer());
|
||||
CacheManager.SetValue(key, tmp, TimeSpan.FromSeconds(expirationsecond));
|
||||
}
|
||||
|
||||
public void SetCacheDataTable(string key, DataTable dt, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (dt == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] buffer = Serialize(dt, createTime);
|
||||
SetCacheData(key, buffer, expirationsecond, slidingExpiration, createTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void SubscribeMessage(int category, Action<IEnumerable<MessageInformation>> action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void WriteLog(string logType, string category, string source, string message, string detail)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog(logType, source, message, detail,category);
|
||||
}
|
||||
|
||||
public List<string> GetUserGroupIDByUserIID(string userIID)
|
||||
{
|
||||
var grps = ContractorHost.Instance.GetUserManager().GetGroupsByUserIID(userIID);
|
||||
List<string> ls = new List<string>(grps.Length);
|
||||
foreach(var grp in grps)
|
||||
{
|
||||
ls.Add(grp.ID);
|
||||
}
|
||||
return ls;
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers(bool hasAdmin)
|
||||
{
|
||||
if (!hasAdmin)
|
||||
{
|
||||
return GetUsers();
|
||||
}
|
||||
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo[] localusers = um.GetSelfUsers();
|
||||
UserInfo[] foresightusers = um.GetForesightUsers();
|
||||
UserInfo[] users = localusers.Union(foresightusers).ToArray();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public LoginContext GetCurrentLoginContext(HttpContext context)
|
||||
{
|
||||
string session = Site.IronIntelBasePage.GetLoginSessionID(context.Request);
|
||||
if (string.IsNullOrWhiteSpace(session))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
LoginContext lc = new LoginContext();
|
||||
lc.SessionID = session;
|
||||
lc.User = GetUserByLoginSessionID(session);
|
||||
lc.LanguageID = GetLgID(context);
|
||||
return lc;
|
||||
}
|
||||
|
||||
private string GetLgID(HttpContext context)
|
||||
{
|
||||
var language = context.Request.Cookies[IronIntelBasePage.LANGUAGECOOKIENAME];
|
||||
if (language != null)
|
||||
{
|
||||
return language.Value;
|
||||
}
|
||||
return ResLanguage.ClientCurrentLanguage;
|
||||
}
|
||||
|
||||
public string ProductEdition
|
||||
{
|
||||
get
|
||||
{
|
||||
return "General";
|
||||
}
|
||||
}
|
||||
|
||||
public string FIExternalDBConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public SpecialDatabaseConnectionInfo[] GetSpecialDatabaseConnections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetStyleDefines(string useriid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//StringBuilder s = new StringBuilder();
|
||||
//s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
//s.Append("<root>");
|
||||
//s.Append("<Workspace><Title><Background>#ff00ff</Background><Foreground>#222222</Foreground></Title></Workspace>");
|
||||
//s.Append("<Chart><Title><Background>#333333</Background><Foreground>#444444</Foreground></Title><Board>#555555</Board></Chart>");
|
||||
//s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
//s.Append("</root>");
|
||||
//return s.ToString();
|
||||
//// Services.CustUIStyle uistyle = SystemParams.GetUIStyle(useriid);
|
||||
|
||||
// StringBuilder s = new StringBuilder();
|
||||
// s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
// s.Append("<root>");
|
||||
// s.Append("<Workspace><Title><Background></Background><Foreground>#000000</Foreground></Title></Workspace>");
|
||||
// s.Append("<Chart><Title><Background>" + uistyle.ChartTitleBackgroundColor + "</Background><Foreground></Foreground></Title><Board>" + uistyle.ChartBorderColor + "</Board></Chart>");
|
||||
// //s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
// s.Append("</root>");
|
||||
// return s.ToString();
|
||||
}
|
||||
public Dictionary<string, string> GetAdditionalParameter()
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("ConnectorToken", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("ConnectorToken"));
|
||||
dic.Add("ConnectorServer", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("ConnectorServer"));
|
||||
dic.Add("LdapAgentID", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("LdapAgentID"));
|
||||
dic.Add("LdapAgentToken", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("LdapAgentToken"));
|
||||
dic.Add("CanUseConnectorLDAP", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("CanUseConnectorLDAP"));
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetSimpleUsers(bool hasAdmin)
|
||||
{
|
||||
var users = GetUsers(hasAdmin);
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
var us = new FICUserInfo();
|
||||
us.IID = user.IID;
|
||||
us.ID = user.ID;
|
||||
us.DisplayName = user.DisplayName;
|
||||
ls.Add(us);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
class FICCacheObject
|
||||
{
|
||||
public byte[] Data = null;
|
||||
public DateTime CreateTime = DateTime.Now;
|
||||
|
||||
public byte[] ToBuffer()
|
||||
{
|
||||
byte[] rst = new byte[Data.Length + 8];
|
||||
byte[] bf1 = BitConverter.GetBytes(CreateTime.Ticks);
|
||||
Buffer.BlockCopy(bf1, 0, rst, 0, 8);
|
||||
Buffer.BlockCopy(Data, 0, rst, 8, Data.Length);
|
||||
|
||||
return rst;
|
||||
}
|
||||
|
||||
public void FromBuffer(byte[] buffer)
|
||||
{
|
||||
long l = BitConverter.ToInt64(buffer, 0);
|
||||
CreateTime = new DateTime(l);
|
||||
Data = new byte[buffer.Length - 8];
|
||||
Buffer.BlockCopy(buffer, 8, Data, 0, buffer.Length - 8);
|
||||
}
|
||||
}
|
||||
|
||||
#region - (De)Serialize -
|
||||
|
||||
private static byte[] Serialize(object obj, DateTime createtime)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var cacheObj = new RedisCacheObject
|
||||
{
|
||||
CreateTime = createtime,
|
||||
Data = obj
|
||||
};
|
||||
byte[] data;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(ms, cacheObj);
|
||||
data = ms.ToArray();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static object Deserialize(byte[] buffer)
|
||||
{
|
||||
using (var ms = new MemoryStream(buffer, false))
|
||||
{
|
||||
return new BinaryFormatter().Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[Serializable]
|
||||
class RedisCacheObject
|
||||
{
|
||||
public DateTime CreateTime { get; set; }
|
||||
public object Data { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
118
IronIntelContractor/IronIntelContractor.csproj
Normal file
118
IronIntelContractor/IronIntelContractor.csproj
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{66F769E6-9708-4924-A9D8-BA8AE92B94D5}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IronIntel.Contractor</RootNamespace>
|
||||
<AssemblyName>IronIntelContractor</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>LHBIS.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FIASPNETCache">
|
||||
<HintPath>..\Reflib\FIASPNETCache.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICacheManager.Redis">
|
||||
<HintPath>..\Reflib\FICacheManager.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICachManager">
|
||||
<HintPath>..\Reflib\FICachManager.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICBLC">
|
||||
<HintPath>..\Reflib\FIC\FICBLC.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntf">
|
||||
<HintPath>..\Reflib\FIC\FICIntf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntfAdv">
|
||||
<HintPath>..\Reflib\FIC\FICIntfAdv.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICModels">
|
||||
<HintPath>..\Reflib\FIC\FICModels.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICore">
|
||||
<HintPath>..\Reflib\FICore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICoreDbCreator">
|
||||
<HintPath>..\Reflib\FICoreDbCreator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FIWinLib">
|
||||
<HintPath>..\Reflib\FIWinLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ForesightServicesClient">
|
||||
<HintPath>..\Reflib\ForesightServicesClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisyslib">
|
||||
<HintPath>..\Reflib\iisyslib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="irondbobjlib">
|
||||
<HintPath>..\Reflib\irondbobjlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Reflib\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StackExchange.Redis.StrongName">
|
||||
<HintPath>..\Reflib\StackExchange.Redis.StrongName.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheManager.cs" />
|
||||
<Compile Include="ContractorHost.cs" />
|
||||
<Compile Include="FIC\FICHost.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Site\IronIntelBasePage.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Site\IronIntelHttpHandlerBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModel\DataModel.csproj">
|
||||
<Project>{b0d49bbd-b287-44f0-aaaf-33833532ce4c}</Project>
|
||||
<Name>DataModel</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="LHBIS.snk" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
BIN
IronIntelContractor/LHBIS.snk
Normal file
BIN
IronIntelContractor/LHBIS.snk
Normal file
Binary file not shown.
36
IronIntelContractor/Properties/AssemblyInfo.cs
Normal file
36
IronIntelContractor/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("IronIntelContractor")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Foresight Intelligence")]
|
||||
[assembly: AssemblyProduct("IronIntelContractor")]
|
||||
[assembly: AssemblyCopyright("Copyright © Foresight Intelligence 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("66f769e6-9708-4924-a9d8-ba8ae92b94d5")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("3.18.1011.0")]
|
436
IronIntelContractor/Site/IronIntelBasePage.cs
Normal file
436
IronIntelContractor/Site/IronIntelBasePage.cs
Normal file
@ -0,0 +1,436 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using Foresight.ServiceModel;
|
||||
using Foresight.Security;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Users;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.Site
|
||||
{
|
||||
public class IronIntelBasePage : System.Web.UI.Page
|
||||
{
|
||||
public const string LOGINSESSION_COOKIENAME = "iiabc_";
|
||||
public const string LANGUAGECOOKIENAME = LOGINSESSION_COOKIENAME + "language";
|
||||
public const string APPNAME = "iron-desktop";
|
||||
public const string CLIENT_TIMEOFFSET_COOKIENAME = "clienttimeoffset";
|
||||
|
||||
private static int _LOCAL_TIMEOFFSET = 10000;
|
||||
|
||||
private static string _HostName = null;
|
||||
|
||||
private static string _Branch = string.Empty;
|
||||
private static string _AboutUrl = string.Empty;
|
||||
private static string _Copyrights = string.Empty;
|
||||
private static string _PageTitle = string.Empty;
|
||||
private static string _ShowTermofuse = string.Empty;
|
||||
|
||||
public static string LocalHostName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_HostName == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_HostName = Dns.GetHostName();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_HostName = string.Empty;
|
||||
}
|
||||
}
|
||||
return _HostName;
|
||||
}
|
||||
}
|
||||
|
||||
public static int LocalTimeOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_LOCAL_TIMEOFFSET == 10000)
|
||||
{
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime dt1 = dt.ToUniversalTime();
|
||||
TimeSpan sp = dt1 - dt;
|
||||
_LOCAL_TIMEOFFSET = Convert.ToInt32(sp.TotalMinutes);
|
||||
}
|
||||
return _LOCAL_TIMEOFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly byte[] KEY = new byte[] { 219, 239, 201, 20, 173, 133, 64, 29, 33, 71, 49, 117, 208, 115, 79, 169, 1, 126, 201, 229, 115, 35, 62, 102, 71, 16, 71, 220, 44, 95, 186, 223 };
|
||||
private static readonly byte[] IV = new byte[] { 255, 180, 99, 244, 147, 37, 175, 243, 193, 52, 167, 82, 143, 199, 242, 171 };
|
||||
|
||||
public static string EncryptString(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
byte[] buf = Encoding.UTF8.GetBytes(s);
|
||||
byte[] tmp = SecurityHelper.AesEncrypt(buf, KEY, IV);
|
||||
return Convert.ToBase64String(tmp);
|
||||
}
|
||||
|
||||
public static string DecryptString(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
byte[] tmp = Convert.FromBase64String(s);
|
||||
byte[] buf = SecurityHelper.AesDecrypt(tmp, KEY, IV);
|
||||
return Encoding.UTF8.GetString(buf);
|
||||
}
|
||||
|
||||
public virtual string GetIronSystemServiceAddress()
|
||||
{
|
||||
return ConfigurationManager.AppSettings["syssvcaddress"];
|
||||
}
|
||||
|
||||
public virtual IronSysServiceClient GetSystemServiceClient()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual CustomerProvider GetCustomerProvider()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
CustomerProvider ic = new CustomerProvider(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual LoginProvider GetLoginProvider()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
private string GetServerParam(string key)
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
StringKeyValue[] kvs = ic.GetServerParams();
|
||||
foreach (StringKeyValue kv in kvs)
|
||||
{
|
||||
if (string.Compare(kv.Key, key, true) == 0)
|
||||
{
|
||||
return kv.Value;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string Branch
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_Branch))
|
||||
{
|
||||
_Branch = GetServerParam("Branch");
|
||||
}
|
||||
return _Branch;
|
||||
}
|
||||
}
|
||||
|
||||
public string AboutUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_AboutUrl))
|
||||
{
|
||||
_AboutUrl = GetServerParam("AboutUrl");
|
||||
}
|
||||
return _AboutUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public string Copyrights
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_Copyrights))
|
||||
{
|
||||
_Copyrights = GetServerParam("Copyrights");
|
||||
}
|
||||
return _Copyrights;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string PageTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_PageTitle))
|
||||
{
|
||||
_PageTitle = GetServerParam("PageTitle");
|
||||
}
|
||||
return _PageTitle;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowTermofuse
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_ShowTermofuse))
|
||||
{
|
||||
_ShowTermofuse = GetServerParam("ShowTermofuse");
|
||||
}
|
||||
return string.Compare(_ShowTermofuse, "True", true) == 0 || string.Compare(_ShowTermofuse, "Yes", true) == 0 || string.Compare(_ShowTermofuse, "1", true) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetLoginSessionID(HttpRequest request)
|
||||
{
|
||||
HttpCookie cookie = request.Cookies[LOGINSESSION_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return DecryptString(cookie.Value);
|
||||
}
|
||||
|
||||
public LoginSession GetCurrentLoginSession()
|
||||
{
|
||||
string sessionid = GetLoginSessionID(Request);
|
||||
if (string.IsNullOrWhiteSpace(sessionid))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
return ic.GetLoginSession(sessionid);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void RedirectToLoginPage()
|
||||
{
|
||||
Response.Redirect(LoginPageUrl);
|
||||
}
|
||||
|
||||
protected string LoginPageUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
return ic.GetPortalLoginUrl();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当用户登录成功后,跳转到用户的默认主界面, 也即是各公司的主界面
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
protected void RedirectToUsersDefaultEntryPage(UserInfo user)
|
||||
{
|
||||
Response.Redirect(GetUserDefaultEntryPageUrl(user), true);
|
||||
}
|
||||
|
||||
protected string GetUserDefaultEntryPageUrl(UserInfo user)
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
return ic.GetCompanyPortalEntryUrl(user.CompanyID);
|
||||
}
|
||||
|
||||
protected void ClearLoginSessionCookie()
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(LOGINSESSION_COOKIENAME);
|
||||
cookie.Value = string.Empty;
|
||||
cookie.Expires = DateTime.Now.AddDays(-3);
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected void SetLoginSessionCookie(string sessionid)
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(LOGINSESSION_COOKIENAME);
|
||||
cookie.Value = EncryptString(sessionid);
|
||||
|
||||
string path = ConfigurationManager.AppSettings["sessioncookiepath"];
|
||||
if (!string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
cookie.Path = path;
|
||||
}
|
||||
string domain = ConfigurationManager.AppSettings["sessioncookiedomain"];
|
||||
if (!string.IsNullOrWhiteSpace(domain))
|
||||
{
|
||||
cookie.Domain = domain;
|
||||
}
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected void SetClientTimeOffset(int offset)
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(CLIENT_TIMEOFFSET_COOKIENAME);
|
||||
cookie.Value = offset.ToString();
|
||||
cookie.Expires = DateTime.Now.AddYears(1);
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected int GetClientTimeOffset()
|
||||
{
|
||||
HttpCookie cookie = Request.Cookies[CLIENT_TIMEOFFSET_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
int n = 0;
|
||||
if (int.TryParse(cookie.Value, out n))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime UtcTimeToClientTime(DateTime dt, int clienttimeoffset)
|
||||
{
|
||||
return dt.AddMinutes(-1 * clienttimeoffset);
|
||||
}
|
||||
|
||||
public static Int64 GetSiteFileDateTime(string url)
|
||||
{
|
||||
string fn = HttpContext.Current.Server.MapPath(url);
|
||||
if (System.IO.File.Exists(fn))
|
||||
{
|
||||
try
|
||||
{
|
||||
return System.IO.File.GetLastWriteTimeUtc(fn).Ticks;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于构造js/css或图片文件的url,在其最后加上版本标识,解决浏览器缓存问题
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetFileUrlWithVersion(string url)
|
||||
{
|
||||
string fn = HttpContext.Current.Server.MapPath(url);
|
||||
if (System.IO.File.Exists(fn))
|
||||
{
|
||||
try
|
||||
{
|
||||
Int64 n = System.IO.File.GetLastWriteTimeUtc(fn).Ticks;
|
||||
return url + "?sn=" + n.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadTextFromStream(System.IO.Stream stream)
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetUserHostAddress(HttpRequest request)
|
||||
{
|
||||
const string CLIENT_IP = "client-ip";
|
||||
if (request == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string rst = request.Headers[CLIENT_IP];
|
||||
if (string.IsNullOrWhiteSpace(rst))
|
||||
{
|
||||
rst = request.UserHostAddress;
|
||||
}
|
||||
if (rst == null)
|
||||
{
|
||||
rst = string.Empty;
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
|
||||
protected string UserHostAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetUserHostAddress(Request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
151
IronIntelContractor/Site/IronIntelHttpHandlerBase.cs
Normal file
151
IronIntelContractor/Site/IronIntelHttpHandlerBase.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using Foresight.Security;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Users;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.Site
|
||||
{
|
||||
public class IronIntelHttpHandlerBase : IDisposable
|
||||
{
|
||||
public static string LocalHostName
|
||||
{
|
||||
get { return IronIntelBasePage.LocalHostName; }
|
||||
}
|
||||
|
||||
public HttpContext Context { get; private set; }
|
||||
protected LoginSession LoginSession { get; private set; }
|
||||
|
||||
protected int ClientTimeOffset { get; private set; }
|
||||
|
||||
public IronIntelHttpHandlerBase(HttpContext context)
|
||||
{
|
||||
Context = context;
|
||||
try
|
||||
{
|
||||
LoginSession = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
LoginSession = null;
|
||||
}
|
||||
ClientTimeOffset = GetClientTimeOffset();
|
||||
}
|
||||
|
||||
public virtual string GetIronSystemServiceAddress()
|
||||
{
|
||||
return ConfigurationManager.AppSettings["syssvcaddress"];
|
||||
}
|
||||
|
||||
public virtual IronSysServiceClient GetSystemServiceClient()
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
if (LoginSession != null)
|
||||
{
|
||||
ic.AppName = LoginSession.AppName;
|
||||
ic.LoginSessionID = LoginSession.SessionID;
|
||||
ic.CurrentUserIID = LoginSession.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual CustomerProvider GetCustomerProvider()
|
||||
{
|
||||
CustomerProvider ic = new CustomerProvider(GetIronSystemServiceAddress());
|
||||
if (LoginSession != null)
|
||||
{
|
||||
ic.AppName = LoginSession.AppName;
|
||||
ic.LoginSessionID = LoginSession.SessionID;
|
||||
ic.CurrentUserIID = LoginSession.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public LoginSession GetCurrentLoginSession()
|
||||
{
|
||||
HttpCookie cookie = Context.Request.Cookies[IronIntelBasePage.LOGINSESSION_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string sessionid = IronIntelBasePage.DecryptString(cookie.Value);
|
||||
try
|
||||
{
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
return ic.GetLoginSession(sessionid);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetClientTimeOffset()
|
||||
{
|
||||
HttpCookie cookie = Context.Request.Cookies[IronIntelBasePage.CLIENT_TIMEOFFSET_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
int n = 0;
|
||||
if (int.TryParse(cookie.Value, out n))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadTextFromStream(System.IO.Stream stream)
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
protected void Dispose(bool disposed)
|
||||
{
|
||||
Context = null;
|
||||
LoginSession = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Dispose(true);
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string UserHostAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return IronIntelBasePage.GetUserHostAddress(Context.Request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user