using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
namespace Breeze.BizTalk.WorkflowLibrary
{ public class FolderMonitorSection : ConfigurationSection
{ #region Static Accessors
/// <summary>
/// Gets the configuration section using the default element name.
/// </summary>
public static FolderMonitorSection GetSection()
{ return GetSection("folderMonitorConfig"); }
/// <summary>
/// Gets the configuration section using the specified element name.
/// </summary>
public static FolderMonitorSection GetSection(string sectionName)
{ FolderMonitorSection section = ConfigurationManager.GetSection(sectionName) as FolderMonitorSection;
if (section == null)
{ string message = string.Format("The specified configuration section (<{0}>) was not found.", sectionName); throw new ConfigurationErrorsException(message);
}
return section;
}
#endregion
#region Configuration Properties
[ConfigurationProperty("folderMonitors", IsDefaultCollection = true)] public FolderMonitorConfigElementCollection FolderMonitors
{ get { return (FolderMonitorConfigElementCollection)this["folderMonitors"]; } set { this["folderMonitors"] = value; } }
public override bool IsReadOnly()
{ return false;
}
#endregion
}
[ConfigurationCollection(typeof(FolderMonitorConfigElement), CollectionType = ConfigurationElementCollectionType.BasicMap)]
public class FolderMonitorConfigElementCollection : ConfigurationElementCollection
{ protected override ConfigurationElement CreateNewElement()
{ return new FolderMonitorConfigElement();
}
protected override string ElementName
{ get { return "folderMonitor"; } }
public override ConfigurationElementCollectionType CollectionType
{ get { return ConfigurationElementCollectionType.BasicMap; } }
public override bool IsReadOnly()
{ return false;
}
#region Indexers
public FolderMonitorConfigElement this[int index]
{ get { return BaseGet(index) as FolderMonitorConfigElement; } set
{ if (BaseGet(index) != null)
{ BaseRemoveAt(index);
}
BaseAdd(index, value);
}
}
public new FolderMonitorConfigElement this[string name]
{ get { return BaseGet(name) as FolderMonitorConfigElement; } }
#endregion
#region Lookup Methods
protected override object GetElementKey(ConfigurationElement element)
{ FolderMonitorConfigElement cfg = element as FolderMonitorConfigElement;
return cfg.TargetFolder;
}
public string GetKey(int index)
{ return (string)BaseGetKey(index);
}
#endregion
#region Add/Remove/Clear Methods
public void Add(FolderMonitorConfigElement item)
{ BaseAdd(item);
}
public void Remove(string name)
{ BaseRemove(name);
}
public void Remove(FolderMonitorConfigElement item)
{ BaseRemove(GetElementKey(item));
}
public void RemoveAt(int index)
{ BaseRemoveAt(index);
}
public void Clear()
{ BaseClear();
}
#endregion
}
public class FolderMonitorConfigElement : ConfigurationElement
{ #region Constructors
public FolderMonitorConfigElement()
{ }
#endregion
#region Configuration Properties
[ConfigurationProperty("targetFolder", IsRequired = true)] public string TargetFolder
{ get { return (string)this["targetFolder"]; } set { this["targetFolder"] = value; } }
[ConfigurationProperty("fileMask", IsRequired = true, DefaultValue = "*.*")] public string FileMask
{ get { return (string)this["fileMask"]; } set { this["fileMask"] = value; } }
[ConfigurationProperty("timerInterval", IsRequired = true, DefaultValue = "3")] [IntegerValidator(ExcludeRange = false, MaxValue = 1440, MinValue = 1)]
public int TimerInterval
{ get { return (int)this["timerInterval"]; } set { this["timerInterval"] = value; } }
[ConfigurationProperty("processingInterval", IsRequired = true, DefaultValue = "5")] [IntegerValidator(ExcludeRange = false, MaxValue = 1440, MinValue = 1)]
public int ProcessingInterval
{ get { return (int)this["processingInterval"]; } set { this["processingInterval"] = value; } }
[ConfigurationProperty("alert")] public AlertConfigElement AlertConfig
{ get { return (AlertConfigElement)this["alert"]; } set { this["alert"] = value; } }
public class AlertConfigElement : ConfigurationElement
{ public AlertConfigElement()
{ }
[ConfigurationProperty("alertInterval", IsRequired = true, DefaultValue = "20")] [IntegerValidator(ExcludeRange = false, MaxValue = 1440, MinValue = 1)]
public int AlertInterval
{ get { return (int)this["alertInterval"]; } set { this["alertInterval"] = value; } }
[ConfigurationProperty("sender")] public string Sender
{ get { return (string)this["sender"]; } set { this["sender"] = value; } }
[ConfigurationProperty("destination")] public string Destination
{ get { return (string)this["destination"]; } set { this["destination"] = value; } }
[ConfigurationProperty("messageType")] public string MessageType
{ get { return (string)this["messageType"]; } set { this["messageType"] = value; } }
[ConfigurationProperty("errorType")] public string ErrorType
{ get { return (string)this["errorType"]; } set { this["errorType"] = value; } }
[ConfigurationProperty("errorCode")] public string ErrorCode
{ get { return (string)this["errorCode"]; } set { this["errorCode"] = value; } }
}
#endregion
}
}