- a module for IT services business
- Mvc-like action binding in the WF web api ... ? * Yavsc.sln: * Web.csproj: * MvcActionValueBinder.cs: * yavscModel.csproj: * WFOrder.cs: * IWFOrder.cs: * BasketImpact.cs: * ProjectInfo.cs: * IWFModule.cs: * IWFCommand.cs: * WorkFlowController.cs: * NewProjectModel.cs: * IContentProvider.cs: * ITCPNpgsqlProvider.cs: * WorkFlowProvider.csproj: * ITContentProvider.csproj: * AssemblyInfo.cs: * OrderStatusChangedEventArgs.cs: * NpgsqlContentProvider.cs:vnext
parent
04804b89a9
commit
fa93ce7fee
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using WorkFlowProvider;
|
||||
using Npgsql;
|
||||
|
||||
namespace ITContentProvider
|
||||
{
|
||||
public class ITCPNpgsqlProvider :NpgsqlContentProvider
|
||||
{
|
||||
public ITCPNpgsqlProvider ()
|
||||
{
|
||||
}
|
||||
|
||||
public ProjectInfo GetProjectInfo(int projectid)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public ProjectInfo[] SearchProject(ProjectInfo pi)
|
||||
{
|
||||
throw new NotImplementedException ();
|
||||
}
|
||||
|
||||
public int NewTask (int projectId, string name, string desc)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
|
||||
public void SetTaskName (int taskId, string name)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public void SetStartDate (int taskId, DateTime d)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
public void SetEndDate (int taskId, DateTime d)
|
||||
{
|
||||
throw new System.NotImplementedException ();
|
||||
}
|
||||
|
||||
|
||||
public void RemoveProject (int prjId)
|
||||
{
|
||||
using (var cnx = CreateConnection()) {
|
||||
cnx.Open ();
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = "delete from projets where id = @id";
|
||||
cmd.Parameters.Add ("@id", prjId);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
cnx.Close ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int NewProject (string name, string desc, string ownerId)
|
||||
{
|
||||
int id = 0;
|
||||
using (var cnx = CreateConnection()) {
|
||||
cnx.Open ();
|
||||
using (NpgsqlCommand cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = "insert into projets (name,managerid,ApplicatonName,prdesc) values (@name,@mid,@appname,@pdesc)";
|
||||
cmd.Parameters.Add ("@name", name);
|
||||
cmd.Parameters.Add ("@mid", ownerId);
|
||||
cmd.Parameters.Add ("@appname", ApplicationName);
|
||||
cmd.Parameters.Add ("@desc", desc);
|
||||
id = (int)cmd.ExecuteScalar ();
|
||||
}
|
||||
cnx.Close ();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
<?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>{9D7D892E-9B77-4713-892D-C26E1E944119}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>ITContentProvider</RootNamespace>
|
||||
<AssemblyName>ITContentProvider</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>full</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="Npgsql" />
|
||||
<Reference Include="System.Data" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ProjectInfo.cs" />
|
||||
<Compile Include="ITCPNpgsqlProvider.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkFlowProvider\WorkFlowProvider.csproj">
|
||||
<Project>{821FF72D-9F4B-4A2C-B95C-7B965291F119}</Project>
|
||||
<Name>WorkFlowProvider</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\yavscModel\yavscModel.csproj">
|
||||
<Project>{68F5B80A-616E-4C3C-91A0-828AA40000BD}</Project>
|
||||
<Name>yavscModel</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using WorkFlowProvider;
|
||||
|
||||
namespace ITContentProvider
|
||||
{
|
||||
public class ProjectInfo
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Licence { get; set; }
|
||||
string BBDescription { get; set; }
|
||||
DateTime StartDate { get; set; }
|
||||
string ProdVersion { get; set; }
|
||||
string StableVersion { get; set; }
|
||||
string TestingVersion { get; set; }
|
||||
string WebSite { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
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 ("ITContentProvider")]
|
||||
[assembly: AssemblyDescription ("")]
|
||||
[assembly: AssemblyConfiguration ("")]
|
||||
[assembly: AssemblyCompany ("")]
|
||||
[assembly: AssemblyProduct ("")]
|
||||
[assembly: AssemblyCopyright ("Paul Schneider")]
|
||||
[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("")]
|
||||
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
using System.Web.Http;
|
||||
using WorkFlowProvider;
|
||||
using yavscModel.WorkFlow;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
|
||||
namespace Yavsc.ApiControllers
|
||||
{
|
||||
|
||||
public class BasketImpact
|
||||
{
|
||||
public string ProductRef { get; set; }
|
||||
public int count { get; set; }
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Formatting;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.ModelBinding;
|
||||
using System.Web.Http.ValueProviders;
|
||||
using System.Web.Http.ValueProviders.Providers;
|
||||
|
||||
namespace Basic
|
||||
{
|
||||
// Binder with MVC semantics. Treat the body as KeyValue pairs and model bind it.
|
||||
public class MvcActionValueBinder : DefaultActionValueBinder
|
||||
{
|
||||
// Per-request storage, uses the Request.Properties bag. We need a unique key into the bag.
|
||||
private const string Key = "5DC187FB-BFA0-462A-AB93-9E8036871EC8";
|
||||
|
||||
public override HttpActionBinding GetBinding (HttpActionDescriptor actionDescriptor)
|
||||
{
|
||||
|
||||
HttpActionBinding actionBinding = new HttpActionBinding ();
|
||||
|
||||
HttpParameterDescriptor[] parameters = actionDescriptor.GetParameters ().ToArray ();
|
||||
HttpParameterBinding[] binders = Array.ConvertAll (parameters, p => DetermineBinding (actionBinding, p));
|
||||
|
||||
actionBinding.ParameterBindings = binders;
|
||||
return actionBinding;
|
||||
}
|
||||
|
||||
private HttpParameterBinding DetermineBinding (HttpActionBinding actionBinding, HttpParameterDescriptor parameter)
|
||||
{
|
||||
HttpConfiguration config = parameter.Configuration;
|
||||
|
||||
var attr = new ModelBinderAttribute(); // use default settings
|
||||
|
||||
ModelBinderProvider provider = attr.GetModelBinderProvider(config);
|
||||
|
||||
// Alternatively, we could put this ValueProviderFactory in the global config.
|
||||
List<ValueProviderFactory> vpfs = new List<ValueProviderFactory>(attr.GetValueProviderFactories(config));
|
||||
vpfs.Add(new BodyValueProviderFactory());
|
||||
//vpfs.Add (new RouteDataValueProviderFactory ());
|
||||
return new ModelBinderParameterBinding(parameter, provider, vpfs);
|
||||
}
|
||||
|
||||
// Derive from ActionBinding so that we have a chance to read the body once and then share that with all the parameters.
|
||||
private class MvcActionBinding : HttpActionBinding
|
||||
{
|
||||
// Read the body upfront , add as a ValueProvider
|
||||
public override Task ExecuteBindingAsync (HttpActionContext actionContext, CancellationToken cancellationToken)
|
||||
{
|
||||
HttpRequestMessage request = actionContext.ControllerContext.Request;
|
||||
HttpContent content = request.Content;
|
||||
if (content != null) {
|
||||
// content.ReadAsStreamAsync ().Result;
|
||||
FormDataCollection fd = content.ReadAsAsync<FormDataCollection> ().Result;
|
||||
if (fd != null) {
|
||||
|
||||
NameValueCollection nvc = fd.ReadAsNameValueCollection ();
|
||||
|
||||
System.Web.Http.ValueProviders.IValueProvider vp = new System.Web.Http.ValueProviders.Providers.NameValueCollectionValueProvider (nvc, CultureInfo.InvariantCulture);
|
||||
|
||||
request.Properties.Add (Key, vp);
|
||||
}
|
||||
}
|
||||
|
||||
return base.ExecuteBindingAsync (actionContext, cancellationToken);
|
||||
}
|
||||
}
|
||||
// Get a value provider over the body. This can be shared by all parameters.
|
||||
// This gets the values computed in MvcActionBinding.
|
||||
private class BodyValueProviderFactory : System.Web.Http.ValueProviders.ValueProviderFactory
|
||||
{
|
||||
public override System.Web.Http.ValueProviders.IValueProvider GetValueProvider (HttpActionContext actionContext)
|
||||
{
|
||||
object vp;
|
||||
actionContext.Request.Properties.TryGetValue (Key, out vp);
|
||||
return (System.Web.Http.ValueProviders.IValueProvider)vp; // can be null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace yavscModel.WorkFlow
|
||||
{
|
||||
public interface IContentProvider: IDisposable
|
||||
{
|
||||
string Order (IWFCommand c);
|
||||
IContent Get (string orderId);
|
||||
IWFOrder CreateOrder ();
|
||||
IWFOrder ImapctOrder (string orderid, FormCollection col);
|
||||
IContent GetBlob (string orderId);
|
||||
int GetStatus (string orderId);
|
||||
/// <summary>
|
||||
/// Gets the status labels.
|
||||
/// 0 is the starting status
|
||||
/// </summary>
|
||||
/// <value>The status labels.</value>
|
||||
bool [] IsFinalStatus { get; }
|
||||
string [] StatusLabels {get;}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace yavscModel.WorkFlow
|
||||
{
|
||||
public interface IWFCommand
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace yavscModel.WorkFlow
|
||||
{
|
||||
public interface IWFOrder
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the unique Identifier for this order, in this application.
|
||||
/// </summary>
|
||||
/// <value>The unique I.</value>
|
||||
string UniqueID {
|
||||
get;
|
||||
}
|
||||
event EventHandler<OrderStatusChangedEventArgs> StatusChanged;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
|
||||
namespace yavscModel.WorkFlow
|
||||
{
|
||||
public class OrderStatusChangedEventArgs: EventArgs
|
||||
{
|
||||
public OrderStatusChangedEventArgs (int oldstatus, int newstatus, string reason)
|
||||
{
|
||||
oldstat = oldstatus;
|
||||
newstat = newstatus;
|
||||
}
|
||||
private int oldstat, newstat;
|
||||
public int OldStatus { get { return oldstat; } }
|
||||
public int NewStatus { get { return newstat; } }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue