// Private Methods (1) /// <summary> /// Fills this instance data members with the information read from <paramref name="wiffFile"/>. /// </summary> /// <param name="wiffFile">A <see cref="FMANWiffFileClass"/> instance. The data source.</param> private void Initialize(FMANWiffFileClass wiffFile) { // retrieve this sample's name name = wiffFile.GetSampleName(index); // get the position information for the selected sample // the position data exists in a seperate file ( one per sample ) // and is read from that file 'manually' AppContext.ProgressStart("reading path file"); try { string pathFile = wiffFileContent.FileName + " (" + index.ToString() + ").path"; FileStream positionStream = new FileStream(@pathFile, FileMode.Open, FileAccess.Read); // calculate the count of position entries positionDataLength = positionStream.Length / 12; // 12 Byte per position entry // the array to hold the position information positionData = new uint[positionDataLength, 3]; BinaryReader positionReader = new BinaryReader(positionStream); for (long i = 0; i < positionDataLength; i++) { positionData[i, 0] = positionReader.ReadUInt32(); positionData[i, 1] = positionReader.ReadUInt32(); positionData[i, 2] = positionReader.ReadUInt32(); if ((i % (positionDataLength / 100.0)) == 0) // hundred progress ticks { AppContext.ProgressSetValue(100.0 * i / positionDataLength); } } positionReader.Close(); positionStream.Close(); } finally { AppContext.ProgressClear(); } #if (false) string csvPosFile = wiffFileContent.FileName + " (" + index.ToString() + ").path" + ".csv"; using (FileStream csvPosStream = new FileStream(@csvPosFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(csvPosStream)) { for (long i = 0; i < positionDataLength; i++) { sw.Write(positionData[i, 0]); sw.Write(','); sw.Write(positionData[i, 1]); sw.Write(','); sw.Write(positionData[i, 2]); sw.WriteLine(); } } } #endif // get user data of the selected sample string userData = wiffFile.GetUserData(index); if (!string.IsNullOrEmpty(userData)) { //width in mm x2 = float.Parse(userData.Split(',')[2]); x1 = float.Parse(userData.Split(',')[0]); width = x2 - x1; //height in mm y2 = float.Parse(userData.Split(',')[3]); y1 = float.Parse(userData.Split(',')[1]); height = y2 - y1; } // get the number of periods int nrPeriods = wiffFile.GetActualNumberOfPeriods(index); // loop through the periods; the index of the periods is zero based!! for (int actPeriod = 0; actPeriod < nrPeriods; actPeriod++) { WiffPeriod period = new WiffPeriod(wiffFile, this, actPeriod); periods.Add(period); } }
/// <summary> /// Load the wiff file's content. /// </summary> /// <returns>A <see cref="bool"/> value indicating the success of the loading.</returns> public bool LoadContent() { #if (COPY_LOCAL) string tempFile = ""; #endif bool result = false; FMANWiffFileControlClass wiffFileControl = null; FMANWiffFileClass wiffFile = null; try { string fileToOpen = fileName; #if (COPY_LOCAL) // if file is not local, copy it to the users tempdir string uncName = Util.PathToUnc(fileName); if (!string.IsNullOrEmpty(uncName)) { string tempDir = Path.GetTempPath(); string file = Path.GetFileName(uncName); tempFile = Path.Combine(tempDir, file); fileToOpen = tempFile; File.Copy(fileName, fileToOpen, true); // and the scan file if (File.Exists(fileName + ".scan")) { File.Copy(fileName + ".scan", fileToOpen + ".scan", true); } } #endif wiffFileControl = new FMANWiffFileControlClass(); // get wiff file object from given file wiffFile = (FMANWiffFileClass)wiffFileControl.GetWiffFileObject(fileToOpen, 1); // get number of samples int nrSamples = wiffFile.GetActualNumberOfSamples(); #if (false) // let the user select one sample to be processed string[] sampleNames = new string[nrSamples]; // the index for the samples in the wiff file is based 1 !! int actSample; for (actSample = 1; actSample <= nrSamples; actSample++) { sampleNames[actSample - 1] = wiffFile.GetSampleName(actSample); } if (nrSamples > 1) { // get the sample which is actually to be used... SelectSampleDlg selectSample = new SelectSampleDlg(sampleNames); selectSample.Owner = AppContext.MainWindow; selectSample.ShowDialog(); if (selectSample.DialogResult == true) { actSample = selectSample.SelectedSampleIndex; } else if (selectSample.DialogResult == false) { return(false); } } else { // just one sample in wiff file actSample = 1; } // create and add the singular sample to this objects list of samples... WiffSample sample = new WiffSample(wiffFile, actSample); samples.Add(sample); #else // create sample objects for all the samples present in the wiff file // the index for the samples in the wiff file is based 1 !! for (int actSample = 1; actSample <= nrSamples; actSample++) { // create and add the sample to this objects list of samples... WiffSample sample = new WiffSample(wiffFile, this, actSample); samples.Add(sample); } #endif result = true; } catch (Exception e) { Util.ReportException(e); result = false; } finally { try { if (wiffFile != null) { wiffFile.CloseWiffFile(); wiffFile = null; } wiffFileControl = null; #if (COPY_LOCAL) if (!string.IsNullOrEmpty(tempFile) && File.Exists(tempFile)) { File.Delete(tempFile); if (File.Exists(tempFile + ".scan")) { File.Delete(tempFile + ".scan"); } } #endif } catch (Exception) { } } return(result); }