private void CheckAndUpdateOffline(MNode megaNode) { var offlineNodePath = OfflineService.GetOfflineNodePath(megaNode); if ((megaNode.getType() == MNodeType.TYPE_FILE && FileService.FileExists(offlineNodePath)) || (megaNode.getType() == MNodeType.TYPE_FOLDER && FolderService.FolderExists(offlineNodePath)) || TransferService.ExistPendingNodeOfflineTransfer(this)) { if (SavedForOfflineDB.ExistsNodeByLocalPath(offlineNodePath)) { SavedForOfflineDB.UpdateNode(megaNode); } else { SavedForOfflineDB.InsertNode(megaNode); } this.IsSavedForOffline = true; return; } if (SavedForOfflineDB.ExistsNodeByLocalPath(offlineNodePath)) { SavedForOfflineDB.DeleteNodeByLocalPath(offlineNodePath); } this.IsSavedForOffline = false; }
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); } }
public static SharedFolderNodeViewModel CreateNewSharedFolder(MegaSDK megaSdk, AppInformation appInformation, MNode megaNode, SharedFoldersListViewModel parent) { if (megaNode == null) { return(null); } try { if (megaNode.getType() == MNodeType.TYPE_FOLDER) { if (megaSdk.isShared(megaNode)) { if (megaSdk.isInShare(megaNode)) { return(new IncomingSharedFolderNodeViewModel(megaNode, parent)); } if (megaSdk.isOutShare(megaNode)) { return(new OutgoingSharedFolderNodeViewModel(megaNode, parent)); } } } } catch (Exception) { return(null); } return(null); }
private void CheckAndUpdateSFO(MNode megaNode) { this.IsAvailableOffline = false; this.IsSelectedForOffline = false; var nodePath = SdkService.MegaSdk.getNodePath(megaNode); if (String.IsNullOrWhiteSpace(nodePath)) { return; } var nodeOfflineLocalPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, AppResources.DownloadsDirectory, nodePath.Remove(0, 1).Replace("/", "\\")); if (SavedForOffline.ExistsNodeByLocalPath(nodeOfflineLocalPath)) { var existingNode = SavedForOffline.ReadNodeByLocalPath(nodeOfflineLocalPath); if ((megaNode.getType() == MNodeType.TYPE_FILE && FileService.FileExists(nodeOfflineLocalPath)) || (megaNode.getType() == MNodeType.TYPE_FOLDER && FolderService.FolderExists(nodeOfflineLocalPath))) { this.IsAvailableOffline = true; this.IsSelectedForOffline = existingNode.IsSelectedForOffline; } else { SavedForOffline.DeleteNodeByLocalPath(nodeOfflineLocalPath); } } else { if (megaNode.getType() == MNodeType.TYPE_FILE && FileService.FileExists(nodeOfflineLocalPath)) { SavedForOffline.Insert(megaNode, true); this.IsAvailableOffline = this.IsSelectedForOffline = true; } else if (megaNode.getType() == MNodeType.TYPE_FOLDER && FolderService.FolderExists(nodeOfflineLocalPath)) { SavedForOffline.Insert(megaNode); this.IsAvailableOffline = true; this.IsSelectedForOffline = false; } } }
public void GoFolderUp() { MNode parentNode = this._megaSdk.getParentNode(this.CurrentRootNode.GetBaseNode()); if (parentNode == null || parentNode.getType() == MNodeType.TYPE_UNKNOWN) { parentNode = this._megaSdk.getRootNode(); } this.CurrentRootNode = new NodeViewModel(App.MegaSdk, parentNode); }
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 void Create(FolderViewModel folder) { this.Items.Clear(); // Top root nodes have no breadcrumbs if (folder.FolderRootNode == null || folder.FolderRootNode.Type == MNodeType.TYPE_ROOT || folder.FolderRootNode.Type == MNodeType.TYPE_RUBBISH) { return; } this.Items.Add(folder.FolderRootNode); MNode parentNode = this.MegaSdk.getParentNode(folder.FolderRootNode.OriginalMNode); while (parentNode != null && parentNode.getType() != MNodeType.TYPE_ROOT && parentNode.getType() != MNodeType.TYPE_RUBBISH) { this.Items.Insert(0, NodeService.CreateNew(this.MegaSdk, App.AppInformation, parentNode, folder)); parentNode = this.MegaSdk.getParentNode(parentNode); } }
public void BuildBreadCrumbs() { this.BreadCrumbs.Clear(); // Top root nodes have no breadcrumbs if (this.FolderRootNode == null || this.FolderRootNode.Type == MNodeType.TYPE_ROOT || FolderRootNode.Type == MNodeType.TYPE_RUBBISH) { return; } this.BreadCrumbs.Add((IBaseNode)this.FolderRootNode); MNode parentNode = FolderRootNode.OriginalMNode; parentNode = this.MegaSdk.getParentNode(parentNode); while ((parentNode != null) && (parentNode.getType() != MNodeType.TYPE_ROOT) && (parentNode.getType() != MNodeType.TYPE_RUBBISH)) { this.BreadCrumbs.Insert(0, (IBaseNode)NodeService.CreateNew(this.MegaSdk, this.AppInformation, parentNode, this.Type)); parentNode = this.MegaSdk.getParentNode(parentNode); } }
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 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 override bool GoFolderUp() { if (this.FolderRootNode == null) { return(false); } MNode parentNode = this.MegaSdk.getParentNode(this.FolderRootNode.OriginalMNode); if (parentNode == null || parentNode.getType() == MNodeType.TYPE_UNKNOWN || parentNode.getType() == MNodeType.TYPE_ROOT) { return(false); } this.FolderRootNode = NodeService.CreateNew(this.MegaSdk, this.AppInformation, parentNode, _containerType, ChildNodes); LoadChildNodes(); return(true); }
/// <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 FetchNodesMainPage(MegaSDK api, MRequest request) { App.AppInformation.HasFetchedNodes = true; // If the user is trying to open a shortcut if (App.ShortCutBase64Handle != null) { bool shortCutError = false; MNode shortCutMegaNode = api.getNodeByBase64Handle(App.ShortCutBase64Handle); App.ShortCutBase64Handle = null; if (_mainPageViewModel != null && shortCutMegaNode != null) { // Looking for the absolute parent of the shortcut node to see the type MNode parentNode; MNode absoluteParentNode = shortCutMegaNode; while ((parentNode = api.getParentNode(absoluteParentNode)) != null) { absoluteParentNode = parentNode; } if (absoluteParentNode.getType() == MNodeType.TYPE_ROOT) { var newRootNode = NodeService.CreateNew(api, _mainPageViewModel.AppInformation, shortCutMegaNode, ContainerType.CloudDrive); var autoResetEvent = new AutoResetEvent(false); Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.ActiveFolderView.FolderRootNode = newRootNode; autoResetEvent.Set(); }); autoResetEvent.WaitOne(); } else { shortCutError = true; } } else { shortCutError = true; } if (shortCutError) { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog(AppMessages.ShortCutFailed_Title, AppMessages.ShortCutFailed, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } } // If the user is trying to open a MEGA link else if (App.LinkInformation.ActiveLink != null) { // Only need to check if is a "file link" or an "internal node link". // The "folder links" are checked in the "SpecialNavigation" method if (!App.LinkInformation.ActiveLink.Contains("https://mega.nz/#F!")) { // Public file link if (App.LinkInformation.ActiveLink.Contains("https://mega.nz/#!")) { SdkService.MegaSdk.getPublicNode(App.LinkInformation.ActiveLink, new GetPublicNodeRequestListener(_mainPageViewModel.CloudDrive)); } // Internal file/folder link else if (App.LinkInformation.ActiveLink.Contains("https://mega.nz/#")) { var nodeHandle = App.LinkInformation.ActiveLink.Split("#".ToCharArray())[1]; var megaNode = SdkService.MegaSdk.getNodeByBase64Handle(nodeHandle); if (megaNode != null) { ContainerType containerType = (SdkService.MegaSdk.isInRubbish(megaNode)) ? containerType = ContainerType.RubbishBin : containerType = ContainerType.CloudDrive; var node = NodeService.CreateNew(SdkService.MegaSdk, App.AppInformation, megaNode, containerType); Deployment.Current.Dispatcher.BeginInvoke(() => { if (node != null) { if (node.IsFolder) { _mainPageViewModel.ActiveFolderView.BrowseToFolder(node); } else { node.Download(TransfersService.MegaTransfers); } } else { new CustomMessageDialog( AppMessages.AM_InternalNodeNotFound_Title, AppMessages.AM_InternalNodeNotFound, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); } }); } else { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog( AppMessages.AM_InternalNodeNotFound_Title, AppMessages.AM_InternalNodeNotFound, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } } } } else { var cloudDriveRootNode = _mainPageViewModel.CloudDrive.FolderRootNode ?? NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRootNode(), ContainerType.CloudDrive); var rubbishBinRootNode = _mainPageViewModel.RubbishBin.FolderRootNode ?? NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRubbishNode(), ContainerType.RubbishBin); var autoResetEvent = new AutoResetEvent(false); Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.CloudDrive.FolderRootNode = cloudDriveRootNode; _mainPageViewModel.RubbishBin.FolderRootNode = rubbishBinRootNode; autoResetEvent.Set(); }); autoResetEvent.WaitOne(); } Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.LoadFolders(); _mainPageViewModel.GetAccountDetails(); // Enable MainPage appbar buttons _mainPageViewModel.SetCommandStatus(true); if (_mainPageViewModel.SpecialNavigation()) { return; } }); // KEEP ALWAYS AT THE END OF THE METHOD, AFTER THE "LoadForlders" call Deployment.Current.Dispatcher.BeginInvoke(() => { // If is a newly activated account, navigates to the upgrade account page if (App.AppInformation.IsNewlyActivatedAccount) { NavigateService.NavigateTo(typeof(MyAccountPage), NavigationParameter.Normal, new Dictionary <string, string> { { "Pivot", "1" } }); } // If is the first login, navigates to the camera upload service config page else if (SettingsService.LoadSetting <bool>(SettingsResources.CameraUploadsFirstInit, true)) { NavigateService.NavigateTo(typeof(InitCameraUploadsPage), NavigationParameter.Normal); } else if (App.AppInformation.IsStartedAsAutoUpload) { NavigateService.NavigateTo(typeof(SettingsPage), NavigationParameter.AutoCameraUpload); } }); }
public async Task <NodeActionResult> RemoveAsync(bool isMultiRemove, AutoResetEvent waitEventRequest = null) { // User must be online to perform this operation if (!IsUserOnline()) { return(NodeActionResult.NotOnline); } if (this.OriginalMNode == null) { return(NodeActionResult.Failed); } // Looking for the absolute parent of the node to remove MNode parentNode; MNode absoluteParentNode = this.OriginalMNode; while ((parentNode = this.MegaSdk.getParentNode(absoluteParentNode)) != null) { absoluteParentNode = parentNode; } // If the node is on the rubbish bin, delete it forever if (absoluteParentNode.getType() == MNodeType.TYPE_RUBBISH) { if (!isMultiRemove) { var result = await new CustomMessageDialog( AppMessages.RemoveItemQuestion_Title, String.Format(AppMessages.RemoveItemQuestion, this.Name), App.AppInformation, MessageDialogButtons.OkCancel, MessageDialogImage.RubbishBin).ShowDialogAsync(); if (result == MessageDialogResult.CancelNo) { return(NodeActionResult.Cancelled); } } this.MegaSdk.remove(this.OriginalMNode, new RemoveNodeRequestListener(this, isMultiRemove, absoluteParentNode.getType(), waitEventRequest)); return(NodeActionResult.IsBusy); } // if the node in in the Cloud Drive, move it to rubbish bin if (!isMultiRemove) { var result = await new CustomMessageDialog( AppMessages.MoveToRubbishBinQuestion_Title, String.Format(AppMessages.MoveToRubbishBinQuestion, this.Name), App.AppInformation, MessageDialogButtons.OkCancel, MessageDialogImage.RubbishBin).ShowDialogAsync(); if (result == MessageDialogResult.CancelNo) { return(NodeActionResult.Cancelled); } } this.MegaSdk.moveNode(this.OriginalMNode, this.MegaSdk.getRubbishNode(), new RemoveNodeRequestListener(this, isMultiRemove, absoluteParentNode.getType(), waitEventRequest)); return(NodeActionResult.IsBusy); }
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); }
private void FetchNodesMainPage(MegaSDK api, MRequest request) { App.AppInformation.HasFetchedNodes = true; // If the user is trying to open a shortcut if (App.ShortCutBase64Handle != null) { bool shortCutError = false; MNode shortCutMegaNode = api.getNodeByBase64Handle(App.ShortCutBase64Handle); App.ShortCutBase64Handle = null; if (_mainPageViewModel != null && shortCutMegaNode != null) { // Looking for the absolute parent of the shortcut node to see the type MNode parentNode; MNode absoluteParentNode = shortCutMegaNode; while ((parentNode = api.getParentNode(absoluteParentNode)) != null) { absoluteParentNode = parentNode; } if (absoluteParentNode.getType() == MNodeType.TYPE_ROOT) { var newRootNode = NodeService.CreateNew(api, _mainPageViewModel.AppInformation, shortCutMegaNode, ContainerType.CloudDrive); var autoResetEvent = new AutoResetEvent(false); Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.ActiveFolderView.FolderRootNode = newRootNode; autoResetEvent.Set(); }); autoResetEvent.WaitOne(); } else { shortCutError = true; } } else { shortCutError = true; } if (shortCutError) { Deployment.Current.Dispatcher.BeginInvoke(() => { new CustomMessageDialog(AppMessages.ShortCutFailed_Title, AppMessages.ShortCutFailed, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); }); } } else { var cloudDriveRootNode = _mainPageViewModel.CloudDrive.FolderRootNode ?? NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRootNode(), ContainerType.CloudDrive); var rubbishBinRootNode = _mainPageViewModel.RubbishBin.FolderRootNode ?? NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRubbishNode(), ContainerType.RubbishBin); var autoResetEvent = new AutoResetEvent(false); Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.CloudDrive.FolderRootNode = cloudDriveRootNode; _mainPageViewModel.RubbishBin.FolderRootNode = rubbishBinRootNode; autoResetEvent.Set(); }); autoResetEvent.WaitOne(); } Deployment.Current.Dispatcher.BeginInvoke(() => { _mainPageViewModel.LoadFolders(); _mainPageViewModel.GetAccountDetails(); // Enable MainPage appbar buttons _mainPageViewModel.SetCommandStatus(true); if (_mainPageViewModel.SpecialNavigation()) { return; } }); // KEEP ALWAYS AT THE END OF THE METHOD, AFTER THE "LoadForlders" call Deployment.Current.Dispatcher.BeginInvoke(() => { // If is a newly activated account, navigates to the upgrade account page if (App.AppInformation.IsNewlyActivatedAccount) { NavigateService.NavigateTo(typeof(MyAccountPage), NavigationParameter.Normal, new Dictionary <string, string> { { "Pivot", "1" } }); } // If is the first login, navigates to the camera upload service config page else if (SettingsService.LoadSetting <bool>(SettingsResources.CameraUploadsFirstInit, true)) { NavigateService.NavigateTo(typeof(InitCameraUploadsPage), NavigationParameter.Normal); } else if (App.AppInformation.IsStartedAsAutoUpload) { NavigateService.NavigateTo(typeof(SettingsPage), NavigationParameter.AutoCameraUpload); } }); }