/*
 * FeedExpress
 * (C) Copyright 2003 Jeppe Cramon
 * 
 * This software is provided "as is" without warranty of any kind,
 * either expressed or implied. The entire risk as to the
 * quality and performance of the software is with you. Should the
 * software prove defective, you assume the cost of all necessary
 * servicing, repair, or correction. In no event shall the author,
 * copyright holder, or any other party who may redistribute the
 * software be liable to you for damages, including any general,
 * special, incidental, or consequential damages arising out of
 * the use or inability to use the software (including, but not
 * limited to, loss of data, data being rendered inaccurate, loss of
 * business profits, loss of business information, business
 * interruptions, loss sustained by you or third parties, or a
 * failure of the software to operate with any other software) even
 * if the author, copyright holder, or other party has been advised
 * of the possibility of such damages. 
 */

namespace FeedExpress {
    [Serializable]
    public class ChannelInformation {
		private string mTitle;
		private string mLink;
		private string mDescription;
		private string mLanguage;
		private string mCreator;
		private string mRights;
		private DateTime mDate;
		private string mGeneratorAgent;
		private string mErrorReportsTo;
		private UpdatePeriodEnum mUpdatePeriod;
		private int mUpdateFrequency;
		private DateTime mUpdateBase;
		private Subscription mSubscription;
		private string mCSSStyle;


		public event EventHandler UpdateSettingsChanged;

		public ChannelInformation() {
		}
		
		public ChannelInformation(Subscription sub) {
			mSubscription = sub;
		}

		public enum UpdatePeriodEnum { Minute, Hour, Day, Month };
		
		public static UpdatePeriodEnum updatePeriodStringToEnum(string name) {
			switch (name.ToLower()) {
				case "minute":
					return UpdatePeriodEnum.Minute;
				case "hourly":
					return UpdatePeriodEnum.Hour;
				case "daily":
					return UpdatePeriodEnum.Day;
				case "monthly":
					return UpdatePeriodEnum.Month;
				default:
					return UpdatePeriodEnum.Hour;
			}
		}

		public static string updatePeriodEnumToString(UpdatePeriodEnum updatePeriode) {
			switch (updatePeriode) {
				case UpdatePeriodEnum.Minute:
					return "minute";
				case UpdatePeriodEnum.Hour:
					return "hourly";
				case UpdatePeriodEnum.Day:
					return "daily";
				case UpdatePeriodEnum.Month:
					return "monthly";
				default:
					throw new Exception("Unknown UpdatePeriodeEnum value " + updatePeriode);
			}
		}

		public Subscription subscription {
			get { return mSubscription; }
			set { mSubscription = value; }
		}

		public string cssStyle {
			get { return mCSSStyle; }
			set { mCSSStyle = value; }
		}

		/// <summary>
		/// Return the update interval in milliseconds.
		/// </summary>
		/// <returns></returns>
		public int getUpdateInterval() {
			// init with the frequency in seconds
			int interval = updateFrequency*1000;
			if (interval == 0) {
				// Interval == 0 isn't a valid number
				interval = 1000;
			}
			switch (mUpdatePeriod) {
				case UpdatePeriodEnum.Minute:
					return interval*60;
				case UpdatePeriodEnum.Hour:
					return interval*3600;
				case UpdatePeriodEnum.Day:
					return interval*3600*24;
				case UpdatePeriodEnum.Month:
					// 30 days is assumed in a month
					return interval*3600*24*30;
			}
			return 1;
		}

		public string title {
			get { return mTitle; }
			set { mTitle = value; }
		}

		public string link {
			get { return mLink; }
			set { mLink = value; }
		}
		public string description {
			get { return mDescription; }
			set { mDescription = value; }
		}
		public string language {
			get { return mLanguage; }
			set { mLanguage = value; }
		}
		public string creator {
			get { return mCreator; }
			set { mCreator = value; }
		}
		public string rights {
			get { return mRights; }
			set { mRights = value; }
		}
		public string generatorAgent {
			get { return mGeneratorAgent; }
			set { mGeneratorAgent = value; }
		}
		public string errorReportsTo {
			get { return mErrorReportsTo; }
			set { mErrorReportsTo = value; }
		}
		public UpdatePeriodEnum updatePeriod {
			get { return mUpdatePeriod; }
			set { 
				mUpdatePeriod = value; 
				if (UpdateSettingsChanged != null) {
					UpdateSettingsChanged(this, EventArgs.Empty);
				}
			}
		}
		public int updateFrequency {
			get { return mUpdateFrequency; }
			set { 
				mUpdateFrequency = value; 
				if (UpdateSettingsChanged != null) {
					UpdateSettingsChanged(this, EventArgs.Empty);
				}
			}
		}

		public DateTime updateBase {
			get { return mUpdateBase; }
			set { mUpdateBase = value; }
		}
		public DateTime date {
			get { return mDate; }
			set { mDate = value; }
		}

		public override string ToString() {
                ...
		}

		public override bool Equals(object obj) {
		...
		}

		public override int GetHashCode() {
		...
		}
    }
}
Close Window