/// <summary> /// Retrieves the format information of the media file. /// </summary> /// <param name="options"></param> public void getFormatData(string options) { if (String.IsNullOrEmpty(options)) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); return; } try { MediaFormatOptions mediaFormatOptions; try { mediaFormatOptions = JSON.JsonHelper.Deserialize <MediaFormatOptions>(options); } catch (Exception ex) { this.DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION, ex.Message)); return; } if (string.IsNullOrEmpty(mediaFormatOptions.FullPath)) { DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } string mimeType = mediaFormatOptions.Type; if (string.IsNullOrEmpty(mimeType)) { mimeType = MimeTypeMapper.GetMimeType(mediaFormatOptions.FullPath); } if (mimeType.Equals("image/jpeg")) { Deployment.Current.Dispatcher.BeginInvoke(() => { WriteableBitmap image = ExtractImageFromLocalStorage(mediaFormatOptions.FullPath); if (image == null) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, "File not found")); return; } MediaFileData mediaData = new MediaFileData(image); DispatchCommandResult(new PluginResult(PluginResult.Status.OK, mediaData)); }); } else { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); } } catch (Exception) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR)); } }
public MediaFile(string filePath, Stream stream) { this.FilePath = filePath; this.FileName = System.IO.Path.GetFileName(this.FilePath); this.Type = MimeTypeMapper.GetMimeType(FileName); this.Size = stream.Length; using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { this.LastModifiedDate = storage.GetLastWriteTime(filePath).DateTime.ToString(); } }
public FileMetadata(string filePath) { using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication()) { if ((string.IsNullOrEmpty(filePath)) || (!isoFile.FileExists(filePath))) { throw new FileNotFoundException("File doesn't exist"); } //TODO get file size the other way if possible using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(filePath, FileMode.Open, FileAccess.Read, isoFile)) { this.Size = stream.Length; } this.FullPath = filePath; this.FileName = System.IO.Path.GetFileName(filePath); this.Type = MimeTypeMapper.GetMimeType(filePath); this.LastModifiedDate = isoFile.GetLastWriteTime(filePath).DateTime.ToString(); } }
public void readAsDataURL(string options) { if (!LoadFileOptions(options)) { return; } try { string base64URL = null; using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication()) { if (!isoFile.FileExists(fileOptions.FilePath)) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_FOUND_ERR)); return; } string mimeType = MimeTypeMapper.GetMimeType(fileOptions.FilePath); using (IsolatedStorageFileStream stream = isoFile.OpenFile(fileOptions.FilePath, FileMode.Open, FileAccess.Read)) { string base64String = GetFileContent(stream); base64URL = "data:" + mimeType + ";base64," + base64String; } } DispatchCommandResult(new PluginResult(PluginResult.Status.OK, base64URL)); } catch (Exception ex) { if (!this.HandleException(ex)) { DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, NOT_READABLE_ERR)); } } }