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);
            }
        }
Beispiel #2
0
        private void saveProfile(string hash, WriteableBitmap _bitmap)
        {
            var m = new ServiceManager <UpdateProfileCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <UpdateProfileCompletedEventArgs> operationCompleted)
            {
                ProfileUpdateData data       = new ProfileUpdateData();
                var copyProfile              = ApplicationState.Current.SessionData.Profile.Copy();
                copyProfile.AboutInformation = viewModel.Profile.AboutInformation;
                copyProfile.Birthday         = viewModel.Profile.Birthday.Value;
                copyProfile.Gender           = viewModel.Profile.User.Gender;
                copyProfile.CountryId        = viewModel.Profile.User.CountryId;
                copyProfile.Settings         = viewModel.Profile.Settings;
                if (!string.IsNullOrEmpty(viewModel.Password1))
                {
                    copyProfile.Password = viewModel.Password1.ToSHA1Hash();
                }
                copyProfile.Privacy = viewModel.Profile.User.Privacy;
                copyProfile.Picture = viewModel.Profile.User.Picture;


                data.Profile = copyProfile;
                data.Wymiary = viewModel.Profile.Wymiary;

                if (picture != null)
                {
                    if (copyProfile.Picture == null)
                    {
                        copyProfile.Picture = new PictureInfoDTO();
                    }

                    copyProfile.Picture.PictureIdk__BackingField = PictureId;
                    copyProfile.Picture.Hashk__BackingField      = hash;
                    copyProfile.Picture.SessionIdk__BackingField = ApplicationState.Current.SessionData.Token.SessionId;
                }
                ApplicationState.Current.EditProfileInfo.User.Picture = copyProfile.Picture;
                data.Profile = copyProfile;
                data.Wymiary = ApplicationState.Current.ProfileInfo.Wymiary;

                client1.UpdateProfileAsync(ApplicationState.Current.SessionData.Token, data);
                client1.UpdateProfileCompleted -= operationCompleted;
                client1.UpdateProfileCompleted += operationCompleted;
            });

            m.OperationCompleted += (s, a) =>
            {
                if (a.Error != null)
                {
                    BugSenseHandler.Instance.SendExceptionAsync(a.Error);
                    progressBar.ShowProgress(false);
                    ApplicationBar.EnableApplicationBar(true);
                    BAMessageBox.ShowError(ApplicationStrings.ErrSaveProfile);
                    return;
                }
                else
                {
                    if (_bitmap != null)
                    {
                        PicturesCache.Instance.Remove(PictureId);
                        PictureCacheItem item = new PictureCacheItem(_bitmap, PictureId, hash);
                        PicturesCache.Instance.AddToCache(item);
                        PicturesCache.Instance.Notify(a.Result.Result.Picture);
                    }
                    ApplicationState.Current.ProfileInfo         = ApplicationState.Current.EditProfileInfo;
                    ApplicationState.Current.SessionData.Profile = a.Result.Result;

                    if (!string.IsNullOrEmpty(viewModel.Password1))
                    {//store new password
                        Settings.Password = viewModel.Password1;
                    }

                    Dispatcher.BeginInvoke(delegate
                    {
                        if (NavigationService.CanGoBack)
                        {
                            NavigationService.GoBack();
                        }
                    });
                }
            };
            progressBar.ShowProgress(true, ApplicationStrings.ProfilePage_ProgressSave);
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }
Beispiel #3
0
        private void uploadPictureAndSaveProfile()
        {
            var m = new ServiceManager <AsyncCompletedEventArgs>(delegate(BodyArchitectAccessServiceClient client1, EventHandler <AsyncCompletedEventArgs> operationCompleted)
            {
                using (OperationContextScope ocs = new OperationContextScope(client1.InnerChannel))
                {
                    var ggg        = (IBodyArchitectAccessService)client1;
                    PictureDTO dto = new PictureDTO();

                    WriteableBitmap _bitmap = new WriteableBitmap(picture);
                    var extImage            = _bitmap.ToImage();
                    var st = (MemoryStream)extImage.ToStream();
                    st.Seek(0, SeekOrigin.Begin);
                    dto.ImageStream = st.ToArray();
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("SessionId", "http://MYBASERVICE.TK/", ApplicationState.Current.SessionData.Token.SessionId));
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("PictureId", "http://MYBASERVICE.TK/", PictureId));
                    OperationContext.Current.OutgoingMessageHeaders.Add(MessageHeader.CreateHeader("Hash", "http://MYBASERVICE.TK/", "test"));
                    ApplicationState.AddCustomHeaders();

                    ggg.BeginUploadImage(dto, delegate(IAsyncResult aRes)
                    {
                        var proxy   = (IBodyArchitectAccessService)aRes.AsyncState;
                        string hash = null;
                        using (OperationContextScope o = new OperationContextScope(((BodyArchitectAccessServiceClient)proxy).InnerChannel))
                        {
                            try
                            {
                                proxy.EndUploadImage(aRes);
                            }
                            catch (Exception ex)
                            {
                                BugSenseHandler.Instance.SendExceptionAsync(ex);
                                Dispatcher.BeginInvoke(delegate
                                {
                                    progressBar.ShowProgress(false);
                                    ApplicationBar.EnableApplicationBar(true);
                                    BAMessageBox.ShowError(ApplicationStrings.ErrUploadPhoto);
                                });

                                return;
                            }

                            hash = OperationContext.Current.IncomingMessageHeaders.GetHeader <string>("Hash", "http://MYBASERVICE.TK/");
                        }

                        saveProfile(hash, _bitmap);
                    }, client1);
                }
            });

            progressBar.ShowProgress(true, ApplicationStrings.ProfilePage_ProgressUploadPhoto);
            ApplicationBar.EnableApplicationBar(false);
            if (!m.Run())
            {
                progressBar.ShowProgress(false);
                if (ApplicationState.Current.IsOffline)
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrOfflineMode);
                }
                else
                {
                    BAMessageBox.ShowError(ApplicationStrings.ErrNoNetwork);
                }
            }
        }