using System;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Reflection;
using System.Linq;
using System.Text;
using System.Net;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Threading;
using System.Data.SqlClient;
using Foresight.Security;
using Foresight.Data;
using IronIntel.Services;
using IronIntel.Services.Business.Admin;
using IronIntel.Contractor.Users;
using IronIntel.Services.Contractor.Machine;
using IronIntel.Services.Users;
using Foresight.Fleet.Services.Asset;
using Foresight.Fleet.Services.Attachment;
using Foresight.ServiceModel;
using Foresight.Fleet.Services.FITracker;
using Foresight.Fleet.Services.AssetHealth;
using Foresight.Fleet.Services.User;
using Foresight.Fleet.Services.Device;
using Foresight.Fleet.Services.JobSite;
using Foresight.Fleet.Services;
using Foresight.Fleet.Services.OTRConfig;
using Foresight.Fleet.Services.Customer;
using Foresight.Fleet.Services.MapView;
using Foresight.Fleet.Services.SystemOption;
using Foresight.Fleet.Services.Inspection;

namespace IronIntel.Contractor
{
    public static class SystemParams
    {
        private static Dictionary<string, string> _CompanyDbString = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

        private static ConcurrentDictionary<string, string> _Params = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);

        private static readonly byte[] KEY = new byte[] { 134, 109, 104, 92, 86, 241, 196, 160, 203, 10, 175, 253, 14, 48, 138, 42, 131, 123, 238, 226, 146, 45, 125, 185, 217, 119, 183, 64, 16, 113, 37, 62 };
        private static readonly byte[] IV = new byte[] { 178, 198, 121, 147, 158, 41, 192, 222, 198, 61, 142, 50, 24, 111, 158, 169 };

        private static string _ContractorVersion = "";
        private static string _FICVersion = "";

        private static string EncryptString(string s)
        {
            byte[] buf = Encoding.UTF8.GetBytes(s);
            byte[] tmp = SecurityHelper.AesEncrypt(buf, KEY, IV);
            return Convert.ToBase64String(tmp);
        }

        private static string GetAssemblyFileVersion()
        {
            try
            {
                string filename = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
                string fn = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\" + filename);
                FileVersionInfo fv = FileVersionInfo.GetVersionInfo(fn);
                return fv.FileVersion.ToString();
            }
            catch
            {
                return string.Empty;
            }
        }

        public static void CreateDbObjects()
        {
            try
            {
                FI.FIC.Database.FIC.FICDbInitializer ficdb = new FI.FIC.Database.FIC.FICDbInitializer(FICDbConnectionString);
                ficdb.RunIronIntel();
            }
            catch
            { }
        }

        public static string AppVersion
        {
            get
            {
                return GetVersion();
            }
        }

        internal static string GetCompanyDbString(string companyid)
        {
            string rst = null;
            if (_CompanyDbString.TryGetValue(companyid, out rst))
            {
                return rst;
            }
            try
            {
                CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
                string dbstr = cust.MasterDataDbString;
                if (!string.IsNullOrWhiteSpace(dbstr))
                {
                    _CompanyDbString[companyid] = dbstr;
                    return dbstr;
                }
            }
            catch
            {
                return string.Empty;
            }
            return string.Empty;
        }

        internal static FISqlConnection GetCompanyDbConnection(string companyid)
        {
            if (string.IsNullOrWhiteSpace(companyid) || string.Compare(companyid, CompanyID, true) == 0)
            {
                return GetDbInstance();
            }
            string s = GetCompanyDbString(companyid);
            if (string.IsNullOrWhiteSpace(s))
            {
                return null;
            }
            else
            {
                return new FISqlConnection(s);
            }
        }

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

        private static string _HostName = null;

        public static string HostName
        {
            get
            {
                if (_HostName == null)
                {
                    try
                    {
                        _HostName = Dns.GetHostName();
                    }
                    catch
                    {
                        _HostName = string.Empty;
                    }
                }
                return _HostName;
            }
        }

        private static string _DataDbConnectionString = null;

        /// <summary>
        /// 获取主数据库连接字符串
        /// </summary>
        /// <returns>获取主数据库连接字符串</returns>
        public static string DataDbConnectionString
        {
            get
            {
                if (_DataDbConnectionString == null)
                {
                    SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(ConfigurationManager.AppSettings["DbConntionString"]);
                    try
                    {
                        sb.Password = DecryptString(sb.Password);
                    }
                    catch
                    {
                    }
                    _DataDbConnectionString = sb.ToString();
                }
                return _DataDbConnectionString;
            }
        }

        private static string _ficdbstr = null;

        public static string FICDbConnectionString
        {
            get
            {
                if (_ficdbstr == null)
                {
                    string db = GetStringParam("FICSysDBName");
                    if (string.IsNullOrWhiteSpace(db))
                    {
                        _ficdbstr = string.Empty;
                    }
                    else
                    {
                        SqlConnectionStringBuilder sc = new SqlConnectionStringBuilder(DataDbConnectionString);
                        sc.InitialCatalog = db;
                        _ficdbstr = sc.ToString();
                    }
                }
                return _ficdbstr;
            }
        }

        public static FISqlConnection GetDbInstance()
        {
            return new FISqlConnection(DataDbConnectionString);
        }

        public static FISqlConnection FICDBInstance
        {
            get
            {
                return new FISqlConnection(FICDbConnectionString);
            }
        }

        public static void SetStringParam(string paramname, string value)
        {
            const string SQL = "if exists(select 1 from SYSPARAMS where PARAMNAME={0}) update SYSPARAMS set PARAMVALUE={1} where PARAMNAME={0}"
              + " else insert into SYSPARAMS(PARAMNAME,PARAMVALUE) values({0},{1})";
            FIDbAccess db = GetDbInstance();
            db.ExecSQL(SQL, paramname, value);
            _Params[paramname] = value;
        }

        /// <summary>
        /// 根据参数名称获取参数值
        /// </summary>
        /// <param name="paramname">参数名称</param>
        /// <returns>参数值</returns>
        public static string GetStringParam(string paramname, bool useCache = true, FISqlConnection db = null)
        {
            const string SQL = "select PARAMVALUE from SYSPARAMS where PARAMNAME={0}";

            string v = null;
            if (useCache && _Params.TryGetValue(paramname, out v))
            {
                return v;
            }
            if (db == null)
                db = GetDbInstance();
            object obj = db.GetRC1BySQL(SQL, paramname);
            v = FIDbAccess.GetFieldString(obj, string.Empty);
            _Params[paramname] = v;
            return v;
        }

        public static string GetFICStringParam(string paramcode)
        {
            const string SQL = "select PARAMVALUE from SystemParams where PARAMCODE={0}";
            if (string.IsNullOrWhiteSpace(FICDbConnectionString))
            {
                return string.Empty;
            }

            object obj = FICDBInstance.GetRC1BySQL(SQL, paramcode);
            return FIDbAccess.GetFieldString(obj, string.Empty);
        }

        public static void SetFICStringParameter(string paramname, string value)
        {
            const string SQL = "if exists(select 1 from SYSTEMPARAMS where PARAMCODE={0}) "
                              + " update SYSTEMPARAMS set PARAMVALUE={1} where PARAMCODE={0} "
                              + "   else insert into SYSTEMPARAMS(IID,PARAMTYPE,PARAMCODE,PARAMNAME,PARAMVALUE,PARAMMEMO) values(newid(),1,{0},{0},{1},{0}) ";

            FICDBInstance.ExecSQL(SQL, paramname, value);
        }

        private static Services.Customers.CustomerInfo _Company = null;

        public static string CompanyID
        {
            get
            {
                return GetStringParam("CompanyID");
            }
        }

        private static CustomerDetail _Customer = null;
        private static object _syccust = new object();

        public static CustomerDetail CustomerDetail
        {
            get
            {
                if (_Customer == null)
                {
                    lock (_syccust)
                    {
                        if (_Customer == null)
                        {
                            _Customer = FleetServiceClientHelper.CreateClient<CustomerProvider>().GetCustomerDetail(CompanyID);
                        }
                    }
                }
                return _Customer;
            }
        }



        public static T GetServiceClient<T>() where T : Foresight.ServiceModel.ServiceClientBase, new()
        {
            T rst = new T();
            rst.ServiceAddress = SystemServiceAddresses[0];
            rst.AppName = APPNAME;
            return rst;
        }

        public static T GetServiceClient<T>(string sessionid) where T : Foresight.ServiceModel.ServiceClientBase, new()
        {
            T rst = new T();
            rst.ServiceAddress = SystemServiceAddresses[0];
            rst.AppName = APPNAME;
            rst.LoginSessionID = sessionid;
            return rst;
        }

        public static Services.LicenseInfo GetLicense()
        {
            var ic = GetServiceClient<Services.Customers.CustomerProvider>();
            return ic.GetLicenseInfo(CompanyID);
        }

        public static bool HasLicense(string itemName)
        {
            bool result = false;
            var license = SystemParams.GetLicense();
            if (license != null && license.Items.Count > 0)
            {
                var item = license.Items.FirstOrDefault(m => m.Key.Equals(itemName, StringComparison.OrdinalIgnoreCase));
                if (item != null && Helper.IsTrue(item.Value))
                    result = true;
            }
            return result;
        }

        public static string GetVersion()
        {
            if (string.IsNullOrEmpty(_ContractorVersion))
            {
                //IronSysServiceClient ic = GetIronSystemServiceClient();
                //_ContractorVersion = ic.GetServerVersion();
                _ContractorVersion = GetAssemblyFileVersion();
            }
            return _ContractorVersion;
        }

        public static string GetFICVersion()
        {
            if (string.IsNullOrEmpty(_FICVersion))
            {
                string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\FICBLC.dll");
                if (File.Exists(path))
                {
                    FileVersionInfo fv = FileVersionInfo.GetVersionInfo(path);
                    _FICVersion = fv.FileVersion.ToString();
                }
            }
            return _FICVersion;
        }

        private static string[] _IronIntelSystemServiceAddresses = null;

        public static string[] SystemServiceAddresses
        {
            get
            {
                if (_IronIntelSystemServiceAddresses == null)
                {
                    string s = GetStringParam("MasterServiceAddress");
                    _IronIntelSystemServiceAddresses = s.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                }
                return _IronIntelSystemServiceAddresses;
            }
        }

        private static string _ReportDbString = string.Empty;

        public static string GetIronIntelReportDataDbString(string companyid = null)
        {
            if (string.IsNullOrEmpty(companyid))
                companyid = CompanyID;
            if (!string.IsNullOrWhiteSpace(_ReportDbString))
            {
                return _ReportDbString;
            }
            string svcaddress = GetStringParam("IronIntelSystemServiceAddress");
            if (string.IsNullOrWhiteSpace(svcaddress))
            {
                return string.Empty;
            }
            CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
            string dbstring = cust.ReportDataDbString;
            if (!string.IsNullOrEmpty(dbstring))
            {
                _ReportDbString = dbstring;
                return _ReportDbString;
            }
            return string.Empty;
        }

        static Dictionary<string, string> _CompanyDBStrings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
        public static string GetDbStringByCompany(string companyid)
        {
            return GetCustomerDbString(companyid, "MASTER_DATA_DB");
        }

        public static string GetCustomerDbString(string companyid, string dbtype)
        {
            string key = companyid + dbtype;
            if (_CompanyDBStrings.ContainsKey(key))
                return _CompanyDBStrings[key];

            CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
            string dbstring = cust.MasterDataDbString;
            _CompanyDBStrings[key] = dbstring;
            return dbstring;
        }

        public static Services.Customers.CustomerInfo GetCompanyInfo()
        {
            if (_Company == null)
            {
                var ic = GetCustomerProvider();
                _Company = ic.GetCustomerByID(CompanyID);
            }
            return _Company;
        }
        public static MainStyle GetMainStyle()
        {
            IronSysServiceClient ic = GetIronSystemServiceClient();
            return ic.GetMainStyle(CompanyID);
        }

        public static bool IsDealer
        {
            get
            {
                return CustomerDetail.IsDealer;
            }
        }

        public static Services.Customers.CustomerInfo[] GetContractors()
        {
            if (IsDealer)
            {
                var cust = GetCustomerProvider();
                return cust.GetContractors(CompanyID);
            }
            else
            {
                return new Services.Customers.CustomerInfo[0];
            }
        }

        public static byte[] GetCompanyLOGO(string companyid)
        {
            return FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerLOGO(companyid);
        }

        public static byte[] GetForesightLOGOInMainStyle()
        {
            IronSysServiceClient ic = GetIronSystemServiceClient();
            return ic.GetLogoInMainStyle(CompanyID, 1);
        }

        public static byte[] GetCompanyLocationLOGO(string companyid)
        {
            byte[] buffer = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetDefaultLocationLOGO(companyid);
            if ((buffer == null) || (buffer.Length == 0))
            {
                return GetCompanyLOGO(companyid);
            }
            else
            {
                return buffer;
            }
        }

        public static Services.Customers.CustomerInfo GetFirstDealerInfo()
        {
            if (IsDealer)
            {
                return GetCompanyInfo();
            }
            else
            {
                var cust = GetCustomerProvider();
                var cmps = cust.GetDealers(CompanyID);
                if ((cmps != null) && (cmps.Length > 0))
                {
                    return cmps[0];
                }
            }
            return null;
        }

        public static bool HasLOGO(string companyid)
        {
            IronSysServiceClient ic = GetIronSystemServiceClient();
            return ic.HasLOGO(companyid);
        }
        public static void ExecSQL(FIDbAccess db, int retrytimes, string sql, params object[] values)
        {
            int n = 0;
            while (true)
            {
                n++;
                try
                {
                    db.ExecSQL(sql, values);
                    return;
                }
                catch
                {
                    if (n >= retrytimes)
                    {
                        throw;
                    }
                }
                System.Threading.Thread.Sleep(100);
            }
        }

        public static IronSysServiceClient GetIronSystemServiceClient()
        {
            IronSysServiceClient ic = GetServiceClient<IronSysServiceClient>();
            return ic;
        }

        public static MachineServiceClient2 GetMachineServiceClient()
        {
            MachineServiceClient2 ic = GetServiceClient<MachineServiceClient2>();
            return ic;
        }

        public static MapAlertLayerClient GetMapAlertLayerClient()
        {
            MapAlertLayerClient ic = GetServiceClient<MapAlertLayerClient>();
            return ic;
        }

        public static Services.Customers.CustomerProvider GetCustomerProvider()
        {
            var ic = GetServiceClient<Services.Customers.CustomerProvider>();
            return ic;
        }

        /**Fleet Service***/
        public static string[] FleetAssetServiceAddresses
        {
            get
            {
                string addresses = ConfigurationManager.AppSettings["FleetAssetServiceAddress"];
                if (!string.IsNullOrWhiteSpace(addresses))
                    return addresses.Split(';');
                return new string[0];
            }
        }

        //public static T GetFleetServiceClient<T>() where T : Foresight.Fleet.Services.RemoteClientBase, new()
        //{
        //    T rst = (T)System.Activator.CreateInstance(typeof(T), new object[] { FleetAssetServiceAddresses });
        //    return rst;
        //}

        //public static T GetFleetServiceClient<T>(string sessionid, string workingCompanyID) where T : Foresight.Fleet.Services.RemoteClientBase, new()
        //{
        //    T rst = (T)System.Activator.CreateInstance(typeof(T), new object[] { FleetAssetServiceAddresses });
        //    rst.SessionID = sessionid;
        //    rst.WorkingCompanyID = sessionid;
        //    return rst;
        //}


        private static string _MachineTypeMapViewIconUrl = string.Empty;
        public static string MachineTypeMapViewIconUrl
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_MachineTypeMapViewIconUrl))
                {
                    MachineServiceClient2 mc2 = SystemParams.GetMachineServiceClient();
                    _MachineTypeMapViewIconUrl = mc2.GetMachineTypeIconUrl();
                }
                return _MachineTypeMapViewIconUrl;
            }
        }

        public static CustUIStyle GetUIStyle(string useriid)
        {
            //var up = UserParams.GetUserParams(useriid);
            string sid = UserParams.GetStringParameter(useriid, UserParams._SystemStyleID);
            int styleID = -1;
            if (string.IsNullOrEmpty(sid) || !int.TryParse(sid, out styleID))
                styleID = -1;
            var sc = GetIronSystemServiceClient();
            CustUIStyle style = sc.GetDefaultUIStyle(SystemParams.CompanyID, styleID);
            return style;
        }

        //public static int GetTimeAdjust()
        //{
        //    var sc = GetIronSystemServiceClient();
        //    return sc.GetCompanyTimeAdjust(CompanyID);
        //}

        public static double GetHoursOffset()
        {
            //double offsetMinutes = 0;
            //string offset = GetStringParam("CustomerTimeZoneOffset");
            //if (!string.IsNullOrEmpty(offset) && double.TryParse(offset, out offsetMinutes))
            //{
            //    return offsetMinutes / 60;
            //}
            //else
            //{
            string tzName = GetStringParam("CustomerTimeZone");
            if (!string.IsNullOrEmpty(tzName))
            {
                var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName.Trim());
                if (tz != null)
                {
                    TimeSpan offset = tz.GetUtcOffset(DateTime.UtcNow);
                    return offset.Hours + (double)offset.Minutes / 60;
                }
            }
            //}

            var sc = GetIronSystemServiceClient();
            double offsetHours = sc.GetCompanyTimeAdjust(CompanyID);
            return offsetHours;
        }

        public static TimeZoneInfo GetTimeZoneInfo(string custid, FISqlConnection db = null)
        {

            string tzName = GetStringParam("CustomerTimeZone", true, db);
            if (string.IsNullOrEmpty(tzName))
                tzName = FleetServiceClientHelper.CreateClient<CustomerProvider>(custid, string.Empty).GetCustomerTimeZoneName(custid);
            var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName.Trim());
            return tz;
        }

        public static StringKeyValue[] GetTimeZones()
        {
            var tzs = TimeZoneInfo.GetSystemTimeZones();
            List<StringKeyValue> result = new List<StringKeyValue>();

            foreach (TimeZoneInfo tz in tzs)
            {
                StringKeyValue skv = new StringKeyValue();
                skv.Key = tz.Id;
                TimeSpan offset = tz.GetUtcOffset(DateTime.UtcNow);
                skv.Value = string.Format("{0}{1}:{2}", offset.Hours >= 0 ? "+" : "", offset.Hours.ToString("00"), Math.Abs(offset.Minutes).ToString("00"));

                skv.Tag1 = offset.TotalMinutes.ToString();
                result.Add(skv);
            }
            return result.OrderBy(tz => double.Parse(tz.Tag1)).ThenBy(tz => tz.Key).ToArray();
            //const string SQL = "select name,current_utc_offset as offset from sys.time_zone_info";

            //FISqlConnection db = GetDbInstance();
            //DataTable tb = db.GetDataTableBySQL(SQL);
            //if (tb.Rows.Count > 0)
            //{
            //    foreach (DataRow dr in tb.Rows)
            //    {
            //        StringKeyValue skv = new StringKeyValue();
            //        skv.Key = FIDbAccess.GetFieldString(dr["name"], string.Empty);
            //        skv.Value = FIDbAccess.GetFieldString(dr["offset"], string.Empty);

            //        string offsetstr = skv.Value;
            //        string symbol = offsetstr.Substring(0, 1);
            //        string offset = offsetstr.Remove(0, 1);
            //        string[] strs = offset.Split(':');

            //        skv.Tag1 = (int.Parse(symbol + strs[0]) * 60 + int.Parse(symbol + strs[1])).ToString();
            //        result.Add(skv);
            //    }
            //}
            //return result.ToArray();
        }


        public const string APPNAME = "IronIntelCustomerSite";
        private const string WORKING_COMPANY_HEADER = "WorkingCompanyID";

        public static void SendMail(System.Net.Mail.MailMessage msg)
        {
            SendMail(APPNAME, msg);
        }

        public static void SendMail(string appname, System.Net.Mail.MailMessage msg)
        {
            FleetServiceClientHelper.CreateClient<SystemUtil>().SendMail(CompanyID, appname, msg);
        }

        public static void WriteLog(string logType, string source, string message, string detail)
        {
            try
            {
                FleetServiceClientHelper.CreateClient<SystemUtil>().WriteLog(CompanyID, APPNAME, logType, source, message, detail, string.Empty);
            }
            catch
            {
            }
        }

        public static void WriteLog(string logType, string category, string source, string message, string detail)
        {
            try
            {
                FleetServiceClientHelper.CreateClient<SystemUtil>().WriteLog(CompanyID, category, logType, source, message, detail, string.Empty);
            }
            catch
            {
            }
        }

        public static void WriteRefreshLog(string useriid, string userhost, string objname, string refreshtype)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback((e) => { _WriteRefreshLog(useriid, userhost, objname, refreshtype); }), null);
        }


        private static void _WriteRefreshLog(string useriid, string userhost, string objname, string refreshtype)
        {
            const string SQL = "insert into REFRESHLOG(USERIID,HOSTADDRESS,OBJNAME,REFRESHTYPE,REFRESHTIME_UTC) values({0},{1},{2},{3},GETUTCDATE())";

            try
            {
                FIDbAccess db = GetDbInstance();
                db.ExecSQL(SQL, useriid, userhost, objname, refreshtype);
            }
            catch
            { }
        }

        public static string GetResourceLock(string resourceid, int locksecond)
        {
            try
            {
                return FleetServiceClientHelper.CreateClient<SystemUtil>().GetResourceLock(CompanyID, resourceid, locksecond);
            }
            catch
            {
                return "";
            }
        }

        public static void ReleaseResourceLock(string lockid)
        {
            try
            {
                FleetServiceClientHelper.CreateClient<SystemUtil>().ReleaseResourceLock(lockid);
            }
            catch
            { }
        }

        public static string ConnectorToken
        {
            get
            {
                return GetFICStringParam("ConnectorToken");
            }
        }

        public static string ConnectorServer
        {
            get
            {
                return GetFICStringParam("ConnectorServer");
            }
        }

        public static string LdapAgentID
        {
            get
            {
                return GetFICStringParam("LdapAgentID");
            }
        }

        public static string LdapAgentToken
        {
            get
            {
                return GetFICStringParam("LdapAgentToken");
            }
        }
        public static bool CanUseConnectorLDAP
        {
            get
            {
                return GetFICStringParam("CanUseConnectorLDAP") == "1";
            }
        }
        public static bool RedisEnabled
        {
            get
            {
                return string.Equals(GetFICStringParam("RedisEnabled"), "Yes", StringComparison.OrdinalIgnoreCase);
            }
        }

        public static string RedisToken
        {
            get
            {
                return GetFICStringParam("RedisToken");
            }
        }

        public static Dictionary<string, string> GetAdditionalParameter()
        {
            var dict = new Dictionary<string, string>
            {
                { "ConnectorToken", ConnectorToken },
                { "ConnectorServer", ConnectorServer },
                { "LdapAgentID", LdapAgentID },
                { "LdapAgentToken", LdapAgentToken },
                { "CanUseConnectorLDAP", CanUseConnectorLDAP ? "1" : "0" }
            };

            return dict;
        }
    }
}
