コード例 #1
0
        public async Task <bool> ReadInFolderAsync()
        {
            Debug.Assert(IsDeWrapper);
            var folders = (await TmpFolder.GetFoldersAsync()).Where(folder => folder.DisplayName == InkStrokesFolderName).ToList();

            if (folders.Count != 0)
            {
                var folder = folders[0];
                var files  = (await folder.GetFilesAsync()).Where(f => f.FileType.ToLower() == ".isf");
                foreach (var file in files)
                {
                    var ic       = new InkCanvas();
                    var filename = file.Name.Substring(0, file.Name.Length - 4);
                    using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await ic.InkPresenter.StrokeContainer.LoadAsync(fs);
                    }
                    var strokes  = ic.InkPresenter.StrokeContainer.GetStrokes().ToList();
                    var gslength = Enum.GetValues(typeof(GraphicsTypes)).Length;
                    var layer    = new LayerModel();
                    foreach (var stroke in strokes)
                    {
                        var gi = stroke.StrokeDuration.Value.Ticks;
                        if (gi > 0 && gi < gslength)
                        {
                            var gr = (GraphicsRectSizeBase)GraphicsInstCreateManager.CreateGraphics((GraphicsTypes)gi, layer.LocPenModel, layer, layer);
                            Debug.Assert(gr != null);
                            stroke.GetInkPoints().ToList().ForEach(p => gr.Points.Add(p));
                            gr.PenAttribute = PenModel.ToPenModel(stroke.DrawingAttributes);
                            layer.GraphicsRects.Add(gr);
                        }
                    }
                    layer.Name       = filename;
                    layer.CanvasSize = CanvasSize;
                    Debug.Assert(XmlDoc != null);
                    var xmlEle = XmlDoc.SelectSingleNode(filename);
                    if (xmlEle != null)
                    {
                        var layerData = xmlEle.ChildNodes.Where(xmlNode => xmlNode.NodeName == "IsLock" || xmlNode.NodeName == "IsAppear").ToArray();
                        Debug.Assert(layerData.Count() == 2);
                        layer.IsLock   = Convert.ToBoolean(layerData[0].InnerText);
                        layer.IsAppear = Convert.ToBoolean(layerData[1].InnerText);
                    }
                    //TODO:Init Others
                    Reading?.Invoke(XmlDoc);
                    Layers.Add(layer);
                }
                return(true);
            }
            return(false);
        }
コード例 #2
0
        public async Task <bool> ReadInFolderAsync()
        {
            Debug.Assert(IsDeWrapper && IsInitSucceed);
            var folders = (await TmpFolder.GetFoldersAsync())
                          .Where(folder => folder.DisplayName == InkStrokesFolderName)
                          .ToList();

            if (folders.Count != 0)
            {
                var folder = folders[0];
                var files  = (await folder.GetFilesAsync()).Where(f => f.FileType.ToLower() == ".isf");
                foreach (var file in files)
                {
                    var ic       = new InkCanvas();
                    var filename = file.Name.Substring(0, file.Name.Length - 4);
                    using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await ic.InkPresenter.StrokeContainer.LoadAsync(fs);
                    }
                    var strokes  = ic.InkPresenter.StrokeContainer.GetStrokes().ToList();
                    var gslength = Enum.GetValues(typeof(GraphicsTypes)).Length;
                    var layer    = new LayerModel();
                    foreach (var stroke in strokes)
                    {
                        var gi = stroke.StrokeDuration.Value.Ticks;
                        if (gi > 0 && gi < gslength)
                        {
                            var gr = (GraphicsRectSizeBase)GraphicsInstCreateManager.CreateGraphics((GraphicsTypes)gi, layer.LocPenModel, layer, layer);
                            Debug.Assert(gr != null);
                            stroke.GetInkPoints().ToList().ForEach(p => gr.Points.Add(p));
                            gr.PenAttribute = PenModel.ToPenModel(stroke.DrawingAttributes);
                            layer.GraphicsRects.Add(gr);
                        }
                    }
                    layer.Name       = filename;
                    layer.CanvasSize = CanvasSize;
                    FileRead?.Invoke(this);
                    Layers.Add(layer);
                }
                return(true);
            }
            return(false);
        }