Created
April 7, 2016 09:15
-
-
Save snmslavk/87fa46088868f895dc17a372b75e0499 to your computer and use it in GitHub Desktop.
Start banch of files every day at specific time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace RunFileLib | |
{ | |
public class ExeFileModel | |
{ | |
public ExeFileModel() | |
{ | |
LastStart = DateTime.Now.AddDays(-1); | |
} | |
public string PathFile { get; set; } | |
public TimeSpan TimeExec { get; set; } | |
public DateTime LastStart { get; set; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Configuration; | |
namespace RunFileLib | |
{ | |
public class MainLogic | |
{ | |
public MainLogic() | |
{ | |
FillDict(); | |
} | |
private List<ExeFileModel> ListExeFileModel = new List<ExeFileModel>(); | |
private void FillDict() | |
{ | |
int i=1; | |
while (GetPath(i)!=null | |
&& GetTimeExec(i).HasValue) | |
{ | |
ListExeFileModel.Add(new ExeFileModel() | |
{ | |
PathFile = GetPath(i), | |
TimeExec = GetTimeExec(i).Value | |
}); | |
i++; | |
} | |
} | |
public void RunFiles() | |
{ | |
ListExeFileModel.ForEach( | |
x => | |
{ | |
if (DateTime.Now.TimeOfDay >= x.TimeExec | |
&& x.LastStart.Date < DateTime.Now.Date) | |
{ | |
System.Diagnostics.Process.Start(x.PathFile); | |
x.LastStart = DateTime.Now; | |
} | |
} | |
); | |
} | |
private string GetPath(int i) | |
{ | |
return ConfigurationManager.AppSettings["file_path" + i]; | |
} | |
private TimeSpan? GetTimeExec(int i) | |
{ | |
return ConfigurationManager.AppSettings["time_exec" + i]==null? | |
(TimeSpan?)null : TimeSpan.Parse(ConfigurationManager.AppSettings["time_exec" + i]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment