Example #1
0
        /// <summary>
        /// 查询短信余额
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiSmsBalance_Click(object sender, EventArgs e)
        {
            int res = SMSHelper.Instance.GetSMSBalance();

            if (res < 0)
            {
                if (res == -1)
                {
                    UserMessageBox.MessageError("错误,账户为空");
                }

                if (res == -2)
                {
                    UserMessageBox.MessageError("错误,密码为空");
                }

                if (res == -3)
                {
                    UserMessageBox.MessageError("错误,企业ID为空");
                }
                else
                {
                    UserMessageBox.MessageError("错误,查询失败!\r\n返回码未知:" + res);
                }
            }
            else
            {
                UserMessageBox.MessageInfo(string.Format("短信剩余{0}条", res));
            }
        }
Example #2
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (!CheckInput())
            {
                return;
            }
            ConfigHelper.UpdateConfig("IPAddress", combIP.SelectedItem.ToString(), true);
            ConfigHelper.UpdateConfig("Port", txtPort.Text, true);
            ConfigHelper.UpdateConfig("DataType", combDBType.Text, true);
            ConfigHelper.UpdateConfig("DataIP", txtDataIp.Text, true);
            ConfigHelper.UpdateConfig("DataName", txtDataName.Text, true);
            ConfigHelper.UpdateConfig("DName", txtDName.Text, true);
            ConfigHelper.UpdateConfig("DPwd", txtPwd.Text, true);
            ConfigHelper.UpdateConfig("DataPort", txtDataPort.Text, true);

            bool suc = TmoConfigManager.Instance.CheckConnection();

            if (suc)
            {
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                DialogResult dr = UserMessageBox.MessageInfo("无法测试数据库连接字符串是否正确!");
                if (dr == System.Windows.Forms.DialogResult.OK)
                {
                    this.DialogResult = DialogResult.OK;
                }
            }
        }
Example #3
0
        void btnClearCache_Click(object sender, EventArgs e)
        {
            //MemoryCacheHelper.GetCacheItem<string>("test", () => "testdata", DateTime.Now.AddHours(1));
            bool suc = MemoryCacheHelper.ClearCache();

            if (suc)
            {
                UserMessageBox.MessageInfo("缓存清理成功");
            }
            else
            {
                UserMessageBox.MessageError("缓存清理失败");
            }
        }
Example #4
0
        /// <summary>
        /// 发送消息 到指定的客户端
        /// </summary>
        private void btnSend_Click(object sender, EventArgs e)
        {
            TCPServerClient client = lbClientList.SelectedItem as TCPServerClient;

            if (client != null)
            {
                string        data  = txtCmdTxt.Text.Trim();
                List <string> datas = StringPlus.GetStrArray(data, ";");
                if (datas.Count < 2)
                {
                    if (string.IsNullOrWhiteSpace(datas[0]))
                    {
                        UserMessageBox.MessageError("发送内容不能为空!");
                        return;
                    }

                    bool suc = client.SendString(datas[0]);
                    if (!suc)
                    {
                        UserMessageBox.MessageError("发送失败");
                    }
                }
                else
                {
                    if (!TmoShare.IsNumricForInt(datas[0]))
                    {
                        UserMessageBox.MessageError("命令ID必须为整数");
                        return;
                    }

                    bool suc = client.SendCommand(int.Parse(datas[0]), datas[1]);
                    if (!suc)
                    {
                        UserMessageBox.MessageError("发送失败");
                    }
                }
            }
            else
            {
                UserMessageBox.MessageInfo("请选择要发送的客户端");
            }
        }
Example #5
0
 private bool CheckInput()
 {
     try
     {
         string IpCheck = @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";
         if (Convert.ToInt32(txtPort.Text) > 65535 || Convert.ToInt32(txtPort.Text) < 0)
         {
             TmoCommon.UserMessageBox.MessageInfo("请正确添写端口号(范围:0-65535)");
             return(false);
         }
         if (txtDataIp.Text.ToLower() != "localhost" && !Regex.IsMatch(txtDataIp.Text.Trim(), IpCheck))
         {
             UserMessageBox.MessageInfo("数据库连接IP地址格式错误!");
             txtDataIp.Focus();
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         UserMessageBox.MessageInfo(ex.Message);
         return(false);
     }
 }
        /// <summary>
        /// 启动服务
        /// </summary>
        /// <returns></returns>
        public bool StartServices()
        {
            if (start)
            {
                return(true); //阻止重复启动
            }
            isTcp = false;    //ConfigHelper.GetConfigBool("ServiceMode", false, true);

            #region 注册前先关闭通道

            try
            {
                if (_serviceHost != null)
                {
                    _serviceHost.CloseAsync().Wait();
                    _serviceHost.Dispose();
                }
            }
            catch
            {
            }

            #endregion

            try
            {
                string port = ConfigHelper.GetConfigString("Port");
                string ip   = ConfigHelper.GetConfigString("IPAddress");
                lblServerAddr.Text = ip + ":" + port;
                Uri baseAddress = new Uri($"http://{ip}:{port}");
                var config      = new HttpSelfHostConfiguration(baseAddress);
                config.Routes.MapHttpRoute("API Default", ServicePath + "/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
                config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
                config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("datatype", "json", "application/json"));
                config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new DefaultContractResolver()
                {
                    IgnoreSerializableAttribute = true
                };
                config.MaxReceivedMessageSize = 20480000;

                _serviceHost = new HttpSelfHostServer(config);
                _serviceHost.OpenAsync().Wait();

                start = true; //标记已启动

                lblStatus.Text      = "已启动...";
                lblStatus.ForeColor = Color.Green;
                return(true);
            }
            catch (System.Runtime.InteropServices.ExternalException ex)
            {
                if (ex.ErrorCode == 10048)
                {
                    UserMessageBox.MessageInfo("服务器端口已被占用,无法启动程序!");
                }
                if (ex.ErrorCode == 10049)
                {
                    UserMessageBox.MessageInfo("本机IP地址配置错误,无法启动程序!");
                }

                LogHelper.Log.Error(ex);
            }
            catch (Exception ex)
            {
                LogHelper.Log.Error($"启动{ServiceName}失败", ex);
            }

            return(false);
        }