Пример #1
0
        public PhotosVideoCellViewModel(PhotoVideo obj, INavigationService _navigation, IDialogue _dialogue)
        {
            navigation = _navigation;
            dialogue   = _dialogue;

            this.Author_DisplayName = obj.Author_DisplayName;
            if (string.IsNullOrWhiteSpace(this.Author_DisplayName))
            {
                this.Author_DisplayName = $"{obj.Author_FirstName} {obj.Author_LastName}";
            }

            if (obj.Sys_Creation != null)
            {
                this.Date = $"{obj.Sys_Creation.ToString("m")}, {obj.Sys_Creation.ToString("hh:mm tt")}";
                this.Time = obj.Sys_Creation.ToString("hh:mm tt");
            }

            this.Photo     = obj.Photo;
            this.ID        = obj.Content_ID;
            this.Author_ID = obj.Author_ID;
        }
Пример #2
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);
                }
            }
        }