Пример #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
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtVehCode.Text.Trim()))
            {
                MessageBox.Show("请输入车辆 GPSCode !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            List<string> gpscodeList = txtVehCode.Text.Trim().Split(',').ToList();
            if (gpscodeList.IsEmpty())
            {
                MessageBox.Show("请输入车辆 GPSCode !", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ShowLoadding();
            foreach (var item in gpscodeList)
            {
                var obj = _MemcachedClient.Get(item + "_movo");
                if (obj != null)
                {
                    var result = obj as byte[];
                    listBox1.Items.Add(string.Format("缓存数据:{0} \r\n", result));

                    if (null != result && result.Length > 0)
                    {
                        GpsDataCachedEntity entity = new GpsDataCachedEntity();
                        entity.ReadBuffer(result);
                        var res = ConvertNewEntityToOldEntity(entity);
                        if (res != null)
                        {
                            listBox1.Items.Add(string.Format("转换数据:vCode:{0}, StartStopCarTime:{1}\r\n", res.VehicleCode, res.StartStopCarTime));
                        }
                        else
                        {
                            listBox1.Items.Add(string.Format("转换数据失败, GPSCode:{0}", item));
                        }
                    }
                    else
                    {
                        listBox1.Items.Add(string.Format("读取Memcached缓存数据为空, GPSCode:{0}", item));
                    }
                }
                else
                {
                    listBox1.Items.Add(string.Format("连接Memcached失败, GPSCode:{0}", item));
                }
            }
            CloseLoadding();
        }
Пример #4
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);
            }
        }
Пример #5
0
        private GPSDataEntity ConvertNewEntityToOldEntity(GpsDataCachedEntity? entity)
        {
            if (entity == null) return null;

            GPSDataEntity data = new GPSDataEntity()
            {
                ACCState = entity.Value.ACCState,
                CoolerStatus = entity.Value.CoolerStatus,
                Direction = entity.Value.Direction,
                DoorStatus = entity.Value.DoorStatus,
                IsSendLongIntervalMessage = entity.Value.IsSendLongIntervalMessage,

                IsStartStopCarTime = entity.Value.IsStartStopCarTime,
                Latitude = entity.Value.Latitude,
                Longitude = entity.Value.Longitude,
                OilState = entity.Value.OilState,
                PowerState = entity.Value.PowerState,

                ReportTime = entity.Value.ReportTime,
                Speed = entity.Value.Speed,
                StarkMileage = entity.Value.StarkMileage,
                StartStopCarTime = entity.Value.StartStopCarTime
            };

            return data;
        }
Пример #6
0
        private GpsDataCachedEntity ConvertOldEntityToNewEntity (GPSDataEntity entity)
        {
            GpsDataCachedEntity data = new GpsDataCachedEntity()
            {
                ACCState=entity.ACCState,
                CoolerStatus=entity.CoolerStatus,
                Direction=entity.Direction,
                DoorStatus=entity.DoorStatus,
                IsSendLongIntervalMessage=entity.IsSendLongIntervalMessage,

                IsStartStopCarTime=entity.IsStartStopCarTime,
                Latitude=entity.Latitude,
                Longitude=entity.Longitude,
                OilState=entity.OilState,
                PowerState=entity.PowerState,

                ReportTime=entity.ReportTime,
                Speed=entity.Speed,
                StarkMileage=entity.StarkMileage,
                StartStopCarTime=entity.StartStopCarTime
            };

            return data;
        }
Пример #7
0
        public PES.GPS.GpsEntityBase.GPSDataEntity Get(string gpsCode)
        {
            try
            {
                string k = Key(gpsCode);
                object o = iCacheProvider.Get(k);
                var result= o as byte[];
                if (null != result&&result.Length>0)
                {
                    GpsDataCachedEntity entity = new GpsDataCachedEntity();
                    entity.ReadBuffer(result);
                    //Logger.Fatal("取出新实体成功");
                    return ConvertNewEntityToOldEntity(entity);

                }
                
                return null;

            }
            catch (Exception ex)
            {
                Logger.Error(ex, null);
                return null;
            }
        }