public static void StopSPServer(out SqlInt32 res) { res = 0; using (SqlConnection conn = new SqlConnection("context connection=true")) { try { conn.Open(); lock (m_cs) { if (Plugin != null) { if (ServerCoreLoader.IsRunning()) { ServerCoreLoader.SetOnIdle(null); Plugin.StopSocketProServer(); res += 1; } Plugin.Dispose(); Plugin = null; res += 1; } } } catch (Exception err) { UConfig.LogMsg(err.Message, "USqlStream::StopSPServer", 57); //line 57 } finally { conn.Close(); } } }
public static void StopSPServer(out SqlInt32 res) { res = 0; using (SqlConnection conn = new SqlConnection("context connection=true")) { try { conn.Open(); lock (m_cs) { if (Plugin != null) { if (ServerCoreLoader.IsRunning()) { ServerCoreLoader.SetOnIdle(null); Plugin.StopSocketProServer(); res += 10; } Plugin.Dispose(); Plugin = null; res += 1; } } } catch (Exception err) { LogError(conn, err.Message); } finally { conn.Close(); } } }
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(); } } }
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(); } } }
public static void PublishDMLEvent() { SqlTriggerContext tc = SqlContext.TriggerContext; if (!SqlContext.IsAvailable || tc == null) { return; } string errMsg = ""; using (SqlConnection conn = new SqlConnection("context connection=true")) { try { DataTable dt = null; List <object[]> rows = null; string[] v = null; lock (m_cs) { if (ServerCoreLoader.IsRunning()) { conn.Open(); v = GetUSqlServerKeys(conn); switch (tc.TriggerAction) { case TriggerAction.Update: rows = GetUpdateRows(conn, out dt); if (dt == null) { errMsg = "DELETED schema table not available"; } break; case TriggerAction.Delete: rows = GetRows(conn, true, out dt); if (dt == null) { errMsg = "DELETED schema table not available"; } break; case TriggerAction.Insert: rows = GetRows(conn, false, out dt); if (dt == null) { errMsg = "INSERTED schema table not available"; } break; default: errMsg = "Unknown DML event"; break; } } do { if (dt == null) { break; } if (ServerHost == null || ServerHost.Length == 0) { ServerHost = GetServerName(conn); } if (ServerHost == null || ServerHost.Length == 0) { errMsg = "Server not available"; break; } string tblName = GuessTablePath(conn, dt); if (tblName == null || tblName.Length == 0) { errMsg = "Table name not available"; break; } lock (m_cs) { foreach (object[] msg in rows) { msg[1] = ServerHost; msg[2] = v[0]; msg[3] = v[1]; msg[4] = tblName; if (!Publish(msg, DB_CONSTS.STREAMING_SQL_CHAT_GROUP_ID)) { errMsg = "Message publishing failed"; break; } } } } while (false); } } catch (Exception err) { errMsg = err.Message; } finally { conn.Close(); if (errMsg.Length > 0) { UConfig.LogMsg(errMsg, "USqkStream::PublishDMEvent", 470); //line 470 } } } }