Exemplo n.º 1
0
        async protected override Task SavingCompleted()
        {
            var entry = Entry;

            if (entry == null || viewModel.Points == null || viewModel.Points.Count == 0)
            {//todo:maybe we should delete coordinates from db?
                return;
            }
            //here GPSEntry should be saved so instead InstanceId we can use GlobalId
            ApplicationState.Current.TrainingDay.CleanUpGpsCoordinates();
            ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[entry.TrainingDay.TrainingDate].CleanUpGpsCoordinates();

            try
            {
                var result = await BAService.GPSCoordinatesOperationAsync(entry.GlobalId, GPSCoordinatesOperationType.UpdateCoordinatesWithCorrection, viewModel.Points);

                result.GPSTrackerEntry.InstanceId = entry.InstanceId;
                var tdi    = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[entry.TrainingDay.TrainingDate];
                var gpsBag = tdi.GetGpsCoordinates(result.GPSTrackerEntry);
                gpsBag.IsSaved = true;
                tdi.Update(result.GPSTrackerEntry);
                ApplicationState.Current.TrainingDay    = tdi.Copy();
                ApplicationState.Current.CurrentEntryId = new LocalObjectKey(result.GPSTrackerEntry);
            }
            catch (NetworkException)
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
            catch (Exception)
            {
                //mark this entry as still modified
                var tdi = ApplicationState.Current.CurrentBrowsingTrainingDays.TrainingDays[entry.TrainingDay.TrainingDate];
                tdi.IsModified = true;
                tdi.GetGpsCoordinates(entry).IsSaved = false;
                progressBar.ShowProgress(false);
                ApplicationBar.EnableApplicationBar(true);
                BAMessageBox.ShowError(ApplicationStrings.GPSTrackerPage_ErrUploadGpsCoordinates);
            }
        }
        async protected virtual Task uploadGPSCoordinates(SynchronizationItemViewModel day, bool firstTime)
        {
            var result = await BAService.GPSCoordinatesOperationAsync(day.GPSEntry.GlobalId, GPSCoordinatesOperationType.UpdateCoordinates, day.GPSBag.Points);

            if (result.GPSTrackerEntry != null)
            {
                result.GPSTrackerEntry.InstanceId = day.GPSEntry.InstanceId;
                day.GPSEntry.GlobalId             = result.GPSTrackerEntry.GlobalId;
            }
            uploadGPSResult(result, day, firstTime);


            //var m = new ServiceManager<AsyncCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler<AsyncCompletedEventArgs> operationCompleted)
            //{
            //    using (OperationContextScope ocs = new OperationContextScope(client1.InnerChannel))
            //    {
            //        var ggg = (IBodyArchitectAccessService)client1;
            //        GPSOperationParam dto = new GPSOperationParam();
            //        var json = JsonConvert.SerializeObject(day.GPSBag.Points);
            //        var bytes = UTF8Encoding.UTF8.GetBytes(json);
            //        dto.CoordinatesStream = bytes.ToZip();

            //        GPSOperationData param = new GPSOperationData();
            //        param.GPSTrackerEntryId = day.GPSEntry.GlobalId;
            //        param.Operation = GPSCoordinatesOperationType.UpdateCoordinates;

            //        OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("SessionId", "http://MYBASERVICE.TK/", ApplicationState.Current.SessionData.Token.SessionId));
            //        OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Params", "http://MYBASERVICE.TK/", param));
            //        ApplicationState.AddCustomHeaders();

            //        ggg.BeginGPSCoordinatesOperation(dto, delegate(IAsyncResult aRes)
            //        {
            //            var proxy = (IBodyArchitectAccessService)aRes.AsyncState;
            //            //using (OperationContextScope o = new OperationContextScope(((BodyArchitectAccessServiceClient)proxy).InnerChannel))
            //            {

            //                try
            //                {
            //                    GPSCoordinatesOperationResult result = proxy.EndGPSCoordinatesOperation(aRes);
            //                    uploadGPSResult(result, day, firstTime);
            //                }
            //                catch (FaultException<BAServiceException> ex)
            //                {
            //                    if (ex.Detail.ErrorCode == ErrorCode.ObjectNotFound)
            //                    {
            //                        uploadGPSResult(new GPSCoordinatesOperationResult(null), day, firstTime);
            //                        return;
            //                    }
            //                    uploadGPSResult(null, day, firstTime);
            //                    day.State = MergeState.Error;
            //                }
            //                catch (Exception ex)
            //                {
            //                    uploadGPSResult(null, day, firstTime);
            //                    day.State = MergeState.Error;
            //                }
            //                finally
            //                {
            //                    IsBusy = false;
            //                }
            //            }
            //        }, client1);

            //    }


            //});
            //if (!m.Run())
            //{

            //}
        }