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) { if (_isImportFolderProcess) { MNode parentNode = api.getNodeByHandle(request.getParentHandle()); MNode newFolderNode = api.getNodeByHandle(request.getNodeHandle()); if (!App.LinkInformation.FoldersToImport.ContainsKey(parentNode.getBase64Handle())) { return; } // Get from the corresponding dictionary all the folders parent folder and explore them. var megaNodes = App.LinkInformation.FoldersToImport[parentNode.getBase64Handle()]; foreach (var node in megaNodes) { if (App.LinkInformation.FolderPaths.ContainsKey(node.getBase64Handle())) { String nodePath = App.LinkInformation.FolderPaths[node.getBase64Handle()]; // If the name of the new folder matches with the last part of the node path // obtained from the dictionary, then this is the current imported folder. if (String.Compare(newFolderNode.getName(), nodePath.Split('/').Last()) == 0) { // Import the content of a recently created node folder. ImportNodeContents(node, newFolderNode); // Remove the node from the list and update the dictionaries. megaNodes.Remove(node); if (App.LinkInformation.FoldersToImport.ContainsKey(parentNode.getBase64Handle())) { App.LinkInformation.FoldersToImport.Remove(parentNode.getBase64Handle()); } if (megaNodes.Count > 0) { if (!App.LinkInformation.FoldersToImport.ContainsKey(parentNode.getBase64Handle())) { App.LinkInformation.FoldersToImport.Add(parentNode.getBase64Handle(), megaNodes); } } if (App.LinkInformation.FolderPaths.ContainsKey(node.getBase64Handle())) { App.LinkInformation.FolderPaths.Remove(node.getBase64Handle()); } break; } } } } }
public NodeViewModel(MegaSDK megaSdk, MNode baseNode) { this._megaSdk = megaSdk; this._baseNode = baseNode; this.Name = baseNode.getName(); this.Size = baseNode.getSize(); this.CreationTime = ConvertDateToString(_baseNode.getCreationTime()).ToString("dd MMM yyyy"); this.ModificationTime = ConvertDateToString(_baseNode.getModificationTime()).ToString("dd MMM yyyy"); this.SizeAndSuffix = Size.ToStringAndSuffix(); this.Type = baseNode.getType(); this.NumberOfFiles = this.Type != MNodeType.TYPE_FOLDER ? null : String.Format("{0} {1}", this._megaSdk.getNumChildren(this._baseNode), UiResources.Files); if (this.Type == MNodeType.TYPE_FOLDER || this.Type == MNodeType.TYPE_FILE) this.ThumbnailImageUri = new Uri((String)new FileTypeToImageConverter().Convert(this, null, null, null), UriKind.Relative); }
public FolderNodeViewModel(MegaSDK megaSdk, AppInformation appInformation, MNode megaNode, ContainerType parentContainerType, ObservableCollection<IMegaNode> parentCollection = null, ObservableCollection<IMegaNode> childCollection = null) : base(megaSdk, appInformation, megaNode, parentContainerType, parentCollection, childCollection) { SetFolderInfo(); this.IsDefaultImage = true; this.DefaultImagePathData = VisualResources.FolderTypePath_default; if (megaSdk.isShared(megaNode)) this.DefaultImagePathData = VisualResources.FolderTypePath_shared; if (!megaNode.getName().ToLower().Equals("camera uploads")) return; this.DefaultImagePathData = VisualResources.FolderTypePath_photo; }
public NodeViewModel(MegaSDK megaSdk, MNode baseNode) { this._megaSdk = megaSdk; this._baseNode = baseNode; this.Name = baseNode.getName(); this.Size = baseNode.getSize(); this.CreationTime = ConvertDateToString(_baseNode.getCreationTime()).ToString("dd MMM yyyy"); this.ModificationTime = ConvertDateToString(_baseNode.getModificationTime()).ToString("dd MMM yyyy"); this.SizeAndSuffix = Size.ToStringAndSuffix(); this.Type = baseNode.getType(); this.NumberOfFiles = this.Type != MNodeType.TYPE_FOLDER ? null : String.Format("{0} {1}", this._megaSdk.getNumChildren(this._baseNode), UiResources.Files); if (this.Type == MNodeType.TYPE_FOLDER || this.Type == MNodeType.TYPE_FILE) { this.ThumbnailImageUri = new Uri((String) new FileTypeToImageConverter().Convert(this, null, null, null), UriKind.Relative); } }
/// <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 override void Update(MNode megaNode, bool externalUpdate = false) { base.Update(megaNode, externalUpdate); SetFolderInfo(); if (megaNode.isInShare()) { return; } OnPropertyChanged(nameof(this.IsOutShare), nameof(this.SharingText)); if (megaNode.isOutShare()) { if (this.ContactsList == null) { this.ContactsList = new ContactsListOutgoingSharedFolderViewModel(megaNode); this.GetContactsList(); } } else { if (this.ContactsList != null) { OnUiThread(() => this.ContactsList.ItemCollection.Clear()); } } this.DefaultImagePathData = megaNode.isOutShare() ? ResourceService.VisualResources.GetString("VR_OutgoingSharedFolderPathData") : ResourceService.VisualResources.GetString("VR_FolderTypePath_default"); if (!megaNode.getName().ToLower().Equals("camera uploads")) { return; } this.DefaultImagePathData = ResourceService.VisualResources.GetString("VR_FolderTypePath_photo"); }
/// <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); } }
public void onNodesUpdate(MegaSDK api, MNodeList nodes) { // exit methods when node list is incorrect if (nodes == null || nodes.size() < 1) { return; } try { // Retrieve the listsize for performance reasons and store local int listSize = nodes.size(); for (int i = 0; i < listSize; i++) { bool isProcessed = false; // 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; } // PROCESS THE FOLDERS LISTENERS if (megaNode.isRemoved()) { // REMOVED Scenario foreach (var folder in Folders) { IMegaNode nodeToRemoveFromView = folder.ChildNodes.FirstOrDefault( node => node.Base64Handle.Equals(megaNode.getBase64Handle())); // If node is found in current view, process the remove action if (nodeToRemoveFromView != null) { // Needed because we are in a foreach loop to prevent the use of the wrong // local variable in the dispatcher code. var currentFolder = folder; Deployment.Current.Dispatcher.BeginInvoke(() => { try { currentFolder.ChildNodes.Remove(nodeToRemoveFromView); ((FolderNodeViewModel)currentFolder.FolderRootNode).SetFolderInfo(); } catch (Exception) { // Dummy catch, surpress possible exception } }); isProcessed = true; break; } } if (!isProcessed) { // REMOVED in subfolder scenario MNode parentNode = api.getParentNode(megaNode); if (parentNode != null) { foreach (var folder in Folders) { IMegaNode nodeToUpdateInView = folder.ChildNodes.FirstOrDefault( node => node.Base64Handle.Equals(parentNode.getBase64Handle())); // If parent folder is found, process the update action if (nodeToUpdateInView != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { try { nodeToUpdateInView.Update(parentNode, folder.Type); var folderNode = nodeToUpdateInView as FolderNodeViewModel; if (folderNode != null) { folderNode.SetFolderInfo(); } } catch (Exception) { // Dummy catch, surpress possible exception } }); } } } } } // UPDATE / ADDED scenarions else { // UPDATE Scenario // PROCESS THE SINGLE NODE(S) LISTENER(S) (NodeDetailsPage live updates) foreach (var node in Nodes) { if (megaNode.getBase64Handle() == node.getNodeBase64Handle()) { Deployment.Current.Dispatcher.BeginInvoke(() => node.updateNode(megaNode)); } } // Used in different scenario's MNode parentNode = api.getParentNode(megaNode); foreach (var folder in Folders) { IMegaNode nodeToUpdateInView = folder.ChildNodes.FirstOrDefault( node => node.Base64Handle.Equals(megaNode.getBase64Handle())); // If node is found, process the update action if (nodeToUpdateInView != null) { bool isMoved = !folder.FolderRootNode.Base64Handle.Equals(parentNode.getBase64Handle()); // Is node is move to different folder. Remove from current folder view if (isMoved) { // Needed because we are in a foreach loop to prevent the use of the wrong // local variable in the dispatcher code. var currentFolder = folder; Deployment.Current.Dispatcher.BeginInvoke(() => { try { currentFolder.ChildNodes.Remove(nodeToUpdateInView); ((FolderNodeViewModel)currentFolder.FolderRootNode).SetFolderInfo(); UpdateFolders(currentFolder); } catch (Exception) { // Dummy catch, surpress possible exception } }); } // Node is updated with new data. Update node in current view else { Deployment.Current.Dispatcher.BeginInvoke(() => { try { nodeToUpdateInView.Update(megaNode, folder.Type); } catch (Exception) { // Dummy catch, surpress possible exception } }); isProcessed = true; break; } } } // ADDED scenario if (parentNode != null && !isProcessed) { foreach (var folder in Folders) { bool isAddedInFolder = folder.FolderRootNode.Base64Handle.Equals(parentNode.getBase64Handle()); // If node is added in current folder, process the add action if (isAddedInFolder) { // Retrieve the index from the SDK // Substract -1 to get a valid list index int insertIndex = api.getIndex(megaNode, UiService.GetSortOrder(parentNode.getBase64Handle(), parentNode.getName())) - 1; // If the insert position is higher than the ChilNodes size insert in the last position if (insertIndex >= folder.ChildNodes.Count()) { // Needed because we are in a foreach loop to prevent the use of the wrong // local variable in the dispatcher code. var currentFolder = folder; Deployment.Current.Dispatcher.BeginInvoke(() => { try { currentFolder.ChildNodes.Add(NodeService.CreateNew(api, _appInformation, megaNode, currentFolder.Type)); ((FolderNodeViewModel)currentFolder.FolderRootNode).SetFolderInfo(); UpdateFolders(currentFolder); } catch (Exception) { // Dummy catch, surpress possible exception } }); } // Insert the node at a specific position else { // Insert position can never be less then zero // Replace negative index with first possible index zero if (insertIndex < 0) { insertIndex = 0; } // Needed because we are in a foreach loop to prevent the use of the wrong // local variable in the dispatcher code. var currentFolder = folder; Deployment.Current.Dispatcher.BeginInvoke(() => { try { currentFolder.ChildNodes.Insert(insertIndex, NodeService.CreateNew(api, _appInformation, megaNode, currentFolder.Type)); ((FolderNodeViewModel)currentFolder.FolderRootNode).SetFolderInfo(); UpdateFolders(currentFolder); } catch (Exception) { // Dummy catch, surpress possible exception } }); } break; } // ADDED in subfolder scenario IMegaNode nodeToUpdateInView = folder.ChildNodes.FirstOrDefault( node => node.Base64Handle.Equals(parentNode.getBase64Handle())); if (nodeToUpdateInView != null) { Deployment.Current.Dispatcher.BeginInvoke(() => { try { nodeToUpdateInView.Update(parentNode, folder.Type); var folderNode = nodeToUpdateInView as FolderNodeViewModel; if (folderNode != null) { folderNode.SetFolderInfo(); } } catch (Exception) { // Dummy catch, surpress possible exception } }); break; } // Unconditional scenarios // Move/delete/add actions in subfolders var localFolder = folder; Deployment.Current.Dispatcher.BeginInvoke(() => { try { UpdateFolders(localFolder); } catch (Exception) { // Dummy catch, surpress possible exception } }); } } } } } catch (Exception) { // Dummy catch, surpress possible exception } }
public static NodeViewModel CreateNew(MegaSDK megaSdk, AppInformation appInformation, MNode megaNode, ContainerType parentContainerType, ObservableCollection <IMegaNode> parentCollection = null, ObservableCollection <IMegaNode> childCollection = null) { if (megaNode == null) { return(null); } try { switch (megaNode.getType()) { case MNodeType.TYPE_UNKNOWN: break; case MNodeType.TYPE_FILE: { if (megaNode.hasThumbnail() || megaNode.hasPreview() || ImageService.IsImage(megaNode.getName())) { return(new ImageNodeViewModel(megaSdk, appInformation, megaNode, parentContainerType, parentCollection, childCollection)); } return(new FileNodeViewModel(megaSdk, appInformation, megaNode, parentContainerType, parentCollection, childCollection)); } case MNodeType.TYPE_FOLDER: case MNodeType.TYPE_ROOT: case MNodeType.TYPE_RUBBISH: { return(new FolderNodeViewModel(megaSdk, appInformation, megaNode, parentContainerType, parentCollection, childCollection)); } case MNodeType.TYPE_INCOMING: break; } } catch (Exception) { return(null); } return(null); }
public static NodeViewModel CreateNew(MegaSDK megaSdk, AppInformation appInformation, MNode megaNode, FolderViewModel folder = null, ObservableCollection <IBaseNode> parentCollection = null, ObservableCollection <IBaseNode> childCollection = null) { if (megaNode == null) { return(null); } try { if (folder == null) { if (megaSdk.isInCloud(megaNode)) { folder = new FolderViewModel(megaSdk, ContainerType.CloudDrive); } if (megaSdk.isInRubbish(megaNode)) { folder = new FolderViewModel(megaSdk, ContainerType.RubbishBin); } if (megaSdk.isInShare(megaNode)) { folder = new FolderViewModel(megaSdk, ContainerType.InShares); } if (megaSdk.isOutShare(megaNode)) { folder = new FolderViewModel(megaSdk, ContainerType.OutShares); } } switch (megaNode.getType()) { case MNodeType.TYPE_UNKNOWN: break; case MNodeType.TYPE_FILE: if (megaNode.hasThumbnail() || megaNode.hasPreview() || ImageService.IsImage(megaNode.getName())) { return(new ImageNodeViewModel(megaSdk, appInformation, megaNode, folder, parentCollection, childCollection)); } return(new FileNodeViewModel(megaSdk, appInformation, megaNode, folder, parentCollection, childCollection)); case MNodeType.TYPE_ROOT: case MNodeType.TYPE_RUBBISH: return(new FolderNodeViewModel(megaSdk, appInformation, megaNode, folder, parentCollection, childCollection)); case MNodeType.TYPE_FOLDER: return(new FolderNodeViewModel(megaSdk, appInformation, megaNode, folder, parentCollection, childCollection)); case MNodeType.TYPE_INCOMING: break; } } catch (Exception) { return(null); } return(null); }