Beispiel #1
0
 /// <summary>
 ///   记录日志
 /// </summary>
 /// <param name="info"> 日志消息 </param>
 public void RecordLog(RecordInfo info)
 {
     using (LogRecordingScope.CreateScope())
     {
         ZeroPublisher.Publish("RemoteLog", "Record", info.TypeName, JsonConvert.SerializeObject(info));
     }
 }
Beispiel #2
0
 protected override void DoAsync()
 {
     ZeroPublisher.Publish("DeviceInstruct", "", "", new DeviceEventArgument
     {
         EventName    = "Message",
         ArgumentJson = "Test From ZeroNet"
     });
 }
Beispiel #3
0
 public ApiResult MachineEvent(MachineEventArg arg)
 {
     ZeroPublisher.Publish("MachineEventMQ", arg.EventName, "Event", arg.JsonStr);
     return(new ApiResult
     {
         Success = true,
         Status = new ApiStatusResult
         {
             ErrorCode = 0,
             ClientMessage = $"{arg.MachineId} : {arg.EventName } IsPublish"
         }
     });
 }
Beispiel #4
0
 /// <summary>
 /// 运行时警告
 /// </summary>
 /// <param name="host"></param>
 /// <param name="api"></param>
 /// <param name="message"></param>
 public static void Waring(string host, string api, string message)
 {
     if (AppConfig.Config.SmsConfig == null || AppConfig.Config.SmsConfig.CycleHours <= 0)
     {
         return;
     }
     ZeroPublisher.Publish("HealthCenter", "RuntimeWaring", "Waring", JsonConvert.SerializeObject(
                               new{
         host,
         api,
         message
     }));
 }
Beispiel #5
0
 /// <summary>
 /// 保存为性能日志
 /// </summary>
 public static void Save()
 {
     ZeroPublisher.Publish("HealthCenter", "PerformanceCounter", "Save", null);
 }
Beispiel #6
0
 /// <summary>
 /// 开始计数
 /// </summary>
 /// <returns></returns>
 public void End(RouteData data)
 {
     data.End = DateTime.Now;
     ZeroPublisher.Publish("HealthCenter", "PerformanceCounter", "Counter", JsonConvert.SerializeObject(data));
 }
Beispiel #7
0
 /// <summary>
 ///     刷新
 /// </summary>
 public static void Flush()
 {
     ZeroPublisher.Publish("HealthCenter", "RuntimeWaring", "Flush", null);
 }
Beispiel #8
0
        /// <summary>
        ///     调用
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private static void CallTask(object arg)
        {
            HttpContext context = (HttpContext)arg;
            var         router  = new Router(context);

            //跨域支持
            if (router.Data.HttpMethod == "OPTIONS")
            {
                HttpProtocol.Cros(context.Response);
                return;
            }

            IoHandler.OnBegin(router.Data);
            try
            {
                if (router.Data.Uri.LocalPath == "/publish")
                {
                    bool suc = ZeroPublisher.Publish(context.Request.Form["Host"], context.Request.Form["Title"], context.Request.Form["Sub"], (string)context.Request.Form["Arg"]);

                    context.Response.WriteAsync(suc ? ApiResult.SucceesJson : ApiResult.NetworkErrorJson, Encoding.UTF8);

                    return;
                }
                //内容页转向
                if (router.Data.Uri.LocalPath.IndexOf(".", StringComparison.OrdinalIgnoreCase) > 0)
                {
                    context.Response.Redirect(RouteOption.Option.SystemConfig.ContextHost +
                                              router.Data.Uri.LocalPath.Trim('/'));
                    return;
                }
                //内容页转向
                if (router.Data.Uri.LocalPath.IndexOf(".", StringComparison.OrdinalIgnoreCase) > 0)
                {
                    context.Response.Redirect(RouteOption.Option.SystemConfig.ContextHost +
                                              router.Data.Uri.LocalPath.Trim('/'));
                    return;
                }

                HttpProtocol.FormatResponse(context.Response);
                //命令
                if (InnerCommand(router.Data.Uri.LocalPath, context.Response))
                {
                    return;
                }

                //开始调用
                if (!router.SecurityChecker.PreCheck())
                {
                    router.Data.Status = ZeroOperatorStatus.DenyAccess;
                    context.Response.WriteAsync(ApiResult.DenyAccessJson, Encoding.UTF8);
                }
                else
                {
                    // 正常调用
                    router.Call();
                    // 写入返回
                    router.WriteResult();
                    // 缓存
                    RouteChahe.CacheResult(router.Data);
                }
            }
            catch (Exception e)
            {
                OnError(router, e, context);
            }
            finally
            {
                IoHandler.OnEnd(router.Data);
            }
        }