Пример #1
0
        /// <summary>
        /// Creates a new subfolder with the specified name in the current folder.
        /// </summary>
        /// <param name="desiredName">The name of the new subfolder to create in the current folder.</param>
        /// <returns>When this method completes, it returns a StorageFolder that represents the new subfolder.</returns>
        public Task <StorageFolder> CreateFolderAsync(string desiredName)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            return(Task.Run <StorageFolder>(async() =>
            {
                var f = await _folder.CreateFolderAsync(desiredName);
                return f == null ? null : new StorageFolder(f);
            }));
#else
            return(CreateFolderAsync(desiredName, CreationCollisionOption.FailIfExists));
#endif
        }
Пример #2
0
        async void enableWedge(bool bEnable)
        {
            try
            {
                //add <uap:Capability Name="documentsLibrary" /> to manifest
                //Note: You must add File Type Associations to your app manifest that declare specific file types that your app can access in this location.

                // Open/create the subfolder where the profile is stored.
                Windows.Storage.StorageFolder storageFolder  = Windows.Storage.KnownFolders.DocumentsLibrary;
                Windows.Storage.StorageFolder profilesFolder = await storageFolder.CreateFolderAsync("Profile", Windows.Storage.CreationCollisionOption.OpenIfExists);

                // Open/create the profile file.
                Windows.Storage.StorageFile profileFile = await profilesFolder.CreateFileAsync("HoneywellDecoderSettingsV2.Exm", Windows.Storage.CreationCollisionOption.ReplaceExisting);

                if (bEnable)
                {
                    // Write the profile to the file.
                    await Windows.Storage.FileIO.WriteLinesAsync(profileFile, WedgeEnable);
                }
                else
                {
                    await Windows.Storage.FileIO.WriteLinesAsync(profileFile, WedgeDisable);
                }
            }catch (Exception ex)
            {
                Class1.doLog("Exception in enableWedge: " + ex.Message);
            }
            // Delay to allow time for new profile(s) to be processed.
            await System.Threading.Tasks.Task.Delay(50);
        }
Пример #3
0
        //- Notice
        //You can't define the path "System.Threading.Tasks.*" and etc. on "using" scheme
        //for respect the portable issues!
        public static async System.Threading.Tasks.Task SavePhotoTask(byte[] image, string name)
        {
            //Debug.WriteLine("[BenchImage_DEBUG]: Salvando imagem filtrada!");

            Windows.Storage.StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;

            Windows.Storage.StorageFolder dataFolder = await local.CreateFolderAsync("BenchImageOutput", Windows.Storage.CreationCollisionOption.OpenIfExists);

            Windows.Storage.StorageFile file = await dataFolder.CreateFileAsync(name, Windows.Storage.CreationCollisionOption.ReplaceExisting);

            using (var stream = await file.OpenStreamForWriteAsync())
            {
                stream.Write(image, 0, image.Length);
            }

            //Debug.WriteLine("[BenchImage_DEBUG]: Salvou imagem filtrada!");
        }
Пример #4
0
        private static async Task <string> ReadFileInWindowsAsync(Windows.Storage.StorageFolder folder, string fileName)
        {
            int index = fileName.IndexOf('/');

            if (index == -1)
            {
                var file = await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.OpenIfExists);

                using (var stream = await file.OpenStreamForReadAsync())
                {
                    using (var reader = new StreamReader(stream))
                    {
                        return(await reader.ReadToEndAsync());
                    }
                }
            }
            else
            {
                return(await ReadFileInWindowsAsync(await folder.CreateFolderAsync(fileName.Remove(index), Windows.Storage.CreationCollisionOption.OpenIfExists), fileName.Substring(index + 1)));
            }
        }
Пример #5
0
        private static async Task WriteFileInWindowsAsync(Windows.Storage.StorageFolder folder, string fileName, string content)
        {
            int index = fileName.IndexOf('/');

            if (index == -1)
            {
                var file = await folder.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);

                var stream = await file.OpenStreamForWriteAsync();

                using (var writer = new StreamWriter(stream))
                {
                    await writer.WriteAsync(content);
                }
                return;
            }
            else
            {
                await WriteFileInWindowsAsync(await folder.CreateFolderAsync(fileName.Remove(index), Windows.Storage.CreationCollisionOption.OpenIfExists), fileName.Substring(index + 1), content);
            }
        }
        public async Task Init()
        {
            _folderForTestFiles = Windows.Storage.ApplicationData.Current.LocalFolder;
            Assert.IsNotNull(_folderForTestFiles, "cannot get LocalFolder - error outside tested method");

            _folderForTestFiles = await _folderForTestFiles.CreateFolderAsync("StorageFolder_GetItems");

            Assert.IsNotNull(_folderForTestFiles, "cannot create folder for test files - error outside tested method");


            foreach (var filename in _filenames)
            {
                try
                {
                    var testFile = await _folderForTestFiles.CreateFileAsync(filename, Windows.Storage.CreationCollisionOption.FailIfExists);

                    Assert.IsNotNull(testFile, "cannot create test file - error outside tested method");
                }
                catch
                {
                    Assert.Fail("CreateFile exception - error outside tested method");
                }
            }

            foreach (var foldername in _foldernames)
            {
                try
                {
                    var testFolder = await _folderForTestFiles.CreateFolderAsync(foldername, Windows.Storage.CreationCollisionOption.FailIfExists);

                    Assert.IsNotNull(testFolder, "cannot create test folder - error outside tested method");
                }
                catch
                {
                    Assert.Fail("CreateFolder exception - error outside tested method");
                }
            }
        }