public void UpdateField(TrackingModel track)
 {
     if (track.Data != null && track.Data.fields != null)
     {
         if (LastFields == null)
         {
             LastFields = new Dictionary <string, FieldModel>();
         }
         foreach (KeyValuePair <string, Field> item in track.Data.fields)
         {
             if (LastFields.ContainsKey(item.Key))
             {
                 LastFields[item.Key].B64Value = item.Value.b64_value;
             }
             else
             {
                 LastFields.Add(item.Key, new FieldModel()
                 {
                     B64Value = item.Value.b64_value, Key = item.Key
                 });
             }
         }
     }
 }
        private void DecodeTracking(MD.CloudConnect.ITracking t, AccountModel account, List<TrackingModel> saveTracks, List<DeviceModel> saveDevices)
        {
            string imei = t.Asset;

            DeviceModel device = RepositoryFactory.Instance.DeviceDb.GetDevice(imei);

            if (device == null)
            {
                device = new DeviceModel() { Imei = imei };
                RepositoryFactory.Instance.DeviceDb.Save(device);
                device = RepositoryFactory.Instance.DeviceDb.GetDevice(imei);
            }

            device.LastReport = t.Recorded_at;
            if (t.IsValid)
            {
                device.LastValidLocation = t.Recorded_at;
                device.LastLongitude = t.Longitude;
                device.LastLatitude = t.Latitude;
            }

            TrackingModel track = new TrackingModel();
            track.DeviceID = device.Id;
            track.Data = (MD.CloudConnect.Data.TrackingData)t;
            track.RecordedDateKey = t.Recorded_at.GenerateKey();
            saveTracks.Add(track);

            device.UpdateField(track);

            if (saveDevices.Where(x => x.Imei == device.Imei).Count() == 0)
                saveDevices.Add(device);
        }