예제 #1
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            // Initialisation SDK succeeded
            scheduledAgent = this;

            // Log message to indicate that the service is invoked and the last exit reason
            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Service invoked. Last exit reason: " +
                           task.LastExitReason);

            // Add notifications listener
            SdkService.MegaSdk.addGlobalListener(new MegaGlobalListener());

            // Abort the service when storage quota exceeded error is raised in the transferlistener
            // Abort will stop the service and it will not be launched again until the user
            // activates it in the main application
            var megaTransferListener = new MegaTransferListener();

            megaTransferListener.StorageQuotaExceeded += (sender, args) =>
            {
                scheduledAgent.Abort();
            };
            // Notify complete when tramsfer quota exceeded error is raised in the transferlistener
            // Notify complete will retry in the next task run
            megaTransferListener.TransferQuotaExceeded += (sender, args) =>
            {
                scheduledAgent.NotifyComplete();
            };

            // Add transfers listener
            SdkService.MegaSdk.addTransferListener(megaTransferListener);

            // Fast login with session token that was saved during MEGA app initial login
            FastLogin();
        }
예제 #2
0
        /// <summary>
        /// Agent that runs a scheduled task
        /// </summary>
        /// <param name="task">
        /// The invoked task
        /// </param>
        /// <remarks>
        /// This method is called when a periodic or resource intensive task is invoked
        /// </remarks>
        protected override void OnInvoke(ScheduledTask task)
        {
            // Initialisation SDK succeeded
            scheduledAgent = this;

            // Set the API to use depending on the settings
            SdkService.MegaSdk.changeApiUrl(SettingsService.LoadSetting <bool>("{BA40B745-D0F5-4AD5-A539-44B1403A9EB8}", false) ?
                                            "https://staging.api.mega.co.nz/" : "https://g.api.mega.co.nz/");

            // Log message to indicate that the service is invoked and the last exit reason
            LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Service invoked. Last exit reason: " +
                           task.LastExitReason);

            // Add notifications listener
            SdkService.MegaSdk.addGlobalListener(new MegaGlobalListener());

            // Notify complete when storage quota exceeded error is raised in the transferlistener
            // Notify complete will retry in the next task run
            var megaTransferListener = new MegaTransferListener();

            megaTransferListener.StorageQuotaExceeded += (sender, args) =>
            {
                scheduledAgent.NotifyComplete();
            };

            // Add transfers listener
            SdkService.MegaSdk.addTransferListener(megaTransferListener);

            // Fast login with session token that was saved during MEGA app initial login
            FastLogin();
        }
예제 #3
0
        public void onTransferFinish(MegaSDK api, MTransfer transfer, MError e)
        {
            if (_timer != null)
            {
                _timer.Dispose();
            }

            if (e.getErrorCode() == MErrorType.API_EOVERQUOTA)
            {
                //Stop the Camera Upload Service
                LogService.Log(MLogLevel.LOG_LEVEL_INFO, "Disabling CAMERA UPLOADS service (API_EOVERQUOTA)");
                OnQuotaExceeded(EventArgs.Empty);
                return;
            }

            try
            {
                if (e.getErrorCode() == MErrorType.API_OK)
                {
                    ulong    mtime       = api.getNodeByHandle(transfer.getNodeHandle()).getModificationTime();
                    DateTime pictureDate = new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(Convert.ToDouble(mtime));
                    SettingsService.SaveSettingToFile <DateTime>("LastUploadDate", pictureDate);

                    // If file upload succeeded. Clear the error information for a clean sheet.
                    ErrorProcessingService.Clear();
                }
                else
                {
                    // An error occured. Log and process it.
                    switch (e.getErrorCode())
                    {
                    case MErrorType.API_EFAILED:
                    case MErrorType.API_EEXIST:
                    case MErrorType.API_EARGS:
                    case MErrorType.API_EREAD:
                    case MErrorType.API_EWRITE:
                    {
                        LogService.Log(MLogLevel.LOG_LEVEL_ERROR, e.getErrorString());
                        ErrorProcessingService.ProcessFileError(transfer.getFileName());
                        break;
                    }
                    }
                }
            }
            catch (Exception)
            {
                // Setting could not be saved. Just continue the run
            }
            finally
            {
                // Start a new upload action
                ScheduledAgent.Upload();
            }
        }
예제 #4
0
 public void onNodesUpdate(MegaSDK api, MNodeList nodes)
 {
     // If the SDK has resumed the possible pending transfers
     if (nodes == null)
     {
         // If no pending transfers to resume start a new upload
         // Else it will start when finish the current transfer
         if (api.getTransfers(MTransferType.TYPE_UPLOAD).size() == 0)
         {
             ScheduledAgent.Upload();
         }
     }
 }