private async void RemoveNote_FromCollection(object sender)
        {
            if (sender != null)
            {
                var id = sender as string;

                //Add Notes to Server
                Animate      = true;
                Instructions = "Deleting Note";

                //Diagnostics
                string Message    = string.Empty;
                string StackTrace = string.Empty;
                bool   _HasError  = false;

                //Remove note
                await Task.Run(() =>
                {
                    try
                    {
                        this.Notes.RemoveAt(this.Notes.IndexOf(this.Notes.SingleOrDefault(w => w.ID == id)));
                        _notesManager.Delete_NoteById(id);

                        DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                        var response = dataService._DeleteNote_ByID(id, Constants.InMemory_ContactID);
                        if (response.Errors.Count != 0)
                        {
                            response.Errors.ForEach(w =>
                            {
                                //Add to log table for diagnostics

                                if (this.logging != null)
                                {
                                    var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                                    this.logging.AddLog(log);
                                }
                            });

                            _HasError = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        _HasError = true;

                        if (ex.InnerException != null)
                        {
                            Message    = ex.InnerException.Message;
                            StackTrace = ex.InnerException.StackTrace;
                        }
                        else
                        {
                            Message    = ex.Message;
                            StackTrace = ex.StackTrace;
                        }
                        var mEx = new Exceptions(logging, Message, StackTrace);
                        if (mEx != null)
                        {
                            mEx.HandleException(mEx, logging);
                        }
                    }
                }).ContinueWith((e) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Animate = false;
                        //if (_HasError)
                        //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                    });
                });
            }
        }
        private async void UpdateNote_ToCollection(Notes obj)
        {
            //Add Notes to Server
            Animate      = true;
            Instructions = "Updating Note";

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;
            bool   _HasError  = false;

            await Task.Run(() =>
            {
                try
                {
                    var Index = this.Notes.IndexOf(this.Notes.SingleOrDefault(i => i.ID == obj.Content_ID_Ref));
                    this.Notes[Index].Subject     = obj.Subject;
                    this.Notes[Index].Description = obj.Description;

                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));
                    var response = dataService._UpdateNote_ByID(LocalMapper.MapNote_ToServer(obj));
                    if (response.Errors.Count != 0)
                    {
                        response.Errors.ForEach(w =>
                        {
                            //Add to log table for diagnostics
                            if (this.logging != null)
                            {
                                var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                                this.logging.AddLog(log);
                            }
                        });

                        _HasError = true;
                    }
                }
                catch (Exception ex)
                {
                    _HasError = true;

                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
            }).ContinueWith((e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate = false;
                    //if (dialogue != null & _HasError)
                    //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                });
            });
        }
        private async void AddNotes_ToCollection(Notes obj)
        {
            //Add Notes to Server
            Animate      = true;
            Instructions = "Adding Note";

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;
            bool   _HasError  = false;

            string cid = obj.Content_ID_Ref; //Temp Client Id

            await Task.Run(() =>
            {
                try
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        var curr             = new NotesCellViewModel(obj, navigation, dialogue);
                        curr._DeleteContent += RemoveNote_FromCollection;
                        this.Notes.Add(curr);
                    });

                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));
                    var response = dataService._AddNote(LocalMapper.MapNote_ToServer(obj));
                    if (response.Errors.Count != 0)
                    {
                        response.Errors.ForEach(w =>
                        {
                            //Add to log table for diagnostics
                            if (this.logging != null)
                            {
                                var log = LocalMapper.Map_LogWithMessage(w, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                                this.logging.AddLog(log);
                            }
                        });

                        _HasError = true;
                    }
                    else
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var note   = this.Notes.SingleOrDefault(w => w.ID.Equals(cid));
                            note.ID    = response.Content_ID;
                            ReloadData = true;
                        });

                        //Update local ID with the Server ID
                        obj.Content_ID_Ref = response.Content_ID;
                        _notesManager.UpdateNote(obj);
                    }
                }
                catch (Exception ex)
                {
                    _HasError = true;

                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
            }).ContinueWith((e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate = false;
                    //if ()
                    //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                });
            });
        }
        public void OnRefresh()
        {
            //Start querying the
            Instructions = "Downloading Notes";
            Animate      = true;
            Refreshing   = true;

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;
            bool   _AnyError  = false;

            Task.Run(() =>
            {
                //Query the user's data from the back end SSMS
                try
                {
                    if (_notesManager != null)
                    {
                        var obj = new List <Notes>();

                        DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));
                        var notes = dataService._GetNotes_ByUserID(Constants.InMemory_ContactID);
                        if (notes._Notes.Count != 0)
                        {
                            if (_notesManager != null)
                            {
                                this.Notes.Clear();
                                _notesManager.Delete_AllNotesByContactID(Constants.InMemory_ContactID); //Clear all notes then download them

                                notes._Notes.ForEach(w => obj.Add(LocalMapper.MapNote_FromServer(w)));
                                _notesManager.AddNotes(obj);
                                OnRefresh_Core();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
                finally
                {
                    //dispose of any memory here
                }
            }).ContinueWith((e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate    = false;
                    Refreshing = false;

                    //if (dialogue != null && _AnyError)
                    //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                });
            });
        }
        public void OnRefresh()
        {
            //Start querying the
            Instructions = "Downloading Contacts";
            Animate      = true;
            Refreshing   = true;

            //Diagnostics
            string Message    = string.Empty;;
            string StackTrace = string.Empty;
            bool   _AnyError  = false;

            Task.Run(() =>
            {
                //Query the user's data from the back end SSMS
                try
                {
                    var contactsCollection = new ObservableCollection <CoreContactsCellViewModel>();

                    var curr = new List <Contact>();
                    var obj  = new List <CoreContactsCellViewModel>();

                    this.Contacts.Clear();
                    contactsManager.ClearContacts_ForUserID(Constants.InMemory_ContactID);

                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));
                    var server_contacts = dataService._GetContacts_ByUserID(Constants.InMemory_ContactID);
                    var contacts        = contactStore.Get_ContactsFromStore <Contact>();
                    if (contacts != null)
                    {
                        contacts.ForEach(w =>
                        {
                            //Add Contact to the contact store for the particular account
                            w.Sys_Creation    = DateTime.Now;
                            w.Sys_Transaction = DateTime.Now;

                            w.Contact_ID = contactsManager.Get_NewContactID();
                            w.User_ID    = Constants.InMemory_ContactID;

                            //Add to Local Collection
                            var cObj             = new CoreContactsCellViewModel(w, dialogue, navigation);
                            cObj._DeleteContent += RemoveContact_FromCollection;

                            if (!curr.Contains(w))
                            {
                                curr.Add(w);
                            }

                            if (!obj.Contains(cObj))
                            {
                                obj.Add(cObj);
                            }
                        });
                    }

                    if (server_contacts._Contacts != null)
                    {
                        server_contacts._Contacts.ForEach(w =>
                        {
                            //Add Contacts to Table
                            var csObj             = new CoreContactsCellViewModel(LocalMapper.MapContact_FromServer(w), dialogue, navigation);
                            csObj._DeleteContent += RemoveContact_FromCollection;

                            if (!curr.Contains(LocalMapper.MapContact_FromServer(w)))
                            {
                                curr.Add(LocalMapper.MapContact_FromServer(w));
                            }

                            if (!obj.Contains(csObj))
                            {
                                obj.Add(csObj);
                            }
                        });
                    }

                    if (contactsManager != null && curr.Count != 0)
                    {
                        contactsManager.AddContacts_ByDetails(curr);
                    }

                    Initialize_Core();
                    //      MessagingCenter.Send<ContactsViewModel>(this, _ContactsUpdate);
                }
                catch (Exception ex)
                {
                    _AnyError = true;
                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
                finally
                {
                    //dispose of any memory here
                }
            }).ContinueWith((e) =>
            {
                //Hide the animator when done

                //If any errors occur render them on the dialogue service

                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate = false; Refreshing = false;

                    if (dialogue != null && _AnyError)
                    {
                        dialogue.ShowAlert("mmm...Something went wrong", Message);
                    }
                });
            });
        }
Exemple #6
0
        public void OpenFloat()
        {
            ReloadData   = false;
            Animate      = true;
            Instructions = "Adding Photo";
            bool HasError = false;

            string eMessage    = string.Empty;
            string eStackTrace = string.Empty;

            string cid = Guid.NewGuid().ToString(); //Temp Client Id

            //Open Dialogue, which allows the user to choose between a photo or video
            if (dialogue != null)
            {
                try
                {
                    CrossMedia.Current.Initialize();
                    var id = Guid.NewGuid().ToString();

                    dialogue.ShowAlert_WithCameraOption("Take or Pick a Photo", "Would you like to take a photo or pick a photo?", async() =>
                    {
                        if (CrossMedia.Current.IsCameraAvailable)
                        {
                            var Photo = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions()
                            {
                                Directory     = "avatar",
                                SaveToAlbum   = false,
                                Name          = "AvatarPhoto.jpg",
                                DefaultCamera = CameraDevice.Rear
                            });

                            if (Photo != null)
                            {
                                var curr = _accountManager.GetSiteUser_ByID <Cross.DataVault.Data.Account>(Constants.InMemory_ContactID);
                                var obj  = new PhotosVideoCellViewModel(navigation, dialogue);

                                obj.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);
                                obj.ID        = id;
                                obj.Author_ID = curr.Contact_ID_Ref;

                                //Subscriptions
                                obj._DeleteContent += RemovePhoto_FromCollection;

                                obj.Date = $"{DateTime.Now.ToString("m")}, {DateTime.Now.ToString("hh:mm tt")}";
                                obj.Time = DateTime.Now.ToString("hh:mm tt");

                                using (BinaryReader reader = new BinaryReader(Photo.GetStream()))
                                    obj.Photo = reader.ReadBytes((int)Photo.GetStream().Length);

                                //Photo Access Object
                                PhotoVideo item = new PhotoVideo();
                                item.User_ID    = curr.Contact_ID_Ref;
                                item.Photo      = obj.Photo;
                                item.Content_ID = id;

                                item.Author_FirstName   = curr.FirstName;
                                item.Author_LastName    = curr.LastName;
                                item.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);

                                item.Sys_Creation = DateTime.Now;

                                //Add Photo To Server
                                await Task.Run(() =>
                                {
                                    try
                                    {
                                        Device.BeginInvokeOnMainThread(() => { this.Photos.Add(obj); });
                                        _photoManager.AddPhoto(item);
                                        Constants.Photos_ID = null;

                                        DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                                        var response = dataService._AddPhoto(LocalMapper.MapPhoto_ToServer(item)); // Add Photo to Server
                                        if (response.Errors.Count != 0)
                                        {
                                            throw new Exception("Message: " + response.Errors[0]);
                                        }
                                        else
                                        {
                                            Device.BeginInvokeOnMainThread(() =>
                                            {
                                                var photo  = this.Photos.SingleOrDefault(w => w.ID.Equals(cid));
                                                photo.ID   = response.Content_ID;
                                                ReloadData = true;
                                            });
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        HasError = true;

                                        if (ex.InnerException != null)
                                        {
                                            eMessage    = ex.InnerException.Message;
                                            eStackTrace = ex.InnerException.StackTrace;
                                        }
                                        else
                                        {
                                            eMessage    = ex.Message;
                                            eStackTrace = ex.StackTrace;
                                        }

                                        var mEx = new Exceptions(logging, eMessage, eStackTrace);
                                        if (mEx != null)
                                        {
                                            mEx.HandleException(mEx, logging);
                                        }
                                    }
                                }).ContinueWith((e) =>
                                {
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        Animate = false;

                                        //Output a dialogue here
                                        //if (dialogue != null && HasError)
                                        //    dialogue.ShowAlert("mmm...Something went wrong", eMessage);
                                    });
                                });
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(() => { Animate = false; });
                            }
                        }
                        else
                        {
                            var PickPhoto = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions()
                            {
                            });
                            if (PickPhoto != null)
                            {
                                var curr = _accountManager.GetSiteUser_ByID <Cross.DataVault.Data.Account>(Constants.InMemory_ContactID);
                                var obj  = new PhotosVideoCellViewModel(navigation, dialogue);
                                obj.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);
                                obj.ID        = id;
                                obj.Author_ID = curr.Contact_ID_Ref;

                                if (string.IsNullOrWhiteSpace(obj.Author_DisplayName))
                                {
                                    obj.Author_DisplayName = curr.SiteUser_DisplayName;
                                }

                                obj.Date = $"{DateTime.Now.ToString("m")}, {DateTime.Now.ToString("hh:mm tt")}";
                                obj.Time = DateTime.Now.ToString("hh:mm tt");

                                //Subscriptions
                                obj._DeleteContent += RemovePhoto_FromCollection;

                                //Photo
                                using (BinaryReader reader = new BinaryReader(PickPhoto.GetStream()))
                                    obj.Photo = reader.ReadBytes((int)PickPhoto.GetStream().Length);

                                //Photo Access Object
                                PhotoVideo item = new PhotoVideo();
                                item.User_ID    = curr.Contact_ID_Ref;
                                item.Content_ID = id;

                                item.Author_FirstName   = curr.FirstName;
                                item.Author_LastName    = curr.LastName;
                                item.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);

                                item.Photo        = obj.Photo;
                                item.Sys_Creation = DateTime.Now;

                                //Add Photo To Server
                                await Task.Run(() =>
                                {
                                    try
                                    {
                                        Device.BeginInvokeOnMainThread(() => { this.Photos.Add(obj); });
                                        _photoManager.AddPhoto(item);
                                        Constants.Photos_ID = null;

                                        DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                                        var response = dataService._AddPhoto(LocalMapper.MapPhoto_ToServer(item)); // Add Photo to Server
                                        if (response.Errors.Count != 0)
                                        {
                                            throw new Exception("Message: " + response.Errors[0]);
                                        }
                                        else
                                        {
                                            Device.BeginInvokeOnMainThread(() =>
                                            {
                                                var photo  = this.Photos.SingleOrDefault(w => w.ID.Equals(cid));
                                                photo.ID   = response.Content_ID;
                                                ReloadData = true;
                                            });
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        HasError = true;
                                        if (ex.InnerException != null)
                                        {
                                            eMessage    = ex.InnerException.Message;
                                            eStackTrace = ex.InnerException.StackTrace;
                                        }
                                        else
                                        {
                                            eMessage    = ex.Message;
                                            eStackTrace = ex.StackTrace;
                                        }
                                        var mEx = new Exceptions(logging, eMessage, eStackTrace);
                                        if (mEx != null)
                                        {
                                            mEx.HandleException(mEx, logging);
                                        }

                                        //Output a dialogue here
                                    }
                                }).ContinueWith((e) =>
                                {
                                    Device.BeginInvokeOnMainThread(() =>
                                    {
                                        Animate = false;

                                        //if (dialogue != null && HasError)
                                        //    dialogue.ShowAlert("mmm...Something went wrong", eMessage);
                                    });
                                });
                            }
                            else
                            {
                                Device.BeginInvokeOnMainThread(() => { Animate = false; });
                            }
                        }
                    }, async() =>
                    {
                        var PickPhoto = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions()
                        {
                        });

                        if (PickPhoto != null)
                        {
                            var curr = _accountManager.GetSiteUser_ByID <Cross.DataVault.Data.Account>(Constants.InMemory_ContactID);
                            var obj  = new PhotosVideoCellViewModel(navigation, dialogue);
                            obj.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);
                            obj.ID        = id;
                            obj.Author_ID = curr.Contact_ID_Ref;

                            if (string.IsNullOrWhiteSpace(obj.Author_DisplayName))
                            {
                                obj.Author_DisplayName = curr.SiteUser_DisplayName;
                            }

                            //Subscriptions
                            obj._DeleteContent += RemovePhoto_FromCollection;

                            obj.Date = $"{DateTime.Now.ToString("m")}, {DateTime.Now.ToString("hh:mm tt")}";
                            obj.Time = DateTime.Now.ToString("hh:mm tt");

                            //Photo
                            using (BinaryReader reader = new BinaryReader(PickPhoto.GetStream()))
                                obj.Photo = reader.ReadBytes((int)PickPhoto.GetStream().Length);

                            //Photo Access Object
                            PhotoVideo item = new PhotoVideo();
                            item.User_ID    = curr.Contact_ID_Ref;
                            item.Content_ID = id;

                            item.Author_FirstName   = curr.FirstName;
                            item.Author_LastName    = curr.LastName;
                            item.Author_DisplayName = String.Format("{0} {1}", curr.FirstName, curr.LastName);

                            item.Photo        = obj.Photo;
                            item.Sys_Creation = DateTime.Now;

                            //Add Photo To Server
                            await Task.Run(() =>
                            {
                                try
                                {
                                    Device.BeginInvokeOnMainThread(() => { this.Photos.Add(obj); });
                                    _photoManager.AddPhoto(item);
                                    Constants.Photos_ID = null;

                                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                                    var response = dataService._AddPhoto(LocalMapper.MapPhoto_ToServer(item)); // Add Photo to Server
                                    if (response.Errors.Count != 0)
                                    {
                                        throw new Exception("Message: " + response.Errors[0]);
                                    }
                                    else
                                    {
                                        Device.BeginInvokeOnMainThread(() =>
                                        {
                                            var photo  = this.Photos.SingleOrDefault(w => w.ID.Equals(cid));
                                            photo.ID   = response.Content_ID;
                                            ReloadData = true;
                                        });
                                    }
                                }
                                catch (Exception ex)
                                {
                                    HasError = true;
                                    if (ex.InnerException != null)
                                    {
                                        eMessage    = ex.InnerException.Message;
                                        eStackTrace = ex.InnerException.StackTrace;
                                    }
                                    else
                                    {
                                        eMessage    = ex.Message;
                                        eStackTrace = ex.StackTrace;
                                    }
                                    var mEx = new Exceptions(logging, eMessage, eStackTrace);
                                    if (mEx != null)
                                    {
                                        mEx.HandleException(mEx, logging);
                                    }
                                }
                            }).ContinueWith((e) =>
                            {
                                Device.BeginInvokeOnMainThread(() =>
                                {
                                    Animate = false;
                                    //if (dialogue != null && HasError)
                                    //    dialogue.ShowAlert("mmm...Something went wrong", eMessage);
                                });
                            });
                        }
                        else
                        {
                            Device.BeginInvokeOnMainThread(() => { Animate = false; });
                        }
                    });
                }
                catch (Exception ex)
                {
                    HasError = true;
                    string pMessage    = string.Empty;
                    string pStackTrace = string.Empty;

                    if (ex.InnerException != null)
                    {
                        pMessage    = ex.InnerException.Message;
                        pStackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        pMessage    = ex.Message;
                        pStackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, pMessage, pStackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }

                    //Output a dialogue here
                    //if (dialogue != null && HasError)
                    //    dialogue.ShowAlert("mmm...Something went wrong", mEx.Message);
                }
            }
        }
Exemple #7
0
        public void OnRefresh()
        {
            //Start querying the
            Instructions = "Downloading Photos & Videos";
            Animate      = true;
            Refreshing   = true;

            //Diagnostics
            string Message    = string.Empty;
            string StackTrace = string.Empty;
            bool   _AnyError  = false;

            Task.Run(() =>
            {
                //Query the user's data from the back end SSMS
                try
                {
                    //Query the local media library
                    //Query the Server's Store and Add to the Collection
                    var obj   = new List <PhotoVideo>();
                    var cells = new ObservableCollection <PhotosVideoCellViewModel>();

                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));

                    var photos = dataService._GetPhotos_ByUserID(Constants.InMemory_ContactID);
                    if (photos._Photos.Count != 0)
                    {
                        var SiteUser = _accountManager.GetSiteUser_ByID <Cross.DataVault.Data.Account>(Constants.InMemory_ContactID);
                        if (SiteUser != null)
                        {
                            if (photos._Photos.Count != 0)
                            {
                                this.Photos.Clear();
                                _photoManager.Delete_PhotosByUserId(Constants.InMemory_ContactID); //Clear all notes then download them

                                photos._Photos.ForEach(w =>
                                {
                                    obj.Add(LocalMapper.MapPhoto_FromServer(w));
                                });

                                if (_photoManager != null)
                                {
                                    _photoManager.AddPhoto_ByCollections(obj);
                                }
                                OnRefresh_Core();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    string eMessage    = string.Empty;
                    string eStackTrace = string.Empty;

                    if (ex.InnerException != null)
                    {
                        eMessage    = ex.InnerException.Message;
                        eStackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        eMessage    = ex.Message;
                        eStackTrace = ex.StackTrace;
                    }
                    var mEx = new Exceptions(logging, eMessage, eStackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
                finally
                {
                    //dispose of any memory here
                    //if (dialogue != null)
                    //    dialogue.ShowAlert("mmm...Something went wrong", Message);
                }
            }).ContinueWith((e) =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    Refreshing = false;
                    Animate    = false;
                });
            });
        }
        public async void OnRefresh()
        {
            //Start querying the
            Instructions = "Downloading your Data";
            Animate      = true;
            Refreshing   = true;

            //Diagnostics
            string Message    = string.Empty;;
            string StackTrace = string.Empty;
            bool   _AnyError  = false;

            await Task.Run(() =>
            {
                //Query the user's data from the back end SSMS
                try
                {
                    DataVaultWebServiceClient dataService = new DataVaultWebServiceClient(ConfigurationManager.InSecurePublicBinding(), new System.ServiceModel.EndpointAddress(Constants.Data_InSecureUrl));
                    if (dataService.HasServiceAvailable())
                    {
                        #region Download Notes
                        var obj = new List <Notes>();
                        notesManager.Delete_AllNotesByContactID(Constants.InMemory_ContactID); //Clear all notes then download them

                        var notes = dataService._GetNotes_ByUserID(Constants.InMemory_ContactID);
                        if (notes._Notes.Count != 0)
                        {
                            notes._Notes.ForEach(w => obj.Add(LocalMapper.MapNote_FromServer(w)));

                            if (notesManager != null)
                            {
                                notesManager.AddNotes(obj);
                            }
                        }
                        #endregion

                        #region Passwords
                        var pObj = new List <Passwords>();
                        passwordManager.Delete_AllPasswordsByContactID(Constants.InMemory_ContactID); //Clear all passwords then download them

                        var passwords = dataService._GetPasswords_ByUserID(Constants.InMemory_ContactID)._Passwords;
                        if (passwords.Count != 0)
                        {
                            passwords.ForEach(w => pObj.Add(LocalMapper.MapPassword_FromServer(w)));

                            if (passwordManager != null)
                            {
                                passwordManager.AddPasswords(pObj);
                            }
                        }
                        #endregion

                        #region Photos

                        var photos = new List <PhotoVideo>();
                        photoVideoManager.Delete_PhotosByUserId(Constants.InMemory_ContactID); //Clear all photos then download them

                        var photos_server = dataService._GetPhotos_ByUserID(Constants.InMemory_ContactID);
                        if (photos_server._Photos.Count != 0)
                        {
                            photos_server._Photos.ForEach(w => photos.Add(LocalMapper.MapPhoto_FromServer(w)));

                            if (photoVideoManager != null)
                            {
                                photoVideoManager.AddPhoto_ByCollections(photos);
                            }
                        }
                        #endregion

                        #region Contacts
                        var curr = new List <Contact>();
                        contactManager.ClearContacts_ForUserID(Constants.InMemory_ContactID);

                        var server_contacts = dataService._GetContacts_ByUserID(Constants.InMemory_ContactID);
                        var contacts        = contactStore.Get_ContactsFromStore <Contact>();
                        if (contacts != null)
                        {
                            contacts.ForEach(w =>
                            {
                                //Add Contact to the contact store for the particular account
                                w.Sys_Creation    = DateTime.Now;
                                w.Sys_Transaction = DateTime.Now;

                                w.Contact_ID = contactManager.Get_NewContactID();
                                w.User_ID    = Constants.InMemory_ContactID;

                                if (!curr.Contains(w))
                                {
                                    curr.Add(w);
                                }
                            });
                        }

                        if (server_contacts._Contacts != null)
                        {
                            server_contacts._Contacts.ForEach(w =>
                            {
                                if (!curr.Contains(LocalMapper.MapContact_FromServer(w)))
                                {
                                    curr.Add(LocalMapper.MapContact_FromServer(w));
                                }
                            });
                        }

                        if (contactManager != null && curr.Count != 0)
                        {
                            contactManager.AddContacts_ByDetails(curr);
                        }

                        #endregion
                    }
                    else
                    {
                        throw new InvalidOperationException("Web Service is not available. Leaving local data intact");
                    }
                }
                catch (Exception ex)
                {
                    _AnyError = true;
                    if (ex.InnerException != null)
                    {
                        Message    = ex.InnerException.Message;
                        StackTrace = ex.InnerException.StackTrace;
                    }
                    else
                    {
                        Message    = ex.Message;
                        StackTrace = ex.StackTrace;
                    }

                    var mEx = new Exceptions(logging, Message, StackTrace);
                    if (mEx != null)
                    {
                        mEx.HandleException(mEx, logging);
                    }
                }
                finally
                {
                    //dispose of any memory here
                }
            }).ContinueWith((e) =>
            {
                //Hide the animator when done
                //If any errors occur render them on the dialogue service
                Device.BeginInvokeOnMainThread(() =>
                {
                    Animate    = false;
                    Refreshing = false;
                });
            });
        }