Beispiel #1
0
		private void TraktFriendApproveDeny(Trakt_FriendRequestVM req, bool isApprove)
		{
			try
			{
				Window parentWindow = Window.GetWindow(this);
				parentWindow.Cursor = Cursors.Wait;
				string retMessage = "";

				bool success = false;
				if (isApprove)
					success = JMMServerVM.Instance.clientBinaryHTTP.TraktFriendRequestApprove(req.Username, ref retMessage);
				else
					success = JMMServerVM.Instance.clientBinaryHTTP.TraktFriendRequestDeny(req.Username, ref retMessage);
				parentWindow.Cursor = Cursors.Arrow;

				if (success)
				{
					MessageBox.Show(retMessage, "Success", MessageBoxButton.OK, MessageBoxImage.Information);
					DashboardVM.Instance.RefreshTraktFriends(togTraktScrobbles.IsChecked.Value, togTraktShouts.IsChecked.Value);
				}
				else
					MessageBox.Show(retMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

				
			}
			catch (Exception ex)
			{
				Utils.ShowErrorMessage(ex);
			}
		}
Beispiel #2
0
		public void RefreshTraktFriends(bool traktScrobbles, bool traktShouts)
		{
			try
			{
				System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
				{
					TraktActivity.Clear();
				});

				JMMServerBinary.Contract_Trakt_Activity traktActivity = JMMServerVM.Instance.clientBinaryHTTP.GetTraktFriendInfo(AppSettings.Dash_TraktFriends_Items,
					AppSettings.Dash_TraktFriends_AnimeOnly, traktShouts, traktScrobbles);

				List<object> activity = new List<object>();

				if (traktActivity.HasTraktAccount)
				{
					foreach (JMMServerBinary.Contract_Trakt_FriendFrequest contractFriend in traktActivity.TraktFriendRequests)
					{
						Trakt_FriendRequestVM req = new Trakt_FriendRequestVM(contractFriend);
						activity.Add(req);
					}

					foreach (JMMServerBinary.Contract_Trakt_FriendActivity contractAct in traktActivity.TraktFriendActivity)
					{
						if (contractAct.ActivityAction == (int)TraktActivityAction.Scrobble)
						{
							Trakt_ActivityScrobbleVM scrobble = new Trakt_ActivityScrobbleVM(contractAct);

							if (!string.IsNullOrEmpty(scrobble.UserFullImagePath) && !File.Exists(scrobble.UserFullImagePath))
							{
								// re-download the friends avatar image
								try
								{
									System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
									{
										ImageDownloadRequest req = new ImageDownloadRequest(ImageEntityType.Trakt_ActivityScrobble, scrobble, true);
										MainWindow.imageHelper.DownloadImage(req);
									});
									
								}
								catch (Exception ex)
								{
									logger.ErrorException(ex.ToString(), ex);
								}
							}

							activity.Add(scrobble);
						}
						else if (contractAct.ActivityAction == (int)TraktActivityAction.Shout)
						{
							if (contractAct.ActivityType == (int)TraktActivityType.Episode)
							{
								Trakt_ActivityShoutEpisodeVM shoutEp = new Trakt_ActivityShoutEpisodeVM(contractAct);
								activity.Add(shoutEp);
							}
							else
							{
								Trakt_ActivityShoutShowVM shoutShow = new Trakt_ActivityShoutShowVM(contractAct);
								activity.Add(shoutShow);
							}
						}
					}

					foreach (JMMServerBinary.Contract_Trakt_Friend contract in traktActivity.TraktFriends)
					{
						if (contract.WatchedEpisodes != null && contract.WatchedEpisodes.Count > 0)
						{
							Trakt_FriendVM friend = new Trakt_FriendVM(contract);
							activity.Add(friend);
						}
					}
				}
				else
				{
					Trakt_SignupVM signup = new Trakt_SignupVM();
					activity.Add(signup);
				}

				System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action)delegate()
				{
					foreach (object act in activity)
						TraktActivity.Add(act);
					ViewTraktActivity.Refresh();
				});
				
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
			finally
			{
			}
		}