public AgilorResponseData SetTargetValue(string targetName, dynamic obj) { AgilorResponseData response = new AgilorResponseData(); if (!checkACIObject()) { response.responseMessage = "Get All Device Names And Status ERROR: ACI IS NULL, Server Need Be Restart!"; response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_AGILOR_ACI_IS_NULL; return(response); } try { response.responseMessage = "Set Target Value Success!"; response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_NORMAL; object val = null; try { switch (agilorACI.GetTarget(targetName).Type) { case Agilor.Interface.Val.Value.Types.BOOL: val = obj.targetValue.ToObject <bool>(); break; case Agilor.Interface.Val.Value.Types.FLOAT: val = obj.targetValue.ToObject <float>(); break; case Agilor.Interface.Val.Value.Types.LONG: val = obj.targetValue.ToObject <int>(); break; case Agilor.Interface.Val.Value.Types.STRING: val = obj.targetValue.ToObject <string>(); break; } } catch (Exception ex) { response.responseMessage = ex.ToString(); response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_TARGET_VALUE_ERROR; return(response); } agilorACI.SetValue(new Agilor.Interface.Val.Value(targetName, val)); response.responseBody = agilorACI.QuerySnapshots(targetName); } catch (Exception ex) { response.responseMessage = ex.ToString(); response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_UNKNOWN_ERROR; } return(response); }
public AgilorResponseData SetTargetValue(string targetName, dynamic obj) { AgilorResponseData response = new AgilorResponseData(); if (!checkACIObject()) { response.responseMessage = "Get All Device Names And Status ERROR: ACI IS NULL, Server Need Be Restart!"; response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_AGILOR_ACI_IS_NULL; return(response); } try { response.responseMessage = "Set Target Value Success!"; response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_NORMAL; object val = null; try { switch (agilorACI.GetTarget(targetName).Type) { case Agilor.Interface.Val.Value.Types.BOOL: val = obj.targetValue.ToObject <bool>(); break; case Agilor.Interface.Val.Value.Types.FLOAT: val = obj.targetValue.ToObject <float>(); break; case Agilor.Interface.Val.Value.Types.LONG: val = obj.targetValue.ToObject <int>(); break; case Agilor.Interface.Val.Value.Types.STRING: val = obj.targetValue.ToObject <string>(); break; } } catch (Exception ex) { response.responseMessage = ex.ToString(); response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_TARGET_VALUE_ERROR; return(response); } Agilor.Interface.Val.Value setVal = new Agilor.Interface.Val.Value(targetName, val); if (agilorSlaveACIs.Count > 0) { // 向 slave 发起二次请求 string[] slaveIps = ConfigurationManager.AppSettings["AgilorServerSlaveIp"].Split(';'); HttpContent httpContent = new StringContent("{\"targetValue\": \"" + val.ToString() + "\"}"); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpClient httpClient = new HttpClient(); foreach (string slaveIp in slaveIps) { httpClient.PostAsync("http://" + slaveIp + ":8098/Agilor/targets/" + targetName + "/set", httpContent); } } else { Thread thread = new Thread(() => ThreadMainWithParameters(agilorACI, setVal)); thread.Start(); } //Thread thread = new Thread(() => ThreadMainWithParameters(agilorACI, setVal)); //thread.Start(); //foreach (ACI slaveAci in agilorSlaveACIs) //{ // thread = new Thread(() => ThreadMainWithParameters(slaveAci, setVal)); // thread.Start(); //} /* * agilorACI.SetValue(new Agilor.Interface.Val.Value(targetName, val)); * foreach (ACI slaveAci in agilorSlaveACIs) * { * try { slaveAci.SetValue(new Agilor.Interface.Val.Value(targetName, val)); } catch { } * } */ response.responseBody = GetTargetValueByTargetName(targetName).responseBody; } catch (Exception ex) { response.responseMessage = ex.ToString(); response.responseCode = (int)AgilorResponseData.RESPONSE_CODE.RESPONSE_UNKNOWN_ERROR; } return(response); }