public async System.Threading.Tasks.Task LoadKML(System.Collections.Generic.List <Windows.Devices.Geolocation.BasicGeoposition> mapdata) { Windows.Data.Xml.Dom.XmlLoadSettings loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings(); loadSettings.ElementContentWhiteSpace = false; Windows.Data.Xml.Dom.XmlDocument kml = new Windows.Data.Xml.Dom.XmlDocument(); FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.List; openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; openPicker.FileTypeFilter.Add(".kml"); Windows.Storage.IStorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { string[] stringSeparators = new string[] { ",17" }; kml = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(file); var element = kml.GetElementsByTagName("coordinates").Item(0); string ats = element.FirstChild.GetXml(); string[] atsa = ats.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries); int size = atsa.Length - 1; for (int i = 0; i < size; i++) { string[] coord = atsa[i].Split(','); double longi = Convert.ToDouble(coord[0]); double lati = Convert.ToDouble(coord[1]); mapdata.Add(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = lati, Longitude = longi }); } } }
protected override void OnFileActivated(FileActivatedEventArgs args) { // The number of files received is args.Files.Size // The first file is args.Files[0].Name Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); SuspensionManager.RegisterFrame(rootFrame, "appFrame"); Window.Current.Content = rootFrame; // Redidects transmitted file only if application is not been opened yet if (args.Files.Count > 0) { App.FileExecuted = (Windows.Storage.IStorageFile)args.Files[0]; } } else { new Windows.UI.Popups.MessageDialog("The application is already opened. Use Open Picker instead").ShowAsync(); } if (rootFrame.Content == null) { if (!rootFrame.Navigate(typeof(MainPage))) { throw new Exception("Failed to create initial page"); } } Window.Current.Activate(); }
private async void OnBtnPlayClick(object sender, RoutedEventArgs e) { mediaPlayer.Source = null; Windows.Storage.IStorageFile file = null; Windows.Storage.StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets"); if (AudioVideo.Title.ToLower() == "audio") { file = await folder.GetFileAsync($"{AudioVideo.CurrentItem.Name.ToLower()}.mp3"); } else { file = await folder.GetFileAsync($"{AudioVideo.CurrentItem.Name.ToLower()}.mp4"); } mediaPlayer.AutoPlay = false; mediaPlayer.AreTransportControlsEnabled = true; mediaPlayer.Source = MediaSource.CreateFromStorageFile(file); if (playing) { mediaPlayer.Source = null; playing = false; } else { mediaPlayer.MediaPlayer.Play(); playing = true; } }
public Downloader(Windows.Storage.IStorageFile loсalFile, OneDrive.IFileStorageFile file) { RemoteFile = file; _loсalFile = loсalFile; TotalBytesToTransfer = RemoteFile.Size; _localFileToken = StorageApplicationPermissions.FutureAccessList.Add(loсalFile); }
public EmailAttachment(Windows.Storage.IStorageFile file) { File = file ?? throw new ArgumentNullException(nameof(file)); FilePath = file.Path; FileName = file.Name; ContentType = file.ContentType; }
public static bool IsEpub(Windows.Storage.IStorageFile file) { if (file.FileType.ToLower() == ".epub") { return(true); } return(false); }
public Uploader(Windows.Storage.IStorageFile loсalFile, ulong fileSize, OneDrive.IFileStorageFolder folder) { _storageFolder = folder; _loсalFile = loсalFile; _pathToLocalFile = _loсalFile.Path; TotalBytesToTransfer = fileSize; _localFileToken = StorageApplicationPermissions.FutureAccessList.Add(loсalFile); }
private async void Button_Click_1(object sender, RoutedEventArgs e) { var fop = new Windows.Storage.Pickers.FileSavePicker(); fop.FileTypeChoices.Add(".txt", new List <string> { ".txt" }); txtfile = await fop.PickSaveFileAsync(); }
public static async Task <IBook> GetBookFromFile(Windows.Storage.IStorageFile file) { if (file == null) { return(null); } else if (Path.GetExtension(file.Path).ToLower() == ".pdf") { var book = new Books.Pdf.PdfBook(); try { await book.Load(file); } catch { return(null); } if (book.PageCount <= 0) { return(null); } return(book); } else if (new string[] { ".zip", ".cbz" }.Contains(Path.GetExtension(file.Path).ToLower())) { var book = new Books.Cbz.CbzBook(); try { await book.LoadAsync(WindowsRuntimeStreamExtensions.AsStream(await file.OpenReadAsync())); } catch { return(null); } if (book.PageCount <= 0) { return(null); } return(book); } else if (new string[] { ".rar", ".cbr", ".7z", ".cb7" }.Contains(Path.GetExtension(file.Path).ToLower())) { var book = new Books.Compressed.CompressedBook(); try { await book.LoadAsync(WindowsRuntimeStreamExtensions.AsStream(await file.OpenReadAsync())); } catch { return(null); } if (book.PageCount <= 0) { return(null); } return(book); } return(null); }
async private void saveBtn_Click(object sender, RoutedEventArgs e) { string fileName = "Image.png"; fileName = Path.GetFileName(fileName); Windows.Storage.IStorageFile photo = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); await media.CapturePhotoToStorageFileAsync(Windows.Media.MediaProperties.ImageEncodingProperties.CreatePng(), photo); }
public async void Initialize(Windows.Storage.IStorageFile value, Control target = null) { this.Loading = true; var book = await Books.BookManager.GetBookFromFile(value); if (book != null && book is Books.IBookFixed) { Initialize(book as Books.IBookFixed, target); this.Title = System.IO.Path.GetFileNameWithoutExtension(value.Name); } this.Loading = false; }
private async Task AddFileSize(SongData s) { try { Windows.Storage.IStorageFile file = await Windows.Storage.StorageFile.GetFileFromPathAsync(s.Path); s.FileSize = file.OpenAsync(Windows.Storage.FileAccessMode.Read).AsTask().Result.Size; } catch (Exception ex) { //DiagnosticHelper.TrackTrace("AddFileSize" + Environment.NewLine + ex.Message, Microsoft.HockeyApp.SeverityLevel.Error); } Song = s; }
public EmailAttachment(Java.IO.File file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(file.Path); string contentType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension); File = file; FilePath = file.Path; FileName = file.Name; ContentType = contentType; }
public async void Initialization(IList <DownloadOperation> downloaders) { foreach (var downloader in downloaders) { if (downloader.Guid.GetHashCode() == _proccessId) { _downloadOperation = downloader; break; } } _loсalFile = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(_localFileToken); var basicProperties = await _loсalFile.GetBasicPropertiesAsync(); _previewDownloadBytes = (uint)basicProperties.Size; }
public async Task <BackgroundOperation.IUploader> Upload(Windows.Storage.IStorageFile storageFile) { BasicProperties basicProperties = await storageFile.GetBasicPropertiesAsync().AsTask(); var folders = from f1 in Folders where f1.Account.Size.FreeSize > basicProperties.Size select f1; IStorageFolder folder = folders.First(); if (folder == null) { throw new InvalidOperationException("You have not enough memory"); } return(await folder.Upload(storageFile)); }
private async void OpenFile(Windows.Storage.IStorageFile fileToUse) { if (fileToUse != null && mainPageVM != null && mainPageVM.OpenProject.CanExecute(null)) { try { var text = await Windows.Storage.FileIO.ReadTextAsync(fileToUse); mainPageVM.OpenProject.Execute(text); } catch (Exception) { new Windows.UI.Popups.MessageDialog("Could not read the selected file").ShowAsync(); } } }
public RequestBuilder DownloadTo(Windows.Storage.IStorageFile file) { this.success = (headers, result) => { long?length = null; if (headers.AllKeys.Contains("Content-Length")) { length = long.Parse(headers["Content-Length"]); } var handle = file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite).AsTask().Result; ProgressCallbackHelper operation = result.CopyToProgress(WindowsRuntimeStreamExtensions.AsStream(handle), length); operation.Completed += (totalbytes) => { handle.Dispose(); }; }; return(this); }
public static void OpenBook(Windows.Storage.IStorageFile file, Frame frame, FrameworkElement sender = null) { if (file == null) { return; } if (file.ContentType == "application/epub+zip" || file.FileType.ToLower() == ".epub") { if (sender != null) { SetTitleByResource(sender, "Epub"); } OpenEpub(frame, file, GetCurrentTabPage(sender)); } else { frame.Navigate(typeof(BookFixed3Viewer), file); } }
public static void OpenEpub(Frame frame, Windows.Storage.IStorageFile file, TabPage tabPage = null) { if (file == null) { return; } var resolver = EpubResolver.GetResolverBibi(file); frame.Navigate(typeof(kurema.BrowserControl.Views.BrowserPage), null); if (frame.Content is kurema.BrowserControl.Views.BrowserPage content) { Uri uri = content.Control.Control.BuildLocalStreamUri("epub", resolver.PathHome); content.Control.Control.NavigateToLocalStreamUri(uri, resolver); if (tabPage != null) { content.Control.Control.NewWindowRequested += (s, e) => { tabPage.OpenTabWeb(e.Uri.ToString()); e.Handled = true; }; } } }
private static async Task WriteToDebugFile(string msg) { if(m_debugFile == null) { try { m_debugFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("debug.txt",Windows.Storage.CreationCollisionOption.OpenIfExists); await Windows.Storage.FileIO.AppendTextAsync(m_debugFile, $"**** New Session Initialized: [{DateTime.Now.ToString()}] ****\r\n"); } catch { // Do nothing } } if(m_debugFile != null) { try { await Windows.Storage.FileIO.AppendTextAsync(m_debugFile, $"[{DateTime.Now.ToString()}] {msg}\r\n"); } catch { // Fail silently } } }
private void Open(Windows.Storage.IStorageFile file) { Binding?.UpdateContainerInfo(file); Binding?.Initialize(file, this.flipView); }
public Task SaveMedia(Windows.Storage.IStorageFile file, LocalItem localItem, ServerInfo server) { return(Task.FromResult(true)); }
private async void Button_Click_2(object sender, RoutedEventArgs e) { if (txtfile == null || pdffile == null) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_pleasechoosefilefirst")).ShowAsync(); return; } ct.IsEnabled = false; cp.IsEnabled = false; start.IsEnabled = false; try { Windows.Data.Pdf.PdfDocument pd = await Windows.Data.Pdf.PdfDocument.LoadFromFileAsync(pdffile); if (pd.IsPasswordProtected) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_pdfwithpassword")).ShowAsync(); return; } pro.Value = 0; pro.Maximum = pd.PageCount; var ocre = lang == null?OcrEngine.TryCreateFromUserProfileLanguages() : OcrEngine.TryCreateFromLanguage(lang); if (ocre == null && lang == null) { await new Windows.UI.Popups.MessageDialog(loader.GetString("error_notsupport")).ShowAsync(); return; } using (Stream txtstr = await txtfile.OpenStreamForWriteAsync()) { using (StreamWriter sw = new StreamWriter(txtstr)) { for (uint i = 0; i < pd.PageCount; i++) { using (var page = pd.GetPage(i)) { await page.PreparePageAsync(); using (var str = new Windows.Storage.Streams.InMemoryRandomAccessStream()) { await page.RenderToStreamAsync(str); var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(str); var re = await ocre.RecognizeAsync(await decoder.GetSoftwareBitmapAsync()); sw.WriteLine(re.Text); } } pro.Value++; } } } } catch { await new Windows.UI.Popups.MessageDialog(loader.GetString("error")).ShowAsync(); } finally { ct.IsEnabled = true; cp.IsEnabled = true; start.IsEnabled = true; txtfile = null; pdffile = null; } }
/// <summary> /// Add the <paramref name="file"/> as an attachment /// </summary> /// <param name="file">File to attach</param> public EmailMessageBuilder WithAttachment(Windows.Storage.IStorageFile file) { _email.Attachments.Add(new EmailAttachment(file)); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="NmeaFileDevice"/> class. /// </summary> /// <param name="fileName"></param> /// <param name="readSpeed">The time to wait between each group of lines being read in milliseconds</param> public NmeaFileDevice(Windows.Storage.IStorageFile fileName, int readSpeed) : base(readSpeed) { m_storageFile = fileName; }
/// <summary> /// Initializes a new instance of the <see cref="NmeaFileDevice"/> class. /// </summary> /// <param name="fileName"></param> public NmeaFileDevice(Windows.Storage.IStorageFile fileName) : this(fileName, 1000) { }
private void Open(Windows.Storage.IStorageFile file) { Binding?.Initialize(file, this.flipView); }
/// <summary> /// Initializes a new instance of the <see cref="NmeaFileDevice"/> class. /// </summary> /// <param name="storageFile"></param> public NmeaFileDevice(Windows.Storage.IStorageFile storageFile) : this(storageFile, 1000) { }
/// <summary> /// Initializes a new instance of the <see cref="NmeaFileDevice"/> class. /// </summary> /// <param name="storageFile"></param> /// <param name="readSpeed">The time to wait between each group of lines being read in milliseconds</param> public NmeaFileDevice(Windows.Storage.IStorageFile storageFile, int readSpeed) : base(readSpeed) { m_storageFile = storageFile ?? throw new ArgumentNullException(nameof(storageFile)); m_filename = storageFile.Path; }
private async void Button_Click(object sender, RoutedEventArgs e) { Windows.Storage.Pickers.FileOpenPicker fop = new Windows.Storage.Pickers.FileOpenPicker(); fop.FileTypeFilter.Add(".pdf"); pdffile = await fop.PickSingleFileAsync(); }
public static async Task SaveStreamToFile(Windows.Storage.Streams.IRandomAccessStream stream, Windows.Storage.IStorageFile file) { using var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite); var buffer = new byte[stream.Size]; var ibuffer = buffer.AsBuffer(); stream.Seek(0); await stream.ReadAsync(ibuffer, (uint)stream.Size, Windows.Storage.Streams.InputStreamOptions.None); await fileStream.WriteAsync(ibuffer); }
public FileValueRecorder(Windows.Storage.IStorageFile outputFile) { m_OutputFile = outputFile; }