From bba917dcc0cafd41605062bd617999d99aec76f1 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 18 Sep 2014 13:58:43 +0200 Subject: [PATCH] * 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 --- ITContent/IITContent.cs | 11 +- ITContentProvider/ITCPNpgsqlProvider.cs | 15 +- ITContentProvider/ITContentProvider.csproj | 3 +- .../BlogProvidersConfigurationSection.cs | 18 ++- WorkFlowProvider/Configuration/Provider.cs | 40 +++++ .../Configuration/ProviderCollection.cs | 22 +++ .../Configuration/WorkflowConfiguration.cs | 38 +++++ WorkFlowProvider/NpgsqlContentProvider.cs | 141 +++++++++++++----- WorkFlowProvider/WFManager.cs | 69 ++++++++- WorkFlowProvider/WorkFlowProvider.csproj | 12 +- web/Catalog.xml | 6 +- web/Controllers/BasketController.cs | 8 +- web/Controllers/FrontOfficeApiController.cs | 22 ++- web/Controllers/WorkFlowController.cs | 10 ++ web/Global.asax.cs | 4 +- web/Web.config | 8 +- web/Web.csproj | 8 + web/style.css | 4 +- yavscModel/IProvider.cs | 12 ++ yavscModel/WorkFlow/IContentProvider.cs | 14 +- yavscModel/yavscModel.csproj | 7 +- 21 files changed, 381 insertions(+), 91 deletions(-) create mode 100644 WorkFlowProvider/Configuration/Provider.cs create mode 100644 WorkFlowProvider/Configuration/ProviderCollection.cs create mode 100644 WorkFlowProvider/Configuration/WorkflowConfiguration.cs create mode 100644 yavscModel/IProvider.cs diff --git a/ITContent/IITContent.cs b/ITContent/IITContent.cs index eeaab5d2..ccf5999f 100644 --- a/ITContent/IITContent.cs +++ b/ITContent/IITContent.cs @@ -6,16 +6,7 @@ namespace ITContent { public interface IITContent: IContentProvider { - int NewProject(string name, string desc, string ownedId); - void AddDevRessource (int prjId, string userName); - int NewTask(int projectId, string name, string desc); - void SetProjectName(int projectId, string name); - void SetProjectDesc(int projectId, string desc); - void SetTaskName(int taskId, string name); - void SetStartDate(int taskId, DateTime d); - void SetEndDate(int taskId, DateTime d); - void SetTaskDesc(int taskId, string desc); - void NewRelease(int projectId, string Version); + } } diff --git a/ITContentProvider/ITCPNpgsqlProvider.cs b/ITContentProvider/ITCPNpgsqlProvider.cs index 5278b218..5f221fe6 100644 --- a/ITContentProvider/ITCPNpgsqlProvider.cs +++ b/ITContentProvider/ITCPNpgsqlProvider.cs @@ -4,8 +4,21 @@ using Npgsql; namespace ITContentProvider { - public class ITCPNpgsqlProvider :NpgsqlContentProvider + public class ITCPNpgsqlProvider : NpgsqlContentProvider { + /* TODO + + int NewProject(string name, string desc, string ownedId); + void AddDevRessource (int prjId, string userName); + int NewTask(int projectId, string name, string desc); + void SetProjectName(int projectId, string name); + void SetProjectDesc(int projectId, string desc); + void SetTaskName(int taskId, string name); + void SetStartDate(int taskId, DateTime d); + void SetEndDate(int taskId, DateTime d); + void SetTaskDesc(int taskId, string desc); + void NewRelease(int projectId, string Version); + */ public ITCPNpgsqlProvider () { } diff --git a/ITContentProvider/ITContentProvider.csproj b/ITContentProvider/ITContentProvider.csproj index 187c7b5d..6a2608b8 100644 --- a/ITContentProvider/ITContentProvider.csproj +++ b/ITContentProvider/ITContentProvider.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 10.0.0 + 8.0.30703 2.0 {9D7D892E-9B77-4713-892D-C26E1E944119} Library @@ -32,6 +32,7 @@ + diff --git a/NpgsqlBlogProvider/Configuration/BlogProvidersConfigurationSection.cs b/NpgsqlBlogProvider/Configuration/BlogProvidersConfigurationSection.cs index 96800d86..e9f1a6bc 100644 --- a/NpgsqlBlogProvider/Configuration/BlogProvidersConfigurationSection.cs +++ b/NpgsqlBlogProvider/Configuration/BlogProvidersConfigurationSection.cs @@ -6,20 +6,30 @@ namespace Npgsql.Web.Blog.Configuration { public class BlogProvidersConfigurationSection : ConfigurationSection { + /// + /// Gets or sets the default provider. + /// + /// The default provider. [ConfigurationProperty("defaultProvider")] public string DefaultProvider { - get { return (string)base ["defaultProvider"]; } - set { base ["defaultProvider"] = value; } + get { return (string) this ["defaultProvider"]; } + set { this["defaultProvider"] = value; } } + + [ConfigurationProperty("providers")] [ConfigurationCollection(typeof(BlogProvidersConfigurationCollection), AddItemName = "add", ClearItemsName = "clear", RemoveItemName = "remove")] + /// + /// Gets or sets the providers. + /// + /// The providers. public BlogProvidersConfigurationCollection Providers{ - get { return (BlogProvidersConfigurationCollection) base ["providers"]; } - set { base ["providers"] = value; } + get { return (BlogProvidersConfigurationCollection) this["providers"]; } + set { this["providers"] = value; } } } diff --git a/WorkFlowProvider/Configuration/Provider.cs b/WorkFlowProvider/Configuration/Provider.cs new file mode 100644 index 00000000..737daffb --- /dev/null +++ b/WorkFlowProvider/Configuration/Provider.cs @@ -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; } + } + } +} + diff --git a/WorkFlowProvider/Configuration/ProviderCollection.cs b/WorkFlowProvider/Configuration/ProviderCollection.cs new file mode 100644 index 00000000..acfc38b8 --- /dev/null +++ b/WorkFlowProvider/Configuration/ProviderCollection.cs @@ -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; + } + } +} + diff --git a/WorkFlowProvider/Configuration/WorkflowConfiguration.cs b/WorkFlowProvider/Configuration/WorkflowConfiguration.cs new file mode 100644 index 00000000..ecbc10e1 --- /dev/null +++ b/WorkFlowProvider/Configuration/WorkflowConfiguration.cs @@ -0,0 +1,38 @@ +using System; +using System.Configuration; + +namespace WorkFlowProvider.Configuration +{ + public class WorkflowConfiguration : ConfigurationSection + { + /// + /// Gets or sets the default provider. + /// + /// The default provider. + [ConfigurationProperty("defaultProvider")] + public string DefaultProvider { + get { return (string)base ["defaultProvider"]; } + set { base ["defaultProvider"] = value; } + } + + /// + /// Gets or sets the providers. + /// + /// The providers. + [ConfigurationProperty("providers")] + [ConfigurationCollection(typeof(WFProvider), + AddItemName = "add", + ClearItemsName = "clear", + RemoveItemName = "remove")] + public WFProviderCollection Providers { + get { + return this["providers"] as WFProviderCollection; + } + + set { + this["providers"]=value; + } + } + } +} + diff --git a/WorkFlowProvider/NpgsqlContentProvider.cs b/WorkFlowProvider/NpgsqlContentProvider.cs index dacb1472..1edc194b 100644 --- a/WorkFlowProvider/NpgsqlContentProvider.cs +++ b/WorkFlowProvider/NpgsqlContentProvider.cs @@ -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); + } } } diff --git a/WorkFlowProvider/WFManager.cs b/WorkFlowProvider/WFManager.cs index c9ccf4fb..00dc5f6b 100644 --- a/WorkFlowProvider/WFManager.cs +++ b/WorkFlowProvider/WFManager.cs @@ -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; + + + } } + + /// + /// Creates the estimate. + /// + /// The estimate identifier. + /// Title. + 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); + } + + + } } diff --git a/WorkFlowProvider/WorkFlowProvider.csproj b/WorkFlowProvider/WorkFlowProvider.csproj index a568c9de..7d479db1 100644 --- a/WorkFlowProvider/WorkFlowProvider.csproj +++ b/WorkFlowProvider/WorkFlowProvider.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 10.0.0 + 8.0.30703 2.0 {821FF72D-9F4B-4A2C-B95C-7B965291F119} Library @@ -33,14 +33,15 @@ - - False - + + + + @@ -49,4 +50,7 @@ yavscModel + + + \ No newline at end of file diff --git a/web/Catalog.xml b/web/Catalog.xml index 4095cd74..d0aa9399 100644 --- a/web/Catalog.xml +++ b/web/Catalog.xml @@ -38,17 +38,17 @@ comment Commentaire - + diff --git a/web/Controllers/BasketController.cs b/web/Controllers/BasketController.cs index 410a3e70..0f4c0254 100644 --- a/web/Controllers/BasketController.cs +++ b/web/Controllers/BasketController.cs @@ -7,6 +7,7 @@ using System.Web.Security; namespace Yavsc.Controllers { + // TODO should mostly be an API Controller public class BasketController : Controller { public ActionResult Index() @@ -21,11 +22,12 @@ namespace Yavsc.Controllers public ActionResult Create() { - var user = Membership.GetUser (); - var username = (user != null)?user.UserName:Request.AnonymousID; + throw new NotImplementedException(); + // var user = Membership.GetUser (); + // var username = (user != null)?user.UserName:Request.AnonymousID; // get an existing basket - return View (); + //return View (); } [HttpPost] diff --git a/web/Controllers/FrontOfficeApiController.cs b/web/Controllers/FrontOfficeApiController.cs index 57ced4f3..263331be 100644 --- a/web/Controllers/FrontOfficeApiController.cs +++ b/web/Controllers/FrontOfficeApiController.cs @@ -11,6 +11,8 @@ using System.Web; using System.Linq; using System.IO; using System.Net; +using WorkFlowProvider; +using System.Web.Security; namespace Yavsc.ApiControllers { @@ -30,13 +32,12 @@ namespace Yavsc.ApiControllers ; } - [AcceptVerbs("POST")] + [AcceptVerbs("GET","POST")] public string Command() { - return null; + throw new NotImplementedException(); } - public HttpResponseMessage Post() { HttpResponseMessage result = null; @@ -80,6 +81,21 @@ namespace Yavsc.ApiControllers return "/path/to/image.png"; } + [HttpGet] + [Authorize] + public long CreateEstimate (string title) + { + return WFManager.CreateEstimate ( + Membership.GetUser().UserName,title); + } + [HttpGet] + [Authorize] + public long AddToBasket (string title) + { + //TODO find the basket for Membership.GetUser().UserName + //return WFManager.Write(estid << from the basket, desc, ucost, count, productid); + throw new NotImplementedException (); + } } } diff --git a/web/Controllers/WorkFlowController.cs b/web/Controllers/WorkFlowController.cs index ebc0e18f..41c2b84b 100644 --- a/web/Controllers/WorkFlowController.cs +++ b/web/Controllers/WorkFlowController.cs @@ -14,8 +14,10 @@ namespace Yavsc.ApiControllers public class WorkFlowController : ApiController { [HttpGet] + [Authorize] public object Index() { + return new { test="Hello World" }; } @@ -25,6 +27,14 @@ namespace Yavsc.ApiControllers return new { c="lmk,", message="Panier impacté", impactRef=bi.ProductRef, count=bi.count}; } + [HttpGet] + [Authorize] + public long Write (long estid, string desc, decimal ucost, int count, long productid=0) { + // TODO ensure estid owner matches the current one + + return WFManager.Write(estid, desc, ucost, count, productid); + } + /* public object Details(int id) { diff --git a/web/Global.asax.cs b/web/Global.asax.cs index bfb3ac3c..d42253d7 100644 --- a/web/Global.asax.cs +++ b/web/Global.asax.cs @@ -42,8 +42,8 @@ namespace Yavsc GlobalConfiguration.Configuration.Routes.MapHttpRoute( name: "DefaultApi", - routeTemplate: "api/{controller}/{action}/{*path}", - defaults: new { controller = "WorkFlow", action="Index", path = "" } + routeTemplate: "api/{controller}/{action}/{*id}", + defaults: new { controller = "WorkFlow", action="Index", id=0 } ); RegisterRoutes (RouteTable.Routes); diff --git a/web/Web.config b/web/Web.config index b5fe46e4..81d938f0 100644 --- a/web/Web.config +++ b/web/Web.config @@ -23,6 +23,7 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
+