// Copyright 2005 by Omar Al Zabir. All rights are reserved.
//
// If you like this code then feel free to go ahead and use it.
// The only thing I ask is that you don't remove or alter my copyright notice.
//
// Your use of this software is entirely at your own risk. I make no claims or
// warrantees about the reliability or fitness of this code for any particular purpose.
// If you make changes or additions to this code please mark your code as being yours.
//
// website http://www.oazabir.com, email OmarAlZabir@gmail.com, msn oazabir@hotmail.com
using System;
using System.Drawing;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Drawing.Design;
namespace RSSCommon{
using PropertyEditor;
/// <summary>
/// Global Configuration Settings
/// </summary>
[System.Xml.Serialization.XmlRoot(Namespace="")]
[System.Xml.Serialization.XmlTypeAttribute("configuration")]
[Serializable]
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Configuration
{
#region Events
///<summary>A PropertyChanged event is raised when a property is changed on a component. A PropertyChangedEventArgs object specifies the name of the property that changed.</summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion
#region Constructors
public static Configuration Instance = new Configuration();
public Configuration()
{
this._OutlookBaseFolder = string.Empty;
//this._StartupDelay = 60;
this._XSLFileName = string.Empty;
this._DefaultDownloadFrequency = 60;
this._LastDownloadTime = DateTime.MinValue;
this._NewspaperXSL = "rss2html.xslt";
//this._NextDownloadTime = DateTime.Now;
this._OutlookBaseFolder = string.Empty;
this._SyncWithOutlook = true;
this._OutlookViewXmlPath = string.Empty;
this._OutlookXSL = string.Empty;
}
#endregion
#region Properties
#region Allowed Attributes
private string [] _AllowedAttributes = new string[] { "class", "href", "target", "border", "src", "align", "width", "height", "color", "size" };
/// <summary>If true, RSS Feeder runs in silent mode</summary>
[Category("Web Log"), Browsable(true), ReadOnly(true),
Description(@"Attributes in HTML that are allowed to be sent to weblogs. Weblog engines have restriction on which attributes and tags can be sent")]
[XmlElement("AllowedAttributes")]
public string[] AllowedAttributes
{
get
{
return this._AllowedAttributes;
}
/*
set
{
bool changed = !object.Equals(this._AllowedAttributes, value);
this._AllowedAttributes = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.AllowedAttributes));
}
*/
}
#endregion
#region Allowed Tags
private string [] _AllowedTags = new string[] { "p", "b", "i", "u", "em", "big", "small",
"div", "img", "span", "blockquote", "code", "pre", "br", "hr",
"ul", "ol", "li", "del", "ins", "strong", "a", "font"};
/// <summary>If true, RSS Feeder runs in silent mode</summary>
[Category("Web Log"), Browsable(true), ReadOnly(true),
Description(@"Attributes in HTML that are allowed to be sent to weblogs. Weblog engines have restriction on which attributes and tags can be sent")]
[XmlElement("AllowedTags")]
public string[] AllowedTags
{
get
{
return this._AllowedTags;
}
/*
set
{
bool changed = !object.Equals(this._AllowedTags, value);
this._AllowedTags = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.AllowedTags));
}
*/
}
#endregion
#region Load at Startup
private bool _LoadAtStartup = true;
/// <summary>If true, RSS Feeder runs at Windows startup</summary>
[Category("Preference"), DefaultValue(true), Browsable(true),
Description(@"If true, RSS Feeder runs at Windows startup")]
[XmlElement("loadAtStartup")]
public bool LoadAtStartup
{
get
{
return this._LoadAtStartup;
}
set
{
bool changed = !object.Equals(this._LoadAtStartup, value);
this._LoadAtStartup = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.LoadAtStartup));
}
}
#endregion
#region Startup load delay
private int _StartupLoadDelay = 5; // minutes
/// <summary>How many minutes RSS Feeder should wait at windows startup before starting so that your computer can start faster</summary>
[Category("Preference"), DefaultValue(5), Browsable(true),
Description(@"How many minutes RSS Feeder should wait at windows startup before starting so that your computer can start faster")]
[XmlElement("startupLoadDelay")]
public int StartupLoadDelay
{
get
{
return this._StartupLoadDelay;
}
set
{
bool changed = !object.Equals(this._StartupLoadDelay, value);
this._StartupLoadDelay = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.StartupLoadDelay));
}
}
#endregion
#region Silent Mode
private bool _SilentMode = false;
/// <summary>If true, RSS Feeder runs in silent mode</summary>
[Category("Preference"), DefaultValue(false), Browsable(true),
Description(@"If true, RSS Feeder runs in silent mode")]
[XmlElement("silentMode")]
public bool SilentMode
{
get
{
return this._SilentMode;
}
set
{
bool changed = !object.Equals(this._SilentMode, value);
this._SilentMode = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.SilentMode));
}
}
#endregion
#region No Baloon Popup
private bool _NoBaloonPopup = false;
/// <summary>If true, RSS Feeder runs in silent mode</summary>
[Category("Preference"), DefaultValue(false), Browsable(true),
Description(@"If true, No baloon popup is displayed")]
[XmlElement("noBaloonPopup")]
public bool NoBaloonPopup
{
get
{
return this._NoBaloonPopup;
}
set
{
bool changed = !object.Equals(this._NoBaloonPopup, value);
this._NoBaloonPopup = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.NoBaloonPopup));
}
}
#endregion
#region New Install
private bool _IsNewInstall = true;
/// <summary>If true, RSS feeds are also stored in outlook</summary>
[Category("Outlook"), DefaultValue(true), Browsable(false),
Description(@"If true, this is the first time the app is running after setup")]
[XmlElement("isNewInstall")]
public bool IsNewInstall
{
get
{
return this._IsNewInstall;
}
set
{
bool changed = !object.Equals(this._IsNewInstall, value);
this._IsNewInstall = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.IsNewInstall));
}
}
#endregion
#region Sync With Outlook
private bool _SyncWithOutlook = true;
/// <summary>If true, RSS feeds are also stored in outlook</summary>
[Category("Outlook"), DefaultValue(true),
Description(@"If true, RSS feeds are also stored in outlook")]
[XmlElement("syncWithOutlook")]
public bool SyncWithOutlook
{
get
{
return this._SyncWithOutlook;
}
set
{
bool changed = !object.Equals(this._SyncWithOutlook, value);
this._SyncWithOutlook = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.SyncWithOutlook));
}
}
#endregion
#region Outlook View XML Path
private string _OutlookViewXmlPath;
/// <summary>Path to an Outlook View XML file which is applied to all channel folders</summary>
[Category("Outlook"),
Description(@"Path to an Outlook View XML file which is applied to all channel folders")]
[XmlElement("outlookViewXmlPath")]
[Editor(typeof(UIFileDialogEditor), typeof(UITypeEditor)),
CommonDialogFilterAttribute("XML File (*.xml)|*.xml")]
public string OutlookViewXmlPath
{
get
{
return this._OutlookViewXmlPath;
}
set
{
bool changed = !object.Equals(this._OutlookViewXmlPath, value);
this._OutlookViewXmlPath = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.OutlookViewXmlPath));
}
}
#endregion
#region Outlook XSL
private string _OutlookXSL;
/// <summary>Path to an XSL file which transforms XML to HTML for outlook view</summary>
[Category("Outlook"),
Description(@"Path to an XSL file which transforms XML to HTML for outlook view")]
[XmlElement("outlookXSL")]
[Editor(typeof(UIFileDialogEditor), typeof(UITypeEditor)),
CommonDialogFilterAttribute("XSLT File (*.xslt)|*.xslt|XSL File (*.xsl)|*.xsl")]
public string OutlookXSL
{
get
{
return this._OutlookXSL;
}
set
{
bool changed = !object.Equals(this._OutlookXSL, value);
this._OutlookXSL = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.OutlookXSL));
}
}
#endregion
#region AtomToRssXsl
private string _AtomToRssXsl;
/// <summary>Path to an XSL file which transforms Atom feed to RSS Feed</summary>
[Category("Atom"),
Description(@"Path to an XSL file which transforms Atom feed to RSS Feed")]
[XmlElement("atomToRssXsl")]
[Editor(typeof(UIFileDialogEditor), typeof(UITypeEditor)),
CommonDialogFilterAttribute("XSLT File (*.xslt)|*.xslt|XSL File (*.xsl)|*.xsl")]
public string AtomToRssXsl
{
get
{
return this._AtomToRssXsl;
}
set
{
bool changed = !object.Equals(this._AtomToRssXsl, value);
this._AtomToRssXsl = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.AtomToRssXsl));
}
}
#endregion
#region Newspaper XSL
private string _NewspaperXSL;
/// <summary>XSL file used to render Newspaper</summary>
[Category("Newspaper"),
Description(@"XSL file used to render Newspaper")]
[XmlElement("newspaperXSL")]
[Editor(typeof(UIFileDialogEditor), typeof(UITypeEditor)),
CommonDialogFilterAttribute("XSLT File (*.xslt)|*.xslt|XSL File (*.xsl)|*.xsl")]
public string NewspaperXSL
{
get
{
return this._NewspaperXSL;
}
set
{
bool changed = !object.Equals(this._NewspaperXSL, value);
this._NewspaperXSL = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.NewspaperXSL));
}
}
#endregion
#region Outlook Base Folder
private string _OutlookBaseFolder = @"\\Personal Folders\RSS Feeds";
/// <summary>Outlook default Base Folder under which channel folders are created</summary>
[Category("Outlook"),
Description(@"Outlook default Base Folder under which channel folders are created")]
[XmlElement("outlookBaseFolder")]
[DefaultValue(@"\\Personal Folders\RSS Feeds")]
[Editor(typeof(UIOutlookFolderPickerEditor), typeof(UITypeEditor))]
public string OutlookBaseFolder
{
get
{
return this._OutlookBaseFolder;
}
set
{
bool changed = !object.Equals(this._OutlookBaseFolder, value);
this._OutlookBaseFolder = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.OutlookBaseFolder));
}
}
#endregion
#region Next Download Time
/*
private DateTime _NextDownloadTime;
/// <summary>Next time when feeds will be downloaded</summary>
[Category("Synchronization"), ReadOnly(true),
Description(@"Next time when feeds will be downloaded")]
[XmlElement("nextDownloadTime")]
public DateTime NextDownloadTime
{
get
{
return this._NextDownloadTime;
}
set
{
bool changed = !object.Equals(this._NextDownloadTime, value);
this._NextDownloadTime = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.NextDownloadTime));
}
}
*/
#endregion
#region Last Download Time
private DateTime _LastDownloadTime;
/// <summary>Last when feeds were downloaded</summary>
[Category("Synchronization"), ReadOnly(true),
Description(@"Last when feeds were downloaded")]
[XmlElement("lastDownloadTime")]
public DateTime LastDownloadTime
{
get
{
return this._LastDownloadTime;
}
set
{
bool changed = !object.Equals(this._LastDownloadTime, value);
this._LastDownloadTime = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.LastDownloadTime));
}
}
#endregion
#region Startup Delay (Unused)
/*
private int _StartupDelay;
/// <summary>Wait for seconds before doing anything</summary>
[Category("Outlook"),
Description(@"Wait for seconds before doing anything")]
[XmlElement("startupDelay")]
public int StartupDelay
{
get
{
return this._StartupDelay;
}
set
{
bool changed = !object.Equals(this._StartupDelay, value);
this._StartupDelay = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.StartupDelay));
}
}
*/
#endregion
#region Default XSL File Name
private string _XSLFileName;
/// <summary>Default XSL transformer</summary>
[Category("Misc"),
Description(@"Default XSL transformer")]
[XmlElement("xslFile")]
[Editor(typeof(UIFileDialogEditor), typeof(UITypeEditor)),
CommonDialogFilterAttribute("XSLT File (*.xslt)|*.xslt|XSL File (*.xsl)|*.xsl")]
public string XSLFileName
{
get
{
return this._XSLFileName;
}
set
{
bool changed = !object.Equals(this._XSLFileName, value);
this._XSLFileName = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.XSLFileName));
}
}
#endregion
#region Default Download Frequency
private int _DefaultDownloadFrequency;
/// <summary>Default download frequency </summary>
[Category("Synchronization"),
Description(@"Default download frequency in minutes")]
[XmlElement("defaultDownloadFrequency")]
public int DefaultDownloadFrequency
{
get
{
return this._DefaultDownloadFrequency;
}
set
{
bool changed = !object.Equals(this._DefaultDownloadFrequency, value);
this._DefaultDownloadFrequency = value;
// Minimum delay of 1 minute is allowed
if( this._DefaultDownloadFrequency < 1 )
this._DefaultDownloadFrequency = 1;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.DefaultDownloadFrequency));
// Set the next download time
this.NextDownloadAt = this.LastDownloadAt.AddMinutes( this.DefaultDownloadFrequency );
}
}
#endregion
#region Proxy Name
private string _ProxyName = string.Empty;
/// <summary>Default Proxy Name</summary>
[Category("Proxy"),
Description(@"Default Proxy Name or IP")]
[DefaultValueAttribute("")]
[XmlElement("proxyName")]
public string ProxyName
{
get
{
return this._ProxyName;
}
set
{
bool changed = !object.Equals(this._ProxyName, value);
this._ProxyName = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.ProxyName));
// Set the next download time
//this.NextDownloadTime = this.LastDownloadTime.Add( this.DefaultDownloadFrequency );
}
}
#endregion
#region Proxy Port
private int _ProxyPort = 8080;
/// <summary>Default Proxy Port</summary>
[Category("Proxy"),
Description(@"Default Proxy Port or IP"),
DefaultValue(8080)]
[XmlElement("proxyPort")]
public int ProxyPort
{
get
{
return this._ProxyPort;
}
set
{
bool changed = !object.Equals(this._ProxyPort, value);
this._ProxyPort = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.ProxyPort));
// Set the next download time
//this.NextDownloadTime = this.LastDownloadTime.Add( this.DefaultDownloadFrequency );
}
}
#endregion
#region Proxy User Name
private string _ProxyUserName = string.Empty;
/// <summary>Proxy User Name</summary>
[Category("Proxy"),
Description(@"Proxy User Name"),
DefaultValue("")]
[XmlElement("proxyUserName")]
public string ProxyUserName
{
get
{
return this._ProxyUserName;
}
set
{
bool changed = !object.Equals(this._ProxyUserName, value);
this._ProxyUserName = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.ProxyUserName));
}
}
#endregion
#region Proxy User Password
private string _ProxyUserPassword = string.Empty;
/// <summary>Proxy User Name</summary>
[Category("Proxy"),
Description(@"Proxy User Password"),
DefaultValue("")]
[XmlElement("proxyUserPassword")]
[Editor(typeof(PasswordEditor), typeof(UITypeEditor))]
public string ProxyUserPassword
{
get
{
return this._ProxyUserPassword;
}
set
{
bool changed = !object.Equals(this._ProxyUserPassword, value);
this._ProxyUserPassword = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.ProxyUserPassword));
}
}
#endregion
#region Window State
private int _WindowState = 0;
/// <summary>Default Proxy Port</summary>
[Category("User Interface"), ReadOnly( true ),
Description(@"Window State"),
DefaultValue(0)]
[XmlElement("windowState")]
public int WindowState
{
get
{
return this._WindowState;
}
set
{
bool changed = !object.Equals(this._WindowState, value);
this._WindowState = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.WindowState));
}
}
#endregion
#region Window Bounds
private Rectangle _WindowBounds = Rectangle.Empty;
/// <summary>Window bounds</summary>
[Category("User Interface"), ReadOnly( true ),
Description(@"Window Bounds"),
DefaultValue(0)]
[XmlElement("windowBounds")]
public Rectangle WindowBounds
{
get
{
return this._WindowBounds;
}
set
{
bool changed = !object.Equals(this._WindowBounds, value);
this._WindowBounds = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.WindowBounds));
}
}
#endregion
#region Popup Window Position
public enum PopupWindowPositionEnum
{
TopLeft = 0,
TopRight = 1,
BottomRight = 2,
BottomLeft = 3
}
private PopupWindowPositionEnum _PopupWindowPosition = PopupWindowPositionEnum.BottomRight;
/// <summary>Corner of screen where popup windows are shown</summary>
[Category("User Interface"),
Description(@"Corner of screen where popup windows are shown"),
DefaultValue(PopupWindowPositionEnum.BottomRight)]
[XmlElement("popupWindowPosition")]
public PopupWindowPositionEnum PopupWindowPosition
{
get
{
return this._PopupWindowPosition;
}
set
{
bool changed = !object.Equals(this._PopupWindowPosition, value);
this._PopupWindowPosition = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.PopupWindowPosition));
}
}
#endregion
#region NoOfItemsInNewspaper
private int _NoOfItemsInNewspaper = 5; // minutes
/// <summary>How many items to show in newspaper</summary>
[Category("Preference"), DefaultValue(5), Browsable(true),
Description(@"How many items to show in newspaper")]
[XmlElement("noOfItemsInNewspaper")]
public int NoOfItemsInNewspaper
{
get
{
return this._NoOfItemsInNewspaper;
}
set
{
bool changed = !object.Equals(this._NoOfItemsInNewspaper, value);
this._NoOfItemsInNewspaper = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.NoOfItemsInNewspaper));
}
}
#endregion
#region Property: LastDownloadAt
private DateTime _LastDownloadAt = DateTime.Now;
/// <summary> When last synchronization occurred </summary>
[Category("Download")]
[Description("When last synchronization occurred")]
[XmlElement("lastDownloadAt")]
public virtual DateTime LastDownloadAt
{
get
{
return this._LastDownloadAt;
}
set
{
bool changed = !object.Equals(this._LastDownloadAt, value);
this._LastDownloadAt = value;
if(changed)
{
this.NextDownloadAt = this.LastDownloadAt.AddMinutes(this.DefaultDownloadFrequency);
OnPropertyChanged(new PropertyChangedEventArgs(Properties.LastDownloadAt));
}
}
}
#endregion
#region Property: NextDownloadAt
private DateTime _NextDownloadAt = DateTime.Now;
/// <summary> When feed synchronization should occur </summary>
[Category("Download")]
[Description("When feed synchronization should occur")]
[XmlElement("nextDownloadAt")]
public virtual DateTime NextDownloadAt
{
get
{
return this._NextDownloadAt;
}
set
{
bool changed = !object.Equals(this._NextDownloadAt, value);
this._NextDownloadAt = value;
if(changed) OnPropertyChanged(new PropertyChangedEventArgs(Properties.NextDownloadAt));
}
}
#endregion
#endregion
#region Public Methods
public void Validate()
{
// Outlook base folder must be specified if outlook synchronization is set.
if( this._SyncWithOutlook && 0 == this._OutlookBaseFolder.Length )
throw new ApplicationException("Please specify outlook base folder.");
}
#endregion
#region Private Methods
///<summary>A PropertyChanged event is raised when a property is
///changed on a component. A PropertyChangedEventArgs object
///specifies the name of the property that changed.</summary>
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
{
if( null != PropertyChanged )
{
PropertyChanged(this, e);
}
}
#endregion
#region Inner Classes
public class Properties
{
public const string NoOfItemsInNewspaper = "NoOfItemsInNewspaper";
public const string NoBaloonPopup = "NoBaloonPopup";
public const string LoadAtStartup = "LoadAtStartup";
public const string StartupLoadDelay = "StarupLoadDelay";
public const string AllowedAttributes = "AllowedAttributes";
public const string SilentMode = "SilentMode";
public const string AtomToRssXsl = "AtomToRssXsl";
public const string IsNewInstall = "IsNewInstall";
public const string ProxyUserPassword = "ProxyUserPassword";
public const string ProxyUserName = "ProxyUserName";
public const string PopupWindowPosition = "PopupWindowPosition";
public const string WindowBounds = "WindowBounds";
public const string WindowState = "WindowState";
public const string ProxyPort = "ProxyPort";
public const string ProxyName = "ProxyName";
public const string OutlookXSL = "OutlookXSL";
public const string OutlookViewXmlPath = "OutlookViewXmlPath";
public const string OutlookBaseFolder = "OutlookBaseFolder";
public const string XSLFileName = "XSLFileName";
public const string StartupDelay = "StartupDelay";
public const string DefaultDownloadFrequency = "DefaultDownloadFrequency";
public const string NextDownloadTime = "NextDownloadTime";
public const string LastDownloadTime = "LastDownloadTime";
public const string NewspaperXSL = "NewspaperXSL";
public const string SyncWithOutlook = "SyncWithOutlook";
public const string LastDownloadAt = "LastDownloadAt";
public const string NextDownloadAt = "NextDownloadAt";
}
#endregion
}
}
|