⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 schedulingprovider.cs

📁 SharpNuke源代码
💻 CS
字号:
using System;
using System.Collections;

using DotNetNuke.Common.Utilities;
using DotNetNuke.Framework.Providers;

//
// DotNetNuke -  http://www.dotnetnuke.com
// Copyright (c) 2002-2005
// by Shaun Walker ( sales@perpetualmotion.ca ) of Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

namespace DotNetNuke.Services.Scheduling
{
	public enum EventName
	{
		//do not add APPLICATION_END
		//it will not reliably complete
		APPLICATION_START
	}
	
	public enum ScheduleSource
	{
		NOT_SET,
		STARTED_FROM_SCHEDULE_CHANGE,
		STARTED_FROM_EVENT,
		STARTED_FROM_TIMER,
		STARTED_FROM_BEGIN_REQUEST
	}
	
	public enum ScheduleStatus
	{
		NOT_SET,
		WAITING_FOR_OPEN_THREAD,
		RUNNING_EVENT_SCHEDULE,
		RUNNING_TIMER_SCHEDULE,
		RUNNING_REQUEST_SCHEDULE,
		WAITING_FOR_REQUEST,
		SHUTTING_DOWN,
		STOPPED
	}
	
	public enum SchedulerMode
	{
		DISABLED = 0,
		TIMER_METHOD = 1,
		REQUEST_METHOD = 2
	}
	
	// set up our delegates so we can track and react to events of the scheduler clients
	public delegate void WorkStarted(SchedulerClient schedulerClient);
	public delegate void WorkProgressing(SchedulerClient schedulerClient);
	public delegate void WorkCompleted(SchedulerClient schedulerClient);
	public delegate void WorkErrored(SchedulerClient schedulerClient, Exception exception);
	
	public abstract class SchedulingProvider
	{
		
		private ProviderConfiguration providerConfiguration;
		private string providerPath;
		private static bool debug;
		private static int maxThreads;
		private EventName eventName;
		
		public string ProviderPath
		{
			get { return this.providerPath; }
		}
		
		public static bool Debug
		{
			get { return debug; }
		}
		
		public static int MaxThreads
		{
			get { return maxThreads; }
		}
		
		public static bool Enabled
		{
			get  { return SchedulerMode != SchedulerMode.DISABLED; }
		}
		
		public EventName EventName
		{
			get { return this.eventName; }
			set { this.eventName = value; }
		}

		public static DateTime ScheduleLastPolled
		{
			get
			{
				if (DataCache.GetCache("ScheduleLastPolled") != null)
				{
					return Convert.ToDateTime(DataCache.GetCache("ScheduleLastPolled"));
				}
				else
				{
					return DateTime.MinValue;
				}
			}
			set
			{
				DateTime nextStart;
				ScheduleItem scheduleItem;
				scheduleItem = Instance().GetNextScheduledTask(Common.Globals.ServerName);
				if (scheduleItem != null && scheduleItem.NextStart >= DateTime.Now)
				{
					nextStart = scheduleItem.NextStart;
				}
				else
				{
					nextStart = DateTime.Now.AddMinutes(1);
				}
				DataCache.SetCache("ScheduleLastPolled", value, nextStart);
			}
		}
		
		public static bool ReadyForPoll
		{
			get { return DataCache.GetCache("ScheduleLastPolled") == null; }
		}
		
		public static SchedulerMode SchedulerMode
		{
			get 
			{
				string mode = Common.Globals.HostSettings["SchedulerMode"] as string;
				if (mode == null || mode.Length == 0)
				{
					return SchedulerMode.TIMER_METHOD;
				}
				else
				{
					return (SchedulerMode)int.Parse(mode);
				}
			}
		}
		
		public SchedulingProvider() 
		{
			providerConfiguration = ProviderConfiguration.GetProviderConfiguration("scheduling");
			
			Provider schedulingProvider = ((Provider) providerConfiguration.Providers[providerConfiguration.DefaultProvider]);
			
			providerPath = schedulingProvider.Attributes["providerPath"];
			
			if (schedulingProvider.Attributes["debug"] != null)
			{
				debug = Convert.ToBoolean(schedulingProvider.Attributes["debug"]);
			}
			if (schedulingProvider.Attributes["maxThreads"] != null)
			{
				maxThreads = Convert.ToInt32(schedulingProvider.Attributes["maxThreads"]);
			}
			else
			{
				maxThreads = 1;
			}
			
		}
		
		#region "Shared/Static Methods"
		
		// singleton reference to the instantiated object
		private static SchedulingProvider schedulingProvider;
		
		// constructor
		static SchedulingProvider() 
		{
//@SV			providerConfiguration = ProviderConfiguration.GetProviderConfiguration("scheduling");
			CreateProvider();
		}
		
		// dynamically create provider
		private static void CreateProvider ()
		{
			schedulingProvider = ((SchedulingProvider) DotNetNuke.Framework.Reflection.CreateObject("scheduling"));
		}
		
		// return the provider
		public static SchedulingProvider Instance()
		{
			return schedulingProvider;
		}
		
		#endregion
		
		#region "Abstract Methods"
		
		public abstract string GetProviderPath();
		
		public abstract void Start ();
		public abstract void ExecuteTasks ();
		public abstract void ReStart (string sourceOfRestart);
		public abstract void StartAndWaitForResponse ();
		public abstract void Halt (string sourceOfHalt);
		public abstract void PurgeScheduleHistory ();
		public abstract void RunEventSchedule (EventName eventName);
		public abstract ArrayList GetSchedule();
		public abstract ArrayList GetSchedule(string server);
		public abstract ScheduleItem GetSchedule(int scheduleID);
		public abstract ScheduleItem GetSchedule(string typeFullName, string server);
		public abstract ScheduleItem GetNextScheduledTask(string server);
		public abstract ArrayList GetScheduleHistory(int scheduleID);
		public abstract Hashtable GetScheduleItemSettings(int scheduleID);
		public abstract ArrayList GetScheduleQueue();
		public abstract ArrayList GetScheduleProcessing();
		public abstract int GetFreeThreadCount();
		public abstract int GetActiveThreadCount();
		public abstract int GetMaxThreadCount();
		public abstract ScheduleStatus GetScheduleStatus();
		public abstract int AddSchedule(ScheduleItem scheduleItem);
		public abstract void UpdateSchedule (ScheduleItem scheduleItem);
		public abstract void DeleteSchedule (ScheduleItem scheduleItem);
		
		#endregion
		
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -