void BuilderForType(Type type) { if (type == null) { return; } if (!type.IsClass) { return; } if (type.IsAbstract) { return; } if (!type.IsSubclassOf(typeof(TBase))) { return; } try { var o = Activator.CreateInstance(typeof(APIProcesserManager <> .APIProcesserCreator <>).MakeGenericType(typeof(TBase), type)) as IAPIProcesserCreator; if (o == null) { return; } _list[o.HandleName] = o; } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); } }
/// <summary> /// /// </summary> public void Restart() { if (!IsRunning) { StartProcess(); } else { try { var ct = currentThread; try { ct?.Abort(this); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } } }
private void AcceptedCallback(object sender, AcceptedEventArgs e) { try { var session = new SocketAgentClientSession(e.AcceptSocket, _config, this); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } }
void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args) { try { BuilderForAssemblie(args.LoadedAssembly); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected virtual void Listen_Accepted(object sender, AcceptedEventArgs e) { try { var webSocketSession = new WebSocketSession(e.AcceptSocket, this); } catch (System.Exception ex) { e.AcceptSocket?.Dispose(); SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } }
//提供给线程池调用的方法 void RunHandleProcess() { try { TryRunHandleProcess(); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } finally { Interlocked.CompareExchange(ref _isRunning, 0, 1); } }
private void do_ProcessSafeConnect(Socket socket) { try { if (socket == null) { return; } var ssl_socket = new SslAppectSocket(socket); ssl_socket.BeginAuthenticateAsServer(serverCertificate, this.SafeConnectAuthenticateCallback, ssl_socket); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } }
/// <summary> /// /// </summary> /// <param name="path"></param> /// <param name="data"></param> /// <param name="call"></param> public static void WriteAllBytesAsync(string path, byte[] data, Action <System.Exception> call) { try { CheckAndCreateDir(path); //异步写入文件 var filestream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); filestream.SetLength(0); filestream.BeginWrite(data, 0, data.Length, (iar) => { if (!iar.IsCompleted) { return; } System.Exception run_ex = null; try { filestream.EndWrite(iar); filestream.Flush(); } catch (System.Exception ex) { run_ex = ex; } finally { filestream?.Dispose(); } try { call(run_ex); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); } }, null); } catch (System.Exception ex) { call(ex); } }
//提供给线程池调用的方法 void RunHandleProcess() { try { TryRunHandleProcess(); } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(this, ex); } finally { _semaphore.Release(); if (!mq.IsEmpty) { StartProcess(); } } }
/// <summary> /// 执行存储过程,返回ReturnValue /// </summary> /// <param name="storedProcName"></param> /// <param name="parameters"></param> /// <param name="dataSet"></param> /// <returns></returns> public object RunProcedure(string storedProcName, IDataParameter[] parameters, out DataSet dataSet) { int tryCount = 1; while (true) { IDbDataAdapter sqlDA = DBEntityProvide.GetNewDbDataAdapter(); try { using (var connection = DBEntityProvide.GetNewDbConnection(connectionString)) { dataSet = new DataSet(); if (connection.State == ConnectionState.Closed) { connection.Open(); } sqlDA.SelectCommand = DBEntityProvide.BuildInitCommand(connection, storedProcName, parameters); sqlDA.Fill(dataSet); return(DBEntityProvide.GetReturnValue(sqlDA.SelectCommand)); } } catch (System.Exception ex) { if (--tryCount > 0) { continue; } var tex = new Exception("调用存储过程“" + storedProcName + "”出现异常!", ex); SystemErrorProvide.OnSystemErrorHandleEvent(null, tex); throw tex; } finally { if (sqlDA.SelectCommand != null && sqlDA.SelectCommand.Parameters.Count >= 0) { sqlDA.SelectCommand.Parameters.Clear(); } } } }
void BuilderForAssemblie(Assembly assem) { if (assem == null) { return; } //获取这个程序集的所有类型信息 try { var types = assem.GetTypes(); foreach (var type in types) { BuilderForType(type); } } catch (System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); } }
/// <summary> /// 计时 Tick方法,由基础计时服务程序调用 /// </summary> internal void Tick(DateTime now) { if (IsRuning) { if (Interlocked.CompareExchange(ref running, 1, 0) != 0) { return; } while (TimeEnd(now)) { this.Next(); try { TimerTick(); } catch (System.Exception ex) { this.Stop(); SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); } } Interlocked.CompareExchange(ref running, 0, 1); } }
/// <summary> /// /// </summary> /// <param name="ex"></param> internal static void OnErrorEvent(System.Exception ex) { SystemErrorProvide.OnSystemErrorHandleEvent(null, ex); }
private void OnRunProcedureAsyncExpection(string storedProcName, System.Exception ex) { var tex = new System.Exception("调用存储过程“" + storedProcName + "”出现异常!", ex); SystemErrorProvide.OnSystemErrorHandleEvent(null, tex); }