Esempio n. 1
0
        public void SaveBeforeClose()
        {
            if (string.IsNullOrWhiteSpace(SerializeFile))
            {
                return;
            }

            var dialogResult = MessageBox.Show("Do you wish to save database before exiting?", "Save database", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                using (var stream = File.OpenWrite(SerializeFile))
                {
                    FaceDatabase.Serialize(stream);
                }
            }
        }
Esempio n. 2
0
        public string Save()
        {
            if (string.IsNullOrEmpty(SerializeFile))
            {
                return(SaveAs());
            }
            try
            {
                using (var fs = File.OpenWrite(SerializeFile))
                {
                    FaceDatabase.Serialize(fs);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(
                    $"Error: An error occured while saving the database to {SerializeFile}:{Environment.NewLine}{exc}");
            }

            return(SerializeFile);
        }
Esempio n. 3
0
        public string SaveAs()
        {
            if (!Directory.Exists(_defaultSerializePath))
            {
                Directory.CreateDirectory(_defaultSerializePath);
            }

            var dialog = new SaveFileDialog
            {
                InitialDirectory = SerializeFile == null ? _defaultSerializePath : Path.GetDirectoryName(SerializeFile),
                DefaultExt       = "xml",
                Filter           = FileFilter
            };

            var result = dialog.STAShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    using (var fs = dialog.OpenFile())
                    {
                        FaceDatabase.Serialize(fs);
                    }
                }
                catch (Exception exc)
                {
                    MessageBox.Show(
                        $"Error: An error occured while saving the database to {dialog.FileName}:{Environment.NewLine}{exc}");
                }

                SerializeFile = dialog.FileName;
            }

            return(SerializeFile);
        }