private async Task <TelemetryRow> GetTelemetryRowForDemodedData(ObservationEntry observationEntry, ObservationEntry.DemodDataEntry demodedData)
        {
            HttpContent httpContents = await satnogsNetworkApi.GetObservationData(observationEntry.Id, demodedData.ResourceName);

            byte[] data = await httpContents.ReadAsByteArrayAsync();

            var fecResult     = FecHelpers.DecodePayload(data, 16, 0, false);
            var beaconDecoded = BeaconDecoder.DecodeBeacon(fecResult.PayloadCorrected ?? fecResult.PayloadUncorrected);

            return(new TelemetryRow()
            {
                Observation = observationEntry,
                DemodData = demodedData,
                FecDecodeResult = fecResult,
                Acrux1Beacon = beaconDecoded
            });
        }
 private Task <TelemetryRow[]> GetTelemetryRowsForObservation(ObservationEntry observationEntry)
 {
     return(Task.WhenAll(observationEntry.DemodData.Select(dde => GetTelemetryRowForDemodedData(observationEntry, dde))));
 }
        private async void Save()
        {
            _hudProvider.DisplayProgress("Saving");
            Observation.ModifiedLocally = true;
            Observation.Changes         = Changes == null ? new ObservableCollection <ObservationChange>() : Changes;
            Observation.Comments        = Comments == null ? new ObservableCollection <ObservationComment>() : Comments;
            Observation.Attachments     = Attachments == null ? new ObservableCollection <ObservationAttachment>() : Attachments;

            //saving observation data
            var obsId = SelectedPeriod.ObservationID;

            Observation.Observation_id = SelectedPeriod.ObservationID;

            if (Observation.ObservationEntries == null)
            {
                Observation.ObservationEntries = new ObservableCollection <ObservationEntry>();
            }
            //checking to see if they toggled
            //bool sameCount = Observation.ObservationEntries.Count == Obs.Count;

            if (obsId > 0)
            {
                //need to load up Observation with entries
                foreach (ObsViewModel ob in Obs)
                {
                    //find entry for this vm
                    ObservationEntry entry = Observation.ObservationEntries.Where(m => m.ObservationEntryId == ob.ObservationEntryId).First();
                    if (entry != null)
                    {
                        entry.LocalObservationID = SelectedPeriod.LocalObservationID;
                        entry.Observation_id     = obsId;
                        entry.ModifiedLocally    = true;
                        entry.Count                  = (int)ob.IndicatorCount;
                        entry.Numerator              = ob.NumeratorValue;
                        entry.Denominator            = ob.DenominatorValue;
                        entry.Yes_No                 = ob.IndicatorYesNo;
                        entry.Indicator_Gender       = ob.IndicatorGender;
                        entry.Indicator_Age_Range_Id = ob.IndicatorAgeRangeId;
                    }
                    else
                    {
                        //new entry
                        ObservationEntry newEntry = new ObservationEntry();
                        newEntry.Observation_id     = obsId;
                        newEntry.LocalObservationID = SelectedPeriod.LocalObservationID;
                        newEntry.ModifiedLocally    = true;
                        newEntry.Count               = (int)ob.IndicatorCount;
                        newEntry.Numerator           = ob.NumeratorValue;
                        newEntry.Denominator         = ob.DenominatorValue;
                        newEntry.Yes_No              = ob.IndicatorYesNo;
                        entry.Indicator_Gender       = ob.IndicatorGender;
                        entry.Indicator_Age_Range_Id = ob.IndicatorAgeRangeId;
                        Observation.ObservationEntries.Add(newEntry);
                    }
                }
            }
            else
            {
                foreach (ObsViewModel ob in Obs)
                {
                    //new entry
                    ObservationEntry newEntry = new ObservationEntry();
                    newEntry.Observation_id     = obsId;
                    newEntry.LocalObservationID = SelectedPeriod.LocalObservationID;
                    newEntry.ModifiedLocally    = true;
                    newEntry.Count                  = (int)ob.IndicatorCount;
                    newEntry.Numerator              = ob.NumeratorValue;
                    newEntry.Denominator            = ob.DenominatorValue;
                    newEntry.Yes_No                 = ob.IndicatorYesNo;
                    newEntry.Indicator_Age_Range_Id = ob.IndicatorAgeRangeId;
                    newEntry.Indicator_Gender       = ob.IndicatorGender;

                    Observation.ObservationEntries.Add(newEntry);
                }
            }
            //need to check if dissagregated then add total row
            if (DisaggregatedSelected)
            {
                ObservationEntry newEntry = new ObservationEntry();
                newEntry.Observation_id     = obsId;
                newEntry.LocalObservationID = SelectedPeriod.LocalObservationID;
                newEntry.ModifiedLocally    = true;
                newEntry.Count       = (int)IndicatorCount;
                newEntry.Numerator   = (int)IndicatorNumCount;
                newEntry.Denominator = (int)IndicatorDenCount;
                //newEntry.Yes_No = ob.IndicatorYesNo;
                //newEntry.Indicator_Age_Range_Id = ob.IndicatorAgeRangeId;
                //newEntry.Indicator_Gender = ob.IndicatorGender;

                Observation.ObservationEntries.Add(newEntry);
            }
            var userinfo = _userInfoService.GetSavedInfo();

            //saving locally
            _observationRep.Upsert(Observation);


            //if connected try to save up to server
            if (App.IsConnected)
            {
                Observation.Begin_Date = OffSetDateTimeZone((DateTime)Observation.Begin_Date);
                Observation.End_Date   = OffSetDateTimeZone((DateTime)Observation.End_Date);
                var response = await _observationService.ObservationSave(userinfo.Email, Observation);

                _observationRep.Upsert(response.observation);
            }

            _hudProvider.Dismiss();
            await _Navigation.PopAsync();
        }