Пример #1
0
        public void Set(PES.GPS.GpsEntityBase.GPSDataEntity data)
        {
            try
            {
                if (data != null)
                {
                    GpsDataCachedEntity entity = new GpsDataCachedEntity();
                    string k = Key(data.GPSCode);

                    byte[] bytes= entity.WriteBuffer(data);
                    iCacheProvider.Add(k, bytes);
                    //Logger.Fatal("保存新实体到缓存");
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
                //iCacheProvider = CacheProviderFactory.Default.CreateCacheProvider();
                //Logger.Trace("[LIXUN] 重新初始化MemCached代理..."); 
            }
        }
Пример #2
0
        /// <summary>
        /// 批量修复
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要批量修复吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            try
            {
                List<GPSDataEntity> datas = MySqlDB.GetDBDataList(txtConnStr.Text.Trim(), string.Empty);
                if (datas != null && datas.Count > 0)
                {
                    foreach (GPSDataEntity g in datas)
                    {
                        try
                        {
                            string k = g.GPSCode + "_movo";

                            GpsDataCachedEntity entity = new GpsDataCachedEntity();
                            byte[] bytes = entity.WriteBuffer(g);

                            _MemcachedClient.Add(k, bytes);

                            listBox1.Items.Add(string.Format("加载数据成功:VehicleCode:{1}, GPSCode:{0}, StarkMileage:{2}\r\n", g.GPSCode, g.VehicleCode, g.StarkMileage));
                        }
                        catch (Exception ex)
                        {
                            listBox1.Items.Add(string.Format("加载数据失败:VehicleCode:{1}, GPSCode:{0}, 错误:{2}\r\n", g.GPSCode, g.VehicleCode, ex.StackTrace));
                        }
                        listBox1.SelectedIndex = listBox1.Items.Count - 1;
                    }

                    MessageBox.Show("加载了" + datas.Count + "条数据到Memcached缓存", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #3
0
        /// <summary>
        /// 修复到Memcached
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            string vehCodes = txtVehCode.Text.Trim();
            if (string.IsNullOrEmpty(vehCodes))
            {
                MessageBox.Show("请输入车辆 GPSCode !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            List<string> gpscodeList = vehCodes.Split(',').ToList();
            if (gpscodeList.IsEmpty())
            {
                MessageBox.Show("请输入车辆 GPSCode !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                List<GPSDataEntity> datas = MySqlDB.GetDBDataList(txtConnStr.Text.Trim(), gpscodeList.JoinToString("','"));
                if (datas.IsEmpty())
                {
                    MessageBox.Show("未查到车辆 GPSCode 对应的数据库记录,请检查数据库连接是否正确或车辆GPSCode是否正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                foreach (var item in datas)
                {
                    if (item != null)
                    {
                        try
                        {
                            string k = item.GPSCode + "_movo";

                            GpsDataCachedEntity entity = new GpsDataCachedEntity();
                            byte[] bytes = entity.WriteBuffer(item);

                            _MemcachedClient.Add(k, bytes);

                            listBox1.Items.Add(string.Format("加载数据成功:VehicleCode:{1}, GPSCode:{0}, StarkMileage:{2}\r\n", item.GPSCode, item.VehicleCode, item.StarkMileage));
                        }
                        catch (Exception ex)
                        {
                            listBox1.Items.Add(string.Format("加载数据失败:VehicleCode:{1}, GPSCode:{0}, 错误:{2}\r\n", item.GPSCode, item.VehicleCode, ex.StackTrace));
                            LogUtil.LogError(string.Format("Memcached修复失败,{0};VehicleCode:{1}, GPSCode:{2}", ex.Message, item.VehicleCode, item.GPSCode), ex);
                        }
                        listBox1.SelectedIndex = listBox1.Items.Count - 1;
                    }
                }
                MessageBox.Show("Memcached修复完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception ex)
            {
                MessageBox.Show("Memcached修复失败," + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                LogUtil.LogError(string.Format("Memcached修复失败,{0}", ex.Message), ex);
            }
        }