Пример #1
0
        /// <summary>
        /// Locate the Camera Uploads folder node to use as parent for the uploads
        /// </summary>
        /// <returns>Camera Uploads folder node</returns>
        private async Task <MNode> GetCameraUploadsNode()
        {
            // First try to retrieve the Cloud Drive root node
            var rootNode = SdkService.MegaSdk.getRootNode();

            if (rootNode == null)
            {
                return(null);
            }

            // Locate the camera upload node
            var cameraUploadNode = FindCameraUploadNode(rootNode);

            // If node found, return the node
            if (cameraUploadNode != null)
            {
                return(cameraUploadNode);
            }

            // Node not found, create a new Camera Uploads node
            var tcs = new TaskCompletionSource <MNode>();

            var createFolderListener = new MegaRequestListener();

            // After reqyest finished, return the newly created Camera Uploads node
            createFolderListener.RequestFinished += (sender, args) =>
            {
                tcs.TrySetResult(args.Succeeded ? FindCameraUploadNode(rootNode) : null);
            };

            // Init folder creation
            SdkService.MegaSdk.createFolder("Camera Uploads", rootNode, createFolderListener);

            return(await tcs.Task);
        }
Пример #2
0
        /// <summary>
        /// Fast login to MEGA account with user session token
        /// </summary>
        private void FastLogin()
        {
            string sessionToken = null;

            try
            {
                // Try to load shared session token file
                sessionToken = SettingsService.LoadSettingFromFile <string>("{85DBF3E5-51E8-40BB-968C-8857B4FC6EF4}");
            }
            catch (Exception)
            {
                // Failed to load shared session token file
                // Notify complete and try next run to load the session string
                this.NotifyComplete();
                return;
            }


            if (String.IsNullOrEmpty(sessionToken) || String.IsNullOrWhiteSpace(sessionToken))
            {
                // No shred session token found
                // Notify complete and try next run to load the session string
                this.NotifyComplete();
                return;
            }

            // Do login
            var fastLoginListener = new MegaRequestListener();

            // After the request is finished. Check for success or failure
            fastLoginListener.RequestFinished += (sender, args) =>
            {
                if (!args.Succeeded)
                {
                    // Login failed
                    // Notify complete and try next run to load the session string
                    this.NotifyComplete();
                    return;
                }

                // Login succeeded
                // Fetch nodes. Needed to find the camera upload node later
                FetchNodes();
            };

            // Init fastlogin
            SdkService.MegaSdk.fastLogin(sessionToken, fastLoginListener);
        }
Пример #3
0
        /// <summary>
        /// Fetch the MEGA nodes from the server
        /// </summary>
        private void FetchNodes()
        {
            var fetchNodesListener = new MegaRequestListener();

            // After the request is finished. Check for success or failure
            fetchNodesListener.RequestFinished += (sender, args) =>
            {
                if (!args.Succeeded)
                {
                    // When failed to retreive nodes we can not proceed to upload
                    // Notify complete and try next run to load the session string
                    this.NotifyComplete();
                    return;
                }

                // Enable the transfers resumption for the Camera Uploads service
                SdkService.MegaSdk.enableTransferResumption();
            };

            // Init fetch nodes
            SdkService.MegaSdk.fetchNodes(fetchNodesListener);
        }