public PortableData Create() { // 1. Decrypt stream ExportDataEncryptor decryptor = new ExportDataEncryptor(dataStream); using (MemoryStream decrypted = new MemoryStream()) { decryptor.Decrypt(decrypted); decrypted.Position = 0; // 2. Decompress stream ExportDataCompressor decompressor = new ExportDataCompressor(decrypted); using (MemoryStream decompressed = new MemoryStream()) { decompressor.Decompress(decompressed); decompressed.Position = 0; // 3. Deserialize stream PsaTracesSerializer deserializer = new PsaTracesSerializer(); PortableData result = deserializer.Deserialize(decompressed); return(result); } } }
private List <PsaDataset> FormDatasets(PortableData data) { IDictionary <string, List <PsaTrace> > sortedTraces = new Dictionary <string, List <PsaTrace> >(); foreach (PsaTrace psaTrace in data.PsaTraces) { string vin = psaTrace.Vin; if (sortedTraces.ContainsKey(vin)) { sortedTraces[vin].Add(psaTrace); } else { sortedTraces[vin] = new List <PsaTrace>() { psaTrace }; } } List <PsaDataset> result = new List <PsaDataset>(); foreach (KeyValuePair <string, List <PsaTrace> > pair in sortedTraces) { PsaDataset dataset = new PsaDataset(); dataset.ExportedDate = data.Date; dataset.Guid = data.Guid; dataset.VehicleId = 0; // Service will fill it dataset.SavedDate = DateTime.Now; foreach (PsaTrace trace in pair.Value) { dataset.Traces.Add(trace); } result.Add(dataset); } return(result.Where(r => supportedVins.Contains(r.GetVin())).ToList()); }
/// <summary> /// Checks data for consistency, excludes duplicates and persists to database. /// Ignores the fact that we are importing data for someboy else's vehicle. Imports anyway. I decided so. /// </summary> public void CheckAndImport(PortableData data) { this.data = data; CheckForUnsupportedVehicles(); }