コード例 #1
0
        private async void SaveAction()
        {
            string validName = await ServiceLocator.ContextService.ConvertToValidFileName(SoundName);

            List <string> nameList = new List <string>();

            foreach (var soundItem in _receivedSelectedSprite.Sounds)
            {
                nameList.Add(soundItem.Name);
            }
            SoundName = await ServiceLocator.ContextService.FindUniqueName(validName, nameList);

            var sound = new Sound(SoundName);
            var path  = Path.Combine(CurrentProgram.BasePath, StorageConstants.ProgramSoundsPath, SoundName);

            using (var storage = StorageSystem.GetStorage())
            {
                using (var stream = await storage.OpenFileAsync(path, StorageFileMode.Create, StorageFileAccess.Write))
                {
                    if (SoundStream != null)
                    {
                        await SoundStream.CopyToAsync(stream);
                    }
                    else
                    {
                        if (Debugger.IsAttached)
                        {
                            Debugger.Break();
                        }
                        // TODO: Show error message
                    }
                }
            }

            ServiceLocator.DispatcherService.RunOnMainThread(() =>
            {
                _receivedSelectedSprite.Sounds.Add(sound);
                ServiceLocator.NavigationService.RemoveBackEntry();
                ServiceLocator.NavigationService.NavigateBack(this.GetType());
            });
        }