private async Task OnDesiredPropertyChanged(TwinCollection desiredProperties, object userContext) { whiteMessage("Desired Twin Property Changed:"); whiteMessage($"{desiredProperties.ToJson()}"); // Read the desired Twin Properties. if (desiredProperties.Contains("fanstate") & fanState != stateEnum.failed) { string desiredFanState = desiredProperties["fanstate"]; desiredFanState = desiredFanState.ToLower(); if (desiredFanState == "on" || desiredFanState == "off") { fanState = (stateEnum)Enum.Parse(typeof(stateEnum), desiredFanState); greenMessage($"Set the fan to: {desiredFanState}"); } else { redMessage($"Illegal fan state received: {desiredFanState}"); } } if (desiredProperties.Contains("temperature")) { string desiredTemperatureString = desiredProperties["temperature"]; try { desiredTemperature = double.Parse(desiredTemperatureString); greenMessage($"Setting the desired temperature to: {desiredTemperatureString}"); } catch { redMessage($"Illegal temperature received: {desiredTemperatureString}"); } } if (desiredProperties.Contains("humidity")) { string desiredHumidityString = desiredProperties["humidity"]; try { desiredHumidity = double.Parse(desiredHumidityString); greenMessage($"Setting the desired humidity to: {desiredHumidityString}"); } catch { redMessage($"Illegal humidity received: {desiredHumidityString}"); } } // Report Twin properties. var reportedProperties = new TwinCollection(); reportedProperties["fanstate"] = fanState.ToString(); reportedProperties["humidity"] = desiredHumidity; reportedProperties["temperature"] = desiredTemperature; await s_deviceClient.UpdateReportedPropertiesAsync(reportedProperties).ConfigureAwait(false); greenMessage($"Reported Twin Properties: {reportedProperties.ToJson()}"); }
private async Task <Tool> updateTool(Tool tool, stateEnum newState, Justification justification, string username) { var curState = _stateConfiguration.states .Where(x => x.state == tool.status.ToString()).FirstOrDefault(); if (curState == null) { return(null); } var newStateObject = _stateConfiguration.states .Where(x => x.state == newState.ToString()).FirstOrDefault(); if (newStateObject.needsJustification) { if (justification == null) { return(null); } else if (String.IsNullOrEmpty(justification.text)) { return(null); } } else { justification = null; } if (curState.possibleNextStates.Contains(newState.ToString())) { tool.status = newState.ToString(); _context.Entry(tool).State = EntityState.Modified; await _context.SaveChangesAsync(); // passa o nome do usuario que fez a modificação na ferramenta tool.username = username; await _stateTransitionHistoryService.addToolHistory(tool.toolId, newStateObject.needsJustification, tool.currentLife, tool, justification, curState.state.ToString(), newState.ToString()); Trigger(tool); return(tool); } return(null); }
public async Task <ProductionOrder> setProductionOrderToStatusById(int productionOrderId, stateEnum newState, string username) { var produtionOrder = await _context.ProductionOrders .Where(x => x.productionOrderId == productionOrderId) .FirstOrDefaultAsync(); //alteração feita para a mudança de status gravar tbm o nome do usuário Console.WriteLine("produtionOrder - from Service: "); //Console.WriteLine (produtionOrder.currentStatus); if (produtionOrder == null) { return(null); } var productionOrderType = await _context.ProductionOrderTypes.Where(x => x.productionOrderTypeId == produtionOrder.productionOrderTypeId).Include(x => x.stateConfiguration).ThenInclude(x => x.states).FirstOrDefaultAsync(); string url = productionOrderType.stateConfiguration.states.Where(x => x.state == newState.ToString()).FirstOrDefault().url; Console.WriteLine(url); produtionOrder.currentStatus = newState.ToString(); produtionOrder.latestUpdate = DateTime.Now.Ticks; if (username != null) { produtionOrder.username = username; } else { produtionOrder.username = "******"; } _context.Entry(produtionOrder).State = EntityState.Modified; await _context.SaveChangesAsync(); await _histStateService.addHistStates(productionOrderId, newState.ToString(), username); if (!string.IsNullOrEmpty(url)) { postAfterChangedState(url, produtionOrder); } return(produtionOrder); }
public async Task <ProductionOrder> setProductionOrderToStatusById(int productionOrderId, stateEnum newState) { var produtionOrder = await _context.ProductionOrders .Where(x => x.productionOrderId == productionOrderId) .FirstOrDefaultAsync(); if (produtionOrder == null) { return(null); } var productionOrderType = await _context.ProductionOrderTypes .Where(x => x.productionOrderTypeId == produtionOrder.productionOrderTypeId) .Include(x => x.stateConfiguration) .ThenInclude(x => x.states) .FirstOrDefaultAsync(); var curState = productionOrderType.stateConfiguration.states .Where(x => x.state == produtionOrder.currentStatus.ToString()).FirstOrDefault(); if (curState == null) { return(null); } if (curState.possibleNextStates.Contains(newState.ToString())) { string url = productionOrderType.stateConfiguration.states .Where(x => x.state == newState.ToString()).FirstOrDefault().url; produtionOrder.currentStatus = newState.ToString(); _context.Entry(produtionOrder).State = EntityState.Modified; await _context.SaveChangesAsync(); await _histStateService.addHistStates(productionOrderId, newState.ToString()); if (!string.IsNullOrEmpty(url)) { postAfterChangedState(url, produtionOrder); } return(produtionOrder); } return(null); }
private static async Task UpdateTwin(double currentTemperature, double currentHumidity) { // Report the properties back to the IoT Hub. var reportedProperties = new TwinCollection(); reportedProperties["fanstate"] = fanState.ToString(); reportedProperties["humidity"] = Math.Round(currentHumidity, 2); reportedProperties["temperature"] = Math.Round(currentTemperature, 2); await s_deviceClient.UpdateReportedPropertiesAsync(reportedProperties); greenMessage("Twin state reported: " + reportedProperties.ToJson()); }
private static async Task OnDesiredPropertyChanged(TwinCollection desiredProperties, object userContext) { try { desiredHumidity = desiredProperties["humidity"]; desiredTemperature = desiredProperties["temperature"]; greenMessage("Setting desired humidity to " + desiredProperties["humidity"]); greenMessage("Setting desired temperature to " + desiredProperties["temperature"]); // Report the properties back to the IoT Hub. var reportedProperties = new TwinCollection(); reportedProperties["fanstate"] = fanState.ToString(); reportedProperties["humidity"] = desiredHumidity; reportedProperties["temperature"] = desiredTemperature; await s_deviceClient.UpdateReportedPropertiesAsync(reportedProperties); greenMessage("\nTwin state reported: " + reportedProperties.ToJson()); } catch { redMessage("Failed to update device twin"); } }
public void FromFile(string path) { //错误信息 int error_lineNum = 0; string error_state = ""; try { store = new Dictionary <string, List <LabelItem> >(); groupStringList = new List <string>(); stateEnum state = stateEnum.start; string nowFilename = ""; string nowText = ""; string[] nowLabelResultValues = { }; getStrlineTypeResult result = new getStrlineTypeResult(); StreamReader sr = new StreamReader(path, Encoding.UTF8, true); while (!sr.EndOfStream) { string str = sr.ReadLine(); error_lineNum++; error_state = "imageFile=" + nowFilename + ", nowState=" + state.ToString(); result = getStrlineType(str); switch (state) { case stateEnum.start: if (result.type == strlineType.fileHead) { //处理Label文件的文件头 readLabelFileStartBlocks(nowText); state = stateEnum.file; nowFilename = result.value[0]; //创建新文件项 addFilenameToStore(nowFilename); } else if (result.type == strlineType.normal) { nowText += "\r\n" + result.value[0]; } break; case stateEnum.file: if (result.type == strlineType.labelHead) { state = stateEnum.label; nowText = ""; nowLabelResultValues = result.value; } else if (result.type == strlineType.fileHead) { state = stateEnum.file; nowFilename = result.value[0]; //创建新文件项 if (!addFilenameToStore(nowFilename)) { state = stateEnum.start; } } break; case stateEnum.label: switch (result.type) { case strlineType.normal: if (nowText == "") { nowText = result.value[0]; } else { nowText += "\r\n" + result.value[0]; } break; case strlineType.labelHead: //保存之前的内容 addLabelToStore(nowText, nowLabelResultValues, nowFilename); nowText = ""; nowLabelResultValues = result.value; break; case strlineType.fileHead: //保存之前的内容 addLabelToStore(nowText, nowLabelResultValues, nowFilename); state = stateEnum.file; nowFilename = result.value[0]; if (!addFilenameToStore(nowFilename)) { state = stateEnum.start; } break; } break; } //switch (state) } //while (!sr.EndOfStream) if (state == stateEnum.label) { addLabelToStore(nowText, nowLabelResultValues, nowFilename); } if (state == stateEnum.start) { //处理Label文件的文件头 readLabelFileStartBlocks(nowText); state = stateEnum.file; nowFilename = result.value[0]; } OnFileListChanged(); OnLabelItemListChanged(); OnGroupListChanged(); } catch (Exception e) { throw new Exception("ReadFromFileError in line" + error_lineNum.ToString() + "\r\n" + error_state + "\r\n\r\n" + e.ToString()); } }
private void progress(stateEnum testState, stateEnum setState) { stateEnum s; lock (_stateLock) { s = _state; if (s == testState) { #if DEBUG // Console.WriteLine(string.Format("\r\nState a: {1}(Test={2})({0})", Thread.CurrentThread.ManagedThreadId.ToString(), setState.ToString(), testState.ToString())); #endif _state = setState; return; } else if (s > testState) { throw new Exception(string.Format("State is {0} (beyond {1})", s.ToString(), testState.ToString())); } } #if DEBUG // lock (_stateLock) // Console.WriteLine(string.Format("\r\nState b: {1}(Test={2})({0})", Thread.CurrentThread.ManagedThreadId.ToString(), setState.ToString(), testState.ToString())); #endif while (_state != testState) { Thread.Sleep(250); //lazy wait, it's not time critical if (_state == stateEnum.Error) { throw new Exception("Exception reported to ProcessCoordinator - Exceptioning out"); } } lock (_stateLock) { #if DEBUG // Console.WriteLine(string.Format("\r\nState c: {1}(Test={2})({0})", Thread.CurrentThread.ManagedThreadId.ToString(), setState.ToString(), testState.ToString())); #endif _state = setState; } }
public stateAndItsEvents() { Name = state.ToString(); }