コード例 #1
0
        public static void DeleteEmployee(string UserId)
        {
            NLogHelper log = NLogFactory.GetLogger("DeleteEmployee");

            try
            {
                Result Result = EmployeeBll.Delete(UserId);
                if (Result != null)
                {
                    if (Result.errcode == "0")
                    {
                        //Console.Write("\r\n更新成功," + Result.errmsg + "\r\n");
                    }
                    else
                    {
                        log.Error("\r\n EmployeeForDingTalkBll-DeleteEmployee() " + Result.errmsg);
                        //Console.Write("\r\n" + Result.errmsg + "\r\n");
                    }
                }
                else
                {
                    //Console.Write("\r\n无返回数据\r\n");
                }
            }
            catch (Exception ex)
            {
                log.Error("\r\n EmployeeForDingTalkBll-DeleteEmployee() " + ex);
                //Console.Write("\r\n" + ex.Message + "\r\n");
            }
        }
コード例 #2
0
ファイル: AdminController.cs プロジェクト: duzhenyi/DL
        public ApiResult <string> UploadImg2([FromForm] IFormFile file)
        {
            var res = new ApiResult <string>();

            try
            {
                if (null == file)
                {
                    res.msg = "文件不可为空!";
                    NLogHelper.Error("Admin-UploadImg 文件不可为空");
                    return(res);
                }
                if (file.FileName != null)
                {
                    var path = _environment.WebRootPath + "/upload/images/headpic/";
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    if (ImageHelper.SaveImage(file, path + file.FileName))
                    {
                        res.msg  = "上传成功";
                        res.data = file.FileName;
                    }
                }
                res.msg = "上传失败";
            }
            catch (Exception ex)
            {
                res.msg = "文件上传异常!";
                NLogHelper.Error("Admin-UploadImg" + ex.Message);
            }
            return(res);
        }
コード例 #3
0
ファイル: MQConsumer.cs プロジェクト: belain/Utils
 /// <summary>
 /// 关闭消费者
 /// </summary>
 public static void CloseConsumer()
 {
     try
     {
         NLogHelper.Info("开始关闭MQ Consumer");
         if (session != null)
         {
             session.Dispose();
             session.Close();
         }
         session = null;
     }
     catch (Exception ex)
     {
         NLogHelper.Error("关闭MQ Session失败:" + ex);
     }
     try
     {
         if (connection != null)
         {
             connection.Stop();
             connection.Dispose();
             connection.Close();
         }
         connection = null;
     }
     catch (Exception ex)
     {
         NLogHelper.Error("关闭MQ连接失败:" + ex);
     }
 }
コード例 #4
0
        /// <summary>
        /// 获取xe下name子元素的值
        /// </summary>
        /// <param name="xe"></param>
        /// <param name="name"></param>
        /// <param name="defaultValue">如果找不到name子元素的返回值</param>
        /// <param name="isTrim">是否忽略结果前后空白</param>
        /// <returns>第一项获取的字符串;第二项是否能够找到指定name的子元素</returns>
        public static Tuple <string, bool> GetString(this XElement xe, string name, string defaultValue = "",
                                                     bool isTrim = true)
        {
            try
            {
                //查找xe的一级子目录
                var temp = GetFirstMatchElement(xe, name);

                if (temp == null)
                {
                    return(new Tuple <string, bool>(defaultValue, false));
                }


                string theValue = temp.Value;
                if (isTrim)
                {
                    return(new Tuple <string, bool>(theValue == null?string.Empty:theValue.Trim(), true));
                }
                else
                {
                    return(new Tuple <string, bool>(theValue, true));
                }
            }
            catch (Exception ex)
            {
                NLogHelper.Error("解析节点{0}失败:{1}".FormatWith(name, ex));
                return(new Tuple <string, bool>(defaultValue, false));
            }
        }
コード例 #5
0
        /// <summary>
        /// socket回调
        /// </summary>
        /// <param name="state"></param>
        private static void SocketTimerCallBack(object state)
        {
            lock (locker)
            {
                if (isRunning)
                {
                    return;
                }

                isRunning = true;
            }

            try
            {
                if (!SocketClientProxy.IsConnected)
                {
                    NLogHelper.Warn("重启socket客户端");
                    SocketClientProxy.Start();
                }
            }
            catch (Exception ex)
            {
                NLogHelper.Error("socket监控定时器异常:" + ex);
            }
            finally
            {
                lock (locker)
                {
                    isRunning = false;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 添加消息
        /// </summary>
        /// <param name="message"></param>
        public static void AddMessage(String message)
        {
            try
            {
                if (String.IsNullOrEmpty(message))
                {
                    return;
                }

                MessageItem msgItem = null;
                #region 丢弃超出容量的消息
                if (MsgQueue.Count > MaxQueueCapacity)
                {
                    for (int i = 0; i < 5; i++)
                    {
                        if (MsgQueue.TryTake(out msgItem))
                        {
                            NLogHelper.Error($"消息{msgItem?.Message}被丢弃");
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                #endregion

                msgItem = new MessageItem(message);
                MsgQueue.Add(msgItem);
            }
            catch { }
        }
コード例 #7
0
ファイル: MQConsumer.cs プロジェクト: belain/Utils
 /// <summary>
 /// init 消费者
 /// </summary>
 public static bool InitConsumer()
 {
     try
     {
         if (connection != null)
         {
             CloseConsumer();
         }
         NLogHelper.Info("开始初始化MQConsumer");
         //通过工厂构建链接
         connection = factory.CreateConnection();
         //设置连接的标识
         connection.ClientId                       = "HuiZhouDatagramPaser";
         connection.ExceptionListener             += connection_ExceptionListener;
         connection.ConnectionInterruptedListener += connection_ConnectionInterruptedListener;
         //启动连接
         connection.Start();
         //通过连接创建一个对话
         session = connection.CreateSession();
         //通过会话创建一个消费者
         IMessageConsumer consumer =
             session.CreateConsumer(new ActiveMQQueue(ConfigurationManager.AppSettings["MQName"]));
         //注册监听事件
         consumer.Listener += ConsumerOnListener;
         isAlive            = true;
         NLogHelper.Info("初始化MQConsumer成功,等待接收报文... ...");
         return(true);
     }
     catch (Exception ex)
     {
         NLogHelper.Error("初始化MQ失败:" + ex);
         return(false);
     }
 }
コード例 #8
0
 /// <summary>
 /// 错误发生事件
 /// </summary>
 /// <param name="exception"></param>
 private static void ConnectionOnExceptionListener(Exception exception)
 {
     lock (locker)
     {
         _isAlive = false;
     }
     NLogHelper.Error("connection_ExceptionListener连接发生异常:" + exception);
 }
コード例 #9
0
        /// <summary>
        /// 连接中断事件
        /// </summary>
        private static void ConnectionOnConnectionInterruptedListener()
        {
            lock (locker)
            {
                _isAlive = false;
            }

            NLogHelper.Error("ConnectionInterruptedListener连接发生异常连接断开");
        }
コード例 #10
0
        public static string GetEmployee(string userid)
        {
            NLogHelper log  = NLogFactory.GetLogger("GetEmployee");
            string     json = "";

            try
            {
                GetEmployee Result = EmployeeBll.Get(userid);

                if (Result != null)
                {
                    if (Result.errcode == "0")
                    {
                        json = JsonConvert.SerializeObject(Result);
                        //Console.Write(json + "\r\n");
                    }
                    else if (Result.errcode == "90002")
                    {
                        System.Threading.Thread.Sleep(1500);
                        json = GetEmployee(userid);
                    }
                    else
                    {
                        if (Result.errcode != "60121")
                        {
                            //Console.Write(Result.errmsg);
                            log.Error("\r\n EmployeeForDingTalkBll-GetEmployee() " + Result.errmsg + "\r\n");
                        }
                        return("-1");
                    }
                }
                else
                {
                    //Console.Write("无返回数据");
                }
            }
            catch (Exception ex)
            {
                log.Error("\r\n EmployeeForDingTalkBll-GetEmployee() " + ex + "\r\n");
                //Console.Write(ex.Message);
            }
            return(json);
        }
コード例 #11
0
        public static void AddAdminSwaggerSetup(this IServiceCollection services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }
            var apiName = "核心内容管理系统管理端";

            services.AddSwaggerGen((s) =>
            {
                //遍历出全部的版本,做文档信息展示
                typeof(CustomApiVersion.ApiVersions).GetEnumNames().ToList().ForEach(version =>
                {
                    s.SwaggerDoc(version, new OpenApiInfo
                    {
                        Version     = version,
                        Title       = $"{apiName} 接口文档",
                        Description = $"{apiName} HTTP API " + version,
                        Contact     = new OpenApiContact {
                            Name = apiName, Email = "*****@*****.**", Url = new Uri("https://CoreCms.Net")
                        },
                    });
                    s.OrderActionsBy(o => o.RelativePath);
                });

                try
                {
                    //生成API XML文档
                    var basePath = AppContext.BaseDirectory;
                    var xmlPath  = Path.Combine(basePath, "doc.xml");
                    s.IncludeXmlComments(xmlPath);
                }
                catch (Exception ex)
                {
                    NLogHelper.Error("Swagger生成失败,Doc.xml丢失,请检查并拷贝。", ex);
                }

                // 开启加权小锁
                s.OperationFilter <AddResponseHeadersFilter>();
                s.OperationFilter <AppendAuthorizeToSummaryOperationFilter>();

                // 在header中添加token,传递到后台
                s.OperationFilter <SecurityRequirementsOperationFilter>();

                // 必须是 oauth2
                s.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
                {
                    Description = "JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)\"",
                    Name        = "Authorization",          //jwt默认的参数名称
                    In          = ParameterLocation.Header, //jwt默认存放Authorization信息的位置(请求头中)
                    Type        = SecuritySchemeType.ApiKey
                });
            });
        }
コード例 #12
0
        /// <summary>
        /// oracleParameters 里可设置 parameterName、parameterValue、out 参数、OracleType、Size
        /// </summary>
        /// <param name="procedure_Name"></param>
        /// <param name="oracleParameters"></param>
        /// <returns></returns>
        public bool ExecuteProcedure(string procedure_Name, List <OracleParameter> oracleParameters, ref string errorMsg)
        {
            OracleTransaction OraTran = null;

            this.oraAdapter         = new OracleDataAdapter();
            this.oraCmd.CommandType = CommandType.StoredProcedure;
            this.oraCmd.CommandText = procedure_Name;
            this.oraCmd.Parameters.Clear();
            for (int i = 0; i < oracleParameters.Count; i++)
            {
                OracleParameter parameter = oracleParameters[i];
                this.oraCmd.Parameters.Add(parameter);
            }

            errorMsg = "";

            try
            {
                this.oraCon.Open();
                OraTran = oraCon.BeginTransaction();
                this.oraCmd.Transaction = OraTran;
                int nSignal = this.oraCmd.ExecuteNonQuery();

                if (nSignal > -1)                       // 成功
                {
                    OraTran.Commit();
                    oraCon.Close();
                    return(true);
                }
                else
                {
                    OraTran.Rollback();
                    oraCon.Close();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (OraTran != null)
                {
                    OraTran.Rollback();
                }
                if (oraCon.State == ConnectionState.Open)
                {
                    oraCon.Close();
                }

                errorMsg = ex.Message;

                NLogHelper.Error(ex);
                return(false);
            }
        }
コード例 #13
0
ファイル: OraAccess.Search.cs プロジェクト: KUN-NT/ToolCode
        public bool IsExist(string tableName, string where_filter, List <string> parameterNames, List <object> parameterValues)
        {
            var ds = new DataSet();

            this.oraAdapter = new OracleDataAdapter();

            string strSQL = "";

            if (where_filter != "")
            {
                strSQL = "select count(*) from " + tableName + " where " + where_filter;
            }
            else
            {
                strSQL = "select count(*) from " + tableName;
            }

            this.oraCmd.CommandType = CommandType.Text;

            this.oraCmd.CommandText = strSQL;
            this.oraCmd.Parameters.Clear();
            for (int i = 0; i < parameterNames.Count; i++)
            {
                var parameter = new OracleParameter(parameterNames[i], parameterValues[i]);
                this.oraCmd.Parameters.Add(parameter);
            }

            this.oraAdapter.SelectCommand = this.oraCmd;

            try
            {
                this.oraAdapter.Fill(ds);
                int nCount = 0;
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    if (Int32.TryParse(StringHelper.SafeToString(ds.Tables[0].Rows[0][0]), out nCount))
                    {
                        if (nCount > 0)
                        {
                            return(true);  // 该表已存在重复记录
                        }
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                NLogHelper.Error(ex);
            }

            return(false);
        }
コード例 #14
0
        /// <summary>
        /// 执行带事务的存储过程,允许设定 out/in 参数
        /// </summary>
        /// <param name="procedure_Name"></param>
        /// <param name="parameterNames"></param>
        /// <param name="parameterValues"></param>
        /// <param name="parameterDirections"></param>
        /// <returns></returns>
        public bool ExecuteProcedure(string procedure_Name, List <string> parameterNames, List <object> parameterValues, List <ParameterDirection> parameterDirections)
        {
            OracleTransaction OraTran = null;

            this.oraAdapter         = new OracleDataAdapter();
            this.oraCmd.CommandType = CommandType.StoredProcedure;
            this.oraCmd.CommandText = procedure_Name;
            this.oraCmd.Parameters.Clear();
            for (int i = 0; i < parameterNames.Count; i++)
            {
                OracleParameter parameter = new OracleParameter(parameterNames[i], parameterValues[i]);
                if (parameterDirections[i] == ParameterDirection.Output)
                {
                    parameter.Direction = parameterDirections[i];
                }
                this.oraCmd.Parameters.Add(parameter);
            }

            try
            {
                this.oraCon.Open();
                OraTran = oraCon.BeginTransaction();
                this.oraCmd.Transaction = OraTran;
                int nSignal = this.oraCmd.ExecuteNonQuery();

                if (nSignal > -1)                       // 成功
                {
                    OraTran.Commit();
                    oraCon.Close();
                    return(true);
                }
                else
                {
                    OraTran.Rollback();
                    oraCon.Close();
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (OraTran != null)
                {
                    OraTran.Rollback();
                }
                if (oraCon.State == ConnectionState.Open)
                {
                    oraCon.Close();
                }
                NLogHelper.Error(ex);
                return(false);
            }
        }
コード例 #15
0
        public static void Main(string[] args)
        {
            //红黑树
            SortedDictionary <string, string> rbTree = new SortedDictionary <string, string>();

            DirectoryHold.ResetCurrentDir();
            NLogHelper.Info(GuidUtils.GetGuid32());
            NLogHelper.Trace("Trace");
            NLogHelper.Debug("Debug");
            NLogHelper.Info("Info");
            NLogHelper.Warn("Warn");
            NLogHelper.Error("Error");
            NLogHelper.Fatal("Fatal");
        }
コード例 #16
0
        /// <summary>
        /// 注:该方法将定期按时执行,
        /// 意味着如果下一个周期到来,而上一次执行未完成,该方法开启一个新线程执行
        ///
        /// 在方法内部使用try/catch捕获所有异常
        /// </summary>
        /// <param name="context"></param>
        public void Execute(IJobExecutionContext context)
        {
            lock (_locker)
            {
                if (_isRunning)
                {
                    return;
                }
                _isRunning = true;
            }

            string jobName = string.Empty;

            try
            {
                jobName = GetType().Name;

                //获取当前进程 dispose不会关闭程序,但是会释放资源
                using (Process currentProcess = Process.GetCurrentProcess())
                {
                    //win98或win me不支持 获取当前进程分配的物理内存
                    long   workset64   = currentProcess.WorkingSet64;
                    double worksetInMb = workset64 / 1024.0 / 1024.0;

                    if (worksetInMb > MaxMemoryCanUseInMb)
                    {
                        NLogHelper.Warn(
                            $"进程{currentProcess.ProcessName}占用内存较大,约{worksetInMb.ToString("F1", CultureInfo.CurrentCulture)}Mb");
                        ErrorCode   = 1;
                        ErrorReason = $"进程{currentProcess.ProcessName}占用内存较大,建议检查或者重启该程序";
                    }
                    else
                    {
                        ErrorCode   = 0;
                        ErrorReason = string.Empty;
                    }
                }
            }
            catch (Exception ex)
            {
                NLogHelper.Error($"执行任务{jobName}异常:" + ex);
            }
            finally
            {
                lock (_locker)
                {
                    _isRunning = false;
                }
            }
        }
コード例 #17
0
        public static void BatchDeleteEmployee(List <string> list)
        {
            NLogHelper log = NLogFactory.GetLogger("BatchDeleteEmployee");

            try
            {
                BatchDeleteEmployee model = new Model.BatchDeleteEmployee();

                model.useridlist = list;

                string param = JsonConvert.SerializeObject(model);

                Result Result = EmployeeBll.BatchDelete(param);
                if (Result != null)
                {
                    if (Result.errcode == "0")
                    {
                        //Console.Write("删除成功," + Result.errmsg);
                    }
                    else
                    {
                        log.Error("\r\n EmployeeForDingTalkBll-BatchDeleteEmployee() " + Result.errmsg);
                        //Console.Write(Result.errmsg);
                    }
                }
                else
                {
                    //Console.Write("无返回数据");
                }
            }
            catch (Exception ex)
            {
                log.Error("\r\n EmployeeForDingTalkBll-BatchDeleteEmployee() " + ex);
                //Console.Write(ex.Message);
            }
        }
コード例 #18
0
        /// <summary>
        /// 关闭Producer
        /// </summary>
        public static void CloseProducer()
        {
            try
            {
                NLogHelper.Debug($"开始关闭MQ Producer:{MqUri}");
                if (producer != null)
                {
                    producer.Close();
                    producer = null;
                }
            }
            catch (Exception e)
            {
                NLogHelper.Error($"开始关闭MQ Producer失败:{e}");
            }

            try
            {
                if (session != null)
                {
                    session.Close();
                    session = null;
                }
            }
            catch (Exception e)
            {
                NLogHelper.Error($"关闭MQ Session失败:{e}");
            }

            try
            {
                if (connection != null)
                {
                    connection.Stop();
                    connection.Close();
                    connection = null;
                }
            }
            catch (Exception e)
            {
                NLogHelper.Error($"关闭MQ连接connection失败:{e}");
            }

            lock (locker)
            {
                _isAlive = false;
            }
        }