Пример #1
0
 public static void StartSPServer(out SqlInt32 res)
 {
     res = 0;
     using (SqlConnection conn = new SqlConnection("context connection=true"))
     {
         try
         {
             lock (m_cs)
             {
                 if (Plugin == null)
                 {
                     if (!Directory.Exists(SQLConfig.WorkingDirectory))
                     {
                         Directory.CreateDirectory(SQLConfig.WorkingDirectory);
                     }
                     Directory.SetCurrentDirectory(SQLConfig.WorkingDirectory);
                     Plugin = new CSqlPlugin(SQLConfig.Param);
                 }
                 if (!ServerCoreLoader.IsRunning())
                 {
                     res += 10;
                     if (SQLConfig.StoreOrPfx != null && SQLConfig.SubjectOrPassword != null && SQLConfig.StoreOrPfx.Length > 0 && SQLConfig.SubjectOrPassword.Length > 0)
                     {
                         if (SQLConfig.StoreOrPfx.IndexOf(".pfx") == -1)
                         {
                             //load cert and private key from windows system cert store
                             Plugin.UseSSL(SQLConfig.StoreOrPfx /*"my"*/, SQLConfig.SubjectOrPassword, "");
                         }
                         else
                         {
                             Plugin.UseSSL(SQLConfig.StoreOrPfx, "", SQLConfig.SubjectOrPassword);
                         }
                     }
                     Plugin.Run(SQLConfig.Port, 16, !SQLConfig.NoV6);
                 }
             }
         }
         catch (Exception err)
         {
             LogError(conn, err.Message);
         }
         finally
         {
             if (ServerCoreLoader.IsRunning())
             {
                 AppDomain.CurrentDomain.DomainUnload += (sender, args) => {
                     ServerCoreLoader.StopSocketProServer();
                     Plugin = null;
                 };
                 res += 1;
             }
             conn.Close();
         }
     }
 }
Пример #2
0
    public static void StartSPServer(out SqlInt32 res)
    {
        res = 0;
        using (SqlConnection conn = new SqlConnection("context connection=true"))
        {
            try
            {
                lock (m_cs)
                {
                    UConfig config;
                    try
                    {
                        if (!Directory.Exists(UConfig.DEFAULT_WORKING_DIRECTORY))
                        {
                            Directory.CreateDirectory(UConfig.DEFAULT_WORKING_DIRECTORY);
                        }
                        Directory.SetCurrentDirectory(UConfig.DEFAULT_WORKING_DIRECTORY);
                    }
                    catch (Exception ex)
                    {
                        UConfig.LogMsg(ex.Message, "USqlStream::StartSPServer", 85); //line 85
                    }
                    finally { }

                    try
                    {
                        string json = System.IO.File.ReadAllText(UConfig.DEFAULT_WORKING_DIRECTORY + UConfig.STREAM_DB_CONFIG_FILE);
                        config = new UConfig(json);
                    }
                    catch (Exception ex)
                    {
                        UConfig.LogMsg(ex.Message, "USqlStream::StartSPServer", 96); //line 96
                        config = new UConfig();
                        UConfig.UpdateConfigFile(config);
                        UConfig.UpdateLog();
                    }
                    if (Plugin == null)
                    {
                        Plugin = new CSqlPlugin(config);
                    }
                    res = 1;
                    if (!ServerCoreLoader.IsRunning())
                    {
                        if (config.cert_root_store.Length > 0 && config.cert_subject_cn.Length > 0)
                        {
                            Plugin.UseSSL(config.cert_root_store, config.cert_subject_cn, "");
                        }
                        if (Plugin.Run(config.port, 16, !config.disable_ipv6))
                        {
                            res += 1;
                        }
                        else
                        {
                            res = 0;
                        }
                    }
                }
            }
            catch (Exception err)
            {
                UConfig.LogMsg(err.Message, "USqlStream::StartSPServer", 125); //line 125
                Plugin = null;
            }
            finally
            {
                if (res == 2 && ServerCoreLoader.IsRunning())
                {
                    AppDomain.CurrentDomain.DomainUnload += (sender, args) =>
                    {
                        ServerCoreLoader.StopSocketProServer();
                        Plugin = null;
                    };
                }
                conn.Close();
            }
        }
    }