//Check if CRCloudMetaData is a folder public Boolean isFolder(CRCloudMetaData metaData) { if (metaData.Folder.NUIntValue == 1) { return(true); } return(false); }
//Share Link public void ShareLink(CRCloudMetaData metaData) { string sharedLink = logic.ShareLinkForFileWithPath(_cloudStorage, metaData.Path); if (sharedLink != "") { UIPasteboard.General.String = sharedLink; helper.Alert("Shared Link Completed", "Shared link is copied \nYou can paste it anywhere", _controller); } }
//Children Of Folder With Path - Returns a list of metadata object for the children of a folder. public CRCloudMetaData[] ChildrenOfFolderWithPath(ICRCloudStorageProtocol cloudStorage, string path) { try { CRCloudMetaData[] array = NSArray.FromArray <CRCloudMetaData>(cloudStorage.ChildrenOfFolderWithPath(path)); return(array); } catch (Exception e) { // Console.WriteLine(e.Message); CRCloudMetaData[] metaData = new CRCloudMetaData[] { }; return(metaData); } }
//Search With Query - Returns a list of files and folders that match the provided search query. public CRCloudMetaData[] SearchWithQuery(ICRCloudStorageProtocol cloudStorage, string query) { try { CRCloudMetaData[] array = NSArray.FromArray <CRCloudMetaData>(cloudStorage.SearchWithQuery(query)); return(array); } catch (Exception e) { Console.WriteLine(e.Message); CRCloudMetaData[] metaData = new CRCloudMetaData[] { }; return(metaData); } }
//Delete File public void DeleteFile(CRCloudMetaData metaData) { logic.DeleteFileWithPath(_cloudStorage, metaData.Path); _controller.GetRootFilesFolders(); if (!helper.isFolder(metaData)) { helper.Alert("Delete Completed", "File deleted", _controller); } else { helper.Alert("Delete Completed", "Folder deleted", _controller); } }
public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath) { UITableViewCell cell = tableView.DequeueReusableCell(cellIdentifier); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Default, cellIdentifier); } CRCloudMetaData data = _metaData[indexPath.Row]; cell.TextLabel.Text = data.Name; cell.ImageView.Image = helper.GetImage(data); return(cell); }
//Check if CRCloudMetaData is a video public Boolean IsVideo(CRCloudMetaData metaData) { try { string fileExtention = new Foundation.NSUrl(metaData.Name).PathExtension.ToLower(); if (fileExtention == "mov" || fileExtention == "mp4" || fileExtention == "mkv" || fileExtention == "avi" || fileExtention == "wmv") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
//Check if CRCloudMetaData is an image public Boolean IsImage(CRCloudMetaData metaData) { try { string fileExtention = new Foundation.NSUrl(metaData.Name).PathExtension.ToLower(); if (fileExtention == "jpg" || fileExtention == "jpeg" || fileExtention == "png") { return(true); } else { return(false); } } catch (Exception e) { Console.WriteLine(e); return(false); } }
public override void RowSelected(UITableView tableView, Foundation.NSIndexPath indexPath) { CRCloudMetaData data = _metaData[indexPath.Row]; if (!helper.isFolder(data)) { var alert = UIAlertController.Create("Options", "Share, Download, Delete File", UIAlertControllerStyle.ActionSheet); alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, null)); alert.AddAction(UIAlertAction.Create("Share Link", UIAlertActionStyle.Default, action => ShareLink(data))); alert.AddAction(UIAlertAction.Create("Download", UIAlertActionStyle.Default, action => DownloadFile(data))); alert.AddAction(UIAlertAction.Create("Delete", UIAlertActionStyle.Default, action => DeleteFile(data))); _controller.PresentViewController(alert, animated: true, completionHandler: null); } else { _controller.PerformSegue("SubfolderSegue", _controller); } tableView.DeselectRow(indexPath, true); }
//Download File public void DownloadFile(CRCloudMetaData metaData) { new System.Threading.Thread(new System.Threading.ThreadStart(() => { InvokeOnMainThread(() => { CloudStorageLogic cloudStorageLogic = new CloudStorageLogic(); NSInputStream inputStream = cloudStorageLogic.DownloadFileWithPath(_cloudStorage, metaData.Path); NSMutableData data = new NSMutableData(); inputStream.Open(); var int32Value = metaData.Size.Int32Value; var intValue = metaData.Size.NIntValue; var buffer = new byte[1024]; while (inputStream.HasBytesAvailable()) { var len = inputStream.Read(buffer, 1024); data.AppendBytes(buffer); } if (inputStream.HasBytesAvailable() == false) { inputStream.Close(); var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var bytes = data.Bytes; string localFilename = metaData.Name; string localPath = Path.Combine(documents, localFilename); byte[] managedArray = new byte[intValue]; Marshal.Copy(bytes, managedArray, 0, int32Value); File.WriteAllBytes(localPath, managedArray); helper.Alert("Download Completed", "File downloaded and saved to file sharing", _controller); } }); })).Start(); }
//Get Image to display in TableView public UIImage GetImage(CRCloudMetaData metaData) { if (this.isFolder(metaData)) { return(UIImage.FromBundle("Folder")); } else { if (this.IsImage(metaData)) { return(UIImage.FromBundle("Picture")); } else if (this.IsVideo(metaData)) { return(UIImage.FromBundle("Video")); } else { return(UIImage.FromBundle("DocFile")); } } }