public bool Post(NewBackup toInsert) { Backups backups = new Backups() { BackupType = toInsert.BackupType, Cron = toInsert.Cron, DaemonId = toInsert.DaemonId, DestinationPath = toInsert.DestinationPath, SourcePath = toInsert.SourcePath, Batches = (toInsert.BatchAfterCode == null && toInsert.BatchAfterPath == null && toInsert.BatchBeforeCode == null && toInsert.BatchBeforePath == null) ? false : true, Ftp = (toInsert.FTPServerAdress == null) ? false : true, Ssh = (toInsert.SSHServerAdress == null) ? false : true, Override = toInsert.Override, Rar = toInsert.Rar }; if (backups.Cron.Substring(0, 1) == "#") { backups.NextRun = Convert.ToDateTime(backups.Cron.Substring(1, backups.Cron.Length)); backups.Cron = "* * * * *"; } else { //ještě než se to uloží do databáze tak to vypočítá z cronu nextrun Schedule = CrontabSchedule.Parse(backups.Cron); backups.NextRun = Schedule.GetNextOccurrence(DateTime.Now); } backups.SourcePath = "[\"" + backups.SourcePath.Replace(",", "\",\"").Replace("\\", "\\\\") + "\"]"; backups.DestinationPath = "[\"" + backups.DestinationPath.Replace(",", "\",\"").Replace("\\", "\\\\") + "\"]"; this.database.Backups.Add(backups); this.database.SaveChanges(); Backups dbRecord = this.database.Backups.Find(backups); int id = dbRecord.Id; if (dbRecord.Ftp) { this.database.FtpSettings.Add(new FTPSettings() { BackupId = id, Password = toInsert.FTPPassword, Port = toInsert.FTPPort, ServerAdress = toInsert.FTPServerAdress, Username = toInsert.FTPUsername }); this.database.SaveChanges(); } if (dbRecord.Ssh) { this.database.SshSettings.Add(new SSHSettings() { BackupId = id, HostOrIp = toInsert.SSHServerAdress, Password = toInsert.SSHPassword, Port = toInsert.SSHPort, Username = toInsert.SSHUsername }); this.database.SaveChanges(); } if (dbRecord.Batches) { if (toInsert.BatchAfterCode != null) { this.database.Batches.Add(new Batches() { BackupId = id, CommandText = toInsert.BatchAfterCode, Time = "AFTER", Type = "COMMAND" }); this.database.SaveChanges(); } if (toInsert.BatchBeforeCode != null) { this.database.Batches.Add(new Batches() { BackupId = id, CommandText = toInsert.BatchBeforeCode, Time = "BEFORE", Type = "COMMAND" }); this.database.SaveChanges(); } if (toInsert.BatchAfterPath != null) { this.database.Batches.Add(new Batches() { BackupId = id, CommandText = toInsert.BatchAfterPath, Time = "AFTER", Type = "SAVED" }); this.database.SaveChanges(); } if (toInsert.BatchBeforePath != null) { this.database.Batches.Add(new Batches() { BackupId = id, CommandText = toInsert.BatchBeforePath, Time = "AFTER", Type = "SAVED" }); this.database.SaveChanges(); } } return(true); }
private void ConnectionToolStripMenuItem_Click(object sender, EventArgs e) { NewBackup.PerformClick(); }