I am facing a problem while doing scheduling work
I have to generate report by reading specified scheduled days from App.Config file like
key="ByRACFID" value="Sunday-Saturday 11:14 AM
or
key="ByRACFID" value="Monday, Wednesday, Friday 12:30 AM
or
key="ByRACFID" value="Saturday 12:30 AM
or
add key="ByRACFID" value="December 31 12:30 AM
User can change the scheduled format in any way as mentioned above.
so in timer elapsed event i put
public static void _timer_Elapsed(object sender, ElapsedEventArgs e)
{
_l.Add(DateTime.Now);
SchedulingRACF("ByRACFID", ConfigurationManager.AppSettings["ByRACFID"].ToString());
}
public static void SchedulingRACF(string ReportType, string StrScheduleInfo)
{
int[] ArrDaysOfWeek = new int[] { 0, 1, 2, 3, 4, 5, 6 };
List<int> ArrSchDays = new List<int>();
try
{
string StrScheduleTime;
string StrScheduleDay;
String StrFromDay, StrToDay;
int StrCurrentWeekDayNum;
if (StrScheduleInfo.Length > 0)
{
StrScheduleTime = StrScheduleInfo.Substring((StrScheduleInfo.IndexOf(":") - 2));
StrScheduleDay = StrScheduleInfo.Substring(0, (StrScheduleInfo.IndexOf(":") - 2));
if ((StrScheduleDay.Length) > 0)
{
if (StrScheduleDay.IndexOf("-") > 0)
{
StrFromDay = FetchDayNumber(StrScheduleDay.Substring(0, (StrScheduleDay.IndexOf("-")))).ToString();
StrToDay = FetchDayNumber(StrScheduleDay.Substring((StrScheduleDay.IndexOf("-") + 1))).ToString();
StrCurrentWeekDayNum = (int)DateTime.Now.DayOfWeek;
if (StrFromDay != StrToDay)
{
if (int.Parse(StrFromDay) <= int.Parse(StrToDay))
{
for (int i = int.Parse(StrFromDay); i <= int.Parse(StrToDay); i++)
{
ArrSchDays.Add(ArrDaysOfWeek[i]);
}
}
else if (int.Parse(StrFromDay) > int.Parse(StrToDay))
{
for (int i = int.Parse(StrFromDay); i <= ArrDaysOfWeek.Length - 1; i++)
{
ArrSchDays.Add(ArrDaysOfWeek[i]);
}
for (int j = 0; j <= int.Parse(StrToDay); j++)
{
ArrSchDays.Add(ArrDaysOfWeek[j]);
}
}
if (int.Parse(StrFromDay) > int.Parse(StrToDay) && int.Parse(StrFromDay) != 6 && int.Parse(StrToDay) != 0)
{
for (int j = 0; j <= int.Parse(StrToDay); j++)
{
if (!ArrSchDays.Contains(ArrDaysOfWeek[j]))
{
ArrSchDays.Add(ArrDaysOfWeek[j]);
}
}
}
if (int.Parse(StrToDay) == 0)
{
ArrSchDays.Add(ArrDaysOfWeek[int.Parse(StrToDay)]);
}
foreach (int Currentday in ArrSchDays)
{
if (StrCurrentWeekDayNum == Currentday)
{
if (StrScheduleTime == DateTime.Now.ToString("hh:mm tt"))
{
GenerateReport gnr = new GenerateReport();
gnr.GetRacfReport();
}
}
}
}
else
{
MessageBox.Show("Start Date and End Date canoot be same");
}
}
else if (StrScheduleDay.IndexOf(",") > 0)
{
StrCurrentWeekDayNum = (int)DateTime.Now.DayOfWeek;
if (StrScheduleDay.Contains(DateTime.Now.DayOfWeek.ToString()))
{
if (StrScheduleTime == DateTime.Now.ToString("hh:mm tt"))
{
GenerateReport gnr = new GenerateReport();
gnr.GetRacfReport();
}
}
}
else if (StrScheduleDay.Contains(DateTime.Now.ToString("MMMM")) && StrScheduleDay.Contains(DateTime.Now.Day.ToString()))
{
if (StrScheduleTime == DateTime.Now.ToString("hh:mm tt"))
{
GenerateReport gnr = new GenerateReport();
gnr.GetRacfReport();
}
}
else
{
StrCurrentWeekDayNum = (int)DateTime.Now.DayOfWeek;
if (StrScheduleDay.Contains(DateTime.Now.DayOfWeek.ToString()))
{
if (StrScheduleTime == DateTime.Now.ToString("hh:mm tt"))
{
GenerateReport gnr = new GenerateReport();
gnr.GetRacfReport();
}
}
}
}
}
else
{
MessageBox.Show("Please enter proper Values in config file");
}
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
finally
{
ArrSchDays.Clear();
}
}
My problem is the method gnr.GetRacfReport() is getting called more than one time.
I want it to call only single time .
Please suggest the solution.