Ejemplo n.º 1
0
        /// <summary>
        /// Update core data associated with the SDK MNode object
        /// </summary>
        /// <param name="megaNode">Node to update</param>
        /// <param name="externalUpdate">Indicates if is an update external to the app. For example from an `onNodesUpdate`</param>
        public virtual void Update(MNode megaNode, bool externalUpdate = false)
        {
            this.OriginalMNode          = megaNode;
            this.Handle                 = megaNode.getHandle();
            this.RestoreHandle          = megaNode.getRestoreHandle();
            this.RestoreNode            = this.MegaSdk.getNodeByHandle(megaNode.getRestoreHandle());
            this.Base64Handle           = megaNode.getBase64Handle();
            this.Type                   = megaNode.getType();
            this.Name                   = megaNode.getName();
            this.Size                   = this.MegaSdk.getSize(megaNode);
            this.CreationTime           = ConvertDateToString(megaNode.getCreationTime()).DateToString();
            this.TypeText               = this.GetTypeText();
            this.LinkExpirationTime     = megaNode.getExpirationTime();
            this.AccessLevel.AccessType = (MShareType)this.MegaSdk.getAccess(megaNode);

            // Needed to filtering when the change is done inside the app or externally and is received by an `onNodesUpdate`
            if (!externalUpdate || megaNode.hasChanged((int)MNodeChangeType.CHANGE_TYPE_PUBLIC_LINK))
            {
                this.IsExported = megaNode.isExported();
                this.ExportLink = this.IsExported ? megaNode.getPublicLink(true) : null;
            }

            if (this.Type == MNodeType.TYPE_FILE)
            {
                this.ModificationTime = ConvertDateToString(megaNode.getModificationTime()).DateToString();
            }
            else
            {
                this.ModificationTime = this.CreationTime;
            }

            if (ParentContainerType != ContainerType.FileLink && ParentContainerType != ContainerType.FolderLink)
            {
                CheckAndUpdateOffline(megaNode);
            }
        }
Ejemplo n.º 2
0
        public void onNodesUpdate(MegaSDK api, MNodeList nodes)
        {
            // Exit methods when node list is incorrect
            if (nodes == null || nodes.size() < 1)
            {
                return;
            }

            // Retrieve the listsize for performance reasons and store local
            int listSize = nodes.size();

            for (int i = 0; i < listSize; i++)
            {
                try
                {
                    // Get the specific node that has an update. If null exit the method
                    // and process no notification
                    MNode megaNode = nodes.get(i);
                    if (megaNode == null)
                    {
                        return;
                    }

                    // Incoming shared folder
                    if (megaNode.isInShare())
                    {
                        if (megaNode.isRemoved()) // REMOVED Scenario
                        {
                            OnInSharedFolderRemoved(megaNode);
                        }
                        else // ADDED/UPDATED scenarios
                        {
                            OnInSharedFolderAdded(megaNode);
                        }
                    }
                    // Outgoing shared folder - ADDED/UPDATED scenarios
                    else if (megaNode.isOutShare())
                    {
                        OnOutSharedFolderAdded(megaNode);
                    }
                    else
                    {
                        // Outgoing shared folder - REMOVED Scenario
                        if (megaNode.hasChanged((int)MNodeChangeType.CHANGE_TYPE_OUTSHARE))
                        {
                            OnOutSharedFolderRemoved(megaNode);
                        }

                        // Normal node
                        if (megaNode.isRemoved()) // REMOVED Scenario
                        {
                            OnNodeRemoved(megaNode);
                        }
                        else // ADDED/UPDATED scenarions
                        {
                            OnNodeAdded(megaNode);
                        }
                    }
                }
                catch (Exception) { /* Dummy catch, suppress possible exception */ }
            }
        }