Esempio n. 1
0
 private void Internal_DataContextConfiguration(LightDataOptions optionList)
 {
     if (optionList != null && optionList.Connections != null && optionList.Connections.Length > 0)
     {
         foreach (var connection in optionList.Connections)
         {
             var setting = new ConnectionSetting()
             {
                 Name             = connection.Name,
                 ConnectionString = connection.ConnectionString,
                 ProviderName     = connection.ProviderName
             };
             var configParam = new ConfigParamSet();
             if (connection.ConfigParams != null && connection.ConfigParams.Count > 0)
             {
                 foreach (var param in connection.ConfigParams)
                 {
                     configParam.SetParamValue(param.Key, param.Value);
                 }
             }
             setting.ConfigParam = configParam;
             var options = DataContextOptions.CreateOptions(setting);
             if (options != null)
             {
                 if (defaultOptions == null)
                 {
                     defaultOptions = options;
                 }
                 optionsDict.Add(setting.Name, options);
             }
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Light.Data.DataContextConfiguration"/> class.
        /// </summary>
        /// <param name="configFilePath">Config file path.</param>
        internal DataContextConfiguration(string configFilePath)
        {
            FileInfo fileInfo;

            if (useEntryAssemblyDirectory)
            {
                fileInfo = FileHelper.GetFileInfo(configFilePath, out bool absolute);
                if (!fileInfo.Exists && !absolute)
                {
                    fileInfo = new FileInfo(configFilePath);
                }
            }
            else
            {
                fileInfo = new FileInfo(configFilePath);
            }
            if (fileInfo.Exists)
            {
                using (StreamReader reader = fileInfo.OpenText()) {
                    string  content = reader.ReadToEnd();
                    JObject dom     = JObject.Parse(content);
                    var     section = dom.GetValue("lightData");
                    if (section != null)
                    {
                        LightDataOptions options = section.ToObject <LightDataOptions>();
                        Internal_DataContextConfiguration(options);
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("config file not found", configFilePath);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Light.Data.DataContextConfiguration"/> class.
 /// </summary>
 /// <param name="optionList">Option list.</param>
 internal DataContextConfiguration(LightDataOptions optionList)
 {
     Internal_DataContextConfiguration(optionList);
 }