Exemple #1
0
        private IEnumerable <DiagBoxTraceSession> GetTraceSessions()
        {
            IList <string> mainTraceSessionFiles = new List <string>();

            foreach (string directory in Directory.GetDirectories(PrimaryDataPath))
            {
                foreach (string xmlFile in Directory.GetFiles(directory, "*.xml"))
                {
                    if (DiagBoxTraceSessionFactory.IsMainTraceSessionFile(xmlFile))
                    {
                        if (!mainTraceSessionFiles.Contains(xmlFile))
                        {
                            mainTraceSessionFiles.Add(xmlFile);
                        }
                    }
                }
            }
            foreach (string sessionFile in mainTraceSessionFiles)
            {
                DiagBoxTraceSession session = null;
                try
                {
                    session = DiagBoxTraceSessionFactory.CreateSession(sessionFile);
                }
                catch (Exception e)
                {
                    Log.Error(e, String.Format("Was not able to create a trace session from {0}", sessionFile));
                }
                if (session != null)
                {
                    yield return(session);
                }
            }
        }
        public static DiagBoxTraceSession CreateSession(string filePath)
        {
            if (String.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath");
            }
            if (!File.Exists(filePath))
            {
                throw new VtsAgentException("DiagBox trace session file does not exist.");
            }
            if (!IsMainTraceSessionFile(filePath))
            {
                throw new VtsAgentException("Provided file is not Main Trace session file.");
            }
            DiagBoxTraceSession result = new DiagBoxTraceSession();

            using (FileStream stream = new FileStream(filePath,
                                                      FileMode.Open,
                                                      FileAccess.Read,
                                                      FileShare.ReadWrite))
            {
                XmlSerializer   serializer = new XmlSerializer(typeof(TraceSessionXml));
                TraceSessionXml sessionXml = serializer.Deserialize(stream) as TraceSessionXml;
                if (sessionXml == null)
                {
                    throw new VtsAgentException("Failed to parse DiagBox session correctly.");
                }
                result.TraceSessionMainFilePath = filePath;
                result.Vin              = sessionXml.Vin;
                result.Date             = DateTime.Parse(sessionXml.Date);
                result.Manufacturer     = ParseManufacturer(sessionXml.Trademark);
                result.TraceId          = sessionXml.TraceId;
                result.VehicleArchiName = sessionXml.VehicleArchiName;
                result.VehicleName      = sessionXml.VehicleName;
                result.Version          = sessionXml.Version;
            }
            string traceUserDataFilePathName = GetTraceUserDataFilePathName(filePath);

            if (!String.IsNullOrWhiteSpace(traceUserDataFilePathName))
            {
                result.AdditionalFilePaths.Add(traceUserDataFilePathName);
                result.Mileage = DetermineMileage(traceUserDataFilePathName);
            }
            // get all channels
            string sessionId     = Path.GetFileNameWithoutExtension(filePath);
            string sessionFolder = Path.GetDirectoryName(filePath);
            string searchPattern = String.Format("{0}.MPM.*.xml", sessionId);

            foreach (string file in Directory.GetFiles(sessionFolder, searchPattern))
            {
                result.AdditionalFilePaths.Add(file);
                LexiaGraphSessionRawData session = CreateSessionFromFile(file);
                if (session != null)
                {
                    result.Data.Add(session);
                }
            }
            return(result);
        }