示例#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++;
            }
        }
示例#3
0
        public async Task LoadNew(InkCanvas inkCanvas, InkCanvas goals, CommentModel commentModel, AnimationModel animationModel)
        {
            if (projectFolder != null)
            {
                var files = await projectFolder.GetFilesAsync();

                foreach (StorageFile file in files)
                {
                    if (file.Name.Equals("InkFile.gif"))
                    {
                        IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                        using (var inputStream = stream.GetInputStreamAt(0))
                        {
                            await inkCanvas.InkPresenter.StrokeContainer.LoadAsync(inputStream);
                        }
                        stream.Dispose();
                    }
                    else if (file.Name.Equals("GoalsFile.gif"))
                    {
                        IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                        using (var inputStream = stream.GetInputStreamAt(0))
                        {
                            await goals.InkPresenter.StrokeContainer.LoadAsync(inputStream);
                        }
                        stream.Dispose();
                    }
                    else if (file.Name.Equals("comments.txt"))
                    {
                        string text = await FileIO.ReadTextAsync(file);

                        string[] components = text.Split('\n');
                        foreach (string component in components)
                        {
                            if (component.Length > 0)
                            {
                                Comment c = Deserialize <Comment>(component);
                                commentModel.Add(c);
                                Debug.WriteLine(commentModel.GetComments().Count());
                            }
                        }
                    }
                    else if (file.Name.Equals("animations.txt"))
                    {
                        string text = await FileIO.ReadTextAsync(file);

                        string[] components = text.Split('\n');
                        foreach (string component in components)
                        {
                            if (component.Length > 0)
                            {
                                Animation a = Deserialize <Animation>(component);
                                animationModel.Add(a);
                            }
                        }
                    }
                }

                foreach (StorageFile file in files)
                {
                    if (file.Name.StartsWith("CommentInk"))
                    {
                        IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                        using (var inputStream = stream.GetInputStreamAt(0))
                        {
                            // first get the # of the ink
                            Regex re     = new Regex(@"\d+");
                            Match m      = re.Match(file.Name);
                            int   inkPos = int.Parse(m.Value);   // we will need to have better error handling

                            // then set it
                            commentModel.GetComments()[inkPos].ic = new Windows.UI.Input.Inking.InkStrokeContainer();

                            await commentModel.GetComments()[inkPos].ic.LoadAsync(inputStream);
                        }
                    }
                }
            }
        }