private void refreshTextlist(SvgConfig config, SvgDocument svg, ResponseValue responseVar) { string name = config.BindingTags.First(p => p.id == responseVar.Id).name; string idAB = config.BindingTags.First(p => p.id == responseVar.Id).id; //yes we should save it (textlistConfig.Id) but this will be in the future var bindingTag = config.BindingTags.First(p => p.id == responseVar.Id); Textlist textlistConfig = config.SchemeTextlist.First( textlist => textlist.name == bindingTag.name); textlistConfig.id = bindingTag.id; int i = 0; while (i < 1000) { string idRect = responseVar.Id + "#" + i; string idText = responseVar.Id + "#" + ++i; if (svg.GetElementById(idRect) is SvgRectangle && svg.GetElementById(idText) is SvgTextSpan) { var rectangle = (SvgRectangle)svg.GetElementById(idRect); var svgText = (SvgTextSpan)svg.GetElementById(idText); setTextlist(svg, responseVar, textlistConfig, ref rectangle, ref svgText); break; } else { i++; } } }
/// <summary> /// Insert a ResponseValue record using an external DB entity without committing the DB changes. /// </summary> /// <param name="db">Database Entity</param> /// <param name="value">String containing the answer</param> /// <param name="formResponseID">Int the responseID</param> /// <param name="formFieldID"></param> /// <param name="rCount">If the field is inside a repeatable, specify the current numeber of repetition</param> /// <returns>Return the ResponseValue record inserted in the database</returns> public static ResponseValue createResponseValue(GRASPEntities db, string value, int formResponseID, int formFieldID, int positionIndex, int rCount, string fieldType) { if(db != null) { var response = new ResponseValue(); response.value = value; response.FormResponseID = formResponseID; response.formFieldId = formFieldID; response.RVCreateDate = DateTime.Now; response.RVRepeatCount = rCount; response.positionIndex = positionIndex; UpdateNumericAndDate(response, fieldType); db.ResponseValue.Add(response); //ONLY FOR DEBUG //try //{ // //db.SaveChanges(); //} //catch(Exception ex) //{ // string err = ex.StackTrace; //} return response; } else { return null; } }
/// <summary> /// 发送设定的参数 /// </summary> /// <param name="address"></param> /// <param name="groupNumber"></param> /// <param name="parameterCount"></param> /// <param name="addressArray"></param> /// <param name="valueArray"></param> public bool ResponseSettingParameter(byte[] address, string groupNumber, List <string> addressArray, List <string> valueArray) { bool flag = true; try { ResponseValueData theResponseValueData = new ResponseValueData(); theResponseValueData.DEVICE_ADDRESS = address; theResponseValueData.VALUE_TYPE = ByteWithString.strToToHexByte(groupNumber)[0]; theResponseValueData.VALUE_COUNT = (byte)addressArray.Count; theResponseValueData.theResponseValueArray = new List <ResponseValue>(); for (int i = 0; i < addressArray.Count; i++) { byte[] theBytes = ByteWithString.strToToHexByte(addressArray[i]); ResponseValue theResponseValue = new ResponseValue(); theResponseValue.VALUE_ADDRESS = new byte[] { theBytes[1], theBytes[0] }; theResponseValue.VALUE = StringConvertByte(addressArray[i], valueArray[i]); theResponseValue.VALUE_LENGTH = (byte)theResponseValue.VALUE.Length; theResponseValueData.theResponseValueArray.Add(theResponseValue); } ClientReport theClientReport = CreateClientReport <ResponseValueData>(0x15, theResponseValueData); byte[] bytes = theScoket.clientReportUnSerialize(theClientReport); if (bytes.Length > 0) { theScoket.sendInfo(bytes); } } catch (Exception msg) { Log.LogWrite(msg); } return(flag); }
private void setDynValue(ResponseValue responseValue, DynValue dynValueConfig, ref SvgTextSpan svgElement) { string newValue = string.Empty; int iValue; double doubleValue; //svg.Children.Remove(element); if (responseValue.value is double) { doubleValue = (double)responseValue.value; double dValue = (doubleValue + dynValueConfig.offset) * dynValueConfig.ratio; newValue = dValue + dynValueConfig.unit; } else { if (int.TryParse(responseValue.value.ToString(), out iValue) == true) { double dValue = (iValue + dynValueConfig.offset) * dynValueConfig.ratio; newValue = dValue + dynValueConfig.unit; } if (newValue == string.Empty) { newValue = responseValue.value.ToString(); } } svgElement.Text = newValue; //svg.Nodes.Add(element); }
public async Task <JsonResult> getData() { StreamReader stream = new StreamReader(Request.InputStream); object data = new object(); List <ResponseValue> responseList = new List <ResponseValue>(); string json = stream.ReadToEnd(); if (json != "[]" || json != null || json != "") { List <SchemeValue> list = new JavaScriptSerializer().Deserialize <List <SchemeValue> >(json); if (list.Count != 0) { List <string> dbNames = XMLHandler.readTag("dbName", (int)Session["id"]); db db = new db(dbNames[0], 12); foreach (var schemeValue in list) { object value = db.singleItemSelectPostgres(schemeValue.columnName, schemeValue.tableName, null); ResponseValue responseValue = new ResponseValue(); responseValue.tableName = schemeValue.tableName; responseValue.columnName = schemeValue.columnName; responseValue.value = value; responseList.Add(responseValue); } db.connection.Close(); data = responseList; } return(Json(data, "application/json", JsonRequestBehavior.AllowGet)); } else { return(Json(data)); } }
public static ResponseValue CreateResponseValue(TenderingCriterionProperty property) { var responseValue = new ResponseValue() { ID = EuComGrowId.Random() }; switch (property.ValueDataTypeCode.Value) { case "AMOUNT": responseValue.ResponseAmount = new AmountType(100m) { CurrencyID = "EUR" }; break; case "QUANTITY": responseValue.ResponseQuantity = new QuantityType(200m) { UnitCode = "pcs" }; break; case "QUANTITY_YEAR": responseValue.ResponseQuantity = new QuantityType(200m) { UnitCode = "YEAR" }; break; case "QUANTITY_INTEGER": responseValue.ResponseQuantity = new QuantityType(200m) { UnitCode = "PCS" }; break; case "CODE": responseValue.ResponseCode = new CodeType("FOO"); break; case "MEASURE": responseValue.ResponseMeasure = new MeasureType(123, "m"); break; case "DATE": responseValue.ResponseDate = new DateType(new DateTime(2020, 1, 1)); break; case "INDICATOR": responseValue.ResponseIndicator = true; break; default: responseValue.Description = new[] { "Some description" }; break; } return(responseValue); }
private void refreshAgeBar(SvgConfig config, SvgDocument svg, ResponseValue responseVar, bool vertical) { AgeBar ageBarConfig = config.SchemeAgeBars.First(p => p.id == responseVar.Id); int i = 0; while (i < 1000) { string id = responseVar.Id + "#" + i; if (svg.GetElementById(id) is SvgRectangle) { var element = (SvgRectangle)svg.GetElementById(id); string defaultAgeBarId = responseVar.Id + "initial"; SvgRectangle defaultAgeBar; if (svg.GetElementById(defaultAgeBarId) is SvgRectangle) { defaultAgeBar = element; } else { defaultAgeBar = createDefaultAgeBar(element, defaultAgeBarId); } setAgeBar(svg, responseVar, ageBarConfig, ref element, ref defaultAgeBar, vertical); break; } else { i++; } } }
public string GetValueString() { if (ResponseValue is IRangeValue rv) { return(rv.StringValue); } else { return(ResponseValue?.ToString()); } }
private void setTextlist(SvgDocument svg, ResponseValue responseVar, Textlist textlist, ref SvgRectangle rectangle, ref SvgTextSpan svgText) { int textId = int.Parse(responseVar.value.ToString()); SvgColourServer rectColor = new SvgColourServer(Color.FromName(textlist.items[textId].bgColor)); rectangle.Fill = rectColor; svgText.Text = textlist.items[textId].value; SvgColourServer textColor = new SvgColourServer(Color.FromName(textlist.items[textId].textColor)); svgText.Fill = textColor; }
private void setGraphiclist(ResponseValue responseValue, Graphiclist graphiclistConfig, ref SvgImage svgElement) { int value = int.Parse(responseValue.value.ToString()); string path = graphiclistConfig.items[value].path; if (path.Contains(PathDef.PhysicalPath)) { path = path.Replace(PathDef.PhysicalPath, ""); } var newValue = path; svgElement.Href = newValue; }
/// <summary> /// Create a single response for a formfield /// </summary> /// <param name="value">A string representing the response value</param> /// <param name="formResponseID">The id of the formresponse</param> /// <param name="formFieldID">The id of the formfield</param> /// <param name="rCount">An int representing the repeatcount (-1 for roster/table, > 0 for roster children, 0 otherwise</param> public static void createResponseValue(string value, int formResponseID, int formFieldID, int rCount) { GRASPEntities db = new GRASPEntities(); var response = new ResponseValue(); response.value = value; response.FormResponseID = formResponseID; response.formFieldId = formFieldID; response.RVCreateDate = DateTime.Now; response.RVRepeatCount = rCount; db.ResponseValue.Add(response); db.SaveChanges(); }
public static string ToString(ResponseValue status) { switch (status) { case ResponseValue.Allowed: return(JsonAllowed); case ResponseValue.Scheduled: return(JsonScheduled); case ResponseValue.Disabled: return(JsonDisabled); case ResponseValue.InActiveHours: return(JsonInActiveHours); case ResponseValue.RejectedByApp: return(JsonRejectedByApp); } return(status.ToString()); }
public string GetValueJson() { string parameterValue; if (ResponseValue is IRangeValue rv) { parameterValue = rv.StringJsonValue; } else { parameterValue = ResponseValue?.ToString(); } return($"{{ \"Command\": \"{ResponseToCommand}\", " + $"\"Parameter\": \"{parameterValue}\" }} "); }
public async override Task <ResponseValue <TEntity> > GetValueAsync(TKey id) { var Entity = await repository.GetByIdAsync(id, Includes); if (Entity == null) { throw new AggregateRootNotFoundException <TKey>(id); } var response = new ResponseValue <TEntity> { Value = Entity }; return(response); }
public string Post([FromBody] string value) { try { JObject jsonObj = JObject.Parse(value); Dictionary <string, string> dictObj = jsonObj.ToObject <Dictionary <string, string> >(); List <String> myKeys = dictObj.Keys.ToList(); List <String> myValues = dictObj.Values.ToList(); Form tform = new Form(); for (int i = 0; i < myKeys.Count; i++) { Field tfield = new Field(); ResponseValue tvalue = new ResponseValue(); tfield.Name = myKeys[i]; tvalue.value = myValues[i]; tfield.Form = tform; tfield.Value = tvalue; tvalue.Field = tfield; tvalue.Form = tform; _context.Fields.Add(tfield); _context.Values.Add(tvalue); tform.Fields.Add(tfield); } _context.Forms.Add(tform); _context.SaveChanges(); return("success!"); } catch (Exception ex) { //System.Diagnostics.Debug.WriteLine(ex.ToString()); return(ex.ToString()); //return "There was an error"; } }
/// <summary> /// /// </summary> /// <param name="list"></param> /// <param name="projectId"></param> /// <returns></returns> private List <ResponseValue> getDBData(List <SchemeValue> list, int projectId) { object data = new object(); List <ResponseValue> responseList = new List <ResponseValue>(); List <string> dbNames = XMLHandler.readTag("dbName", projectId); db db = new db(dbNames[0], 12); foreach (var schemeValue in list) { object value = db.singleItemSelectPostgres(schemeValue.columnName, schemeValue.tableName, null); ResponseValue responseValue = new ResponseValue(); responseValue.Id = schemeValue.id; responseValue.Type = schemeValue.Type; responseValue.value = value; responseList.Add(responseValue); } db.connection.Close(); return(responseList); }
public async Task <IActionResult> Get(int id) { await _context.Forms .Include(fo => fo.Fields) .ThenInclude(field => field.Value) .Where(fo => fo.ID == id).ToListAsync(); var form = await _context.Forms.FindAsync(id); var fields = form.Fields; var ret_form = new Form(); ret_form.Fields = new List <Field>(); ret_form.ID = form.ID; foreach (Field fi in fields) { Field tmp_fi = new Field(); tmp_fi.Name = fi.Name; tmp_fi.ID = fi.ID; ResponseValue tmp_val = new ResponseValue(); tmp_val.value = fi.Value.value; tmp_val.ID = fi.Value.ID; tmp_fi.Value = tmp_val; ret_form.Fields.Add(tmp_fi); } if (form == null) { //System.Diagnostics.Debug.WriteLine(ex.ToString()); return(NotFound()); } return(Ok(ret_form)); }
private void setAgeBar(SvgDocument svg, ResponseValue responseValue, AgeBar ageBar, ref SvgRectangle rectangle, ref SvgRectangle defaultRectangle, bool vertical = false) { float value = float.Parse(responseValue.value.ToString()); if (vertical == false) { var widthType = defaultRectangle.Width.Type; float widthValue = (defaultRectangle.Width.Value / ageBar.maxAge) * value; SvgUnit width = new SvgUnit(widthType, widthValue); if (widthValue > ageBar.firstLimit && widthValue < ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.firstColor)); rectangle.Fill = rectangleColor; } else if (widthValue > ageBar.secLimit) { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.secondColor)); rectangle.Fill = rectangleColor; } else { SvgColourServer rectangleColor = new SvgColourServer(Color.FromName(ageBar.thirdColor)); rectangle.Fill = rectangleColor; } rectangle.Width = width; } else { var c = Color.FromName(ageBar.thirdColor); //initial height is missing in config SvgColourServer rectangleColor = new SvgColourServer(c); rectangle.Fill = rectangleColor; var heightType = defaultRectangle.Height.Type; float heightValue = (defaultRectangle.Height.Value / ageBar.maxAge) * value; SvgUnit height = new SvgUnit(heightType, heightValue); rectangle.Height = heightValue; } }
private void refreshDynValue(SvgConfig config, SvgDocument svg, ResponseValue responseVar) { if (config.SchemeTags.Exists(p => p.id == responseVar.Id)) { var dynValueconfig = config.SchemeTags.First(p => p.id == responseVar.Id); SvgTextSpan element; int j = 0; while (j < 1000) { string id = responseVar.Id + "#" + j; if (svg.GetElementById(id) is SvgTextSpan) { element = (SvgTextSpan)svg.GetElementById(id); setDynValue(responseVar, dynValueconfig, ref element); break; } else { j++; } } } }
private void refreshGraphicList(SvgConfig config, SvgDocument svg, ResponseValue responseVar) { string name = config.BindingTags.First(p => p.id == responseVar.Id).name; string idG = config.BindingTags.First(p => p.id == responseVar.Id).id; config.SchemeGraphicsList.First(p => p.name == name).id = idG; Graphiclist graphiclistConfig = config.SchemeGraphicsList.First(p => p.id == responseVar.Id); int i = 0; while (i < 1000) { string id = responseVar.Id + "#" + i; if (svg.GetElementById(id) is SvgImage) { var element = (SvgImage)svg.GetElementById(id); setGraphiclist(responseVar, graphiclistConfig, ref element); break; } else { i++; } } }
/// <summary> /// 接收 /// </summary> /// <param name="data"></param> /// <returns></returns> public ClientReport clientReportSerialize(byte[] data) { HandelControls theHandelControls = HandelControls.createHandelControls(); ClientReport theClientReport = new ClientReport(); try { theClientReport.HEAD_FIELD = data[0]; theClientReport.REPORT_LENGTH = data.Skip(1).Take(4).ToArray(); byte[] dataLength = data.Skip(1).Take(4).ToArray(); int dataLengthInt = returnByteLengthRight(dataLength); data = data.Skip(0).Take(dataLengthInt).ToArray(); theClientReport.CONTROL_FIELD = data[5]; // theClientReport.REPORT_BODY = data.Skip(6).Take(dataLengthInt-8); theClientReport.END_FIELD = data[data.Length - 1]; data = data.Skip(6).Take(dataLengthInt - 8).ToArray(); int fileCount = 0; //默认文件长度; int nowIndex = 0; //当前位置; int dataCount = 0; TheCatalog theCatalog = new TheCatalog(); //文件目录 CatalogFiles theCatalogFiles = new CatalogFiles(); //文件 TheRemoteDataArray theRemoteDataArray = new TheRemoteDataArray(); //遥信 ResponseValueData theResponseValue = new ResponseValueData(); //设定值 switch (theClientReport.CONTROL_FIELD) { case 0x02: returnLoginInfo theReturnLoginInfo = new returnLoginInfo(); byte[] theByte = data; theReturnLoginInfo.isOk = theByte[0]; theClientReport.REPORT_BODY = theReturnLoginInfo; break; case 0x03: byte[] checkData = data; DeviceData theTreeArrayData = new DeviceData(); theTreeArrayData.theDeviceData = new List <DeviceDataInfo>(); int count = checkData[0]; checkData = checkData.Skip(1).ToArray(); while (count > 0) { DeviceDataInfo theDeviceDataInfo = new DeviceDataInfo(); int ct = checkData.Skip(nowIndex).Take(1).ToArray()[0];//设备名称长度 theDeviceDataInfo.DeviceName = checkData.Skip(nowIndex + 1).Take(ct).ToArray <byte>(); theDeviceDataInfo.DeviceAddress = checkData.Skip(nowIndex + ct + 1).Take(2).ToArray <byte>(); theDeviceDataInfo.DeviceStatue = checkData.Skip(nowIndex + ct + 3).Take(1).ToArray()[0]; theDeviceDataInfo.DeviceLastOnline = checkData.Skip(nowIndex + ct + 4).Take(7).ToArray(); nowIndex += ct + 11; theTreeArrayData.theDeviceData.Add(theDeviceDataInfo); count--; } theClientReport.REPORT_BODY = theTreeArrayData; break; case 0x05: byte[] checkCatalogData = data; theCatalog.DEVICE_ADDRESS = checkCatalogData.Take(2).ToArray <byte>(); //设备地址 theCatalog.FILES_COUNT = checkCatalogData[2]; //文件数量 fileCount = theCatalog.FILES_COUNT; theCatalog.THE_CATALOG_FILES = new List <CatalogFiles>(); byte[] nowCatalogData = checkCatalogData.Skip(3).Take(checkCatalogData.Length - 2).ToArray <byte>(); while (fileCount > 0) { CatalogFiles catalogFiles = new CatalogFiles(); catalogFiles.FILE_LENGTH = nowCatalogData[nowIndex]; catalogFiles.FILE_NAME = nowCatalogData.Skip(nowIndex + 1).Take(catalogFiles.FILE_LENGTH).ToArray <byte>(); theCatalog.THE_CATALOG_FILES.Add(catalogFiles); nowIndex += catalogFiles.FILE_LENGTH + 1; fileCount--; } theClientReport.REPORT_BODY = theCatalog; break; case 0x07: byte[] updateCatalogData = data; theCatalogFiles.DeviceAddress = updateCatalogData.Take(2).ToArray <byte>(); //文件地址 theCatalogFiles.FILE_LENGTH = updateCatalogData[2]; //文件名长度 theCatalogFiles.FILE_NAME = updateCatalogData.Skip(3).Take(theCatalogFiles.FILE_LENGTH).ToArray <byte>(); //文件名 int fileContent = theCatalogFiles.FILE_NAME.Length + 3; theCatalogFiles.FILE_CONTENT = updateCatalogData.Skip(fileContent).ToArray <byte>(); //文件长度 theClientReport.REPORT_BODY = theCatalogFiles; break; case 0x10: //遥信返回(不带时标) byte[] notHaveTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = notHaveTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = notHaveTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥信"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); notHaveTimeMark = notHaveTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.RemoteAddress = notHaveTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = notHaveTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>(); nowIndex = nowIndex + 3; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x11: //遥信返回(带时标) byte[] haveTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = haveTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = haveTimeMark[2]; theRemoteDataArray.THE_COUNT = haveTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥信"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); haveTimeMark = haveTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.RemoteAddress = haveTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = haveTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>(); theRemoteData.LastestModify = haveTimeMark.Skip(nowIndex + 3).Take(7).ToArray <byte>(); nowIndex = nowIndex + 10; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x12: //遥测 byte[] telemeteringTimeMark = data; theRemoteDataArray.DEVICE_ADDRESS = telemeteringTimeMark.Take(2).ToArray <byte>(); theRemoteDataArray.THE_COUNT = telemeteringTimeMark[2]; theRemoteDataArray.THE_TYPE_NAME = "遥测"; fileCount = theRemoteDataArray.THE_COUNT; theRemoteDataArray.THE_REMOTE_DATA = new List <TheRemoteData>(); telemeteringTimeMark = telemeteringTimeMark.Skip(3).ToArray <byte>(); while (fileCount > 0) { TheRemoteData theRemoteData = new TheRemoteData(); theRemoteData.LastestModify = new byte[] { 0x00 }; theRemoteData.RemoteAddress = telemeteringTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); theRemoteData.RemoteValue = telemeteringTimeMark.Skip(nowIndex + 2).Take(2).ToArray <byte>(); theRemoteData.quility = telemeteringTimeMark.Skip(nowIndex + 4).Take(1).ToArray <byte>()[0]; nowIndex = nowIndex + 5; fileCount--; theRemoteDataArray.THE_REMOTE_DATA.Add(theRemoteData); } theClientReport.REPORT_BODY = theRemoteDataArray; theThreadMethod = new Thread(forEachList); theThreadMethod.IsBackground = true; theThreadMethod.Start(theRemoteDataArray); break; case 0x14: byte[] responseValueTimeMark = data; theResponseValue.DEVICE_ADDRESS = responseValueTimeMark.Take(2).ToArray <byte>(); theResponseValue.VALUE_TYPE = responseValueTimeMark[2]; theResponseValue.VALUE_COUNT = responseValueTimeMark[3]; fileCount = theResponseValue.VALUE_COUNT; theResponseValue.theResponseValueArray = new List <ResponseValue>(); responseValueTimeMark = responseValueTimeMark.Skip(4).ToArray <byte>(); while (fileCount > 0) { ResponseValue rsponseValue = new ResponseValue(); rsponseValue.VALUE_ADDRESS = responseValueTimeMark.Skip(nowIndex).Take(2).ToArray <byte>(); int length = responseValueTimeMark.Skip(nowIndex + 2).Take(1).ToArray <byte>()[0]; rsponseValue.VALUE = responseValueTimeMark.Skip(nowIndex + 3).Take(length).ToArray <byte>(); nowIndex = nowIndex + 3 + length; theResponseValue.theResponseValueArray.Add(rsponseValue); fileCount--; } theClientReport.REPORT_BODY = theResponseValue; break; case 0x0a: byte[] contentText = data; ReportContentText theReportContent = new ReportContentText(); theReportContent.ReportType = contentText[0]; theReportContent.ReportDateTime = contentText.Skip(1).Take(7).ToArray <byte>(); theReportContent.ReportContent = contentText.Skip(8).ToArray <byte>(); theClientReport.REPORT_BODY = theReportContent; break; case 0x21: byte[] writeBytes = data; WriteFile theWriteFile = new WriteFile(); theWriteFile.DEVICE_ADDRESS = writeBytes.Take(2).ToArray(); theWriteFile.FILE_LENGTH = writeBytes.Skip(2).Take(1).ToArray()[0]; theWriteFile.FILE_NAME = writeBytes.Skip(3).Take(theWriteFile.FILE_LENGTH).ToArray(); theWriteFile.FILE_COUNT = writeBytes.Skip(3 + theWriteFile.FILE_LENGTH).ToArray(); break; case 0x23: //接收变电站 List <ConvertingStation> theConvertingStationArray = new List <ConvertingStation>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { ConvertingStation theConvertingStation = new ConvertingStation(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theConvertingStation.stationName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theConvertingStation.stationRemarks = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theConvertingStation.stationID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theConvertingStationArray.Add(theConvertingStation); } theClientReport.REPORT_BODY = theConvertingStationArray; break; case 0x24: //接收母线 List <Generatrix> theGeneratrixArray = new List <Generatrix>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Generatrix theGeneratrix = new Generatrix(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theGeneratrix.GeneratrixID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int convertingLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theGeneratrix.GeneratrixToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingLength).ToArray(), "utf-8"); nowIndex += convertingLength; theGeneratrix.GeneratrixToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theGeneratrixArray.Add(theGeneratrix); } theClientReport.REPORT_BODY = theGeneratrixArray; break; case 0x25: //接收线路 List <Circuit> theCircuitArray = new List <Circuit>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Circuit theCircuit = new Circuit(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int remarksLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(remarksLength).ToArray(), "utf-8"); nowIndex += remarksLength; theCircuit.CircuitID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int convertingLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theCircuit.CircuitToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingLength).ToArray(), "utf-8"); nowIndex += convertingLength; theCircuit.CircuitToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theCircuitArray.Add(theCircuit); } theClientReport.REPORT_BODY = theCircuitArray; break; case 0x26: //接收检测点 List <Detection> theDetectionArray = new List <Detection>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { Detection theDetection = new Detection(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); nowIndex += convertingNameLength; int theNumber = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionNumber = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(theNumber).ToArray(), "utf-8"); nowIndex += theNumber; theDetection.DetectionID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int detectionToSecondName = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionToSecondName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(detectionToSecondName).ToArray(), "utf-8"); nowIndex += detectionToSecondName; theDetection.DetectionToSecondID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; theDetection.RemoteA = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; theDetection.RemoteB = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; theDetection.RemoteC = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()); nowIndex += 2; int circuitLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DetectionToName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(circuitLength).ToArray(), "utf-8"); nowIndex += circuitLength; theDetection.DetectionToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theDetectionArray.Add(theDetection); } theClientReport.REPORT_BODY = theDetectionArray; break; case 0x33: List <DeviceDataSetting> theDeviceDataArray = new List <DeviceDataSetting>(); dataCount = returnByteLengthRight(data.Take(4).ToArray()); data = data.Skip(4).ToArray(); while (dataCount > 0) { DeviceDataSetting theDetection = new DeviceDataSetting(); int convertingNameLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.DeviceDataName = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(convertingNameLength).ToArray(), "utf-8"); //ok nowIndex += convertingNameLength; theDetection.DeviceDataID = ByteWithString.byteToHexStr(data.Skip(nowIndex).Take(2).ToArray()).ToString(); nowIndex += 2; theDetection.LastDateTime = ByteWithString.ConvertCP56TIME2aToDateTime(data.Skip(nowIndex).Take(7).ToArray()).ToString("yyyy-MM-dd HH:mm:ss"); nowIndex += 7; int ALength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteA = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(ALength).ToArray(), "utf-8"); nowIndex += ALength; theDetection.RemoteAToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int BLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteB = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(BLength).ToArray(), "utf-8"); nowIndex += BLength; theDetection.RemoteBToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; int CLength = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()); nowIndex += 4; theDetection.TheRemoteC = ByteWithString.bytetoCodeString(data.Skip(nowIndex).Take(CLength).ToArray(), "utf-8"); nowIndex += CLength; theDetection.RemoteCToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; theDetection.DeviceDataToID = returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray()).ToString(); nowIndex += 4; dataCount--; theDeviceDataArray.Add(theDetection); } theClientReport.REPORT_BODY = theDeviceDataArray; break; case 0x35: List <int> valueBuilder = new List <int>(); valueBuilder.Add(returnByteLengthRight(data.Skip(0).Take(4).ToArray())); valueBuilder.Add(returnByteLengthRight(data.Skip(4).Take(4).ToArray())); valueBuilder.Add(returnByteLengthRight(data.Skip(8).Take(4).ToArray())); theClientReport.REPORT_BODY = valueBuilder; break; case 0x38: Hitch theHitch = new Hitch(); theHitch.COUNT = dataCount = returnByteLengthRight(data.Take(4).ToArray()); theHitch.NOW_ID = new List <int>(); data = data.Skip(4).ToArray(); while (dataCount > 0) { theHitch.NOW_ID.Add(returnByteLengthRight(data.Skip(nowIndex).Take(4).ToArray())); nowIndex += 4; dataCount--; } theClientReport.REPORT_BODY = theHitch; break; default: break; } theClientReport.VALIDATE_FIELD = data.Skip(data.Length - 2).Take(1).ToArray()[0]; theClientReport.END_FIELD = 0x16; } catch (Exception msg) { Log.LogWrite(msg); } return(theClientReport); }
private ResponseValue getDataFromSnapshot(SvgConfig config, SchemeValue tag, int projectId) { Snapshot snapshot = new Snapshot(); string pathToDataForThisDay; if (PathDef.PhysicalPath.EndsWith(@"\")) { pathToDataForThisDay = PathDef.PhysicalPath + DateTime.Now.ToShortDateString(); } else { pathToDataForThisDay = PathDef.PhysicalPath + @"\" + DateTime.Now.ToShortDateString(); } if (pathToDataForThisDay.Contains("/")) { pathToDataForThisDay = pathToDataForThisDay.Replace("/", "."); } if (Directory.Exists(pathToDataForThisDay) == true) { string pathToDataForThisDayAndThisProject = pathToDataForThisDay + @"\" + projectId; if (Directory.Exists(pathToDataForThisDayAndThisProject) == true) { FileStream fileStreamOfBinData = System.IO.File.OpenRead(pathToDataForThisDayAndThisProject + @"\data.bin"); BinaryFormatter binaryFormatter = new BinaryFormatter(); snapshot = (Snapshot)binaryFormatter.Deserialize(fileStreamOfBinData); //here should be only one element RequestValue value = snapshot.SnapshotValues.FirstOrDefault( p => tag.id.EndsWith(p.tableName) && tag.id.StartsWith(p.columnName)); ResponseValue responseValue = new ResponseValue(); if (value != null) { if (value.sValue != null) { responseValue.value = value.sValue; } else { responseValue.value = 0; if (value.rValue != 0) { responseValue.value = value.rValue; } if (value.iValue != 0) { responseValue.value = value.iValue; } } var bindingTag = config.BindingTags.FirstOrDefault( p => p.id.EndsWith(value.tableName) && p.id.StartsWith(value.columnName)); if (bindingTag != null) { responseValue.Id = bindingTag.id; responseValue.Type = bindingTag.Type; return(responseValue); } } } else { Error.toFile("Warning no data found on : " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), this.GetType().ToString()); } } else { Error.toFile("Warning no data found on : " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), this.GetType().ToString()); } return(null); }
/// <summary> /// /// </summary> /// <param name="responseValue"></param> /// <param name="fieldType"></param> /// <author>Saad Mansour</author> private static void UpdateNumericAndDate(ResponseValue responseValue, string fieldType) { try { if (fieldType.Length != 0) { switch (fieldType) { case "NUMERIC_TEXT_FIELD": double nvalue = 0; if (responseValue.value.Length != 0) { Double.TryParse(responseValue.value, out nvalue); } responseValue.nvalue = nvalue; break; case "DATE_FIELD": DateTime dvalue; if (DateTime.TryParse(responseValue.value, out dvalue)) { responseValue.dvalue = dvalue; } break; } } } catch (Exception ex) { LogUtils.WriteErrorLog(ex.ToString()); } }
public ReportedProperties(ResponseValue r) { response = ToString(r); }