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 void OnSharedFolderRemoved(object sender, MNode megaNode) { if (megaNode == null) { return; } var node = this.ItemCollection.Items.FirstOrDefault( n => n.Base64Handle.Equals(megaNode.getBase64Handle())); // If node isn't found in current view, don't process the remove action if (node == null) { return; } try { OnUiThread(() => { this.ItemCollection.Items.Remove(node); if (this.ItemCollection.FocusedItem?.Equals(node) == true) { this.ClosePanels(); } }); } catch (Exception) { /* Dummy catch, supress possible exception */ } }
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 */ } } }
/// <summary> /// Method to import the content of a recently created node folder during /// the process to import a folder link. /// </summary> /// <param name="nodeToImport">Node folder to import.</param> /// <param name="parentNode">Parent folder of the node to import.</param> private void ImportNodeContents(MNode nodeToImport, MNode parentNode) { // Obtain the child nodes and the number of them. var childNodes = App.MegaSdkFolderLinks.getChildren(nodeToImport); var childNodesSize = childNodes.size(); // Explore the child nodes. Store the folders in a new list and add them to // the corresponding dictionary. Copy the file nodes. List <MNode> folderNodesToImport = new List <MNode>(); for (int i = 0; i < childNodesSize; i++) { var node = childNodes.get(i); if (node.isFolder()) { folderNodesToImport.Add(node); if (!App.LinkInformation.FolderPaths.ContainsKey(node.getBase64Handle())) { App.LinkInformation.FolderPaths.Add(node.getBase64Handle(), App.MegaSdkFolderLinks.getNodePath(node)); } } else { App.MegaSdk.copyNode(node, parentNode, new CopyNodeRequestListener(true)); } } // Add the list with the new folder nodes to import to the corresponding dictionary. if (!App.LinkInformation.FoldersToImport.ContainsKey(parentNode.getBase64Handle())) { App.LinkInformation.FoldersToImport.Add(parentNode.getBase64Handle(), folderNodesToImport); } // Create all the new folder nodes. foreach (var node in folderNodesToImport) { App.MegaSdk.createFolder(node.getName(), parentNode, new CreateFolderRequestListener(true)); } }
// Insert the new node in the SavedForOffline table. public static void Insert(MNode megaNode, bool isSelectedForOffline = false) { var nodeOfflineLocalPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, AppResources.DownloadsDirectory, SdkService.MegaSdk.getNodePath(megaNode).Remove(0, 1).Replace("/", "\\")); var sfoNode = new SavedForOffline() { Fingerprint = SdkService.MegaSdk.getNodeFingerprint(megaNode), Base64Handle = megaNode.getBase64Handle(), LocalPath = nodeOfflineLocalPath, ParentBase64Handle = (SdkService.MegaSdk.getParentNode(megaNode)).getBase64Handle(), IsSelectedForOffline = isSelectedForOffline }; Insert(sfoNode); }
/// <summary> /// Insert a node in the database. /// </summary> /// <param name="megaNode">Node to insert.</param> public static void InsertNode(MNode megaNode) { var offlineNodePath = OfflineService.GetOfflineNodePath(megaNode); var parentNode = SdkService.MegaSdk.getParentNode(megaNode); var sfoNode = new SavedForOfflineDB() { Fingerprint = SdkService.MegaSdk.getNodeFingerprint(megaNode), Base64Handle = megaNode.getBase64Handle(), LocalPath = offlineNodePath, ParentBase64Handle = parentNode != null? parentNode.getBase64Handle() : string.Empty }; InsertItem(sfoNode); }
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; } } } } }
/// <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 } }