public string StartTracing(string essaiId, string savePath, GpsDeviceType gpsDeviceType) { var extension = new MetaDataExtension { DeviceType = gpsDeviceType }; return(StartTracing(essaiId, savePath, extension)); }
/// <summary> /// Starts the tracing. /// </summary> public string StartTracing(string essaiId, string savePath, MetaDataExtension extension) { if (string.IsNullOrEmpty(savePath)) { throw new ArgumentNullException("savePath"); } if (extension == null) { throw new ArgumentNullException("extension"); } string outputFullPath; Log.Debug().Message("Démarrage de la trace GPS. AcquisitionId: '{0}'.", essaiId).Write(); try { string prefix = this.Append ? null : essaiId; outputFullPath = Path.Combine(savePath, prefix + "." + this.FileExtension); try { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } } catch (IOException ex) { Log.Warn().Exception(ex).Write(); } _output = XmlWriter.Create(outputFullPath, new XmlWriterSettings { Indent = true }); _output.WriteStartDocument(); { _output.WriteStartElement("gpx", "http://www.topografix.com/GPX/1/1"); _output.WriteAttributeString("version", "2.0"); _output.WriteAttributeString("creator", "Transports Québec"); _output.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"); _output.WriteAttributeString("xmlns", "ins", null, "http://www.w3.org/2001/XMLSchema-instance/ins"); _output.WriteAttributeString("xmlns", "dlc", null, "http://www.w3.org/2001/XMLSchema-instance/dlc"); { _output.WriteStartElement("metadata"); _output.WriteElementString("name", essaiId); _output.WriteElementString("time", DateTimePrecise.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffffffK")); { _output.WriteStartElement("extensions"); { if (!String.IsNullOrEmpty(extension.CreationSource)) { _output.WriteElementString("CreationSource", extension.CreationSource); } if (!String.IsNullOrEmpty(extension.CreationSourceType)) { _output.WriteElementString("CreationSourceType", extension.CreationSourceType); } if (!String.IsNullOrEmpty(extension.CreationSourceVersion)) { _output.WriteElementString("CreationSourceVersion", extension.CreationSourceVersion); } if (!String.IsNullOrEmpty(extension.FileStructVersion)) { _output.WriteElementString("FileStructVersion", extension.FileStructVersion); } _output.WriteElementString("gpsDeviceType", Convert.ToString(extension.DeviceType)); } _output.WriteEndElement(); } _output.WriteEndElement(); } } _output.WriteStartElement("rte"); _output.Flush(); _capture = true; } catch (Exception ex) { //Console.WriteLine(ex.Message); outputFullPath = string.Empty; Log.Warn().Exception(ex).Write(); } return(outputFullPath); }