Exemple #1
0
        private void saveMotionData(string path)
        {
            string ext = Path.GetExtension(path);

            try {
                DialogResult result = DialogResult.None;
                using (Stream stream = new FileStream(path + "~", FileMode.Create)) {
                    WaitForForm waitForm = new WaitForForm(ctrl => {
                        try {
                            if (ext == ".mdsx2")
                            {
                                using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stream)) {
                                    _dataSet.SerializeXml(writer);
                                }
                            }
                            else if (ext == ".mdsb2")
                            {
                                using (BinaryWriter writer = new BinaryWriter(stream)) {
                                    _dataSet.SerializeBinary(writer);
                                }
                            }
                            else
                            {
                                throw new ArgumentException("Unknown format: " + ext);
                            }
                            ctrl.DialogResult = DialogResult.OK;
                        } catch (Exception ex) {
                            ErrorLogger.Tell(ex, path + ": ファイルを保存できませんでした");
                        }
                    }, () => _dataSet.ProgressChangedEventArgs);
                    waitForm.SetOperationTitle(path);
                    result = waitForm.ShowDialog();
                }
                if (result == DialogResult.OK)
                {
                    if (File.Exists(path))
                    {
                        File.Replace(path + "~", path, path + "~~");
                        File.Delete(path + "~~");
                    }
                    else
                    {
                        File.Move(path + "~", path);
                    }
                    _isDataSetModified = false;
                    _isOverWritable    = true;
                }
            } catch (NullReferenceException ex) {
                ErrorLogger.Tell(ex, path + ": ファイルを保存できませんでした");
            }
        }