12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using MySystem.Models;
- using System;
- using System.Linq;
- namespace MySystem
- {
- public class MachineApplyHelper
- {
- public readonly static MachineApplyHelper Instance = new MachineApplyHelper();
- private MachineApplyHelper()
- { }
- public string Start()
- {
- bool op = true;
- WebCMSEntities db = new WebCMSEntities();
- string result = "";
- int total = 0;
- while (op)
- {
- MachineApply PopData = new MachineApply();
- try
- {
- //获取apserver待同步的数据,执行入库
- PopData = TendisDbconn.Instance.RPop<MachineApply>("Pop:MachineApply");
- if (PopData != null)
- {
- MachineApply checkExist = db.MachineApply.FirstOrDefault(m => m.Id == PopData.Id);
- if (checkExist != null)
- {
- checkExist = PopData;
- }
- else
- {
- db.MachineApply.Add(PopData);
- }
- if (total >= 20)
- {
- total = 0;
- db.SaveChanges();
- }
- if (string.IsNullOrEmpty(result)) result = "success";
- }
- else
- {
- db.SaveChanges();
- op = false;
- }
- }
- catch (Exception ex)
- {
- ErrorMsg msg = new ErrorMsg();
- msg.Obj = PopData;
- msg.Time = DateTime.Now;
- msg.ErrorContent = ex.ToString();
- TendisDbconn.Instance.AddList("Pop:MachineApply:Error", msg);
- result = "有异常,请查看Pop:MachineApply:Error队列";
- }
- }
- db.Dispose();
- return result;
- }
- }
- }
|