Exemplo n.º 1
0
 void LoadComments()
 {
     IsLoadingComments = true;
     try
     {
         PhotoServiceClient svc = new PhotoServiceClient();
         svc.GetCommentsCompleted += (sender, e) =>
         {
             if (e.Error != null)
             {
                 e.Error.Handle();
             }
             else
             {
                 _comments = new BindableCollection <PhotoCommentViewModel>(e.Result.Select(x => MapToPhotoCommentViewModel(x)));
                 NotifyOfPropertyChange(() => Comments);
                 NotifyOfPropertyChange(() => HasComment);
             }
             IsLoadingComments = false;
         };
         svc.GetCommentsAsync(Id);
     }
     catch
     {
         IsLoadingComments = false;
     }
 }
Exemplo n.º 2
0
        public void Create()
        {
            RefreshBindingScope.Scope();
            if (this.Validator.HasErrors)
            {
                return;
            }

            IsBusy = true;
            try
            {
                PhotoServiceClient svc = new PhotoServiceClient();
                Album album            = new Album();
                album.Name = Name;
                svc.CreateAlbumCompleted += (sender, e) =>
                {
                    IsBusy = false;
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    if (CreateCompleted != null)
                    {
                        CreateCompleted(this, new AsyncOperationCompletedEventArgs(e.Error));
                    }
                };
                svc.CreateAlbumAsync(album);
            }
            catch
            {
                IsBusy = false;
            }
        }
Exemplo n.º 3
0
 void DeleteComment(PhotoCommentViewModel comment)
 {
     comment.IsDeleting = true;
     try
     {
         PhotoServiceClient svc = new PhotoServiceClient();
         svc.DeleteCommentCompleted += (sender, e) =>
         {
             comment.IsDeleting = false;
             if (e.Error != null)
             {
                 e.Error.Handle();
             }
             else
             {
                 if (_comments != null)
                 {
                     _comments.Remove(comment);
                 }
             }
             NotifyOfPropertyChange(() => HasComment);
         };
         svc.DeleteCommentAsync(comment.Id);
     }
     catch
     {
         comment.IsDeleting = false;
     }
 }
Exemplo n.º 4
0
        public void Create()
        {
            RefreshBindingScope.Scope();
            if (this.Validator.HasErrors)
                return;

            IsBusy = true;
            try
            {
                PhotoServiceClient svc = new PhotoServiceClient();
                Album album = new Album();
                album.Name = Name;
                svc.CreateAlbumCompleted += (sender, e) =>
                {
                    IsBusy = false;
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    if (CreateCompleted != null)
                        CreateCompleted(this, new AsyncOperationCompletedEventArgs(e.Error));
                };
                svc.CreateAlbumAsync(album);
            }
            catch
            {
                IsBusy = false;
            }
        }
Exemplo n.º 5
0
        public void DeleteSelectedPhotos()
        {
            if (IsBusy)
            {
                return;
            }
            if (_photos != null && _photos.Any(x => x.IsSelected))
            {
                MessageBoxViewModel message = new MessageBoxViewModel()
                {
                    Buttons      = MessageBoxButtons.YesNo,
                    MessageLevel = MessageLevel.Exclamation,
                    Header       = AppStrings.DeletePhotoMessageHeader,
                    Message      = AppStrings.ConfirmDeletePhotoMessage,
                    DisplayName  = AppStrings.ConfirmationWindowTitle
                };
                message.Closed += (messageSender, messageEventArgs) =>
                {
                    if (message.Result != MessageBoxResult.Positive)
                    {
                        return;
                    }

                    try
                    {
                        IsBusy = true;
                        var parameters = _photos.Where(x => x.IsSelected).Select(x =>
                                                                                 new DeletePhotoParameters()
                        {
                            PhotoId = x.Id, FileName = Path.GetFileName(x.PhotoURI)
                        }).ToList();
                        PhotoServiceClient svc = new PhotoServiceClient();
                        svc.DeletePhotosCompleted += (sender, e) =>
                        {
                            IsBusy = false;
                            if (e.Error != null)
                            {
                                e.Error.Handle();
                            }
                            else
                            {
                                _photos.RefreshCurrentPage();
                                Covers = GetCovers(e.Result);
                            }
                        };
                        svc.DeletePhotosAsync(parameters, Id);
                    }
                    catch
                    {
                        IsBusy = false;
                    }
                };
                IoC.Get <IWindowManager>().ShowDialog(message);
            }
        }
Exemplo n.º 6
0
        private async void GetAllPhotos_Click(object sender, EventArgs e)
        {
            PhotoServiceClient client = new PhotoServiceClient("NetTcpBinding_IPhotoService");
            var photos = await client.GetAllAsync();

            client.Close();
            foreach (var photo in photos)
            {
                ListViewItem item = new ListViewItem(photo.Event);
                item.SubItems.Add(photo.DateAdded.ToString());
                item.SubItems.Add(photo.Place);
                item.SubItems.Add(photo.Description);
                PhotoList.Items.Add(item);
            }
        }
Exemplo n.º 7
0
        void DeleteAlbum(string id)
        {
            if (IsBusy)
            {
                return;
            }
            MessageBoxViewModel message = new MessageBoxViewModel()
            {
                Buttons      = MessageBoxButtons.YesNo,
                MessageLevel = MessageLevel.Exclamation,
                Header       = AppStrings.DeleteAlbumMessageHeader,
                Message      = AppStrings.ConfirmDeleteAlbumMessage,
                DisplayName  = AppStrings.ConfirmationWindowTitle
            };

            message.Closed += (messageSender, messageEventArgs) =>
            {
                if (message.Result != MessageBoxResult.Positive)
                {
                    return;
                }

                try
                {
                    IsBusy = true;
                    PhotoServiceClient svc = new PhotoServiceClient();
                    svc.DeleteAlbumCompleted += (sender, e) =>
                    {
                        if (e.Error != null)
                        {
                            e.Error.Handle();
                        }
                        else
                        {
                            _albums.RefreshCurrentPage();
                        }
                    };
                    svc.DeleteAlbumAsync(id);
                }
                catch
                {
                    IsBusy = false;
                }
            };
            IoC.Get <IWindowManager>().ShowDialog(message);
        }
        public async Task <IActionResult> OnGetAsync(int id)
        {
            PhotoServiceClient client = new PhotoServiceClient(PhotoServiceClient.EndpointConfiguration.NetTcpBinding_IPhotoService);
            var result = await client.GetByFilterAsync(new PhotoFilter { Id = id });

            if (SearchText.Length >= 1)
            {
                this.ExtraProperties = result.FirstOrDefault().PhotoExtraProperties.OrderBy(x => x.PropertyName)
                                       .Where(x => x.PropertyValue.ToLower().Contains(SearchText) || x.PropertyName.ToLower().Contains(SearchText))
                                       .ToArray();
            }
            else
            {
                this.ExtraProperties = result.FirstOrDefault().PhotoExtraProperties.OrderBy(x => x.PropertyName).ToArray();
            }
            await client.CloseAsync();

            return(Page());
        }
Exemplo n.º 9
0
        void PostComment(string contents)
        {
            if (IsLoadingComments)
            {
                return;
            }

            CanPostComment = false;
            PhotoComment comment = new PhotoComment();

            comment.Contents  = contents;
            comment.CreatedBy = SecurityContext.Current.User.Name;
            comment.PhotoId   = Id;
            comment.AlbumId   = AlbumId;
            PhotoServiceClient svc = new PhotoServiceClient();

            try
            {
                svc.CreateCommentCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    else
                    {
                        if (_comments != null)
                        {
                            _comments.Insert(0, MapToPhotoCommentViewModel(e.Result));
                        }
                    }
                    CanPostComment  = true;
                    CommentContents = string.Empty;
                    NotifyOfPropertyChange(() => HasComment);
                };
                svc.CreateCommentAsync(comment);
            }
            catch
            {
                CanPostComment = true;
            }
        }
Exemplo n.º 10
0
        public void FetchData(int pageIndex, int pageSize, Action <PagedDataResponse <PhotoViewModel> > responseCallback)
        {
            PhotoServiceClient client = new PhotoServiceClient();

            client.GetPagedPhotosCompleted += (sender, e) =>
            {
                PagedDataResponse <PhotoViewModel> response = new PagedDataResponse <PhotoViewModel>();
                if (e.Error != null)
                {
                    response.Error = e.Error;
                }
                else
                {
                    response.TotalItemCount = e.Result.TotalItemCount;
                    response.Items          = new System.Collections.Generic.List <PhotoViewModel>();
                    response.Items.AddRange(e.Result.Entities.Select(x => MapToPhotoViewModel(x)));
                }
                responseCallback(response);
            };
            client.GetPagedPhotosAsync(pageIndex, pageSize, AlbumId);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> OnGetAsync()
        {
            PhotoServiceClient client = new PhotoServiceClient(PhotoServiceClient.EndpointConfiguration.NetTcpBinding_IPhotoService);

            if (SearchText.Length >= 3)
            {
                DateTime dateSearch;
                try
                {
                    dateSearch = DateTime.Parse(SearchText);
                }
                catch
                {
                    dateSearch = new DateTime();
                }
                int idSearch;
                try
                {
                    idSearch = Convert.ToInt32(SearchText);
                }
                catch
                {
                    idSearch = 0;
                }
                this.Photos = (await client.GetAllAsync()).Where(x => x.Id.ToString().Contains(idSearch.ToString()) ||
                                                                 x.Path.ToLower().Contains(SearchText) ||
                                                                 x.PathChanged.ToString().Contains(SearchText) ||
                                                                 x.Place.ToLower().Contains(SearchText)).ToArray();
            }
            else
            {
                this.Photos = await client.GetAllAsync();
            }
            await client.CloseAsync();

            return(Page());
        }
Exemplo n.º 12
0
        public void Save()
        {
            RefreshBindingScope.Scope();
            if (this.Validator.HasErrors)
            {
                return;
            }

            IsBusy = true;
            try
            {
                PhotoServiceClient svc = new PhotoServiceClient();
                svc.UpdateAlbumCompleted += (sender, e) =>
                {
                    IsBusy = false;
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    else
                    {
                        _target.Name        = Name;
                        _target.Description = Description;
                        if (EditCompleted != null)
                        {
                            EditCompleted(this, EventArgs.Empty);
                        }
                    }
                };
                svc.UpdateAlbumAsync(Name, Description, _target.Id);
            }
            catch
            {
                IsBusy = false;
            }
        }
Exemplo n.º 13
0
 public void SaveDescription()
 {
     IsEditingDescription = false;
     if (Description != DescriptionBackup)
     {
         Description = DescriptionBackup;
         try
         {
             PhotoServiceClient svc = new PhotoServiceClient();
             svc.UpdateDescriptionCompleted += (sender, e) =>
             {
                 if (e.Error != null)
                 {
                     e.Error.Handle();
                 }
             };
             svc.UpdateDescriptionAsync(Description, Id);
         }
         catch (Exception ex)
         {
             ex.Handle();
         }
     }
 }
Exemplo n.º 14
0
 public PhotoServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
     base(PhotoServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Exemplo n.º 15
0
        void PostComment(string contents)
        {
            if (IsLoadingComments)
                return;

            CanPostComment = false;
            PhotoComment comment = new PhotoComment();
            comment.Contents = contents;
            comment.CreatedBy = SecurityContext.Current.User.Name;
            comment.PhotoId = Id;
            comment.AlbumId = AlbumId;
            PhotoServiceClient svc = new PhotoServiceClient();
            try
            {
                svc.CreateCommentCompleted += (sender, e) =>
                {
                    if (e.Error != null)
                    {
                        e.Error.Handle();
                    }
                    else
                    {
                        if (_comments != null)
                        {
                            _comments.Insert(0, MapToPhotoCommentViewModel(e.Result));
                        }
                    }
                    CanPostComment = true;
                    CommentContents = string.Empty;
                    NotifyOfPropertyChange(() => HasComment);
                };
                svc.CreateCommentAsync(comment);
            }
            catch
            {
                CanPostComment = true;
            }
        }
Exemplo n.º 16
0
 void LoadComments()
 {
     IsLoadingComments = true;
     try
     {
         PhotoServiceClient svc = new PhotoServiceClient();
         svc.GetCommentsCompleted += (sender, e) =>
             {
                 if (e.Error != null)
                 {
                     e.Error.Handle();
                 }
                 else
                 {
                     _comments = new BindableCollection<PhotoCommentViewModel>(e.Result.Select(x => MapToPhotoCommentViewModel(x)));
                     NotifyOfPropertyChange(() => Comments);
                     NotifyOfPropertyChange(() => HasComment);
                 }
                 IsLoadingComments = false;
             };
         svc.GetCommentsAsync(Id);
     }
     catch
     {
         IsLoadingComments = false;
     }
 }
Exemplo n.º 17
0
 void DeleteComment(PhotoCommentViewModel comment)
 {
     comment.IsDeleting = true;
     try
     {
         PhotoServiceClient svc = new PhotoServiceClient();
         svc.DeleteCommentCompleted += (sender, e) =>
         {
             comment.IsDeleting = false;
             if (e.Error != null)
             {
                 e.Error.Handle();
             }
             else
             {
                 if (_comments != null)
                 {
                     _comments.Remove(comment);
                 }
             }
             NotifyOfPropertyChange(() => HasComment);
         };
         svc.DeleteCommentAsync(comment.Id);
     }
     catch
     {
         comment.IsDeleting = false;
     }
 }
Exemplo n.º 18
0
 public void SaveDescription()
 {
     IsEditingDescription = false;
     if (Description != DescriptionBackup)
     {
         Description = DescriptionBackup;
         try
         {
             PhotoServiceClient svc = new PhotoServiceClient();
             svc.UpdateDescriptionCompleted += (sender, e) =>
                 {
                     if (e.Error != null)
                     {
                         e.Error.Handle();
                     }
                 };
             svc.UpdateDescriptionAsync(Description, Id);
         }
         catch (Exception ex)
         {
             ex.Handle();
         }
     }
 }
Exemplo n.º 19
0
 public PhotoServiceClient(EndpointConfiguration endpointConfiguration) :
     base(PhotoServiceClient.GetBindingForEndpoint(endpointConfiguration), PhotoServiceClient.GetEndpointAddress(endpointConfiguration))
 {
     this.Endpoint.Name = endpointConfiguration.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Exemplo n.º 20
0
 public PhotoServiceClient() :
     base(PhotoServiceClient.GetDefaultBinding(), PhotoServiceClient.GetDefaultEndpointAddress())
 {
     this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IPhotoService.ToString();
     ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
 }
Exemplo n.º 21
0
 private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
 {
     return(PhotoServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IPhotoService));
 }
Exemplo n.º 22
0
 private static System.ServiceModel.Channels.Binding GetDefaultBinding()
 {
     return(PhotoServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IPhotoService));
 }