public void Update(MNode megaNode, ContainerType parentContainerType)
        {
            OriginalMNode            = megaNode;
            this.Handle              = megaNode.getHandle();
            this.Base64Handle        = megaNode.getBase64Handle();
            this.Type                = megaNode.getType();
            this.ParentContainerType = parentContainerType;
            this.Name                = megaNode.getName();
            this.Size                = MegaSdk.getSize(megaNode);
            this.SizeText            = this.Size.ToStringAndSuffix(2);
            this.IsExported          = megaNode.isExported();
            this.CreationTime        = ConvertDateToString(megaNode.getCreationTime()).ToString("dd MMM yyyy");

            if (this.Type == MNodeType.TYPE_FILE)
            {
                this.ModificationTime = ConvertDateToString(megaNode.getModificationTime()).ToString("dd MMM yyyy");
            }
            else
            {
                this.ModificationTime = this.CreationTime;
            }

            if (!SdkService.MegaSdk.isInShare(megaNode) && this.ParentContainerType != ContainerType.PublicLink &&
                this.ParentContainerType != ContainerType.InShares && this.ParentContainerType != ContainerType.ContactInShares &&
                this.ParentContainerType != ContainerType.FolderLink)
            {
                CheckAndUpdateSFO(megaNode);
            }
        }
        protected override void OnSuccesAction(MegaSDK api, MRequest request)
        {
            App.LinkInformation.ActiveLink = request.getLink();
            MNode publicNode = App.LinkInformation.PublicNode = request.getPublicMegaNode();

            if (publicNode != null)
            {
                // Save the handle of the last public node accessed (Task #10800)
                SettingsService.SaveLastPublicNodeHandle(publicNode.getHandle());

                #if WINDOWS_PHONE_80
                // Detect if is an image to allow directly download to camera albums
                bool isImage = false;
                if (publicNode.isFile())
                {
                    FileNodeViewModel node = new FileNodeViewModel(api, null, publicNode, ContainerType.PublicLink);
                    isImage = node.IsImage;
                }
                #endif

                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    try
                    {
                        #if WINDOWS_PHONE_80
                        DialogService.ShowOpenLink(publicNode, _folderViewModel, isImage);
                        #elif WINDOWS_PHONE_81
                        DialogService.ShowOpenLink(publicNode, _folderViewModel);
                        #endif
                    }
                    catch (Exception e)
                    {
                        new CustomMessageDialog(
                            ErrorMessageTitle,
                            String.Format(ErrorMessage, e.Message),
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    }
                });
            }
            else
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    new CustomMessageDialog(
                        ErrorMessageTitle,
                        AppMessages.AM_ImportFileFailedNoErrorCode,
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();
                });
            }
        }
Exemple #3
0
        public static bool IsAlreadyUploaded(StorageFile fileToUpload, Stream fileStream, MNode rootNode, ulong mTime)
        {
            // Make sure the stream pointer is at the start of the stream
            fileStream.Position = 0;
            // Get the unique fingerprint of the file
            string fingerprint = MegaSdk.getFileFingerprint(new MegaInputStream(fileStream), mTime);
            // Check if the fingerprint is already in the subfolders of the Camera Uploads
            var mNode = MegaSdk.getNodeByFingerprint(fingerprint, rootNode);

            if (mNode == null)
            {
                return(false);
            }

            if (MegaSdk.isInCloud(mNode))
            {
                var parent = MegaSdk.getParentNode(mNode);
                return(parent?.getHandle() == rootNode.getHandle());
            }

            return(!MegaSdk.isInRubbish(mNode));
        }
Exemple #4
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);
            }
        }
        private void OnOutSharedFolderUpdated(object sender, MNode node)
        {
            if (node.getHandle() != this._sharedFolder.getHandle())
            {
                return;
            }

            var outSharesList     = SdkService.MegaSdk.getOutShares(node);
            var outSharesListSize = outSharesList.size();

            // If the folder is no longer shared with one or more contacts of the list (REMOVE SCENARIO)
            if (outSharesListSize < this.ItemCollection.Items.Count)
            {
                List <ContactOutgoingSharedFolderViewModel> contactsToRemove = new List <ContactOutgoingSharedFolderViewModel>();
                foreach (var item in this.ItemCollection.Items)
                {
                    bool foundItem = false;
                    for (int i = 0; i < outSharesListSize; i++)
                    {
                        var contact = SdkService.MegaSdk.getContact(outSharesList.get(i).getUser());
                        if (item.Handle != contact.getHandle())
                        {
                            continue;
                        }
                        foundItem = true;
                        break;
                    }

                    if (!foundItem)
                    {
                        contactsToRemove.Add(item as ContactOutgoingSharedFolderViewModel);
                    }
                }

                foreach (var item in contactsToRemove)
                {
                    if (item != null)
                    {
                        OnUiThread(() => this.ItemCollection.Items.Remove(item));
                    }
                }
            }
            // If folder is shared with a new contact or permission have changed (ADD and UPDATE scenarios)
            else
            {
                for (int i = 0; i < outSharesListSize; i++)
                {
                    var contact = SdkService.MegaSdk.getContact(outSharesList.get(i).getUser());

                    var existingContact = this.ItemCollection.Items.FirstOrDefault(
                        c => c.Handle.Equals(contact.getHandle()));

                    // If the contact exists in the contact list (UPDATE SCENARIO)
                    if (existingContact != null && existingContact is ContactOutgoingSharedFolderViewModel)
                    {
                        (existingContact as ContactOutgoingSharedFolderViewModel).GetAccesLevel(outSharesList.get(i));
                    }
                    // If the shared folder is shared with a new contact (ADD SCENARIO)
                    else
                    {
                        var megaContact = new ContactOutgoingSharedFolderViewModel(outSharesList.get(i), this);

                        OnUiThread(() => this.ItemCollection.Items.Add(megaContact));

                        megaContact.GetContactFirstname();
                        megaContact.GetContactLastname();
                        megaContact.GetContactAvatarColor();
                        megaContact.GetContactAvatar();
                        megaContact.GetAccesLevel(outSharesList.get(i));
                    }
                }
            }
        }