Initial import
This commit is contained in:
parent
0c865416ca
commit
04804b89a9
279 changed files with 12945 additions and 0 deletions
15
SalesCatalog/XmlImplementation/XmlCatalog.cs
Normal file
15
SalesCatalog/XmlImplementation/XmlCatalog.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using SalesCatalog.Model;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SalesCatalog.XmlImplementation
|
||||
{
|
||||
[XmlRoot]
|
||||
public class XmlCatalog : Catalog
|
||||
{
|
||||
public XmlCatalog ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
55
SalesCatalog/XmlImplementation/XmlCatalogProvider.cs
Normal file
55
SalesCatalog/XmlImplementation/XmlCatalogProvider.cs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Xml.Serialization;
|
||||
using SalesCatalog.Model;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace SalesCatalog.XmlImplementation
|
||||
{
|
||||
public class XmlCatalogProvider: CatalogProvider
|
||||
{
|
||||
#region implemented abstract members of SalesCatalog.CatalogProvider
|
||||
|
||||
public override Catalog GetCatalog ()
|
||||
{
|
||||
// Assert fileName != null
|
||||
FileInfo fi = new FileInfo (fileName);
|
||||
if (fi.LastWriteTime > lastModification)
|
||||
LoadCatalog ();
|
||||
return catInstance;
|
||||
}
|
||||
|
||||
protected XmlCatalog catInstance = null;
|
||||
protected DateTime lastModification;
|
||||
protected string fileName = null;
|
||||
#endregion
|
||||
|
||||
public override void Initialize (string name, System.Collections.Specialized.NameValueCollection config)
|
||||
{
|
||||
fileName = config ["connection"];
|
||||
LoadCatalog ();
|
||||
}
|
||||
private void LoadCatalog ()
|
||||
{
|
||||
FileInfo fi = new FileInfo (fileName);
|
||||
if (!fi.Exists)
|
||||
throw new Exception (
|
||||
string.Format ("Le fichier Xml decrivant le catalogue n'existe pas ({0})", fi.FullName));
|
||||
XmlSerializer xsr = new XmlSerializer (typeof(XmlCatalog),new Type[]{
|
||||
typeof(Service),
|
||||
typeof(PhysicalProduct),
|
||||
typeof(Euro),
|
||||
typeof(Text),
|
||||
typeof(TextInput),
|
||||
typeof(SelectInput)});
|
||||
|
||||
using (FileStream fs = fi.OpenRead()) {
|
||||
catInstance = (XmlCatalog) xsr.Deserialize (fs);
|
||||
}
|
||||
fileName = fi.FullName;
|
||||
lastModification = fi.LastWriteTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue