Exemplo n.º 1
0
        /// <summary>
        /// 发送广播
        /// </summary>
        /// <param name="station"></param>
        /// <param name="title"></param>
        /// <param name="sub"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static bool DoPublish(string station, string title, string sub, string value)
        {
            var socket = ZeroConnectionPool.GetSocket(station, RandomOperate.Generate(8));

            if (socket.Socket == null)
            {
                return(false);
            }
            using (socket)
            {
                return(socket.Socket.Publish(new PublishItem
                {
                    Station = station,
                    Title = title,
                    SubTitle = sub,
                    RequestId = GlobalContext.RequestInfo.RequestId,
                    Content = value ?? "{}"
                }));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     远程调用
        /// </summary>
        /// <returns></returns>
        private void Call()
        {
            if (!ZeroApplication.ZerCenterIsRun)
            {
                State = ZeroOperatorStateType.LocalNoReady;
                return;
            }

            var socket = ZeroConnectionPool.GetSocket(Station, ApiContext.RequestContext.RequestId);

            if (socket.Socket == null)
            {
                //ApiContext.Current.LastError = ErrorCode.NoReady;
                _json = ApiResult.NoReadyJson;
                State = ZeroOperatorStateType.LocalNoReady;
                return;
            }

            using (socket)
            {
                ReadNetWork(socket);
            }
        }
Exemplo n.º 3
0
        public ApiResult NewPlan(ClientPlan clientPlan)
        {
            if (string.IsNullOrWhiteSpace(clientPlan.station) || string.IsNullOrWhiteSpace(clientPlan.command))
            {
                return(ApiResult.Error(ErrorCode.LogicalError, "命令不能为空"));
            }
            var config = ZeroApplication.Config[clientPlan.station];

            if (config == null)
            {
                return(ApiResult.Error(ErrorCode.LogicalError, "站点名称错误"));
            }
            if (config.StationType != ZeroStationType.Dispatcher && config.IsBaseStation)
            {
                return(ApiResult.Error(ErrorCode.LogicalError, "不允许对基础站点设置计划(SystemManage除外)"));
            }

            clientPlan.station = config.StationName;


            CustomPlan plan = new CustomPlan
            {
                plan_type   = clientPlan.plan_type,
                plan_value  = clientPlan.plan_value,
                plan_repet  = clientPlan.plan_repet,
                description = clientPlan.description,
                no_skip     = clientPlan.no_skip,
                plan_time   = clientPlan.plan_time < new DateTime(1970, 1, 1) ? 0 : (int)((clientPlan.plan_time.ToUniversalTime().Ticks - 621355968000000000) / 10000000),
                skip_set    = clientPlan.skip_set
            };

            if (clientPlan.plan_type == plan_date_type.week && plan.plan_value == 7)
            {
                plan.plan_value = 0;
            }
            if (clientPlan.plan_type > plan_date_type.time)
            {
                if (clientPlan.skip_set > 0)
                {
                    plan.plan_repet += clientPlan.skip_set;
                }
            }
            else
            {
                plan.skip_set   = 0;
                plan.plan_repet = 1;
            }
            var socket = ZeroConnectionPool.GetSocket(clientPlan.station, null);

            if (socket.Socket == null)
            {
                return(ApiResult.Error(ErrorCode.LocalError, "无法联系ZeroCenter"));
            }
            bool success;

            if (config.StationType == ZeroStationType.Api || config.StationType == ZeroStationType.Vote)
            {
                success = socket.Socket.SendTo(planApiDescription,
                                               plan.ToZeroBytes(),
                                               clientPlan.context.ToZeroBytes(),
                                               clientPlan.command.ToZeroBytes(),
                                               clientPlan.argument.ToZeroBytes());
            }
            else if (config.StationType == ZeroStationType.Publish)
            {
                success = socket.Socket.SendTo(planPubDescription,
                                               plan.ToZeroBytes(),
                                               clientPlan.context.ToZeroBytes(),
                                               clientPlan.command.ToZeroBytes(),
                                               clientPlan.argument.ToZeroBytes());
            }
            else//Manage
            {
                clientPlan.command = clientPlan.command.ToLower();
                if (clientPlan.command != "pause" && clientPlan.command != "close" && clientPlan.command != "resume")
                {
                    return(ApiResult.Error(ErrorCode.LogicalError, "系统命令仅支持暂停(pause)关闭(close)和恢复(resume) 非系统站点"));
                }
                config = ZeroApplication.Config[clientPlan.station];
                if (config == null || config.State == ZeroCenterState.Stop || config.IsBaseStation)
                {
                    return(ApiResult.Error(ErrorCode.LogicalError, "命令参数为有效的非系统站点名称"));
                }

                success = socket.Socket.SendTo(commandDescription,
                                               plan.ToZeroBytes(),
                                               clientPlan.command.ToZeroBytes(),
                                               clientPlan.argument.ToZeroBytes());
            }
            if (!success)
            {
                ZeroTrace.WriteInfo("NewPlan", "Send", socket.Socket.GetLastError());

                return(ApiResult.Error(ErrorCode.NetworkError, socket.Socket.GetLastError().Text));
            }
            if (!socket.Socket.Recv(out var message))
            {
                ZeroTrace.WriteInfo("NewPlan", "Recv", socket.Socket.LastError);
                return(ApiResult.Error(ErrorCode.NetworkError, socket.Socket.GetLastError().Text));
            }
            var value = message.Unpack();

            return(value.State == ZeroOperatorStateType.Plan ? ApiResult.Succees() : ApiResult.Error(ErrorCode.LogicalError, value.State.Text()));
        }