Initial import

This commit is contained in:
Paul Schneider 2014-07-16 20:35:03 +02:00
commit 04804b89a9
279 changed files with 12945 additions and 0 deletions

View file

@ -0,0 +1,27 @@
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("SalesCatalog")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("paul")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View file

@ -0,0 +1,45 @@
using System;
using System.Configuration;
using System.Reflection;
using System.Collections.Specialized;
using SalesCatalog.Configuration;
namespace SalesCatalog
{
/// <summary>
/// Catalog helper.
/// Used by the catalog manager to get the catalog provider from the configuration.
/// </summary>
public static class CatalogHelper
{
public static CatalogProvider GetProvider ()
{
CatalogProvidersConfigurationSection config = ConfigurationManager.GetSection ("system.web/catalog") as CatalogProvidersConfigurationSection;
if (config == null)
throw new ConfigurationErrorsException("The configuration bloc for the catalog provider was not found");
CatalogProviderConfigurationElement celt =
config.Providers.GetElement (config.DefaultProvider);
if (celt == null)
throw new ConfigurationErrorsException("The default catalog provider was not found");
Type catprtype = Type.GetType (celt.Type);
if (catprtype == null)
throw new Exception (
string.Format("The catalog provider type ({0}) could not be found",celt.Type));
ConstructorInfo ci = catprtype.GetConstructor (Type.EmptyTypes);
if (ci==null)
throw new Exception (
string.Format("The catalog provider type ({0}) doesn't contain public constructor with empty parameter list",celt.Type));
CatalogProvider cp = ci.Invoke (Type.EmptyTypes) as CatalogProvider;
NameValueCollection c = new NameValueCollection ();
c.Add ("name", celt.Name);
c.Add ("type", celt.Type);
c.Add ("connection", celt.Connection);
c.Add ("description", celt.Description);
c.Add ("applicationName", celt.ApplicationName);
cp.Initialize (celt.Name, c);
return cp;
}
}
}

View file

@ -0,0 +1,19 @@
using System;
using SalesCatalog.Model;
namespace SalesCatalog
{
/// <summary>
/// Catalog manager.
/// Use this class to retreive the catalog or its elements
/// </summary>
public static class CatalogManager
{
public static Catalog GetCatalog ()
{
CatalogProvider p = CatalogHelper.GetProvider ();
return p.GetCatalog ();
}
}
}

View file

@ -0,0 +1,16 @@
using System;
using System.Configuration.Provider;
using SalesCatalog.Model;
namespace SalesCatalog
{
/// <summary>
/// Catalog provider.<br/>
/// Abstract class, inherited to implement a catalog provider.
/// </summary>
public abstract class CatalogProvider: ProviderBase
{
public abstract Catalog GetCatalog ();
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Configuration;
namespace SalesCatalog.Configuration
{
public class CatalogProviderConfigurationElement : ConfigurationElement
{
[ConfigurationProperty("name", IsRequired = true, IsKey=true)]
public string Name {
get { return (string)this ["name"]; }
set { this ["name"] = value; }
}
[ConfigurationProperty("type", IsRequired = true)]
public string Type {
get { return (string)this ["type"]; }
set { this ["type"] = value; }
}
[ConfigurationProperty("connection")]
public string Connection {
get { return (string)this ["connection"]; }
set { this ["connection"] = value; }
}
[ConfigurationProperty("description")]
public string Description {
get { return (string)this ["description"]; }
set { this ["description"] = value; }
}
[ConfigurationProperty("applicationName")]
public string ApplicationName {
get { return (string)this ["applicationName"]; }
set { this ["applicationName"] = value; }
}
}
}

View file

@ -0,0 +1,26 @@
using System;
using System.Configuration;
using System.ComponentModel;
namespace SalesCatalog.Configuration
{
public class CatalogProvidersConfigurationCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement ()
{
return new CatalogProviderConfigurationElement();
}
protected override object GetElementKey (ConfigurationElement element)
{
return ((CatalogProviderConfigurationElement) element).Name;
}
public CatalogProviderConfigurationElement GetElement (string name)
{
return this.BaseGet(name) as CatalogProviderConfigurationElement;
}
}
}

View file

@ -0,0 +1,26 @@
using System;
using System.Configuration;
using System.ComponentModel;
namespace SalesCatalog.Configuration
{
public class CatalogProvidersConfigurationSection : ConfigurationSection
{
[ConfigurationProperty("defaultProvider")]
public string DefaultProvider {
get { return (string)base ["defaultProvider"]; }
set { base ["defaultProvider"] = value; }
}
[ConfigurationProperty("providers")]
[ConfigurationCollection(typeof(CatalogProvidersConfigurationCollection),
AddItemName = "add",
ClearItemsName = "clear",
RemoveItemName = "remove")]
public CatalogProvidersConfigurationCollection Providers{
get { return (CatalogProvidersConfigurationCollection) base ["providers"]; }
set { base ["providers"] = value; }
}
}
}

View file

@ -0,0 +1,37 @@
using System;
using System.Xml.Serialization;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
public class Brand
{
public Brand ()
{
}
[Required]
public string Name { get; set; }
public string Slogan { get; set; }
public ProductImage Logo { get; set; }
public ProductCategory[] Categories { get; set; }
/// <summary>
/// Gets or sets the default form.
/// </summary>
/// <value>The default form.</value>
public SaleForm DefaultForm { get; set; }
public ProductCategory GetProductCategory(string reference)
{
return Array.Find<ProductCategory>(Categories, c => c.Reference == reference);
}
public ProductCategory GetProductCategoryByName(string catName)
{
return Array.Find<ProductCategory>(Categories, c => c.Name == catName);
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
namespace SalesCatalog.Model
{
/// <summary>
/// Catalog.
/// </summary>
public class Catalog {
/// <summary>
/// Gets or sets the brands.
/// </summary>
/// <value>The brands.</value>
public Brand[] Brands { get; set; }
public Brand GetBrand(string brandName)
{
return Array.Find<Brand>(Brands, b => b.Name == brandName);
}
public Brand AddBrand(string brandName,string slogan=null, ProductImage logo=null)
{
Brand[] oldbrs = (Brand[]) Brands.Clone ();
int oldl = Brands.Length;
Array.Resize<Brand>(ref oldbrs,oldl+1);
Brand b = new Brand ();
b.Name=brandName;
b.Slogan = slogan;
b.Logo = logo;
oldbrs [oldl] = b;
Brands=oldbrs;
return b;
}
public bool RemoveBrand(string brandName)
{
Brand b = this.GetBrand (brandName);
if (b == null)
return false;
//assert(Brands.Length>0);
List<Brand> nb = new List<Brand> (Brands);
nb.Remove (b);
Brands = nb.ToArray ();
return true;
}
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class CheckBox : FormInput
{
public CheckBox ()
{
}
public bool Value { get; set; }
public override string ToHtml ()
{
return string.Format ("<input type=\"checkbox\" id=\"{0}\" name=\"{1}\" {2}/>", Id,Name,Value?"checked":"");
}
}
}

View file

@ -0,0 +1,9 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Currency: Unit
{
}
}

View file

@ -0,0 +1,34 @@
using System;
namespace SalesCatalog.Model
{
public class Euro : Currency
{
public Euro ()
{
}
public override string Name {
get {
return "Euro";
}
}
public override string Description {
get {
return "European currency";
}
}
public override bool MayConvertTo (Unit other)
{
return other.GetType().IsSubclassOf(typeof (Currency));
}
public override object ConvertTo (Unit dest, object value)
{
throw new NotImplementedException();
}
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class FilesInput : FormInput
{
public FilesInput ()
{
}
public override string ToHtml ()
{
return string.Format ("<input type=\"file\" id=\"{0}\" name=\"{0}\"/>", Id);
}
}
}

View file

@ -0,0 +1,10 @@
using System;
namespace SalesCatalog.Model
{
public abstract class FormElement
{
public abstract string ToHtml ();
}
}

View file

@ -0,0 +1,19 @@
using System;
namespace SalesCatalog.Model
{
public abstract class FormInput: FormElement
{
/// <summary>
/// Gets or sets the identifier, unique in its Form.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public string Id { get; set; }
private string name=null;
public string Name { get { return name == null ? Id : name; } set { name = value; } }
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class Label:FormElement
{
public Label ()
{
}
string Text { get; set; }
string For { get; set ; }
public override string ToHtml ()
{
return string.Format ("<label for=\"{0}\">{1}</label>", For, Text);
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
public class Link:Label
{
public Link ()
{
}
[Required]
public string Ref { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace SalesCatalog.Model
{
public class Note:Text
{
public override string ToHtml ()
{
return string.Format("<quote>{0}</quote>",Val);
}
}
}

View file

@ -0,0 +1,19 @@
using System;
namespace SalesCatalog.Model
{
public class Option : FormElement
{
public Option ()
{
}
public string Value { get; set; }
public string Text { get; set; }
public override string ToHtml ()
{
return string.Format ("<option value=\"{0}\">{1}</option>\n",Value,Text);
}
}
}

View file

@ -0,0 +1,15 @@
using System;
namespace SalesCatalog.Model
{
public class Period
{
public Period ()
{
}
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
}

View file

@ -0,0 +1,27 @@
using System;
namespace SalesCatalog.Model
{
public class PhysicalProduct : Product
{
public PhysicalProduct ()
{
}
public Price UnitaryPrice { get; set; }
#region implemented abstract members of SalesCatalog.Model.Product
public override string[] GetSalesConditions ()
{
return new string [] { string.Format(
"Prix unitaire : {0} {1}",
UnitaryPrice.Quantity.ToString(),
UnitaryPrice.Unit.Name) };
}
#endregion
public override string ToString ()
{
return string.Format ("[PhysicalProduct: UnitaryPrice={0}]", UnitaryPrice);
}
}
}

View file

@ -0,0 +1,36 @@
using System;
namespace SalesCatalog.Model
{
public class Price: Scalar
{
public Price ()
{
}
decimal quantity;
#region implemented abstract members of SalesCatalog.Value
public override object Quantity {
get {
return quantity;
}
set {
quantity = (decimal) value;
}
}
Currency curr;
public override SalesCatalog.Model.Unit Unit {
get {
return curr;
}
set {
curr = (Currency)value;
}
}
#endregion
}
}

View file

@ -0,0 +1,37 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
/// <summary>
/// Product.
/// Crucial object in the catalog,
/// being at each origin of form display
/// its properties may be used to fill some form input values or other form element.
/// <c>in text values, within {} ex: {Name} : {Price} ({stockStatus}) ($description) </c>.
/// </summary>
public abstract class Product
{
/// <summary>
/// Gets or sets the product name.
/// </summary>
/// <value>The name.</value>
[Required]
[StringLength(1024)]
public string Name { get; set; }
/// <summary>
/// Gets or sets the product description.
/// </summary>
/// <value>The description.</value>
public string Description { get; set; }
public ProductImage[] Images { get; set; }
public SaleForm CommandForm { get; set; }
[Required]
[StringLength(255)]
public string Reference { get; set; }
public Period CommandValidityDates { get; set; }
public abstract string[] GetSalesConditions();
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class ProductCategory
{
public ProductCategory ()
{
}
public string Name { get; set; }
public string Reference { get; set; }
public Product[] Products { get; set; }
public Product GetProductByName (string productName)
{
return Array.Find<Product> (Products, p => p.Name == productName);
}
public Product GetProduct (string reference)
{
return Array.Find<Product> (Products, p => p.Reference == reference);
}
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class ProductImage: FormElement
{
#region implemented abstract members of FormElement
public override string ToHtml ()
{
return string.Format ("<img src=\"\" alt=\"\"/>", Src, Alt);
}
#endregion
public ProductImage ()
{
}
public string Src { get; set; }
public string Alt { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using System;
namespace SalesCatalog.Model
{
public class RadioButton:FormInput
{
public RadioButton ()
{
}
public string Choice { get; set; }
public override string ToHtml ()
{
return string.Format ("<input type=\"radio\" id=\"{0}\" name=\"{1}\" value=\"{2}\"/><label for=\"{0}\">{2}</label>", Id,Name,Choice);
}
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace SalesCatalog.Model
{
public class SaleForm
{
public SaleForm ()
{
}
public string Action {
get;
set;
}
public FormElement[] Items { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Scalar
{
public Scalar ()
{
}
public abstract object Quantity { get; set; }
public abstract Unit Unit{ get; set; }
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Text;
using System.Web.Mvc;
namespace SalesCatalog.Model
{
public class SelectInput: FormInput
{
public Option[] Items;
public int SelectedIndex;
public override string ToHtml ()
{
StringBuilder sb = new StringBuilder ();
foreach (Option opt in Items)
sb.Append (opt.ToHtml());
return string.Format ("<select id=\"{0}\" name=\"{1}\">{2}</select>\n", Id,Name,sb.ToString());
}
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class SelectItem
{
public SelectItem(string t)
{
Value = t;
}
public string Value { get; set; }
public static implicit operator string(SelectItem t)
{
return t.Value;
}
public static implicit operator SelectItem(string t)
{
return new SelectItem(t);
}
}
}

View file

@ -0,0 +1,28 @@
using System;
namespace SalesCatalog.Model
{
public class Service : Product
{
public Service ()
{
}
public Price HourPrice { get; set; }
#region implemented abstract members of SalesCatalog.Model.Product
public override string [] GetSalesConditions ()
{
return new string [] { string.Format(
"Prix horaire de la prestation : {0} {1}",
HourPrice.Quantity.ToString(),
HourPrice.Unit.Name) } ;
}
#endregion
public override string ToString ()
{
return string.Format ("[Service: HourPrice={0}]", HourPrice);
}
}
}

View file

@ -0,0 +1,11 @@
using System;
namespace SalesCatalog.Model
{
public enum StockStatus
{
NoStock,
InStock
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class Text: FormElement
{
public string Val {
get;
set;
}
public override string ToHtml ()
{
return Val;
}
}
}

View file

@ -0,0 +1,46 @@
using System;
namespace SalesCatalog.Model
{
public class TextInput:FormInput
{
public TextInput ()
{
}
public TextInput (string txt)
{
text = txt;
}
string text = null;
public static implicit operator string(TextInput t)
{
return t.text;
}
public static implicit operator TextInput(string t)
{
return new TextInput(t);
}
public string DefaultValue {
get {
return text;
}
set {
text = (string) value;
}
}
private bool multiline = false;
public bool MultiLine { get { return multiline; } set { multiline = value; } }
public override string ToHtml ()
{
return MultiLine?
string.Format ("<textarea id=\"{0}\" name=\"{1}\">{2}</textarea>", Id,Name,DefaultValue)
: string.Format ("<input type=\"text\" id=\"{0}\" name=\"{1}\" value=\"{2}\"/>", Id,Name,DefaultValue);
}
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Unit
{
public abstract string Name { get; }
public abstract string Description { get; }
public abstract object ConvertTo (Unit dest, object value);
public abstract bool MayConvertTo (Unit other);
}
}

View file

@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{90BF2234-7252-4CD5-B2A4-17501B19279B}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>SalesCatalog</RootNamespace>
<AssemblyName>SalesCatalog</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Private>False</Private>
</Reference>
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Configuration\CatalogProviderConfigurationElement.cs" />
<Compile Include="Configuration\CatalogProvidersConfigurationSection.cs" />
<Compile Include="Configuration\CatalogProvidersConfigurationCollection.cs" />
<Compile Include="CatalogManager.cs" />
<Compile Include="Model\CheckBox.cs" />
<Compile Include="Model\Currency.cs" />
<Compile Include="Model\Euro.cs" />
<Compile Include="Model\FilesInput.cs" />
<Compile Include="Model\FormElement.cs" />
<Compile Include="Model\FormInput.cs" />
<Compile Include="Model\Label.cs" />
<Compile Include="Model\Link.cs" />
<Compile Include="Model\Price.cs" />
<Compile Include="Model\ProductCategory.cs" />
<Compile Include="Model\RadioButton.cs" />
<Compile Include="Model\SelectInput.cs" />
<Compile Include="Model\TextInput.cs" />
<Compile Include="Model\Unit.cs" />
<Compile Include="Model\Brand.cs" />
<Compile Include="CatalogProvider.cs" />
<Compile Include="XmlImplementation\XmlCatalog.cs" />
<Compile Include="CatalogHelper.cs" />
<Compile Include="Tests\TestCatalogInit.cs" />
<Compile Include="Model\Product.cs" />
<Compile Include="Model\Period.cs" />
<Compile Include="Model\Service.cs" />
<Compile Include="Model\PhysicalProduct.cs" />
<Compile Include="Model\Catalog.cs" />
<Compile Include="XmlImplementation\XmlCatalogProvider.cs" />
<Compile Include="Model\Text.cs" />
<Compile Include="Model\SelectItem.cs" />
<Compile Include="Model\StockStatus.cs" />
<Compile Include="Model\Scalar.cs" />
<Compile Include="Tests\TestBrands.cs" />
<Compile Include="Model\SaleForm.cs" />
<Compile Include="Model\ProductImage.cs" />
<Compile Include="Model\Option.cs" />
<Compile Include="Model\Note.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedFlat" ResourceNamePolicy="FileFormatDefault" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
<ItemGroup>
<None Include="catalog.xsd" />
</ItemGroup>
<ItemGroup>
<Folder Include="Model\" />
<Folder Include="XmlImplementation\" />
<Folder Include="Tests\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,31 @@
using NUnit.Framework;
using System;
using SalesCatalog.Model;
namespace SalesCatalog.Tests
{
[TestFixture ()]
public class TestBrands
{
[Test ()]
public void TestCaseAddRemoveBrand ()
{
Catalog c = new Catalog ();
c.Brands = new Brand[0];
Brand b=c.AddBrand ("coko");
if (c.Brands.Length != 1)
throw new Exception ("Pas ajouté");
if (b == null)
throw new Exception ("Renvoyé null");
if (b.Name != "coko")
throw new Exception ("Pas le bon nom");
if (c.Brands [0] != b)
throw new Exception ("err index 0");
if (c.GetBrand ("coko") != b)
throw new Exception ("err get by name");
if (!c.RemoveBrand ("coko"))
throw new Exception ("Pas supprimé");
}
}
}

View file

@ -0,0 +1,106 @@
using System;
using NUnit.Framework;
using SalesCatalog.XmlImplementation;
using SalesCatalog.Model;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;
namespace SalesCatalog.Tests
{
[TestFixture()]
public class TestCatalogInit
{
[Test()]
public void TestSerDeserCat ()
{
Catalog cat = new XmlCatalog ();
Brand b = new Brand ();
b.Logo = new ProductImage ();
b.Logo.Src = "/images/dev.png";
b.Logo.Alt = "Dev";
b.Name = "Developpement à la carte";
b.Slogan = "Votre logiciel, efficace, sûr, et sur mesure";
ProductCategory si = new ProductCategory ();
si.Name = "Systèmes d'information et sites Web";
ProductCategory progiciel = new ProductCategory ();
progiciel.Name = "Progiciels";
b.Categories = new ProductCategory[]{ si, progiciel };
Service simaint = new Service ();
simaint.Name = "Maintenance logicielle";
simaint.Description = "Correction des bugs, évolution";
Service sidev = new Service ();
sidev.Name = "Développement logiciel";
sidev.Description = "Votre intranet, votre site Web, sur mesure, " +
"développé en cycles courts, et en étroite collaboration avec vous";
Service aubb = new Service ();
aubb.Name = "Audit de sécurité en black box";
aubb.Description = "Je recherche les failles de sécurité de votre SI ou site Web, depuis l'exterieur de " +
"votre système, sans avoir eu connaissance d'aucun élément sur l'architécture de votre " +
"système";
Service auwb = new Service ();
auwb.Name = "Audit de sécurité en white box";
auwb.Description = "Je me déplace chez vous, pour travailler à partir de votre code source, " +
"et isoler ses failles de sécurités";
si.Products = new Product[] { simaint, sidev, aubb, auwb };
Service maint = new Service ();
maint.Name = "Maintenance logicielle";
maint.Description = "Correction des bugs, évolution";
Service dev = new Service ();
dev.Name = "Développement logiciel";
dev.Description = "Votre progiciel, sur mesure, " +
"développé en cycles courts, et en étroite collaboration avec vous";
progiciel.Products = new Product[] { maint, dev };
SaleForm f = new SaleForm ();
f.Action = "/testAction";
TextInput ticat = new TextInput ("Choose a Title");
ticat.Id = "title" ;
ticat.MultiLine = true;
SelectInput selSize = new SelectInput ();
selSize.Id="size";
Option o1 = new Option ();
o1.Value = "1m"; o1.Text = "1 mois";
Option o2 = new Option ();
o2.Value = "2m"; o2.Text = "2 mois";
Option o3 = new Option ();
o3.Value = "6m"; o3.Text = "6 mois";
selSize.Items = new Option [] { o1, o2, o3 };
var txt1 = new SalesCatalog.Model.Text ();
var txt2 = new SalesCatalog.Model.Text ();
txt1.Val="Choose a title : ";
txt2.Val = "[br]Choose the size : ";
f.Items = new FormElement[] {txt1,ticat,txt2,selSize};
b.DefaultForm = f;
cat.Brands = new Brand[] { b };
b.Categories = new ProductCategory[] { si, progiciel };
XmlSerializer ser =
new XmlSerializer
(typeof(XmlCatalog),
new Type[]{typeof(Service),
typeof(PhysicalProduct),
typeof(Euro),
typeof(TextInput),
typeof(SalesCatalog.Model.Text),
typeof(TextInput),
typeof(SelectInput)
});
FileInfo fi = new FileInfo ("Catalog.xml");
if (fi.Exists)
fi.Delete ();
using (FileStream ws = fi.OpenWrite()) {
ser.Serialize (ws, cat);
}
using (FileStream rs = fi.OpenRead()) {
using (XmlTextReader rdr = new XmlTextReader(rs)) {
XmlCatalog copy = (XmlCatalog)ser.Deserialize (rdr);
if (copy.Brands == null) throw new Exception("Null brand array!");
if (copy.Brands.Length != cat.Brands.Length) throw new Exception("Not the same count of brands");
if (copy.Brands[0].DefaultForm.Action != cat.Brands[0].DefaultForm.Action) throw new Exception("not the same default form");
// ...
}
}
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using SalesCatalog.Model;
using System.Xml.Serialization;
namespace SalesCatalog.XmlImplementation
{
[XmlRoot]
public class XmlCatalog : Catalog
{
public XmlCatalog ()
{
}
}
}

View 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;
}
}
}

151
SalesCatalog/catalog.xsd Normal file
View file

@ -0,0 +1,151 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Catalog" nillable="true" type="Catalog" />
<xs:complexType name="Catalog">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Brands" type="ArrayOfBrand" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfBrand">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Brand" nillable="true" type="Brand" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Brand">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Slogan" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Url" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Categories" type="ArrayOfProductCategory" />
<xs:element minOccurs="0" maxOccurs="1" name="DefaultForm" type="ArrayOfFormElement" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfProductCategory">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="ProductCategory" nillable="true" type="ProductCategory" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ProductCategory">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Products" type="ArrayOfProduct" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="ArrayOfProduct">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Product" nillable="true" type="Product" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="Product" />
<xs:complexType name="ArrayOfFormElement">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="FormElement" nillable="true" type="FormElement" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="FormElement" />
<xs:element name="Brand" nillable="true" type="Brand" />
<xs:element name="Product" nillable="true" type="Product" />
<xs:element name="Currency" nillable="true" type="Currency" />
<xs:complexType name="Currency">
<xs:complexContent mixed="false">
<xs:extension base="Unit" />
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Unit" />
<xs:element name="ArrayOfFormElement" nillable="true" type="ArrayOfFormElement" />
<xs:element name="FormInput" nillable="true" type="FormInput" />
<xs:complexType name="FormInput">
<xs:complexContent mixed="false">
<xs:extension base="FormElement">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Value" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="TextInput" nillable="true" type="TextInput" />
<xs:complexType name="TextInput">
<xs:complexContent mixed="false">
<xs:extension base="FormElement" />
</xs:complexContent>
</xs:complexType>
<xs:element name="SelectInput" nillable="true" type="SelectInput" />
<xs:complexType name="SelectInput">
<xs:complexContent mixed="false">
<xs:extension base="FormElement" />
</xs:complexContent>
</xs:complexType>
<xs:element name="Label" nillable="true" type="Label" />
<xs:complexType name="Label">
<xs:complexContent mixed="false">
<xs:extension base="FormElement" />
</xs:complexContent>
</xs:complexType>
<xs:element name="Comment" nillable="true" type="Comment" />
<xs:complexType name="Comment">
<xs:complexContent mixed="false">
<xs:extension base="FormElement" />
</xs:complexContent>
</xs:complexType>
<xs:element name="CheckBox" nillable="true" type="CheckBox" />
<xs:complexType name="CheckBox">
<xs:complexContent mixed="false">
<xs:extension base="FormInput" />
</xs:complexContent>
</xs:complexType>
<xs:element name="RadioButton" nillable="true" type="RadioButton" />
<xs:complexType name="RadioButton">
<xs:complexContent mixed="false">
<xs:extension base="FormInput">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Choice" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="Link" nillable="true" type="Link" />
<xs:complexType name="Link">
<xs:complexContent mixed="false">
<xs:extension base="FormElement" />
</xs:complexContent>
</xs:complexType>
<xs:element name="FilesInput" nillable="true" type="FilesInput" />
<xs:complexType name="FilesInput">
<xs:complexContent mixed="false">
<xs:extension base="FormInput" />
</xs:complexContent>
</xs:complexType>
<xs:element name="FormElement" nillable="true" type="FormElement" />
<xs:element name="Unit" nillable="true" type="Unit" />
<xs:element name="Value" nillable="true" type="Value" />
<xs:complexType name="Value">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Quantity" />
<xs:element minOccurs="0" maxOccurs="1" name="Unit" type="Unit" />
</xs:sequence>
</xs:complexType>
<xs:element name="Image" nillable="true" type="Image" />
<xs:complexType name="Image">
<xs:complexContent mixed="false">
<xs:extension base="FormElement">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="Src" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Alt" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="ProductCategory" nillable="true" type="ProductCategory" />
<xs:element name="Price" nillable="true" type="Price" />
<xs:complexType name="Price">
<xs:complexContent mixed="false">
<xs:extension base="Value" />
</xs:complexContent>
</xs:complexType>
<xs:element name="Euro" nillable="true" type="Euro" />
<xs:complexType name="Euro">
<xs:complexContent mixed="false">
<xs:extension base="Currency" />
</xs:complexContent>
</xs:complexType>
</xs:schema>