示例#1
0
        public async Task LoadAll(InkCanvas inkCanvas, InkCanvas goals, CommentModel commentModel, AnimationModel animationModel)
        {
            commentModel.GetComments().Clear();
            animationModel.GetAnimations().Clear();

            var folderPicker = new FolderPicker();

            folderPicker.FileTypeFilter.Add("*");

            projectFolder = await folderPicker.PickSingleFolderAsync();

            await LoadNew(inkCanvas, goals, commentModel, animationModel);
        }
示例#2
0
        public async Task SaveAll(InkCanvas inkCanvas, InkCanvas goals, CommentModel comments, AnimationModel animations)
        {
            // delete everything first
            var files = await projectFolder.GetFilesAsync();

            foreach (StorageFile file in files)
            {
                await file.DeleteAsync(StorageDeleteOption.Default);
            }

            // save ink
            var inkFile = await projectFolder.CreateFileAsync("InkFile.gif", CreationCollisionOption.ReplaceExisting);

            using (IRandomAccessStream streamX = await inkFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(streamX);
            }

            // save goals
            var goalsFile = await projectFolder.CreateFileAsync("GoalsFile.gif", CreationCollisionOption.ReplaceExisting);

            using (IRandomAccessStream streamX = await goalsFile.OpenAsync(FileAccessMode.ReadWrite))
            {
                await goals.InkPresenter.StrokeContainer.SaveAsync(streamX);
            }

            // save animations
            var animationsFile = await projectFolder.CreateFileAsync("animations.txt", CreationCollisionOption.ReplaceExisting);

            var animationStream = await animationsFile.OpenAsync(FileAccessMode.ReadWrite);

            using (var outputStream = animationStream.GetOutputStreamAt(0))
            {
                using (var dataWriter = new DataWriter(outputStream))
                {
                    foreach (Animation animation in animations.GetAnimations())
                    {
                        dataWriter.WriteString($"{Serialize(animation)}\n");
                    }
                    await dataWriter.StoreAsync();

                    await outputStream.FlushAsync();
                }
            }
            animationStream.Dispose();

            // save comments
            var commentsFile = await projectFolder.CreateFileAsync("comments.txt", CreationCollisionOption.ReplaceExisting);

            var stream = await commentsFile.OpenAsync(FileAccessMode.ReadWrite);

            using (var outputStream = stream.GetOutputStreamAt(0))
            {
                using (var dataWriter = new DataWriter(outputStream))
                {
                    foreach (Comment comment in comments.GetComments())
                    {
                        dataWriter.WriteString($"{Serialize(comment)}\n");
                    }
                    await dataWriter.StoreAsync();

                    await outputStream.FlushAsync();
                }
            }

            stream.Dispose();

            var iterator = 0;

            foreach (Comment comment in comments.GetComments())
            {
                var inkComment = await projectFolder.CreateFileAsync("CommentInk" + iterator + ".gif", CreationCollisionOption.ReplaceExisting);

                using (IRandomAccessStream s = await inkComment.OpenAsync(FileAccessMode.ReadWrite))
                {
                    await comment.ic.SaveAsync(s);
                }
                iterator++;
            }
        }