예제 #1
0
        protected async void GetOutgoingSharedItems()
        {
            // User must be online to perform this operation
            if (!await IsUserOnlineAsync())
            {
                return;
            }

            // First cancel any other loading task that is busy
            CancelLoad();

            // Create the option to cancel
            CreateLoadCancelOption();

            // Process is started so we can set the empty content template to loading already
            SetEmptyContent(true);

            await OnUiThreadAsync(() => this.ItemCollection.Clear());

            MShareList outSharedItems = SdkService.MegaSdk.getOutShares();

            await Task.Factory.StartNew(() =>
            {
                try
                {
                    ulong lastFolderHandle     = 0;
                    var outSharedItemsListSize = outSharedItems.size();
                    for (int i = 0; i < outSharedItemsListSize; i++)
                    {
                        // If the task has been cancelled, stop processing
                        if (LoadingCancelToken.IsCancellationRequested)
                        {
                            LoadingCancelToken.ThrowIfCancellationRequested();
                        }

                        var item = outSharedItems.get(i);

                        // To avoid null values and repeated values (folders shared with more than one user)
                        if (item == null || lastFolderHandle == item.getNodeHandle())
                        {
                            continue;
                        }

                        lastFolderHandle = item.getNodeHandle();

                        var node = NodeService.CreateNewSharedFolder(SdkService.MegaSdk, App.AppInformation,
                                                                     SdkService.MegaSdk.getNodeByHandle(item.getNodeHandle()), this);

                        // If node creation failed for some reason, continue with the rest and leave this one
                        if (node == null)
                        {
                            continue;
                        }

                        OnUiThread(() => this.ItemCollection.Items.Add(node));
                    }
                }
                catch (OperationCanceledException)
                {
                    // Do nothing. Just exit this background process because a cancellation exception has been thrown
                }
            }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current);

            this.SortBy(this.CurrentOrder, this.ItemCollection.CurrentOrderDirection);
            OnItemCollectionChanged(this, EventArgs.Empty);
            SetEmptyContent(false);
        }
예제 #2
0
        /// <summary>
        /// Gets the outgoing shared folders and fills the list.
        /// </summary>
        public void GetOutgoingSharedFolders()
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return;
            }

            // First cancel any other loading task that is busy
            CancelLoad();

            // Create the option to cancel
            CreateLoadCancelOption();

            OutShares.SetProgressIndication(true);

            // Process is started so we can set the empty content template to loading already
            OutShares.SetEmptyContentTemplate(true);

            MShareList outSharesList = MegaSdk.getOutShares();

            if (outSharesList == null)
            {
                OnUiThread(() =>
                {
                    new CustomMessageDialog(
                        AppMessages.AM_LoadFailed_Title,
                        AppMessages.AM_LoadOutSharesFailed,
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();

                    OutShares.SetEmptyContentTemplate(false);
                });

                return;
            }

            OnUiThread(() => OutShares.ChildNodes.Clear());

            Task.Factory.StartNew(() =>
            {
                try
                {
                    ulong lastFolderHandle = 0;
                    int outSharesListSize  = outSharesList.size();
                    for (int i = 0; i < outSharesListSize; i++)
                    {
                        // If the task has been cancelled, stop processing
                        if (LoadingCancelToken.IsCancellationRequested)
                        {
                            LoadingCancelToken.ThrowIfCancellationRequested();
                        }

                        MShare outSharedFolder = outSharesList.get(i);

                        // To avoid null values and public links
                        if ((outSharedFolder != null) && MegaSdk.isOutShare(MegaSdk.getNodeByHandle(outSharedFolder.getNodeHandle())))
                        {
                            // To avoid repeated values, folders shared with more than one user
                            if (lastFolderHandle != outSharedFolder.getNodeHandle())
                            {
                                lastFolderHandle = outSharedFolder.getNodeHandle();

                                var _outSharedFolder = NodeService.CreateNew(this.MegaSdk, this.AppInformation,
                                                                             MegaSdk.getNodeByHandle(lastFolderHandle), ContainerType.OutShares, OutShares.ChildNodes);

                                if (_outSharedFolder != null)
                                {
                                    _outSharedFolder.DefaultImagePathData = VisualResources.FolderTypePath_shared;
                                    OnUiThread(() => OutShares.ChildNodes.Add(_outSharedFolder));
                                }
                            }
                        }
                    }

                    OnUiThread(() =>
                    {
                        OnPropertyChanged("HasOutSharedFolders");
                        OnPropertyChanged("NumberOfOutSharedFolders");
                        OnPropertyChanged("NumberOfOutSharedFoldersText");
                    });
                }
                catch (OperationCanceledException)
                {
                    // Do nothing. Just exit this background process because a cancellation exception has been thrown
                }
                finally
                {
                    // Show the user that processing the childnodes is done
                    OutShares.SetProgressIndication(false);

                    // Set empty content to folder instead of loading view
                    OutShares.SetEmptyContentTemplate(false);
                }
            }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current);
        }