Beispiel #1
0
        private async Task LoadPointfile(MapDocument document, string file)
        {
            if (file != null && File.Exists(file))
            {
                var       text = File.ReadAllLines(file);
                Pointfile point;
                try
                {
                    point = Pointfile.Parse(text);
                }
                catch
                {
                    MessageBox.Show(String.Format(InvalidPointfile, Path.GetFileName(file)));
                    return;
                }

                await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                       d => d.Map.Data.Replace(point),
                                                       c => c.Add(c.Document.Map.Root)
                                                       ));

                if (point.Lines.Any())
                {
                    var start = point.Lines[0].Start;
                    await Oy.Publish("MapDocument:Viewport:Focus2D", start);

                    await Oy.Publish("MapDocument:Viewport:Focus3D", start);
                }
            }
        }
        protected override async Task Invoke(MapDocument document, CommandParameters parameters)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter           = "Pointfiles (*.lin, *.pts)|*.lin;*.pts";
                ofd.InitialDirectory = Path.GetDirectoryName(document.FileName);
                ofd.Multiselect      = false;
                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                var       file = ofd.FileName;
                var       text = File.ReadAllLines(file);
                Pointfile point;
                try
                {
                    point = Pointfile.Parse(text);
                }
                catch
                {
                    MessageBox.Show(String.Format(InvalidPointfile, Path.GetFileName(file)));
                    return;
                }

                await MapDocumentOperation.Perform(document, new TrivialOperation(
                                                       d => d.Map.Data.Replace(point),
                                                       c => c.Add(c.Document.Map.Root)
                                                       ));

                if (point.Lines.Any())
                {
                    var start = point.Lines[0].Start;
                    await Oy.Publish("MapDocument:Viewport:Focus2D", start);

                    await Oy.Publish("MapDocument:Viewport:Focus3D", start);
                }
            }
        }