Beispiel #1
0
 /// <summary>
 /// 返回发送字符串
 /// </summary>
 /// <param name="jkdid">监控点ID</param>
 /// <returns></returns>
 private string GetSendStr(string jkdid)
 {
     var senStr = $"{Properties.Settings.Default.SendStr},{jkdid}";
     if (Properties.Settings.Default.Crypt)
     {
         senStr = DataPacketCodec.Encode(senStr, Properties.Settings.Default.CryptKey) + "#";
         return senStr;
     }
     return senStr + "#";
 }
Beispiel #2
0
 private void GridMenuItemClick(object obj)
 {
     try
     {
         if (obj == null)
         {
             return;
         }
         var compara = obj.ToString();
         if (compara.Equals("清空"))
         {
             ExceptionModels?.Clear();
         }
         else if (compara.Equals("解密"))
         {
             if (string.IsNullOrEmpty(SelectJkd.JKD_VALUE))
             {
                 return;
             }
             if (SelectJkd.JKD_VALUE.TrimEnd('#').Length == 0)
             {
                 return;
             }
             DeCodeWindow dcw = new DeCodeWindow();
             var deStr = DataPacketCodec.Decode(SelectJkd.JKD_VALUE.TrimEnd('#'),
                 Properties.Settings.Default.CryptKey);
             dcw.Tb1.Text = deStr;
             dcw.ShowDialog();
         }
         else if (compara.Equals("打开"))
         {
             if (string.IsNullOrEmpty(SelectJkd.JKD_VALUE))
             {
                 return;
             }
             DeCodeWindow dcw = new DeCodeWindow();
             dcw.Tb1.Text = SelectJkd.JKD_VALUE;
             dcw.ShowDialog();
         }
     }
     catch (Exception e)
     {
         WriteLog(e.Message, ExEnum.Error);
     }
 }
Beispiel #3
0
        private void RadContextMenu_ItemClick(object sender, RadRoutedEventArgs e)
        {
            var menu        = (RadContextMenu)sender;
            var clickedItem = e.OriginalSource as RadMenuItem;
            var row         = menu.GetClickedElement <GridViewRow>();

            if (clickedItem != null && row != null)
            {
                var header = Convert.ToString(clickedItem.Header);

                switch (header)
                {
                case "解密":
                    var jkd = row.Item as YXJK_JKD;
                    if (string.IsNullOrEmpty(jkd?.JKD_VALUE))
                    {
                        return;
                    }
                    if (jkd.JKD_VALUE.TrimEnd('#').Length == 0)
                    {
                        return;
                    }
                    var dcw   = new DeCodeWin();
                    var deStr = DataPacketCodec.Decode(jkd.JKD_VALUE.TrimEnd('#'), Settings.CryptKey);
                    dcw.Tb1.Text = deStr;
                    dcw.ShowDialog();
                    break;
//                    case "Edit":
//                        gridView.BeginEdit();
//                        break;
//                    case "Delete":
//                        gridView.Items.Remove(row.DataContext);
//                        break;
//                    default:
//                        break;
                }
            }
        }
Beispiel #4
0
        private void StartMethod()
        {
            Parallel.ForEach(SoureJkds, item =>
            {
                Task.Factory.StartNew(async delegate
                {
                    var client     = new EasyClient();
                    int retryCount = 0;

                    /***
                     * 初始化socket连接, 接受返回数据处理
                     * HxReceiveFilter为自定义的协议
                     * ***/
                    client.Initialize(new HxReceiveFilter(), request =>
                    {
                        try
                        {
                            item.CURR_TIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            item.JKD_VALUE = request.Key;
                            if (request.Key.Equals("#"))
                            {
                                retryCount++;
                            }
                            else
                            {
                                retryCount = 0;
                            }
                            if (retryCount <= Settings.RetryCount && retryCount != 0)
                            {
                                item.REDIS_SAVE = bool.FalseString;
                                return;
                            }
                            using (var redis = new RedisClient(Settings.RedisIp, Settings.RedisPort, Settings.RedisPw))
                            {
                                try
                                {
                                    item.REDIS_SAVE = redis.Set(item.JKD_ID, item.JKD_VALUE).ToString();
                                }
                                catch (Exception e)
                                {
                                    item.REDIS_SAVE = bool.FalseString;
                                    LogHelper.WriteLog(e.Source, e);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.WriteLog(ex.Source, ex);
                        }
                    });
                    // Connect to the server
                    await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(Settings.RmiIp), Settings.RmiPort));

                    while (_taskFlag)
                    {
                        try
                        {
                            if (client.IsConnected)
                            {
                                //获取发送字符串
                                var enStr = DataPacketCodec.Encode($"rij,{item.JKD_ID}", Settings.CryptKey) + "#";
                                // Send data to the server
                                client.Send(Encoding.UTF8.GetBytes(enStr));
                            }
                            else
                            {
                                await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(Settings.RmiIp),
                                                                         Settings.RmiPort));
                            }
                        }
                        catch (Exception ex)
                        {
                            LogHelper.WriteLog(ex.Source, ex);
                            // reconnet
                            await client.ConnectAsync(new IPEndPoint(IPAddress.Parse(Settings.RmiIp),
                                                                     Settings.RmiPort));
                        }
                    }
                    finally
                    {
                        await Task.Delay(3000);
                    }
                    await client.Close();
                });