Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        void CreateJobsForSingleLocation(FtpBackupLocation location, List <long> unsent,
                                         out long lastSerialNumber, out List <job> jobsToBeCreated)
        {
            lastSerialNumber = 0;
            jobsToBeCreated  = new List <job>();
            List <string> newJobNamesAll           = unsent.Select(c => location.Name + "/" + c.ToString()).ToList();
            List <string> existingAmongNewJobNames = Context.jobs.Where(c => c.jobname.StartsWith(location.Name) &&
                                                                        newJobNamesAll.Contains(c.jobname)).Select(c => c.jobname).ToList();
            List <string> jobNamesToBeCreated = newJobNamesAll.Except(existingAmongNewJobNames).ToList();

            foreach (string newJobName in jobNamesToBeCreated)
            {
                job newJob = new job()
                {
                    jobname      = newJobName,
                    creationtime = DateTime.Now,
                    status       = 0,
                    parameters   = JsonConvert.SerializeObject(location)
                };
                long newSerialNumber = Convert.ToInt64(newJob.jobname.Split('/')[1]);
                lastSerialNumber = newSerialNumber > lastSerialNumber ? newSerialNumber : lastSerialNumber;
                jobsToBeCreated.Add(newJob);
            }

            Context.SaveChanges();
        }