private void btnHandshake_Click(object sender, RoutedEventArgs e) { if (PresetInfo.currentObjectId != null) { _commPresenter.DeviceGatherStart(OperateType.Gather); labelCollectStatus.Content = "正在进行数据采集"; return; } CloudAreaItem item = new CloudAreaItem() { time = DateTime.Now, status = true, processStatus = 1, processBar = 0, photoUri = "http://img.bitlight.cc/printPhoto1.jpg", name = "测点「1」", enabled = true, detail = "未发现任何异常", coordinate = "110.343317,25.28906", }; PresetInfo.bmobWindows.Create("CloudAreaItem", item, (result, ex) => { if (ex == null) { PresetInfo.currentObjectId = result.objectId; Dispatcher.Invoke(() => { _commPresenter.DeviceGatherStart(OperateType.Gather); labelCollectStatus.Content = "正在进行数据采集"; }); } else { CloudDisconnected(); } }); }
private void DataTimer_Tick(object sender, EventArgs e) { Console.WriteLine("定时器"); if (PresetInfo.currentObjectId == null) { return; } PresetInfo.bmobWindows.Get <CloudAreaItem>("CloudAreaItem", PresetInfo.currentObjectId, (result, ex) => { if (ex == null) { CloudAreaItem item = new CloudAreaItem() { }; int statusCode = result.processStatus.Get(); int value = 0; string statusShow = ""; if (statusCode == 1) { if (currentCollectSumNum > 0) { value = currentCollectNum * 100 / currentCollectSumNum; } item.processBar = value; if (value == 100) { statusCode = 2; value = 0; } } else if (statusCode == 2) { value = result.processBar.Get() + new Random().Next(8, 15); if (value >= 100) { statusCode = 3; value = 0; } } else { PresetInfo.currentObjectId = null; return; } item.processStatus = statusCode; item.processBar = value; switch (statusCode) { case 1: statusShow = "正在数据采集「" + value + "%」"; break; case 2: statusShow = "正在数据处理「" + value + "%」"; break; default: statusShow = "任务执行完毕"; break; } Dispatcher.Invoke(() => { labelCollectStatus.Content = statusShow; }); PresetInfo.bmobWindows.Update("CloudDevice", "L3fM2226", new CloudDevice() { status = statusCode * 100 + value }, (result2, exUpdate) => { }); PresetInfo.bmobWindows.Update("CloudAreaItem", PresetInfo.currentObjectId, item, (result2, exUpdate) => { if (exUpdate == null) { if (statusCode == 3) { PresetInfo.currentObjectId = null; } } else { CloudDisconnected(); } }); } else { CloudDisconnected(); PresetInfo.currentObjectId = null; } }); }