private bool TuneMethodsMatch(TuneMethod udtMethod1, TuneMethod udtMethod2) { if (udtMethod1.Settings.Count != udtMethod2.Settings.Count) { // Different segment number of setting count; the methods don't match return false; } for (var intIndex = 0; intIndex <= udtMethod1.Settings.Count - 1; intIndex++) { if (udtMethod1.Settings[intIndex].Category != udtMethod2.Settings[intIndex].Category || udtMethod1.Settings[intIndex].Name != udtMethod2.Settings[intIndex].Name || udtMethod1.Settings[intIndex].Value != udtMethod2.Settings[intIndex].Value) { // Different segment data; the methods don't match return false; } } return true; }
private void GetTuneData() { var numTuneData = 0; mXRawFile.GetNumTuneData(ref numTuneData); for (var index = 0; index <= numTuneData - 1; index++) { var tuneLabelCount = 0; object objLabels = null; object objValues = null; string msg; try { if (!mCorruptMemoryEncountered) { mXRawFile.GetTuneData(index, ref objLabels, ref objValues, ref tuneLabelCount); } } catch (AccessViolationException) { msg = "Unable to load tune data; possibly a corrupt .Raw file"; RaiseWarningMessage(msg); break; } catch (Exception ex) { // Exception getting TuneData msg = "Warning: Exception calling mXRawFile.GetTuneData for Index " + index + ": " + ex.Message; RaiseWarningMessage(msg); tuneLabelCount = 0; if (ex.Message.ToLower().Contains("memory is corrupt")) { mCorruptMemoryEncountered = true; break; } } if (tuneLabelCount > 0) { msg = string.Empty; if (objLabels == null) { // .GetTuneData returned a non-zero count, but no parameter names; unable to continue msg = "Warning: the GetTuneData function returned a positive tune parameter count but no parameter names"; } else if (objValues == null) { // .GetTuneData returned parameter names, but objValues is nothing; unable to continue msg = "Warning: the GetTuneData function returned tune parameter names but no tune values"; } if (msg.Length > 0) { msg += " (Tune Method " + (index + 1) + ")"; RaiseWarningMessage(msg); tuneLabelCount = 0; } } if (tuneLabelCount <= 0 || objLabels == null || objValues == null) { continue; } var newTuneMethod = new TuneMethod(); newTuneMethod.Clear(); var tuneSettingNames = ((IEnumerable)objLabels).Cast<object>() .Select(x => x.ToString()) .ToArray(); var tuneSettingValues = ((IEnumerable)objValues).Cast<object>() .Select(x => x.ToString()) .ToArray(); // Step through the names and store in the .Setting() arrays var tuneCategory = "General"; for (var settingIndex = 0; settingIndex <= tuneLabelCount - 1; settingIndex++) { if (tuneSettingValues[settingIndex].Length == 0 && !tuneSettingNames[settingIndex].EndsWith(":")) { // New category if (tuneSettingNames[settingIndex].Length > 0) { tuneCategory = string.Copy(tuneSettingNames[settingIndex]); } else { tuneCategory = "General"; } } else { var tuneMethodSetting = new udtTuneMethodSetting() { Category = string.Copy(tuneCategory), Name = tuneSettingNames[settingIndex].TrimEnd(':'), Value = string.Copy(tuneSettingValues[settingIndex]) }; newTuneMethod.Settings.Add(tuneMethodSetting); } } if (mFileInfo.TuneMethods.Count == 0) mFileInfo.TuneMethods.Add(newTuneMethod); else { // Compare this tune method to the previous one; if identical, then don't keep it if (!TuneMethodsMatch(mFileInfo.TuneMethods.Last(), newTuneMethod)) { mFileInfo.TuneMethods.Add(newTuneMethod); } } } }