Example #1
0
        /// <remarks>
        /// ScheduledAgent constructor, initializes the UnhandledException handler
        /// </remarks>
        static ScheduledAgent()
        {
            SdkService.InitializeSdkParams();

            // Subscribe to the managed exception handler
            Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
                Application.Current.UnhandledException += UnhandledException;
            });
        }
Example #2
0
        /// <summary>
        /// Code to detect if the network has changed and refresh all open connections on this case
        /// </summary>
        public static void CheckNetworkChange()
        {
            var ipAddressChanged   = HasChangedIP();
            var networkNameChanged = HasChangedNetworkName();

            if (ipAddressChanged || networkNameChanged)
            {
                SdkService.SetDnsServers();
            }
        }
Example #3
0
        /// <summary>
        /// Code to detect if the network has changed and refresh all open connections on this case
        /// </summary>
        public static void CheckNetworkChange()
        {
            var ipAddressChanged   = HasChangedIP();
            var networkNameChanged = HasChangedNetworkName();

            if (ipAddressChanged || networkNameChanged)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Network or IP address changed.");
                SdkService.SetDnsServers();
            }
        }
Example #4
0
        public NodeActionResult Rename()
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return(NodeActionResult.NotOnline);
            }

            // Only 1 CustomInputDialog should be open at the same time.
            if (this.AppInformation.PickerOrAsyncDialogIsOpen)
            {
                return(NodeActionResult.Cancelled);
            }

            var settings = new CustomInputDialogSettings()
            {
                DefaultText                = this.Name,
                SelectDefaultText          = true,
                IgnoreExtensionInSelection = true,
            };

            var inputDialog = new CustomInputDialog(UiResources.Rename, UiResources.RenameItem, this.AppInformation, settings);

            inputDialog.OkButtonTapped += (sender, args) =>
            {
                if (SdkService.ExistsNodeByName(this.MegaSdk.getParentNode(this.OriginalMNode), args.InputText, this.OriginalMNode.isFolder()))
                {
                    inputDialog.HideDialog();
                    OnUiThread(() =>
                    {
                        new CustomMessageDialog(
                            AppMessages.RenameNodeFailed_Title,
                            this.OriginalMNode.isFolder() ? AppMessages.AM_FolderAlreadyExists : AppMessages.AM_FileAlreadyExists,
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });

                    return;
                }

                this.MegaSdk.renameNode(this.OriginalMNode, args.InputText, new RenameNodeRequestListener(this));
            };
            inputDialog.ShowDialog();

            return(NodeActionResult.IsBusy);
        }
Example #5
0
        /// <summary>
        /// Load folders of the view model
        /// </summary>
        public async void LoadFolders()
        {
            if (this.CloudDrive?.FolderRootNode == null)
            {
                this.CloudDrive.FolderRootNode =
                    NodeService.CreateNew(this.MegaSdk, App.AppInformation,
                                          this.MegaSdk.getRootNode(), this.CloudDrive);
            }

            if (this.ActiveFolderView.Equals(this.CloudDrive))
            {
                this.CloudDrive.LoadChildNodes();
            }

            if (this.RubbishBin?.FolderRootNode == null)
            {
                this.RubbishBin.FolderRootNode =
                    NodeService.CreateNew(this.MegaSdk, App.AppInformation,
                                          this.MegaSdk.getRubbishNode(), this.RubbishBin);
            }

            if (this.ActiveFolderView.Equals(this.RubbishBin))
            {
                this.RubbishBin.LoadChildNodes();
            }

            if (this.CameraUploads?.FolderRootNode == null)
            {
                var cameraUploadsNode = await SdkService.GetCameraUploadRootNodeAsync();

                this.CameraUploads.FolderRootNode =
                    NodeService.CreateNew(this.MegaSdk, App.AppInformation,
                                          cameraUploadsNode, this.CameraUploads);
            }

            if (this.ActiveFolderView.Equals(this.CameraUploads))
            {
                if (!TaskService.IsBackGroundTaskActive(CameraUploadService.TaskEntryPoint, CameraUploadService.TaskName) &&
                    this.CameraUploads?.FolderRootNode == null)
                {
                    return;
                }

                this.CameraUploads.LoadChildNodes();
            }
        }
Example #6
0
        /// <remarks>
        /// ScheduledAgent constructor, initializes the UnhandledException handler
        /// </remarks>
        static ScheduledAgent()
        {
            // Initialize SDK parameters
            SdkService.InitializeSdkParams();

            // Initialize the network parameters
            NetworkService.InitializeNetworkParams();

            // Subscribe to the NetworkAvailabilityChanged event
            DeviceNetworkInformation.NetworkAvailabilityChanged +=
                new EventHandler <NetworkNotificationEventArgs>(NetworkAvailabilityChanged);

            // Subscribe to the managed exception handler
            Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
                Application.Current.UnhandledException += UnhandledException;
            });
        }
Example #7
0
        private void InitializeApplication()
        {
            if (ApplicationInitialized)
            {
                return;
            }

            // Clear settings values we do no longer use
            AppService.ClearObsoleteSettings();

            // Initialize the application information
            if (AppInformation == null)
            {
                AppInformation = new AppInformation();
            }

            // Initialize the links information
            LinkInformationService.Reset();

            // Initialize SDK parameters
            SdkService.InitializeSdkParams();

            // Add a global notifications listener
            GlobalListener = new GlobalListener();
            SdkService.MegaSdk.addGlobalListener(GlobalListener);

            // Add a global request listener to process all.
            SdkService.MegaSdk.addRequestListener(this);

            // Add a global transfer listener to process all transfers.
            SdkService.MegaSdk.addTransferListener(TransferService.GlobalTransferListener);

            // Initialize Folders
            AppService.InitializeAppFolders();

            // Initialize the DB
            AppService.InitializeDatabase();

            // Save the app information for future use (like deleting settings)
            AppService.SaveAppInformation();

            // Ensure we don't initialize again
            ApplicationInitialized = true;
        }
Example #8
0
 private void OnSdkVersionPointerPressed(object sender, PointerRoutedEventArgs e)
 {
     SdkService.ChangeApiUrlActionStarted();
 }
 /// <summary>
 /// 方法说明:获取接收到的平台SDK聊天消息,转化为触角SDK聊天消息
 /// </summary>
 /// <param name="entity">SDK聊天信息</param>
 /// <returns>触角SDK聊天信息</returns>
 internal static GroupBase GetReceiveAntSdkGroupInfo(MsSdkMessageGroupBase entity)
 {
     try
     {
         var sdkcreateObj = entity as CreateGroup;
         if (sdkcreateObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <Create>(sdkcreateObj);
             antsdkchatgroupMsg.content = new Create_content
             {
                 groupId      = sdkcreateObj.content?.groupId,
                 groupName    = sdkcreateObj.content?.groupName,
                 groupPicture = sdkcreateObj.content?.groupPicture,
                 memberCount  = sdkcreateObj.content?.memberCount ?? 0,
                 groupOwnerId = sdkcreateObj.content?.groupOwnerId
             };
             //收到创建讨论组通知,必须订阅讨论组主题收消息
             if (!string.IsNullOrEmpty(sdkcreateObj.content?.groupId))
             {
                 //连接成功需要订阅的默认主题
                 var topics = new List <string> {
                     sdkcreateObj.content.groupId
                 };
                 //订阅默认主题
                 var temperrorMsg = string.Empty;
                 if (!SdkService.Subscribe(topics.ToArray(), ref temperrorMsg))
                 {
                     //记录收到创建讨论组通知后订阅讨论组主题失败日志
                     LogHelper.WriteError($"Received Create Group Message Subscribe Group Topic,{Resources.AntSdkSubscribeGroupTopicsError}:{temperrorMsg}");
                 }
             }
             return(antsdkchatgroupMsg);
         }
         var sdkmodifyObj = entity as MsModifyGroup;
         if (sdkmodifyObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <Modify>(sdkmodifyObj);
             antsdkchatgroupMsg.content = new Modify_content
             {
                 operateId    = sdkmodifyObj.content?.operateId,
                 groupId      = sdkmodifyObj.content?.groupId,
                 groupName    = sdkmodifyObj.content?.groupName,
                 groupPicture = sdkmodifyObj.content?.groupPicture
             };
             return(antsdkchatgroupMsg);
         }
         var sdkdeleteObj = entity as MsDeleteGroup;
         if (sdkdeleteObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <Delete>(sdkdeleteObj);
             antsdkchatgroupMsg.content = new Delete_content
             {
                 groupId = sdkdeleteObj.content?.groupId
             };
             //收到删除讨论组通知,必须取消订阅讨论组主题收消息
             if (!string.IsNullOrEmpty(sdkdeleteObj.content?.groupId))
             {
                 //连接成功需要订阅的默认主题
                 var topics = new List <string> {
                     sdkdeleteObj.content?.groupId
                 };
                 //取消订阅主题
                 var temperrorMsg = string.Empty;
                 if (!SdkService.UnSubscribe(topics.ToArray(), ref temperrorMsg))
                 {
                     //记录收到删除讨论组通知后取消订阅讨论组主题失败日志
                     LogHelper.WriteError($"Received Delete Group Message UnSubscribe Group Topic,{Resources.AntSdkSubscribeDissolveGroupTopicsError}:{temperrorMsg}");
                 }
             }
             return(antsdkchatgroupMsg);
         }
         var sdkaddmemberObj = entity as MsAddGroupMembers;
         if (sdkaddmemberObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <AddMembers>(sdkaddmemberObj);
             var addmemberList      = new List <AntSdkMember>();
             if (sdkaddmemberObj.content?.members?.Count > 0)
             {
                 addmemberList.AddRange(sdkaddmemberObj.content.members.Select(c => new AntSdkMember
                 {
                     userId   = c.userId,
                     userName = c.userName
                 }));
                 //判断被删除的人中存在当前用户,则当前用户的该组主题需要取消订阅
                 var delcurrentUser =
                     addmemberList.FirstOrDefault(u => u.userId == AntSdkService.AntSdkLoginOutput.userId);
                 if (delcurrentUser != null && !string.IsNullOrEmpty(antsdkchatgroupMsg.sessionId))
                 {
                     //当前客户被群主删除,则订阅此群主题
                     var topics = new List <string> {
                         antsdkchatgroupMsg.sessionId
                     };
                     //订阅主题
                     var temperrorMsg = string.Empty;
                     if (!SdkService.Subscribe(topics.ToArray(), ref temperrorMsg))
                     {
                         //收到群主删除组员包含当前用户则取消订阅讨论组主题失败日志
                         LogHelper.WriteError($"Received Delete Group Member Message Contains Self UnSubscribe Group Topic,{Resources.AntSdkSubscribeDeleteGroupMemberTopicsError}:{temperrorMsg}");
                     }
                 }
             }
             antsdkchatgroupMsg.content = new AddMembers_content
             {
                 operateId = sdkaddmemberObj.content?.operateId,
                 members   = addmemberList
             };
             return(antsdkchatgroupMsg);
         }
         var sdkdeletememberObj = entity as MsDeleteGroupMembers;
         if (sdkdeletememberObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <DeleteMembers>(sdkdeletememberObj);
             var addmemberList      = new List <AntSdkMember>();
             if (sdkdeletememberObj.content?.members?.Count > 0)
             {
                 addmemberList.AddRange(sdkdeletememberObj.content.members.Select(c => new AntSdkMember
                 {
                     userId   = c.userId,
                     userName = c.userName
                 }));
                 //判断被删除的人中存在当前用户,则当前用户的该组主题需要取消订阅
                 var delcurrentUser =
                     addmemberList.FirstOrDefault(u => u.userId == AntSdkService.AntSdkLoginOutput.userId);
                 if (delcurrentUser != null && !string.IsNullOrEmpty(antsdkchatgroupMsg.sessionId))
                 {
                     //当前客户被群主删除,则取消订阅此群主题
                     var topics = new List <string> {
                         antsdkchatgroupMsg.sessionId
                     };
                     //取消订阅主题
                     var temperrorMsg = string.Empty;
                     if (!SdkService.UnSubscribe(topics.ToArray(), ref temperrorMsg))
                     {
                         //收到群主删除组员包含当前用户则取消订阅讨论组主题失败日志
                         LogHelper.WriteError($"Received Delete Group Member Message Contains Self UnSubscribe Group Topic,{Resources.AntSdkSubscribeDeleteGroupMemberTopicsError}:{temperrorMsg}");
                     }
                 }
             }
             antsdkchatgroupMsg.content = new DeleteMembers_content
             {
                 operateId = sdkdeletememberObj.content?.operateId,
                 members   = addmemberList
             };
             return(antsdkchatgroupMsg);
         }
         var sdkquitmembersObj = entity as MsQuitGroupMember;
         if (sdkquitmembersObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <QuitMember>(sdkquitmembersObj);
             antsdkchatgroupMsg.content = new QuitMember_content
             {
                 userId         = sdkquitmembersObj.content?.userId,
                 userName       = sdkquitmembersObj.content?.userName,
                 groupOwnerId   = sdkquitmembersObj.content?.groupOwnerId,
                 groupOwnerName = sdkquitmembersObj.content?.groupOwnerName
             };
             return(antsdkchatgroupMsg);
         }
         var sdkmodifymembersObj = entity as MsModifyGroupMember;
         if (sdkmodifymembersObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <ModifyMember>(sdkmodifymembersObj);
             antsdkchatgroupMsg.content = new ModifyMember_content
             {
                 operateId = sdkmodifymembersObj.content?.operateId,
                 userId    = sdkmodifymembersObj.content?.userId,
                 userName  = sdkmodifymembersObj.content?.userName,
             };
             return(antsdkchatgroupMsg);
         }
         var sdkownerburnmodeObj = entity as MsGroupOwnerBurnMode;
         if (sdkownerburnmodeObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <OwnerBurnMode>(sdkownerburnmodeObj);
             antsdkchatgroupMsg.content = new OwnerBurnMode_content
             {
                 maxIndex = sdkownerburnmodeObj.content?.maxIndex ?? 0
             };
             return(antsdkchatgroupMsg);
         }
         var sdkownerburndeleteObj = entity as MsGroupOwnerBurnDelete;
         if (sdkownerburndeleteObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <OwnerBurnDelete>(sdkownerburndeleteObj);
             antsdkchatgroupMsg.content = new OwnerBurnDelete_content
             {
                 maxIndex = sdkownerburndeleteObj.content?.maxIndex ?? 0
             };
             return(antsdkchatgroupMsg);
         }
         var sdkownerburnnomalObj = entity as MsGroupOwnerNormal;
         if (sdkownerburnnomalObj != null)
         {
             var antsdkchatgroupMsg = GetReceiveAntSdkGroupBaseInfo <OwnerNormal>(sdkownerburnnomalObj);
             antsdkchatgroupMsg.content = sdkownerburnnomalObj.content;
             return(antsdkchatgroupMsg);
         }
         var sdkgroupownerchangObj = entity as MsGroupOwnerChanged;
         if (sdkgroupownerchangObj != null)
         {
             var antsdkownerchangedMsg = GetReceiveAntSdkGroupBaseInfo <OwnerChanged>(sdkgroupownerchangObj);
             antsdkownerchangedMsg.content = new OwnerChanged_content
             {
                 newOwnerId = sdkgroupownerchangObj.content?.newOwnerId,
                 oldOwnerId = sdkgroupownerchangObj.content?.oldOwnerId
             };
             return(antsdkownerchangedMsg);
         }
         var sdkgroupadminsetObj = entity as MsGroupAdminSet;
         if (sdkgroupadminsetObj != null)
         {
             var antsdkowneradminsetMsg = GetReceiveAntSdkGroupBaseInfo <AdminSet>(sdkgroupadminsetObj);
             antsdkowneradminsetMsg.content = new AdminSet_content
             {
                 manageId  = sdkgroupadminsetObj.content?.manageId,
                 roleLevel = sdkgroupadminsetObj.content?.roleLevel ?? 0
             };
             return(antsdkowneradminsetMsg);
         }
         //返回空
         return(null);
     }
     catch (Exception ex)
     {
         LogHelper.WriteError(
             $"[AntSdkChatRoomMsg.GetReceiveAntSdkChatRoomInfo]:{Environment.NewLine}{ex.Message}{ex.StackTrace}");
         return(null);
     }
 }
Example #10
0
 private void OnMegaHeaderLogoManipulationFinished(object sender, ManipulationCompletedEventArgs e)
 {
     SdkService.ChangeApiUrlActionFinished();
 }
 private void OnAppVersionManipulationFinished(object sender, ManipulationCompletedEventArgs e)
 {
     SdkService.ChangeApiUrlActionFinished();
 }
 private void OnMegaHeaderLogoReleased(object sender, PointerRoutedEventArgs e)
 {
     SdkService.ChangeApiUrlActionFinished();
 }
 private void OnMegaHeaderLogoPressed(object sender, PointerRoutedEventArgs e)
 {
     SdkService.ChangeApiUrlActionStarted();
 }
Example #14
0
 private void OnSdkVersionPointerReleased(object sender, PointerRoutedEventArgs e)
 {
     SdkService.ChangeApiUrlActionFinished();
 }
Example #15
0
        public async Task RenameAsync()
        {
            // User must be online to perform this operation
            if (!await IsUserOnlineAsync())
            {
                return;
            }

            if (this.Parent?.FolderRootNode == null)
            {
                OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_RenameNodeFailed_Title"),
                        ResourceService.AppMessages.GetString("AM_RenameNodeFailed"));
                });
                return;
            }

            await DialogService.ShowInputAsyncActionDialogAsync(
                ResourceService.UiResources.GetString("UI_Rename"),
                ResourceService.UiResources.GetString("UI_TypeNewName"),
                async (string inputName) =>
            {
                if (string.IsNullOrWhiteSpace(inputName))
                {
                    return(false);
                }
                if (this.Name.Equals(inputName))
                {
                    return(true);
                }

                if (SdkService.ExistsNodeByName(this.Parent.FolderRootNode.OriginalMNode, inputName, this.OriginalMNode.isFolder()))
                {
                    DialogService.SetInputDialogWarningMessage(this.OriginalMNode.isFolder() ?
                                                               ResourceService.AppMessages.GetString("AM_FolderAlreadyExists") :
                                                               ResourceService.AppMessages.GetString("AM_FileAlreadyExists"));
                    return(false);
                }

                var rename  = new RenameNodeRequestListenerAsync();
                var newName = await rename.ExecuteAsync(() =>
                                                        this.MegaSdk.renameNode(this.OriginalMNode, inputName, rename));

                if (string.IsNullOrEmpty(newName))
                {
                    DialogService.SetInputDialogWarningMessage(ResourceService.AppMessages.GetString("AM_RenameNodeFailed"));
                    return(false);
                }

                OnUiThread(() => this.Name = newName);

                return(true);
            },
                new InputDialogSettings
            {
                InputText                  = this.Name,
                IsTextSelected             = true,
                IgnoreExtensionInSelection = this.OriginalMNode.isFile()
            });
        }
Example #16
0
        // Do not add any additional code to this method
        private async void InitializePhoneApplication()
        {
            if (phoneApplicationInitialized)
            {
                return;
            }

            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame = new RadPhoneApplicationFrame
            {
                // Add default page transitions animations
                Transition = new RadTransition()
                {
                    ForwardInAnimation   = AnimationService.GetPageInAnimation(),
                    ForwardOutAnimation  = AnimationService.GetPageOutAnimation(),
                    BackwardInAnimation  = AnimationService.GetPageInAnimation(),
                    BackwardOutAnimation = AnimationService.GetPageOutAnimation(),
                }
            };

            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Handle reset requests for clearing the backstack
            RootFrame.Navigated += CheckForResetNavigation;

#if WINDOWS_PHONE_81
            RootFrame.Navigating += RootFrameOnNavigating;

            // Handle contract activation such as returned values from file open or save picker
            PhoneApplicationService.Current.ContractActivated += CurrentOnContractActivated;
#endif

            // Assign the URI-mapper class to the application frame.
            RootFrame.UriMapper = new AssociationUriMapper();

            // Initialize the application information
            AppInformation = new AppInformation();

            // Initialize the links information
            LinkInformation = new LinkInformation();

            // Initialize SDK parameters
            SdkService.InitializeSdkParams();

            // Initialize the main drive
            CloudDrive = new CloudDriveViewModel(SdkService.MegaSdk, AppInformation);

            // Add a global notifications listener.
            GlobalListener = new GlobalListener(AppInformation);
            SdkService.MegaSdk.addGlobalListener(GlobalListener);

            // Add a global request listener to process all.
            SdkService.MegaSdk.addRequestListener(this);

            // Add a global transfer listener to process all transfers.
            SdkService.MegaSdk.addTransferListener(TransfersService.GlobalTransferListener);

            // Initialize Folders
            AppService.InitializeAppFolders();

            // Set the current resolution that we use later on for our image selection
            AppService.CurrentResolution = ResolutionHelper.CurrentResolution;

            // Clear settings values we do no longer use
            AppService.ClearObsoleteSettings();

            // Save the app version information for future use (like deleting settings)
            AppService.SaveAppInformation();

            // Set MEGA red as Accent Color
            ((SolidColorBrush)Resources["PhoneAccentBrush"]).Color = (Color)Resources["MegaRedColor"];

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;
        }
Example #17
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();

            // Check for network changes
            NetworkService.CheckNetworkChange();

            // Set the API to use depending on the settings
            if (SettingsService.LoadSetting(ResourceService.SettingsResources.GetString("SR_UseStagingServer"), false))
            {
                SdkService.MegaSdk.changeApiUrl("https://staging.api.mega.co.nz/");
            }
            else if (SettingsService.LoadSetting(ResourceService.SettingsResources.GetString("SR_UseStagingServerPort444"), false))
            {
                SdkService.MegaSdk.changeApiUrl("https://staging.api.mega.co.nz:444/", true);
            }
            else
            {
                SdkService.MegaSdk.changeApiUrl("https://g.api.mega.co.nz/");
            }

            // Log message to indicate that the service is invoked
            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Service invoked.");

            // Load the connection upload settings
            CameraUploadsConnectionType cameraUploadsConnectionType = CameraUploadsConnectionType.EthernetWifiOnly;

            try
            {
                cameraUploadsConnectionType = (CameraUploadsConnectionType)await SettingsService.LoadSettingFromFileAsync <int>("CameraUploadsSettingsHowKey");
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Could not load settings", e);
            }

            if (!CheckNetWork(cameraUploadsConnectionType))
            {
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Task finished: connection type");
                _deferral.Complete();
                return;
            }

            SdkService.InitializeSdkParams();

            var loggedIn = await LoginAsync();

            if (loggedIn)
            {
                var fetched = await FetchNodesAsync();

                if (fetched)
                {
                    // Add notifications listener
                    var megaGlobalListener = new MegaGlobalListener();
                    SdkService.MegaSdk.addGlobalListener(megaGlobalListener);

                    // Enable the transfers resumption for the Camera Uploads service
                    await megaGlobalListener.ExecuteAsync(() => SdkService.MegaSdk.enableTransferResumption());

                    var cameraUploadRootNode = await SdkService.GetCameraUploadRootNodeAsync();

                    if (cameraUploadRootNode == null)
                    {
                        // No camera upload node found or created
                        // Just finish this run and try again next time
                        LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "No Camera Uploads folder detected/created");
                        _deferral.Complete();
                        return;
                    }

                    // Load the file upload settings
                    CameraUploadsFileType cameraUploadsFileType = CameraUploadsFileType.PhotoAndVideo;
                    try
                    {
                        cameraUploadsFileType = (CameraUploadsFileType)await SettingsService.LoadSettingFromFileAsync <int>("CameraUploadsSettingsFileKey");
                    }
                    catch (Exception e)
                    {
                        LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Could not load settings", e);
                    }

                    var uploadFolders = new List <StorageFolder>();
                    switch (cameraUploadsFileType)
                    {
                    case CameraUploadsFileType.PhotoAndVideo:
                        uploadFolders.Add(KnownFolders.PicturesLibrary);
                        uploadFolders.Add(KnownFolders.VideosLibrary);
                        break;

                    case CameraUploadsFileType.PhotoOnly:
                        uploadFolders.Add(KnownFolders.PicturesLibrary);
                        break;

                    case CameraUploadsFileType.VideoOnly:
                        uploadFolders.Add(KnownFolders.VideosLibrary);
                        break;
                    }

                    // Get the IMAGE and/or VIDEO files to upload to MEGA
                    var fileToUpload = await TaskService.GetAvailableUploadAsync(
                        TaskService.ImageDateSetting, uploadFolders.ToArray());

                    foreach (var storageFile in fileToUpload)
                    {
                        // Skip the current file if it has failed more than the max error count
                        if (await ErrorHandlingService.SkipFileAsync(
                                storageFile.Name,
                                ErrorHandlingService.ImageErrorFileSetting,
                                ErrorHandlingService.ImageErrorCountSetting))
                        {
                            continue;
                        }

                        if (!CheckNetWork(cameraUploadsConnectionType))
                        {
                            break;
                        }

                        // Calculate time for fingerprint check and upload
                        ulong mtime = TaskService.CalculateMtime(storageFile.DateCreated.DateTime);
                        try
                        {
                            using (var fs = await storageFile.OpenStreamForReadAsync())
                            {
                                var isUploaded = SdkService.IsAlreadyUploaded(storageFile, fs, cameraUploadRootNode, mtime);
                                if (isUploaded)
                                {
                                    await TaskService.SaveLastUploadDateAsync(storageFile, TaskService.ImageDateSetting);

                                    continue;
                                }
                                await UploadAsync(storageFile, fs, cameraUploadRootNode, mtime);

                                // No error, clear error storage
                                await ErrorHandlingService.ClearAsync(ErrorHandlingService.ImageErrorFileSetting,
                                                                      ErrorHandlingService.ImageErrorCountSetting);
                            }
                        }
                        catch (OutOfMemoryException e)
                        {
                            // Something went wrong (could be memory limit)
                            // Just finish this run and try again next time
                            LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Out of memory while uploading", e);
                            break;
                        }
                        catch (Exception e)
                        {
                            LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error uploading item", e);
                            await ErrorHandlingService.SetFileErrorAsync(storageFile.Name,
                                                                         ErrorHandlingService.ImageErrorFileSetting, ErrorHandlingService.ImageErrorCountSetting);
                        }
                    }
                }
                else
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failed to fetch nodes");
                }
            }
            else
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Failed to login");
            }

            _deferral.Complete();
        }