コード例 #1
0
        public void TriggerEvent(GameGlobeVar.EventId eventId)
        {
            Delegate del = null;

            if (_dicEvents.TryGetValue((int)eventId, out del))
            {
                if (null == del)
                {
                    return;
                }
                Delegate[] invocationList = del.GetInvocationList();
                for (int i = 0; i < invocationList.Length; ++i)
                {
                    Action action = invocationList[i] as Action;
                    if (null == action)
                    {
                        LogModule.LogError(string.Format("## Trigger Event {0} Parameters type [void] are not match  target type : {1}.",
                                                         eventId.ToString(),
                                                         invocationList[i].GetType()));
                        return;
                    }
                    action();
                }
            }
        }
コード例 #2
0
        public void TriggerEvent <T0, T1, T2>(GameGlobeVar.EventId eventId, T0 p0, T1 p1, T2 p2)
        {
            Delegate del = null;

            if (_dicEvents.TryGetValue((int)eventId, out del))
            {
                if (null == del)
                {
                    return;
                }
                Delegate[] invocationList = del.GetInvocationList();
                for (int i = 0; i < invocationList.Length; ++i)
                {
                    Action <T0, T1, T2> action = invocationList[i] as Action <T0, T1, T2>;
                    if (null == action)
                    {
                        LogModule.LogError(string.Format("## Trigger Event {0} Parameters type [{1}, {2}, {3}] are not match  target type : {4}.",
                                                         eventId.ToString(),
                                                         p0.GetType(),
                                                         p1.GetType(),
                                                         p2.GetType(),
                                                         invocationList[i].GetType()));
                        return;
                    }
                    action(p0, p1, p2);
                }
            }
        }
コード例 #3
0
    /// <summary>
    /// 获取MD5
    /// </summary>
    /// <param name="pathName"></param>
    /// <returns></returns>
    public static string GetMD5Hash(string pathName)
    {
        string strResult   = "";
        string strHashData = "";

#if !UNITY_WP8
        byte[] arrbytHashValue;
#endif
        System.IO.FileStream     oFileStream = null;
        MD5CryptoServiceProvider oMD5Hasher  = new MD5CryptoServiceProvider();
        try
        {
            oFileStream = new System.IO.FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite);
#if UNITY_WP8
            strHashData = oMD5Hasher.ComputeHash(oFileStream);
            oFileStream.Close();
#else
            arrbytHashValue = oMD5Hasher.ComputeHash(oFileStream);
            oFileStream.Close();
            strHashData = System.BitConverter.ToString(arrbytHashValue);
            strHashData = strHashData.Replace("-", "");
#endif

            strResult = strHashData;
        }
        catch (System.Exception ex)
        {
            LogModule.LogError("read md5 file error :" + pathName + " e: " + ex.ToString());
        }
        return(strResult);
    }
コード例 #4
0
        public void OnException(ExceptionContext filterContext)
        {
            var  httpContext = filterContext.HttpContext;//"为所欲为"
            bool result      = false;

            var xreq = httpContext.Request.Headers.ContainsKey("x-requested-with");

            if (xreq)
            {
                result = httpContext.Request.Headers["x-requested-with"] == "XMLHttpRequest";
            }

            if (!filterContext.ExceptionHandled)
            {
                LogModule.LogError(this.GetLogStr(filterContext.HttpContext, filterContext.Exception));
                HttpResponse response = filterContext.HttpContext.Response;
                response.ContentType = "application/json";
                response.StatusCode  = -1;
                response.WriteAsync(new
                {
                    Result       = 0,
                    DebugMessage = filterContext.Exception.Message,
                    RetValue     = "",
                    PromptMsg    = "发生错误,请联系管理员"
                }.ToJson());
                filterContext.ExceptionHandled = true;//已经被我处理了
            }
        }
コード例 #5
0
 /// <summary>
 /// EventLog日志输出
 /// </summary>
 /// <param name="eventId"></param>
 /// <param name="handleType"></param>
 /// <param name="targetEventType"></param>
 /// <param name="listener"></param>
 private void LogTypeError(GameGlobeVar.EventId eventId, CoreGlobeVar.HandleType handleType, Delegate targetEventType, Delegate listener)
 {
     LogModule.LogError(string.Format("Event Id {0}, [{1}] Wrong Listener Type {2}, needed Type {3}.",
                                      eventId.ToString(),
                                      CoreGlobeVar.HandleTypeDic[(int)handleType],
                                      targetEventType.GetType(),
                                      listener.GetType()));
 }
コード例 #6
0
        /// <summary>
        /// 创建Db实例 例如:创建MySql上下文参数问MySql.
        /// </summary>
        /// <param name="dbType">Db类型.</param>
        /// <param name="connectionString">connectionString.</param>
        /// <returns>BaseContext.</returns>
        public static BaseContext CreateDbInstance(DbEnum.DbType dbType = DbEnum.DbType.MySql, string connectionString = "")
        {
            string className = string.Format("SzwHighSpeedRack.EntityFrameworkCore.{0}Context", dbType);

            try
            {
                return(Activator.CreateInstance(Type.GetType(className), connectionString) as BaseContext);
            }
            catch (Exception ex)
            {
                LogModule.LogError("数据库创建异常", ex);
                throw new Exception("Create Dynamic DbInstance Error:" + ex.Message + ex.InnerException == null ? "" : ex.InnerException.Message);
            }
        }
コード例 #7
0
 /// <summary>
 /// 将一行字符串写入文件
 /// </summary>
 /// <param name="path"></param>
 /// <param name="text"></param>
 /// <returns></returns>
 public static bool WriteStringToFile(string path, string text)
 {
     try
     {
         FileStream   fs = new FileStream(path, FileMode.Create);
         StreamWriter sw = new StreamWriter(fs);
         sw.WriteLine(text);
         sw.Close();
         fs.Close();
         return(true);
     }
     catch (Exception ex)
     {
         LogModule.LogError(ex);
     }
     return(false);
 }
コード例 #8
0
    /// <summary>
    /// 从文件读取一个INT值
    /// </summary>
    /// <param name="path"></param>
    /// <param name="retInt"></param>
    /// <returns></returns>
    public static bool ReadFileInt(string path, out int retInt)
    {
        string text = "";

        retInt = 0;
        if (!ReadFileString(path, ref text))
        {
            return(false);
        }

        if (!int.TryParse(text, out retInt))
        {
            LogModule.LogError("parse int error path:" + path);
            return(false);
        }
        return(true);
    }
コード例 #9
0
        public override void ExecuteJobBusiness(IJobExecutionContext jobContext)
        {
            var dbJobManagerList = QuartzJobEx.dbJobManagerList.Where(w => w.JobKey == jobContext.Trigger.JobKey.Name.ToString()).ToList();

            try
            {
                dbJobManagerList.ForEach(o =>
                {
                    //执行Job任务
                    TaskRunBusiness(o);
                });
            }
            catch (Exception ex)
            {
                LogModule.LogError(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "->" + ex.Message + "");
                throw new Exception(ex.Message);
            }
        }
コード例 #10
0
        /// <summary>
        /// 实例化IInterceptor唯一方法
        /// </summary>
        /// <param name="invocation">包含被拦截方法的信息</param>
        public void Intercept(IInvocation invocation)
        {
            //记录被拦截方法信息的日志信息
            var dataIntercept = $"当前执行方法命名空间:{ invocation.TargetType.Namespace} " +
                                $"当前执行方法类名:{ invocation.TargetType.FullName} " +
                                $"当前执行方法名:{ invocation.Method.Name} " +
                                $"参数是: {string.Join(", ", invocation.Arguments.Select(a => (a ?? string.Empty).ToString()).ToArray())} \r\n";

            try
            {
                //在被拦截的方法执行完毕后 继续执行当前方法,注意是被拦截的是异步的
                invocation.Proceed();
                dataIntercept += ($"方法执行完毕,返回结果:{invocation.ReturnValue.ToJson()}");
                LogModule.LogInfo(dataIntercept);
            }
            catch (Exception ex)
            {
                LogModule.LogError(dataIntercept, ex);
                throw new Exception(ex.Message);
            }
        }
コード例 #11
0
    /// <summary>
    /// 从文件读取一个字符串
    /// </summary>
    /// <param name="path"></param>
    /// <param name="retString"></param>
    /// <returns></returns>
    public static bool ReadFileString(string path, ref string retString)
    {
        try
        {
            if (!File.Exists(path))
            {
                return(false);
            }
            FileStream   fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader sr = new StreamReader(fs);
            retString = sr.ReadToEnd();
            sr.Close();
            fs.Close();

            return(true);
        }
        catch (Exception ex)
        {
            LogModule.LogError(ex.ToString());
            return(false);
        }
    }
コード例 #12
0
        public static async void SchedulerBusiness(IScheduler IScheduler)
        {
            try
            {
                if (dbJobManagerList == null || dbJobManagerList.Count() == 0)
                {
                    LogModule.LogError(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "->未找到JobManager的配置数据...");
                    throw new Exception("未找到JobManager的配置数据...");
                }
                Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> > keyValuePairs = new Dictionary <IJobDetail, IReadOnlyCollection <ITrigger> >();
                //任务列表塞入调度器
                dbJobManagerList.ForEach(o =>
                {
                    var jobDetail = JobBuilder.Create <JobBusinessEx>().WithIdentity(o.JobKey, o.Group)
                                    .UsingJobData(o.JobKey, o.JobValue)
                                    .Build();
                    var trigger = TriggerBuilder.Create().WithIdentity(o.TriggerName, o.Group)
                                  .StartNow()
                                  .WithCronSchedule(o.CronExpression)
                                  .Build();
                    List <ITrigger> triggerSource = new List <ITrigger>();
                    triggerSource.Add(trigger);
                    ReadOnlyCollection <ITrigger> triggers = new ReadOnlyCollection <ITrigger>(triggerSource);
                    keyValuePairs.Add(jobDetail, triggers);
                });
                LogModule.LogWarm(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "->scheduler开始加载JobTasks");
                ReadOnlyDictionary <IJobDetail, IReadOnlyCollection <ITrigger> > triggersAndJobs = new ReadOnlyDictionary <IJobDetail, IReadOnlyCollection <ITrigger> >(keyValuePairs);
                await IScheduler.ScheduleJobs(triggersAndJobs, false);

                LogModule.LogWarm(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "->scheduler加载JobTasks完成");
            }
            catch (Exception ex)
            {
                LogModule.LogError(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "->" + ex.Message + "");
                throw new Exception(ex.Message);
            }
        }