static void ProcessRunJobs(Object source, ElapsedEventArgs e) { timerRunJobs.Enabled = false; try { Console.WriteLine("Running Jobs: " + DateTime.Now); using (telcobrightmediationEntities context = new telcobrightmediationEntities()) { List <job> unfinishedJobs = context.jobs.Where(c => c.status != 1).ToList(); foreach (job j in unfinishedJobs) { FtpBackupLocation location = JsonConvert.DeserializeObject <FtpBackupLocation>(j.parameters); FtpManager ftpManager = new FtpManager (ftpUrl: "ftp://" + location.Server, ftpUser: location.User, ftpPass: location.Password ); string fileName = string.Concat("p0" + j.jobname.Split('/')[1] + ".dat"); ftpManager.FTPSendSingleFile(@"C:/CDR/Purple Telecom/PurDhkHW/" + fileName, fileName); if (ftpManager.FtpCheckSingleFile(fileName)) { // string Sql = "update telcobrightmediation.job status=1,finishtime={DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'where jobname='{j.jobname}'"; context.Database.ExecuteSqlCommand($@"update telcobrightmediation.job set status=1,finishtime='{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}' where jobname='{j.jobname}'"); } } } } catch (Exception e1) { Console.WriteLine(e1); } timerRunJobs.Enabled = true; }
static void ProcessDeleteFiles(Object source, ElapsedEventArgs e) { timerDeleteJobs.Enabled = false; using (telcobrightmediationEntities context = new telcobrightmediationEntities()) { var dir = new DirectoryInfo(@"C:\CDR\Purple Telecom\PurDhkHW\"); List <FileInfo> allfiles = dir.GetFiles().ToList(); try { Console.WriteLine("Deleting Jobs: " + DateTime.Now); foreach (FileInfo file in allfiles) { List <FtpBackupLocation> locations = GetFtpLocations(); List <string> jobNamesForThisFile = new List <string>(); foreach (FtpBackupLocation location in locations) { string fileName = file.Name; string jobName = location.Name + "/" + fileName.Substring(2, 7); jobNamesForThisFile.Add(jobName); } bool deleteFlag = true; foreach (string jobName in jobNamesForThisFile) { int status = context.jobs.Where(j => j.jobname == jobName).ToList().Select(c => c.status).First(); if (Convert.ToInt32(status) != 1)//if status not complete { deleteFlag = false; } if (deleteFlag == false) { break; } } if (deleteFlag == true) { File.Delete(@"C:\CDR\Purple Telecom\PurDhkHW\" + file); } } } catch (Exception e1) { Console.WriteLine(e1); } } timerDeleteJobs.Enabled = true; }
static void ProcessCreateJobs(Object source, ElapsedEventArgs e) { timerCreatJobs.Enabled = false; try { Console.WriteLine("Creating Jobs: " + DateTime.Now); using (telcobrightmediationEntities context = new telcobrightmediationEntities()) { new ProcessBackup(GetFtpLocations(), context).CreateBackupJobs(); } } catch (Exception e1) { Console.WriteLine(e1); } timerCreatJobs.Enabled = true; }
public ProcessBackup(List <FtpBackupLocation> locations, telcobrightmediationEntities Context) { this.Locations = locations; this.Context = Context; }