/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.
This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using Everest.CmsServices.Models;
using Everest.Library.Data;
using Everest.Library.Data.Entity;
using Everest.Library.Scheduler;
namespace Everest.CmsServices.Providers{
public class CmsScheduleProvider : IScheduleProvider
{
#region IScheduleProvider Members
/// <summary>
/// Gets the schedules.
/// </summary>
/// <param name="initial">if set to <c>true</c> indicate it first time to get the schedules when scheduler running ,else the refresh schedule setting changed.</param>
/// <returns></returns>
public IEnumerable<Schedule> GetSchedules(bool initial)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
List<Schedule> schedules = new List<Schedule>();
var schedulesQuery = from s in dataContext.Cms_Schedule
where s.Enabled == true
select new
{
Schedule = s,
Parameters = s.Cms_ScheduleParameter
};
foreach (var item in schedulesQuery)
{
Schedule schedule = new Schedule();
schedule.Key = item.Schedule.EntityKey.GetEntityKey() + ",Schedule Name:" + item.Schedule.ScheduleName;
schedule.Changed = item.Schedule.Changed;
schedule.JobType = Type.GetType(item.Schedule.ScheduleType);
if (schedule.JobType == null)
{
continue;
}
schedule.Interval = item.Schedule.Interval;
if (item.Parameters != null)
{
NameValueCollection nameValues = new NameValueCollection();
foreach (var p in item.Parameters)
{
nameValues.Add(p.ParameterName, p.ParameterValue);
}
schedule.Parameter = nameValues;
}
schedules.Add(schedule);
item.Schedule.Changed = false;
}
dataContext.SaveChanges();
return schedules;
}
#endregion
}
}
|