private static byte[] GetResult_ByteArray(string resultName, List <Dictionary <string, EdiabasNet.ResultData> > resultSets) { byte[] result = null; if (resultSets != null) { foreach (Dictionary <string, EdiabasNet.ResultData> dictionary in resultSets) { foreach (string key in from x in dictionary.Keys orderby x select x) { EdiabasNet.ResultData resultData = dictionary[key]; if (resultData.Name == resultName && resultData.OpData.GetType() == typeof(byte[])) { result = (byte[])resultData.OpData; } } } } return(result); }
private static string GetResult_String(string resultName, List <Dictionary <string, EdiabasNet.ResultData> > resultSets) { string result = string.Empty; if (resultSets != null) { foreach (Dictionary <string, EdiabasNet.ResultData> dictionary in resultSets) { foreach (string key in from x in dictionary.Keys orderby x select x) { EdiabasNet.ResultData resultData = dictionary[key]; if (resultData.Name == resultName && resultData.OpData is string) { result = (string)resultData.OpData; } } } } return(result); }
static void PrintResults(List <string> formatList, bool printAllTypes, List <Dictionary <string, EdiabasNet.ResultData> > resultSets) { int dataSet = 0; if (resultSets != null) { if (resultSets.Count > 0) { EdiabasNet.ResultData resultData; if (resultSets[0].TryGetValue("VARIANTE", out resultData)) { string data = resultData.OpData as string; if (data != null) { _outputWriter.WriteLine("Variant: " + data); } } } foreach (Dictionary <string, EdiabasNet.ResultData> resultDict in resultSets) { _outputWriter.WriteLine(string.Format(Culture, "DATASET: {0}", dataSet)); foreach (string key in resultDict.Keys.OrderBy(x => x)) { EdiabasNet.ResultData resultData = resultDict[key]; string resultText = string.Empty; if (resultData.OpData is string) { resultText = (string)resultData.OpData; } else if (resultData.OpData is double) { resultText = string.Format(Culture, "R: {0}", (Double)resultData.OpData); } else if (resultData.OpData is long) { Int64 value = (Int64)resultData.OpData; switch (resultData.ResType) { case EdiabasNet.ResultType.TypeB: // 8 bit resultText = string.Format(Culture, "B: {0} 0x{1:X02}", value, (Byte)value); break; case EdiabasNet.ResultType.TypeC: // 8 bit char resultText = string.Format(Culture, "C: {0} 0x{1:X02}", value, (Byte)value); break; case EdiabasNet.ResultType.TypeW: // 16 bit resultText = string.Format(Culture, "W: {0} 0x{1:X04}", value, (UInt16)value); break; case EdiabasNet.ResultType.TypeI: // 16 bit signed resultText = string.Format(Culture, "I: {0} 0x{1:X04}", value, (UInt16)value); break; case EdiabasNet.ResultType.TypeD: // 32 bit resultText = string.Format(Culture, "D: {0} 0x{1:X08}", value, (UInt32)value); break; case EdiabasNet.ResultType.TypeL: // 32 bit signed resultText = string.Format(Culture, "L: {0} 0x{1:X08}", value, (UInt32)value); break; default: resultText = "?"; break; } } else if (resultData.OpData.GetType() == typeof(byte[])) { byte[] data = (byte[])resultData.OpData; foreach (byte value in data) { resultText += string.Format(Culture, "{0:X02} ", value); } } if (printAllTypes) { if ((resultData.OpData is long) || (resultData.OpData is double)) { resultText += " ALL: "; if (resultData.OpData is long) { Int64 value = (Int64)resultData.OpData; resultText += string.Format(Culture, " {0}", (sbyte)value); resultText += string.Format(Culture, " {0}", (byte)value); resultText += string.Format(Culture, " {0}", (short)value); resultText += string.Format(Culture, " {0}", (ushort)value); resultText += string.Format(Culture, " {0}", (int)value); resultText += string.Format(Culture, " {0}", (uint)value); resultText += string.Format(Culture, " {0}", (double)value); } else { Double valueDouble = (Double)resultData.OpData; Int64 value = (Int64)valueDouble; resultText += string.Format(Culture, " {0}", (sbyte)value); resultText += string.Format(Culture, " {0}", (byte)value); resultText += string.Format(Culture, " {0}", (short)value); resultText += string.Format(Culture, " {0}", (ushort)value); resultText += string.Format(Culture, " {0}", (int)value); resultText += string.Format(Culture, " {0}", (uint)value); resultText += string.Format(Culture, " {0}", valueDouble); } } } foreach (string format in formatList) { string[] words = format.Split(new[] { '=' }, 2); if (words.Length == 2) { if (string.Compare(words[0], resultData.Name, StringComparison.OrdinalIgnoreCase) == 0) { string resultString = EdiabasNet.FormatResult(resultData, words[1]); if (resultString != null) { resultText += " F: '" + resultString + "'"; } else { ErrorRaisedFunc(EdiabasNet.ErrorCodes.EDIABAS_API_0005); } } } } _outputWriter.WriteLine(resultData.Name + ": " + resultText); } dataSet++; } _outputWriter.WriteLine(); } }