Exemplo n.º 1
0
    public void AddNewSchedule(string ScheduleName, string FullNameSpace, string StartDate, string EndDate, int StartHour, int StartMin, int RepeatWeeks, int RepeatDays,
                               int WeekOfMonth, int EveryHour, int EveryMin, string Dependencies, int RetryTimeLapse, int RetryFrequencyUnit, int AttachToEvent, bool CatchUpEnabled,
                               string Servers, string CreatedByUserID, bool IsEnable, int RunningMode, List <string> WeekDays, List <string> Months, string Dates, string AssemblyFileName)
    {
        MembershipUser user = Membership.GetUser();

        Schedule objSchedule = new Schedule();

        objSchedule.ScheduleName       = ScheduleName;
        objSchedule.FullNamespace      = FullNameSpace;
        objSchedule.StartDate          = StartDate ?? DateTime.Now.ToString();
        objSchedule.EndDate            = EndDate ?? DateTime.Now.ToString();
        objSchedule.StartHour          = StartHour;
        objSchedule.StartMin           = StartMin;
        objSchedule.RepeatWeeks        = RepeatWeeks;
        objSchedule.RepeatDays         = RepeatDays;
        objSchedule.WeekOfMonth        = WeekOfMonth;
        objSchedule.EveryMin           = EveryMin;
        objSchedule.EveryHours         = EveryHour;
        objSchedule.ObjectDependencies = Dependencies;
        objSchedule.RetryTimeLapse     = RetryTimeLapse;
        objSchedule.RetryFrequencyUnit = RetryFrequencyUnit;
        objSchedule.AttachToEvent      = AttachToEvent.ToString();
        objSchedule.CatchUpEnabled     = CatchUpEnabled;
        objSchedule.Servers            = Servers;
        // objSchedule.CreatedByUserID = user.ProviderUserKey.ToString();

        objSchedule.CreatedOnDate    = DateTime.Now.ToString();
        objSchedule.IsEnable         = IsEnable;
        objSchedule.RunningMode      = (RunningMode)RunningMode;
        objSchedule.AssemblyFileName = AssemblyFileName;


        try
        {
            Schedule schedule = SchedulerController.AddNewSchedule(objSchedule);
            if (schedule.ScheduleID < 1)
            {
                string fileName = objSchedule.AssemblyFileName;
                string filepath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, "bin\\" + fileName);
                SchedulerController.DeleteFile(filepath);
            }
            else
            {
                if (WeekDays.Count > 0)
                {
                    SchedulerController.AddNewScheduleWeeks(schedule.ScheduleID, WeekDays);
                }
                if (Months.Count > 0)
                {
                    SchedulerController.AddNewScheduleMonths(schedule.ScheduleID, Months);
                }
                if (!string.IsNullOrEmpty(Dates) && Dates.Trim().Length > 0)
                {
                    SchedulerController.AddNewScheduleDate(schedule.ScheduleID, Dates);
                }

                SchedulerController.RunScheduleItemNow(schedule);
            }
        }
        catch (Exception)
        {
            throw;
        }
    }