SecureDelete.Schedule.HistoryManager.SaveHistory C# (CSharp) Method

SaveHistory() public method

Save the history database to disk.
public SaveHistory ( string path ) : bool
path string
return bool
        public bool SaveHistory(string path)
        {
            if(path == null) {
                throw new ArgumentNullException("path");
            }

            try {
                // create the store
                FileStore.FileStore store = new FileStore.FileStore();
                store.Encrypt = true;
                store.UseDPAPI = true;

                // add the file
                FileStore.StoreFile file = store.CreateFile("history.dat");
                byte[] data = SerializeHistory(_categories);

                if(data == null) {
                    return false;
                }

                // write the file contents
                store.WriteFile(file, data, FileStore.StoreMode.Encrypted);
                return store.Save(path);
            }
            catch(Exception e) {
                Debug.ReportError("Error while saving task history. Exception: {0}", e.Message);
                return false;
            }
        }

Usage Example

示例#1
0
        private void button5_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Do you really want to remove all task history ?", "SecureDelete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) {
                HistoryManager man = new HistoryManager();

                man.LoadHistory(SecureDeleteLocations.GetScheduleHistoryFile());
                man.Clear();
                man.SaveHistory(SecureDeleteLocations.GetScheduleHistoryFile());
            }
        }