Exemple #1
0
        private void extractData(string _pathToZip, string _destinationPath, Ionic.Zip.ZipFile _newZip, List <string> _folderList, List <string> _fileList, List <string> _zipList, List <string> _internalZipList, string _pathOfNewZip, bool _keepUnproccessedData, ref List <string> _summaryText)
        {
            string pathToAdd           = makeRelative(_pathToZip, txtBox_Input.Text);
            string visiTagRelativePath = "";
            int    padLength           = 105 - pathToAdd.Length;
            int    numOfExtractions    = 0;
            bool   isVisiTagLoadError  = false;

            if (padLength < 0)
            {
                padLength = 0;
            }
            try
            {
                using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(_pathToZip))
                {
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;

                    foreach (Ionic.Zip.ZipEntry ze in zip)
                    {//Look at each entry and see if it is a match to extract.
                        string fileName             = ze.FileName;
                        bool   isThereItemToExtract = isThereMatch(fileName.ToLower(), _folderList, _fileList);
                        bool   isItInternalZip      = isMatchingZip(fileName.ToLower(), _internalZipList);

                        if (fileName.EndsWith("WiseTag/"))
                        {
                            visiTagRelativePath = ze.FileName;
                        }

                        if (isThereItemToExtract || isItInternalZip)
                        {
                            numOfExtractions++;
                            string pathOfFileToExtract = (_destinationPath + "\\" + ze.FileName).Replace('/', '\\');
                            string pathInNewZipFile    = goUpOneDirectoryRelative(ze.FileName);
                            ze.Extract(_destinationPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                            if (fileName.EndsWith(".mesh"))
                            {
                                meshToText(fileName, _destinationPath, _newZip);
                                if (_keepUnproccessedData)
                                {
                                    _newZip.AddItem(pathOfFileToExtract, pathInNewZipFile);
                                }
                            }
                            else
                            {
                                if (!(fileName.Contains("/WiseTag/") && (_keepUnproccessedData == false)))
                                {
                                    _newZip.AddItem(pathOfFileToExtract, pathInNewZipFile);
                                }
                            }
                            if (isItInternalZip)
                            {
                                using (Ionic.Zip.ZipFile internalZip = Ionic.Zip.ZipFile.Read(pathOfFileToExtract))
                                {
                                    internalZip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;
                                    foreach (Ionic.Zip.ZipEntry zie in internalZip)
                                    {
                                        string internalFileName = zie.FileName;
                                        if (isThereMatch(internalFileName.ToLower(), _folderList, _fileList))
                                        {
                                            string extractionPath = goUpOneDirectoryAbsolute(pathOfFileToExtract);             //path of where to extract the internal zip contents.
                                            string filePath       = (extractionPath + "\\" + zie.FileName).Replace('/', '\\'); //path of directory to be saved inside the zipfile
                                            zie.Extract(extractionPath, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently);
                                            _newZip.AddItem(filePath, pathInNewZipFile);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    _newZip.Save();
                }
            }
            catch (Ionic.Zip.BadReadException)
            {//If zip file is unreadable.
                string name = getLastDirectoryName(_pathToZip);
                if (name.Contains(".zip"))
                {
                    _summaryText.Add(pathToAdd + "Unable to Read".PadLeft(padLength));
                    txtbox_Summary.AppendText(pathToAdd + "Unable to Read".PadLeft(padLength) + "\r\n");
                    txtbox_Summary.Update();
                    System.IO.File.Delete(_newZip.Name);
                }
            }
            catch (Ionic.Zip.ZipException)
            {//If zip file is unreadable.
                string name = getLastDirectoryName(_pathToZip);
                if (name.Contains(".zip"))
                {
                    _summaryText.Add(pathToAdd + "Unable to Read".PadLeft(padLength));
                    txtbox_Summary.AppendText(pathToAdd + "Unable To Read".PadLeft(padLength) + "\r\n");
                    txtbox_Summary.Update();
                    System.IO.File.Delete(_newZip.Name);
                }
            }
            string visiTagDirectory = "";

            getVisiTagPath(_destinationPath, ref visiTagDirectory);
            try
            {
                if (System.IO.Directory.Exists(visiTagDirectory))
                {
                    coretechlib.CartoMapReaderDotNet cmrdn = new coretechlib.CartoMapReaderDotNet();
                    string visiTagDirectoryOpen            = visiTagDirectory + "\\";
                    uint[] visiTagIDs = cmrdn.GetAllVisiTagIDs(visiTagDirectoryOpen);
                    if (visiTagIDs.Length != 0)
                    {
                        visiTagToText(visiTagIDs, visiTagDirectory, _destinationPath, visiTagRelativePath, _newZip, ref isVisiTagLoadError);
                    }
                    cmrdn = null;
                }
            }
            catch (System.Runtime.InteropServices.SEHException)
            {
            }
            if (numOfExtractions == 0)
            {
                _summaryText.Add(pathToAdd + "No Data".PadLeft(padLength));
                txtbox_Summary.AppendText(pathToAdd + "No Data".PadLeft(padLength) + "\r\n");
                txtbox_Summary.Update();
                System.IO.File.Delete(_newZip.Name);
            }
            else if (isVisiTagLoadError)
            {
                _summaryText.Add(pathToAdd + "Unable to Read VisiTag".PadLeft(padLength));
                txtbox_Summary.AppendText(pathToAdd + "Unable to read VisiTag".PadLeft(padLength) + "\r\n");
                txtbox_Summary.Update();
            }
            else
            {
                _summaryText.Add(pathToAdd + "Success".PadLeft(padLength));
                txtbox_Summary.AppendText(pathToAdd + "Success".PadLeft(padLength) + "\r\n");
                txtbox_Summary.Update();
            }
            deleteTempEntries(_destinationPath, _zipList);
        }
Exemple #2
0
        private void visiTagToText(uint[] _visiTagIDs, string _pathToVisiTag, string _destinationPath, string _fileName, Ionic.Zip.ZipFile _newZip, ref bool _isVisiTagLoadError)
        {
            string visiTagExportDirectory = _pathToVisiTag + "\\VisiTagExport";
            string fileNameWithoutWiseTag = goUpOneDirectoryRelative(goUpOneDirectoryRelative(_fileName));
            string txtFolderDestination   = fileNameWithoutWiseTag + "/VisiTagExport";

            coretechlib.CartoMapReaderDotNet cmr = new coretechlib.CartoMapReaderDotNet();
            System.IO.DirectoryInfo          di  = System.IO.Directory.CreateDirectory(visiTagExportDirectory);

            string allPosPath = visiTagExportDirectory + "\\AllPositions.txt";
            //string EndEmperiumPosPath = visiTagExportDirectory + "\\EndEmperium.txt";
            string VisiTagInfoPath     = visiTagExportDirectory + "\\VisiTagInfo.txt";
            string VisiTagSessionsPath = visiTagExportDirectory + "\\VisiTagSessions.txt";

            var allPositionsText = new List <string>();
            //var endEmperiumPosText = new List<string>();
            var visiTagInfoText     = new List <string>();
            var visiTagSessionsText = new List <string>();


            int numOfFilesRead = 0;

            allPositionsText.Add("\tVisiTagID\tSessionID\tAllPosTimeStamp\tAllPosValidStatus\tX\tY\tZ");
            //endEmperiumPosText.Add("\tVisiTagID\tSessionID\tEndEmpPosTimeStamp\tEndEmpValidStatus\tX\tY\tZ");
            visiTagSessionsText.Add("\tVisiTagID\tSessionID\tStartTs\tEndTs\tPresetID\tMapID");

            for (int i = 0; i < _visiTagIDs.Length; i++)
            {
                try
                {
                    object[] loadVisiTag = cmr.LoadVisiTagData(_pathToVisiTag + "\\", _visiTagIDs[i]);
                    string   statusText  = (string)loadVisiTag[0]; //Success or Error
                    if (statusText == "Success")
                    {
                        numOfFilesRead++;
                        Int32  sessionID            = (Int32)loadVisiTag[1];                  //Session ID for synchronization with RF and CF recordings
                        string ablatingCatheterName = (string)loadVisiTag[3];                 //Ablation catheter name as String value
                        Int32[,] ablatingChannelsID = (Int32[, ])loadVisiTag[4];              //unipolar ID, bipolar ID (if not a bipolar channel, bipolarID = -1)
                        Int32[] startEndTimestamp = (Int32[])loadVisiTag[5];                  //Start and end VisiTag timestamps
                        Int32[] mapIDs            = (Int32[])loadVisiTag[6];                  //the selected map when the ablation was performed
                        Int32[][,] ablationIntervalsPerChannel = (Int32[][, ])loadVisiTag[7]; //used in multi electrode ablation - single list for focal catheter
                        bool     isForceCatheter          = (bool)loadVisiTag[8];             // Indicates if this is a Biosense batheter with eeprom or external on(Only Bionsense Catheter are allowed)
                        bool     isMultiElectrodeCatheter = (bool)loadVisiTag[9];             //Used for nMarq catheter
                        bool     isTGA               = (bool)loadVisiTag[10];                 //Is temperature guided ablation used.
                        Int32    presetID            = (Int32)loadVisiTag[11];                //User setup settings ID. The settings stored in CARTO Data Table - CONFIG_VISI_TAG_PRESET_TABLE
                        string[] touchAtStartSession = (string[])loadVisiTag[12];             //Could be one of: "In Touch", "Not In Touch", "Unknown", "Not Supported" -this is part of the TPI capability
                        //All the catheter positions included in this session.
                        UInt32[][][] allPositionTimestamps = (UInt32[][][])loadVisiTag[13];
                        Double[][][,] allPositions = (Double[][][, ])loadVisiTag[14];
                        Int32[][][] allPositionValidStatuses = (Int32[][][])loadVisiTag[15];   //Valid status per timestamp
                        //All the catheter positions included in this session.
                        //UInt32[][][] endExperiumTimestamps = (UInt32[][][])loadVisiTag[16];
                        //Double[][][,] endExperiumPositions = (Double[][][,])loadVisiTag[17];
                        //Int32[][][] endExperiumValidStatuses = (Int32[][][])loadVisiTag[18];
                        //Three typed data indices for synchronization between Visitag Vatheter positions, RF Ablation data, and Catheter Force Data.
                        for (int x = 0; x < allPositions.Length; x++)
                        {
                            for (int y = 0; y < allPositions[x].Length; y++)
                            {
                                for (int z0 = 0; z0 < allPositions[x][y].GetLength(0); z0++)
                                {
                                    for (int z1 = 0; z1 < allPositions[x][y].GetLength(1); z1 += 3)
                                    {
                                        allPositionsText.Add("\t" + _visiTagIDs[i] + "\t" + sessionID + "\t" + allPositionTimestamps[x][y][z0] + "\t" + allPositionValidStatuses[x][y][z0] + "\t" + string.Format("{0:0.000}", allPositions[x][y][z0, z1]) + "\t" + string.Format("{0:0.000}", allPositions[x][y][z0, z1 + 1]) + "\t" + string.Format("{0:0.000}", allPositions[x][y][z0, z1 + 2]));
                                    }
                                }
                            }
                        }

                        /*for (int x = 0; x < endExperiumPositions.Length; x++)
                         * {
                         *  for (int y = 0; y < endExperiumPositions[x].Length; y++)
                         *  {
                         *      for (int z0 = 0; z0 < endExperiumPositions[x][y].GetLength(0); z0++)
                         *      {
                         *          for (int z1 = 0; z1 < endExperiumPositions[x][y].GetLength(1); z1 += 3)
                         *          {
                         *              endEmperiumPosText.Add("\t" + _visiTagIDs[i] + "\t" + sessionID + "\t" + endExperiumTimestamps[x][y][z0] + "\t" + endExperiumValidStatuses[x][y][z0] + "\t" + string.Format("{0:0.000}", endExperiumPositions[x][y][z0, z1]) + "\t" + string.Format("{0:0.000}", endExperiumPositions[x][y][z0, z1 + 1]) + "\t" + string.Format("{0:0.000}", endExperiumPositions[x][y][z0, z1 + 2]));
                         *          }
                         *      }
                         *  }
                         * }*/
                        visiTagSessionsText.Add("\t" + _visiTagIDs[i] + "\t" + sessionID + "\t" + startEndTimestamp[0] + "\t" + startEndTimestamp[1] + "\t" + presetID + "\t" + mapIDs[0]);
                        if (i == 0)
                        {
                            string ablatingChannelsIDString = "AblatingChannelsIDs: ";
                            visiTagInfoText.Add("AblatingCatheterName: " + ablatingCatheterName);
                            if (touchAtStartSession.Length > 0)
                            {
                                visiTagInfoText.Add("TouchAtStartSession: " + touchAtStartSession[0]);
                            }
                            else
                            {
                                visiTagInfoText.Add("TouchAtStartSession: null");
                            }
                            for (int j = 0; j < ablatingChannelsID.GetLength(0); j++)
                            {
                                for (int k = 0; k < ablatingChannelsID.GetLength(1); k++)
                                {
                                    ablatingChannelsIDString += ablatingChannelsID[i, j].ToString() + "\t";
                                }
                            }
                            visiTagInfoText.Add(ablatingChannelsIDString);
                            visiTagInfoText.Add("IsForceCatheter: " + isForceCatheter);
                            visiTagInfoText.Add("IsMultiElectrodeCatheter: " + isMultiElectrodeCatheter);
                            visiTagInfoText.Add("IsTGA: " + isTGA);
                        }
                    }
                }
                catch (System.Runtime.InteropServices.SEHException)
                {
                }
                catch (System.IndexOutOfRangeException)
                {
                }
            }

            System.IO.File.WriteAllLines(allPosPath, allPositionsText);
            //System.IO.File.WriteAllLines(EndEmperiumPosPath, endEmperiumPosText.ToArray());
            System.IO.File.WriteAllLines(VisiTagSessionsPath, visiTagSessionsText.ToArray());
            System.IO.File.WriteAllLines(VisiTagInfoPath, visiTagInfoText.ToArray());

            if (!System.IO.Directory.Exists(txtFolderDestination))
            {
                if (!txtBox_Input.Text.Contains("Processed_"))
                {
                    _newZip.AddItem(visiTagExportDirectory, txtFolderDestination);
                }
            }
            if (numOfFilesRead == 0)
            {
                _isVisiTagLoadError = true;
            }
            _newZip.Save();
            cmr = null;
        }