1 using System.Collections.Generic;
5 using System.Xml.Serialization;
12 public class FilePattern : INotifyPropertyChanged, IXmlSerializable
16 #region IXmlSerializable Member
17 public System.Xml.Schema.XmlSchema GetSchema()
32 Pattern = reader.ReadString();
33 if (!reader.IsEmptyElement)
35 reader.ReadEndElement();
39 reader.ReadStartElement();
49 writer.WriteString(Pattern);
54 #region INotifyPropertyChanged Member
61 private void NotifyPropertyChanged(
string PropertyName)
63 if (PropertyChanged != null)
65 PropertyChanged(
this,
new PropertyChangedEventArgs(PropertyName));
71 private string _Pattern=
"";
81 get {
return _Pattern; }
84 if (_Pattern != value)
87 NotifyPropertyChanged(
"Pattern");
100 if (ReplaceValues != null)
102 foreach (KeyValuePair<string, string> KV
in ReplaceValues)
104 P = P.Replace(
"{" + (KV.Key) +
"}", KV.Value);
118 if (Pattern.IsNullOrWhiteSpace())
return new List<FileInfo>();
120 string P = ReplacePlaceholders(ReplaceValues);
126 DirectoryInfo FilesDirectory =
new DirectoryInfo((Path.GetDirectoryName(P).IsNullOrWhiteSpace() ?
"." : Path.GetDirectoryName(P)));
128 if (FilesDirectory.Exists)
130 return FilesDirectory.GetFiles(Path.GetFileName(P)).ToList<FileInfo>();
134 return new List<FileInfo>();
139 return new List<FileInfo>();
150 List<FileInfo> L = GetMatchingFiles(ReplaceValues);
172 if (Pattern.IsNullOrWhiteSpace())
return true;
176 FileInfo DummyFileInfo =
new FileInfo(Pattern.Replace(
"*",
"test").Replace(
"?",
"X"));
183 bool BracketOpen =
false;
184 bool JustOpend =
false;
185 foreach (
char C
in Pattern)
190 if (BracketOpen)
return false;
195 if (!BracketOpen)
return false;
196 if (JustOpend)
return false;
203 if (BracketOpen)
return false;
211 if (BracketOpen)
return false;
225 this.Pattern = Pattern;
FilePattern(string Pattern)
Initializes a new instance of the FilePattern class.
string ReplacePlaceholders(Dictionary< string, string > ReplaceValues=null)
Returns the pattern with replaced placeholders.
void ReadXml(System.Xml.XmlReader reader)
Deserializes the FilePattern in the XmlReader. ReadXml is part of the IXmlSerializable interface...
FileInfo GetFirstMatchingFile(Dictionary< string, string > ReplaceValues=null)
Gets the first file matching the value of the Pattern property.
override string ToString()
Returns a System.String that represents this instance.
List< FileInfo > GetMatchingFiles(Dictionary< string, string > ReplaceValues=null)
Gets the files matching the value of the property Pattern.
void WriteXml(System.Xml.XmlWriter writer)
Serializes the FilePattern to Xml. WriteXml is part of the IXmlSerializable interface.
FilePattern()
Initializes a new instance of the FilePattern class.
PropertyChangedEventHandler PropertyChanged
Is fired if the value of a property changes.
A file pattern class used to lookup files matching a specified pattern.