1 /** 2 * @file BaseRequestListener.cs 3 * @brief Base class for the listeners of request events. 4 * 5 * (c) 2013-2014 by Mega Limited, Auckland, New Zealand 6 * 7 * This file is part of the MEGA SDK - Client Access Engine. 8 * 9 * Applications using the MEGA API must present a valid application key 10 * and comply with the the rules set forth in the Terms of Service. 11 * 12 * The MEGA SDK is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 * 16 * @copyright Simplified (2-clause) BSD License. 17 * 18 * You should have received a copy of the license along with this 19 * program. 20 */ 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 26 using System.Threading.Tasks; 27 using System.Windows; 28 using mega; 29 using MegaApp.Classes; 30 using MegaApp.Services; 31 32 namespace MegaApp.MegaApi 33 { 34 abstract class BaseRequestListener: MRequestListenerInterface 35 { 36 #region Properties 37 38 abstract protected string ProgressMessage { get; } 39 abstract protected string ErrorMessage { get; } 40 abstract protected string ErrorMessageTitle { get; } 41 abstract protected string SuccessMessage { get; } 42 abstract protected string SuccessMessageTitle { get; } 43 abstract protected bool ShowSuccesMessage { get; } 44 abstract protected bool NavigateOnSucces { get; } 45 abstract protected bool ActionOnSucces { get; } 46 abstract protected Action SuccesAction { get; } 47 abstract protected Type NavigateToPage { get; } 48 abstract protected NavigationParameter NavigationParameter { get; } 49 50 #endregion 51 52 #region MRequestListenerInterface 53 onRequestFinish(MegaSDK api, MRequest request, MError e)54 public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e) 55 { 56 Deployment.Current.Dispatcher.BeginInvoke(() => 57 { 58 ProgessService.SetProgressIndicator(false); 59 60 //this.ControlState = true; 61 62 if (e.getErrorCode() == MErrorType.API_OK) 63 { 64 if (ShowSuccesMessage) 65 MessageBox.Show(SuccessMessage, SuccessMessageTitle, MessageBoxButton.OK); 66 67 if (ActionOnSucces) 68 OnSuccesAction(request); 69 70 if (NavigateOnSucces) 71 NavigateService.NavigateTo(NavigateToPage, NavigationParameter); 72 } 73 else 74 MessageBox.Show(String.Format(ErrorMessage, e.getErrorString()), ErrorMessageTitle, MessageBoxButton.OK); 75 }); 76 } 77 onRequestStart(MegaSDK api, MRequest request)78 public virtual void onRequestStart(MegaSDK api, MRequest request) 79 { 80 Deployment.Current.Dispatcher.BeginInvoke(() => 81 { 82 //this.ControlState = false; 83 ProgessService.SetProgressIndicator(true, ProgressMessage); 84 }); 85 } 86 onRequestTemporaryError(MegaSDK api, MRequest request, MError e)87 public virtual void onRequestTemporaryError(MegaSDK api, MRequest request, MError e) 88 { 89 Deployment.Current.Dispatcher.BeginInvoke(() => 90 { 91 ProgessService.SetProgressIndicator(false); 92 MessageBox.Show(String.Format(ErrorMessage, e.getErrorString()), ErrorMessageTitle, MessageBoxButton.OK); 93 }); 94 } 95 onRequestUpdate(MegaSDK api, MRequest request)96 public virtual void onRequestUpdate(MegaSDK api, MRequest request) 97 { 98 // No update status necessary 99 } 100 101 #endregion 102 103 #region Virtual Methods 104 OnSuccesAction(MRequest request)105 protected virtual void OnSuccesAction(MRequest request) 106 { 107 // No standard succes action 108 } 109 110 #endregion 111 } 112 } 113