// Take the collection of samples the user gave us, and convert them into the underlying format. private void StoreTwo() { List<OtherItemDataCsvItem> rawSamples = new List<OtherItemDataCsvItem>(); double currentSamplingInterval = SamplingInterval; double lastOffset = -SamplingInterval; for (int sampleNumber = 0; sampleNumber < _twoValuedSamples.Count; sampleNumber++) { ExerciseSampleTwoValue sample = _twoValuedSamples[sampleNumber]; // Is this sample coming when it's expected? // if not, we need to put in an escape... if (lastOffset + currentSamplingInterval != sample.OffsetInSeconds) { currentSamplingInterval = sample.OffsetInSeconds - lastOffset; OtherItemDataCsvEscape escape = new OtherItemDataCsvEscape("i", currentSamplingInterval.ToString()); rawSamples.Add(escape); } rawSamples.Add(new OtherItemDataCsvDouble(sample.Value1)); rawSamples.Add(new OtherItemDataCsvDouble(sample.Value2)); lastOffset = sample.OffsetInSeconds; } SetOtherData(rawSamples); }
/// <summary> /// Parse the comma-separated representation into an array of strings. /// </summary> /// <remarks> /// When this method returns, the Escapes collection will contain any /// escapes encountered during the parsing. /// </remarks> /// <returns>A collection of the strings.</returns> /// <exception cref="ArgumentException"> /// If the content type is not "text/csv". /// </exception> /// <exception cref="ArgumentNullException"> /// If the Data section is null. /// </exception> protected Collection<OtherItemDataCsvItem> GetAsString() { Validator.ThrowArgumentExceptionIf( ContentType != "text/csv", "contentType", "OtherItemDataFormat"); Validator.ThrowIfArgumentNull(Data, "Data", "OtherItemDataNull"); Collection<OtherItemDataCsvItem> values = new Collection<OtherItemDataCsvItem>(); List<string> stringValues = BreakStringAtCharacter(Data, ','); for (int i = 0; i < stringValues.Count; i++) { // Get current value, remove any comma escapes (no longer needed)... string current = stringValues[i].Replace(@"\,", ","); // See if this is a name=value escape... List<string> escapeParts = BreakStringAtCharacter(current, '='); for (int parts = 0; parts < escapeParts.Count; parts++) { escapeParts[0] = escapeParts[0].Replace(@"\=", "="); escapeParts[0] = escapeParts[0].Replace(@"\\", @"\"); } if (escapeParts.Count >= 2) { OtherItemDataCsvEscape escapeItem = new OtherItemDataCsvEscape(escapeParts[0], escapeParts[1]); values.Add(escapeItem); } else { values.Add(new OtherItemDataCsvString(escapeParts[0])); } } return values; }