Exemplo n.º 1
0
        /// <summary>
        /// 开始转发
        /// </summary>
        /// <returns></returns>
        public async Task Forward()
        {
            var forward = new ForwardRequestBody
            {
                Target_IP   = Extension.ReadInput("请输入目标IP: "),
                Target_Port = Convert.ToUInt16(Extension.ReadInput("请输入目标端口: "))
            };

            try
            {
                Logger.Log(
                    NLog.LogLevel.Trace,
                    LogType.系统跟踪,
                    $"发送开始转发信息, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort}.");

                await SendAsync(forward);
            }
            catch (Exception ex)
            {
                Logger.Log(
                    NLog.LogLevel.Error,
                    LogType.系统异常,
                    $"发送开始转发信息时异常, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort}.",
                    null,
                    ex);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <returns></returns>
        public async Task Login()
        {
            var login = new LoginRequestBody
            {
                UserID           = Convert.ToUInt32(Extension.ReadInput("请输入用户Id: ", true, "001")),
                Password         = Extension.ReadPassword("请输入密码: "),
                Msg_GnsscenterID = Convert.ToUInt32(Extension.ReadInput("请输入下级平台接入码: ", true, Config.GnsscenterID.ToString())),
                Down_link_IP     = Extension.ReadInput("请输入下级平台提供对应的从链路服务端IP地址: ", true, "127.0.0.1"),
                Down_link_Port   = Convert.ToUInt16(Extension.ReadInput("请输入下级平台提供对应的从链路服务端口号: ", true, "4040"))
            };

            try
            {
                Logger.Log(
                    NLog.LogLevel.Trace,
                    LogType.系统跟踪,
                    $"发送登录信息, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort}.");

                await SendAsync(login);
            }
            catch (Exception ex)
            {
                Logger.Log(
                    NLog.LogLevel.Error,
                    LogType.系统异常,
                    $"发送登录信息时异常, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort}.",
                    null,
                    ex);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 发送JTT1078消息
        /// </summary>
        /// <returns></returns>
        public async Task SendJTT1078Msg()
        {
            try
            {
                //await SendAsync(new UpRealVideoMsgBody
                //{
                //    DataType = 0x1801,
                //    VehicleNo = "666",
                //    VehicleColor = 2,
                //    DataLength = 35,
                //    SubBody = new RealVideoStartupReplyBody
                //    {
                //        Result = 0,
                //        ServerIP = "192.168.0.1",
                //        ServerPort = 4040
                //    }
                //});

                //return;

                var options = typeof(SuperSocket.JTT.JTT1078.Const.DataType).GetFields()
                              .ToDictionary(k => k.Name, v => $"0x{v.GetValue(null):x2}");

                options.ForEach(o => o.Value.ConsoleWrite(ConsoleColor.White, o.Key, true, 1));

                string datatype    = Extension.ReadInput("请选择业务类型: "),
                       subdatatype = null;

                var type = Assembly.Load(Protocol.InternalEntitysMappings[datatype].Assembly)
                           .GetType(Protocol.InternalEntitysMappings[datatype].TypeName);

                var obj = Activator.CreateInstance(type);

                Protocol.Structures
                .Find(o => o.IsBody)
                .Internal[datatype]
                .ForEach(o =>
                {
                    var property = obj.GetProperty(o.Property.Split('.'));

                    object value = null;

                    if (o.InternalKey == null)
                    {
                        string value_;
                        if (o.Property == "DataType")
                        {
                            var suboptions = typeof(SuperSocket.JTT.JTT1078.Const.SubDataType).GetFields()
                                             .ToDictionary(k => k.Name, v => $"0x{v.GetValue(null):x2}");

                            suboptions.ForEach(o => o.Value.ConsoleWrite(ConsoleColor.White, o.Key, true, 1));

                            subdatatype = Extension.ReadInput("请选择子业务类型: ");

                            value_ = subdatatype;
                            value  = value_.ToObject(property.PropertyType);
                        }
                        else
                        {
                            value_ = Extension.ReadInput($"请输入{o.Explain}: ");

                            if (string.IsNullOrWhiteSpace(value_))
                            {
                                return;
                            }

                            if (property.PropertyType == typeof(string))
                            {
                                value = value_;
                            }
                            else
                            {
                                value = value_.ToJson().ToObject(property.PropertyType);
                            }
                        }
                    }
                    else
                    {
                        var subtype = Assembly.Load(Protocol.InternalEntitysMappings[subdatatype].Assembly)
                                      .GetType(Protocol.InternalEntitysMappings[subdatatype].TypeName);

                        value = Activator.CreateInstance(subtype);

                        o.Internal[subdatatype]
                        .ForEach(subo =>
                        {
                            var subproperty = value.GetProperty(subo.Property.Split('.'));

                            object subvalue = null;

                            var subvalue_ = Extension.ReadInput($"请输入{subo.Explain}: ");

                            if (string.IsNullOrWhiteSpace(subvalue_))
                            {
                                return;
                            }

                            if (subproperty.PropertyType == typeof(string))
                            {
                                subvalue = subvalue_;
                            }
                            else
                            {
                                subvalue = subvalue_.ToObject(subproperty.PropertyType);
                            }

                            value.SetValueToProperty(subo.Property.Split('.'), subvalue);
                        });
                    }

                    obj.SetValueToProperty(o.Property.Split('.'), value);
                });

                Logger.Log(
                    NLog.LogLevel.Trace,
                    LogType.系统跟踪,
                    $"发送JTT1078消息, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort} " +
                    $"\r\t\n业务类型: {datatype} " +
                    $"\r\t\n子业务类型: {subdatatype}.");

                await SendAsync((IJTTMessageBody)obj);
            }
            catch (Exception ex)
            {
                Logger.Log(
                    NLog.LogLevel.Error,
                    LogType.系统异常,
                    $"发送JTT1078消息时异常, " +
                    $"\r\t\nServer: {Config.ServerHost}:{Config.ServerPort}.",
                    null,
                    ex);
            }
        }