示例#1
0
        /// <summary>
        /// Method call for SaveToFileClick
        /// </summary>
        /// <param name="sender">Sender Object</param>
        /// <param name="e">Routed Event Arg</param>
        private void SaveToFileClick(object sender, RoutedEventArgs e)
        {
            try
            {
                var view = AppContext.ActiveView as ViewImage;
                if (view != null)
                {
                    Imaging imageData = view.GetImagingData();
                    if (imageData != null)
                    {
                        ImageMetaData imageMetaData = imageData.MetaData;
                        if (imageMetaData != null && imageMetaData.Count > 0)
                        {
                            // get the filename (and path) with the common dialog
                            var saveAsFileDialog = new CommonDialog();
                            var filter           = new FilterEntry(Strings.XmlFileDescription, Strings.XmlFileExtension);
                            saveAsFileDialog.Filters.Add(filter);
                            if (imageData.ObjectDocument != null)
                            {
                                if (!string.IsNullOrEmpty(imageData.ObjectDocument.FileName))
                                {
                                    string proposal = Path.GetFileNameWithoutExtension(imageData.ObjectDocument.FileName);
                                    proposal += "_meta" + Strings.XmlFileExtension;
                                    saveAsFileDialog.FileName = proposal;
                                }
                            }

                            saveAsFileDialog.ShowSaveAs();
                            string fileName = saveAsFileDialog.FileName;
                            if (string.IsNullOrEmpty(fileName))
                            {
                                return;
                            }

                            string extension = Path.GetExtension(fileName);
                            if (string.IsNullOrEmpty(extension))
                            {
                                fileName += Strings.XmlFileExtension;
                            }

                            // write the meta data
                            imageMetaData.SaveToXml(fileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Util.ReportException(ex);
            }
        }