Пример #1
0
        protected void OnSharedFolderAdded(object sender, MNode megaNode)
        {
            if (megaNode == null)
            {
                return;
            }

            var node = (IMegaNode)this.ItemCollection.Items.FirstOrDefault(
                n => n.Base64Handle.Equals(megaNode.getBase64Handle()));

            // If exists update it
            if (node != null)
            {
                try { OnUiThread(() => node.Update(megaNode, true)); }
                catch (Exception) { /* Dummy catch, supress possible exception */ }
            }
            else
            {
                try
                {
                    OnUiThread(() =>
                    {
                        this.ItemCollection.Items.Add(NodeService.CreateNewSharedFolder(
                                                          this.MegaSdk, App.AppInformation, megaNode, this));
                    });
                }
                catch (Exception) { /* Dummy catch, supress possible exception */ }
            }
        }
Пример #2
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);
        }