* style.css:

* Web.csproj:
* Web.config:
* Catalog.xml:
* Global.asax.cs:
* TestBinding.cs:
* IProvider.cs:
* yavscModel.csproj:
* WFManager.cs:
* BasketController.cs:
* WorkFlowController.cs:
* ITCPNpgsqlProvider.cs:
* IContentProvider.cs:
* WorkFlowProvider.csproj:
* NpgsqlContentProvider.cs:
* Provider.cs:
* ITContentProvider.csproj:
* FrontOfficeApiController.cs:
* ProviderCollection.cs:
* WorkflowConfiguration.cs:
* BlogProvidersConfigurationSection.cs: 

* IITContent.cs: Estimate creation
This commit is contained in:
Paul Schneider
2014-09-18 13:58:43 +02:00
parent fa93ce7fee
commit bba917dcc0
21 changed files with 381 additions and 91 deletions

View File

@ -0,0 +1,40 @@
using System;
using System.Configuration;
namespace WorkFlowProvider.Configuration
{
public class WFProvider:ConfigurationElement
{
[ConfigurationProperty("name", IsKey=true, IsRequired=true)]
public string Name {
get {
return (string) base ["name"];
}
set { base ["name"] = value; }
}
[ConfigurationProperty("type")]
public string Type {
get { return (string) this ["type"]; }
set {
this ["type"] = value;
}
}
[ConfigurationProperty("applicationName")]
public string ApplicationName {
get {
return (string)this ["applicationName"];
}
set {
this ["applicationName"] = value;
}
}
[ConfigurationProperty("connectionStringName")]
public string ConnectionStringName {
get { return (string)this ["connectionStringName"]; }
set { this ["connectionStringName"] = value; }
}
}
}

View File

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

View File

@ -0,0 +1,38 @@
using System;
using System.Configuration;
namespace WorkFlowProvider.Configuration
{
public class WorkflowConfiguration : ConfigurationSection
{
/// <summary>
/// Gets or sets the default provider.
/// </summary>
/// <value>The default provider.</value>
[ConfigurationProperty("defaultProvider")]
public string DefaultProvider {
get { return (string)base ["defaultProvider"]; }
set { base ["defaultProvider"] = value; }
}
/// <summary>
/// Gets or sets the providers.
/// </summary>
/// <value>The providers.</value>
[ConfigurationProperty("providers")]
[ConfigurationCollection(typeof(WFProvider),
AddItemName = "add",
ClearItemsName = "clear",
RemoveItemName = "remove")]
public WFProviderCollection Providers {
get {
return this["providers"] as WFProviderCollection;
}
set {
this["providers"]=value;
}
}
}
}

View File

@ -5,58 +5,73 @@ using System.Configuration;
using System.Collections.Specialized;
using yavscModel.WorkFlow;
using System.Web.Mvc;
using System.Configuration.Provider;
namespace WorkFlowProvider
{
public class NpgsqlContentProvider: IContentProvider
public class NpgsqlContentProvider: ProviderBase, IContentProvider
{
public IWFOrder CreateOrder ()
public Estimate GetEstimate (long estimid)
{
throw new NotImplementedException ();
}
public IWFOrder ImapctOrder (string orderid, FormCollection col)
public void SetTitle (long estid, string newTitle)
{
throw new NotImplementedException ();
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"update estimate set title = @tit where _id = @estid";
cmd.Parameters.Add ("@tit", newTitle);
cmd.Parameters.Add ("@estid", estid);
cnx.Open ();
cmd.ExecuteNonQuery ();
cnx.Close ();
}
}
}
public bool[] IsFinalStatus {
public long Write (long estid, string desc, decimal ucost, int count, long productid)
{
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"insert into writtings (description, estimid) VALUES (@dscr,@estid) returning _id";
cmd.Parameters.Add ("@dscr", desc);
// cmd.Parameters.Add ("@prdid", productid);
// cmd.Parameters.Add("@ucost", ucost);
// cmd.Parameters.Add("@mult", count);
cmd.Parameters.Add("@estid", estid);
cnx.Open ();
long res = (long) cmd.ExecuteScalar ();
cnx.Close ();
return res;
}
}
}
public void SetDesc (long writid, string newDesc)
{
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"update writtings set description = @dscr where _id = @writid";
cmd.Parameters.Add ("@tit", newDesc);
cmd.Parameters.Add ("@writid", writid);
cnx.Open ();
cmd.ExecuteNonQuery ();
cnx.Close ();
}
}
}
public bool[] FinalStatuses {
get {
throw new NotImplementedException ();
}
}
string applicationName=null;
public string ApplicationName {
get {
return applicationName;
}
}
string cnxstr = null;
public NpgsqlContentProvider ()
{
Initialize("NpgsqlYavscContentProvider",ConfigurationManager.AppSettings);
}
public void Initialize (string name, NameValueCollection config)
{
cnxstr = ConfigurationManager.ConnectionStrings [config ["connectionStringName"]].ConnectionString;
applicationName = config["applicationName"] ?? "/";
}
protected NpgsqlConnection CreateConnection ()
{
return new NpgsqlConnection (cnxstr);
}
#region IDisposable implementation
public void Dispose ()
{
}
#endregion
public string Order (IWFOrder c)
{
throw new NotImplementedException ();
@ -78,11 +93,57 @@ namespace WorkFlowProvider
}
}
#region IITContentProvider implementation
#region IDisposable implementation
public void Dispose ()
{
}
#endregion
public long CreateEstimate (string client, string title)
{
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"insert into estimate (title,username,applicationname) " +
"values (@tit,@un,@app) returning _id";
cmd.Parameters.Add ("@tit", title);
cmd.Parameters.Add ("@un", client);
cmd.Parameters.Add("@app", ApplicationName);
cnx.Open ();
long res = (long)cmd.ExecuteScalar ();
cnx.Close ();
return res;
}
}
}
string applicationName=null;
public string ApplicationName {
get {
return applicationName;
}
set {
applicationName = value;
}
}
string cnxstr = null;
public override void Initialize (string name, NameValueCollection config)
{
if ( string.IsNullOrWhiteSpace(config ["connectionStringName"]))
throw new ConfigurationErrorsException ("No name for Npgsql connection string found");
cnxstr = ConfigurationManager.ConnectionStrings [config ["connectionStringName"]].ConnectionString;
applicationName = config["applicationName"] ?? "/";
}
protected NpgsqlConnection CreateConnection ()
{
return new NpgsqlConnection (cnxstr);
}
}
}

View File

@ -1,18 +1,73 @@
using System;
using yavscModel.WorkFlow;
using System.Configuration;
using WorkFlowProvider.Configuration;
using System.Collections.Specialized;
namespace WorkFlowProvider
{
public static class WFManager
{
public static IContentProvider GetContentProviderFWC ()
{
string clsName = System.Configuration.ConfigurationManager.AppSettings ["WorkflowContentProviderClass"];
if (clsName == null)
throw new Exception ("No content provider specified in the configuration file (Application parameter \"WorkflowContentProviderClass\")");
System.Reflection.ConstructorInfo ci = Type.GetType (clsName).GetConstructor (System.Type.EmptyTypes);
return (IContentProvider) ci.Invoke (System.Type.EmptyTypes);
static IContentProvider contentProvider;
public static IContentProvider ContentProvider {
get {
WorkflowConfiguration c = (WorkflowConfiguration) ConfigurationManager.GetSection ("system.web/workflow");
if (c == null)
throw new Exception ("No system.web/workflow configuration section found");
WFProvider confprov = c.Providers.GetElement (c.DefaultProvider);
if (confprov == null)
throw new Exception ("Default workflow provider not found (system.web/workflow@defaultProvider)");
string clsName = confprov.Type;
if (clsName == null)
throw new Exception ("Provider type not specified (system.web/workflow@type)");
if (contentProvider != null)
{
if (contentProvider.GetType ().Name != clsName)
contentProvider = null;
}
if (contentProvider == null)
{
Type cpt = Type.GetType (clsName);
if (cpt == null)
throw new Exception (string.Format("Type not found : {0} (wrong name, or missing assembly reference?)",clsName));
System.Reflection.ConstructorInfo ci =cpt.GetConstructor (System.Type.EmptyTypes);
contentProvider = (IContentProvider)ci.Invoke (System.Type.EmptyTypes);
}
contentProvider.ApplicationName = confprov.ApplicationName;
NameValueCollection config = new NameValueCollection ();
config.Add ("name", confprov.Name);
config.Add ("connectionStringName", confprov.ConnectionStringName);
config.Add ("applicationName", confprov.ApplicationName);
contentProvider.Initialize (confprov.Name, config);
return contentProvider;
}
}
/// <summary>
/// Creates the estimate.
/// </summary>
/// <returns>The estimate identifier.</returns>
/// <param name="title">Title.</param>
public static long CreateEstimate(string client, string title)
{
return ContentProvider.CreateEstimate (client, title);
}
public static long Write(long estid, string desc, decimal ucost, int count, long productid)
{
return ContentProvider.Write(estid, desc, ucost, count, productid);
}
}
}

View File

@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.0</ProductVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{821FF72D-9F4B-4A2C-B95C-7B965291F119}</ProjectGuid>
<OutputType>Library</OutputType>
@ -33,14 +33,15 @@
<Reference Include="Npgsql" />
<Reference Include="System.Configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Private>False</Private>
</Reference>
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="NpgsqlContentProvider.cs" />
<Compile Include="WFManager.cs" />
<Compile Include="Configuration\WorkflowConfiguration.cs" />
<Compile Include="Configuration\ProviderCollection.cs" />
<Compile Include="Configuration\Provider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@ -49,4 +50,7 @@
<Name>yavscModel</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration\" />
</ItemGroup>
</Project>