* 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

@ -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);
}
}

View File

@ -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 ()
{
}

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>{9D7D892E-9B77-4713-892D-C26E1E944119}</ProjectGuid>
<OutputType>Library</OutputType>
@ -32,6 +32,7 @@
<Reference Include="System" />
<Reference Include="Npgsql" />
<Reference Include="System.Data" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -6,20 +6,30 @@ namespace Npgsql.Web.Blog.Configuration
{
public class BlogProvidersConfigurationSection : 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; }
get { return (string) this ["defaultProvider"]; }
set { this["defaultProvider"] = value; }
}
[ConfigurationProperty("providers")]
[ConfigurationCollection(typeof(BlogProvidersConfigurationCollection),
AddItemName = "add",
ClearItemsName = "clear",
RemoveItemName = "remove")]
/// <summary>
/// Gets or sets the providers.
/// </summary>
/// <value>The providers.</value>
public BlogProvidersConfigurationCollection Providers{
get { return (BlogProvidersConfigurationCollection) base ["providers"]; }
set { base ["providers"] = value; }
get { return (BlogProvidersConfigurationCollection) this["providers"]; }
set { this["providers"] = value; }
}
}

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>

View File

@ -38,17 +38,17 @@
<Id>comment</Id>
<Value xsi:type="xsd:string">Commentaire</Value>
</FormElement>
<FormElement xsi:type="Text">
<!-- <FormElement xsi:type="Text">
<Val>Choisissez le type d'intervention souhaité: </Val>
</FormElement>
<FormElement xsi:type="SelectInput">
- <FormElement xsi:type="SelectInput">
<Id>ad</Id>
<Items>
<string>à distance</string>
<string>sur site</string>
</Items>
<SelectedIndex>0</SelectedIndex>
</FormElement>
</FormElement> -->
</Items>
</DefaultForm>
</Brand>

View File

@ -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]

View File

@ -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 ();
}
}
}

View File

@ -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)
{

View File

@ -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);

View File

@ -23,6 +23,7 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<section name="blog" type="Npgsql.Web.Blog.Configuration.BlogProvidersConfigurationSection, NpgsqlBlogProvider" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
<section name="thanks" type="Yavsc.ThanksConfigurationSection, Yavsc" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
<section name="catalog" type="SalesCatalog.Configuration.CatalogProvidersConfigurationSection, SalesCatalog" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
<section name="workflow" type="WorkFlowProvider.Configuration.WorkflowConfiguration, WorkFlowProvider" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<!-- <runtime>
@ -88,7 +89,6 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<add namespace="Yavsc.Helpers" />
</namespaces>
</pages>
<authorization>
<allow users="*" />
</authorization>
@ -118,6 +118,12 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<add name="NpgsqlRoleProvider" connectionStringName="yavsc" applicationName="/" type="Npgsql.Web.NpgsqlRoleProvider, NpgsqlMRPProviders" autogenerateschema="false" />
</providers>
</roleManager>
<workflow defaultProvider="ITProvider">
<providers>
<clear/>
<add name="ITProvider" type="ITContentProvider.ITCPNpgsqlProvider, ITContentProvider" applicationName="/" connectionStringName="yavsc"/>
</providers>
</workflow>
<profile defaultProvider="NpgsqlProfileProvider">
<providers>
<clear />

View File

@ -251,5 +251,13 @@
<Project>{59E1DF7B-FFA0-4DEB-B5F3-76EBD98D5356}</Project>
<Name>WebControls</Name>
</ProjectReference>
<ProjectReference Include="..\ITContentProvider\ITContentProvider.csproj">
<Project>{9D7D892E-9B77-4713-892D-C26E1E944119}</Project>
<Name>ITContentProvider</Name>
</ProjectReference>
<ProjectReference Include="..\ITContent\ITContent.csproj">
<Project>{88D83FC9-4158-4435-98A6-1F8F7F448B8F}</Project>
<Name>ITContent</Name>
</ProjectReference>
</ItemGroup>
</Project>

View File

@ -6,7 +6,7 @@ body {
color: #D0FFD0;
margin:1em;
padding:1em;
font-family: 'Dancing Script', cursive;
font-family: 'Arial', cursive;
line-height:135%;
}
@ -138,7 +138,7 @@ padding-left: 20px;
@media print {
body {background-color:white;color:black;}
.postcomment,#login,.actionlink{ display:none;}
.postcomment,#login,.actionlink,.metablog,.thanks{ display:none;}
}
@media all and (max-width: 15em) {

12
yavscModel/IProvider.cs Normal file
View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Specialized;
namespace yavscModel
{
public interface IProvider
{
string ApplicationName { get; set; }
void Initialize (string name, NameValueCollection config);
}
}

View File

@ -4,19 +4,21 @@ using System.Web.Mvc;
namespace yavscModel.WorkFlow
{
public interface IContentProvider: IDisposable
public interface IContentProvider : IProvider, IDisposable
{
IWFOrder CreateOrder ();
IWFOrder ImapctOrder (string orderid, FormCollection col);
IContent GetBlob (string orderId);
int GetStatus (string orderId);
int GetStatus (string estimId);
/// <summary>
/// Gets the status labels.
/// 0 is the starting status
/// </summary>
/// <value>The status labels.</value>
bool [] IsFinalStatus { get; }
string [] StatusLabels {get;}
bool [] FinalStatuses { get; }
long CreateEstimate (string client, string title);
void SetTitle (long estid, string newTitle);
long Write (long estid, string desc, decimal ucost, int count, long productid);
void SetDesc (long writid, string newDesc);
Estimate GetEstimate (long estimid);
}
}

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>{68F5B80A-616E-4C3C-91A0-828AA40000BD}</ProjectGuid>
<OutputType>Library</OutputType>
@ -33,9 +33,7 @@
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="nunit.framework" />
<Reference Include="System.Web" />
<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" />
@ -59,6 +57,7 @@
<Compile Include="WorkFlow\IWFModule.cs" />
<Compile Include="WorkFlow\IWFOrder.cs" />
<Compile Include="WorkFlow\OrderStatusChangedEventArgs.cs" />
<Compile Include="IProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>