Esempio n. 1
0
 /// <summary>
 /// Set socket pools configuration from a JSON text file
 /// </summary>
 /// <param name="midTier">True if calling from a middle tier; Otherwise, false</param>
 /// <param name="jsonConfig">A file path to a JSON configuration text file, which defaults to sp_config.json at current directory</param>
 /// <returns>An instance of CSpConfig</returns>
 public static CSpConfig SetConfig(bool midTier = false, string jsonConfig = null)
 {
     lock (m_cs) {
         if (m_sc != null)
         {
             return(m_sc);
         }
     }
     if (jsonConfig == null || jsonConfig.Length == 0)
     {
         jsonConfig = "sp_config.json";
     }
     using (StreamReader sr = File.OpenText(jsonConfig)) {
         string       json = sr.ReadToEnd();
         MemoryStream ms   = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json));
         DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(CSpConfig), new DataContractJsonSerializerSettings {
             UseSimpleDictionaryFormat = true
         });
         CSpConfig sc = ser.ReadObject(ms) as CSpConfig;
         sc.CheckErrors();
         lock (m_cs) {
             m_sc     = sc;
             m_Middle = midTier;
             return(m_sc);
         }
     }
 }