* Web.csproj:

* YavscModel.csproj:
* Basket.cs:
* Basket.aspx:
* Commande.cs:
* BasketController.cs:
* CommandSet.cs:
* NpgsqlWorkflow.csproj:
* FileSystemController.cs:
* FrontOfficeController.cs:
* NpgsqlContentProvider.cs: implementing a basket

* ProjectInfo.cs:
* ITCPNpgsqlProvider.cs:
* CommandStatus.cs:
* NpgsqlBlogProvider.cs: xml doc

* CalendarApi.cs: document formatting

* FileSystemManager.cs: refactoring

* WorkFlowManager.cs:
* IContentProvider.cs: provides a basket

* WebFileInfoCollection.cs: not used
This commit is contained in:
Paul Schneider
2015-02-18 13:32:25 +01:00
parent b505ad90e7
commit 75fe032822
19 changed files with 388 additions and 127 deletions

View File

@ -4,6 +4,9 @@ using Npgsql;
namespace ITContentProvider namespace ITContentProvider
{ {
/// <summary>
/// ITCP npgsql provider.
/// </summary>
public class ITCPNpgsqlProvider : NpgsqlContentProvider public class ITCPNpgsqlProvider : NpgsqlContentProvider
{ {
/* TODO /* TODO
@ -19,42 +22,79 @@ namespace ITContentProvider
void SetTaskDesc(int taskId, string desc); void SetTaskDesc(int taskId, string desc);
void NewRelease(int projectId, string Version); void NewRelease(int projectId, string Version);
*/ */
/// <summary>
/// Initializes a new instance of the <see cref="ITContentProvider.ITCPNpgsqlProvider"/> class.
/// </summary>
public ITCPNpgsqlProvider () public ITCPNpgsqlProvider ()
{ {
} }
/// <summary>
/// Gets the project info.
/// </summary>
/// <returns>The project info.</returns>
/// <param name="projectid">Projectid.</param>
public ProjectInfo GetProjectInfo(int projectid) public ProjectInfo GetProjectInfo(int projectid)
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
/// <summary>
/// Searchs the project.
/// </summary>
/// <returns>The project.</returns>
/// <param name="pi">Pi.</param>
public ProjectInfo[] SearchProject(ProjectInfo pi) public ProjectInfo[] SearchProject(ProjectInfo pi)
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
/// <summary>
/// News the task.
/// </summary>
/// <returns>The task.</returns>
/// <param name="projectId">Project identifier.</param>
/// <param name="name">Name.</param>
/// <param name="desc">Desc.</param>
public int NewTask (int projectId, string name, string desc) public int NewTask (int projectId, string name, string desc)
{ {
throw new System.NotImplementedException (); throw new System.NotImplementedException ();
} }
/// <summary>
/// Sets the name of the task.
/// </summary>
/// <param name="taskId">Task identifier.</param>
/// <param name="name">Name.</param>
public void SetTaskName (int taskId, string name) public void SetTaskName (int taskId, string name)
{ {
throw new System.NotImplementedException (); throw new System.NotImplementedException ();
} }
/// <summary>
/// Sets the start date.
/// </summary>
/// <param name="taskId">Task identifier.</param>
/// <param name="d">D.</param>
public void SetStartDate (int taskId, DateTime d) public void SetStartDate (int taskId, DateTime d)
{ {
throw new System.NotImplementedException (); throw new System.NotImplementedException ();
} }
/// <summary>
/// Sets the end date.
/// </summary>
/// <param name="taskId">Task identifier.</param>
/// <param name="d">D.</param>
public void SetEndDate (int taskId, DateTime d) public void SetEndDate (int taskId, DateTime d)
{ {
throw new System.NotImplementedException (); throw new System.NotImplementedException ();
} }
/// <summary>
/// Removes the project.
/// </summary>
/// <param name="prjId">Prj identifier.</param>
public void RemoveProject (int prjId) public void RemoveProject (int prjId)
{ {
using (var cnx = CreateConnection()) { using (var cnx = CreateConnection()) {
@ -68,7 +108,13 @@ namespace ITContentProvider
} }
} }
/// <summary>
/// News the project.
/// </summary>
/// <returns>The project.</returns>
/// <param name="name">Name.</param>
/// <param name="desc">Desc.</param>
/// <param name="ownerId">Owner identifier.</param>
public int NewProject (string name, string desc, string ownerId) public int NewProject (string name, string desc, string ownerId)
{ {
int id = 0; int id = 0;

View File

@ -3,15 +3,50 @@ using WorkFlowProvider;
namespace ITContentProvider namespace ITContentProvider
{ {
/// <summary>
/// Project info.
/// </summary>
public class ProjectInfo public class ProjectInfo
{ {
/// <summary>
/// Gets or sets the name.
/// </summary>
/// <value>The name.</value>
string Name { get; set; } string Name { get; set; }
/// <summary>
/// Gets or sets the licence.
/// </summary>
/// <value>The licence.</value>
string Licence { get; set; } string Licence { get; set; }
/// <summary>
/// Gets or sets the BB description.
/// </summary>
/// <value>The BB description.</value>
string BBDescription { get; set; } string BBDescription { get; set; }
/// <summary>
/// Gets or sets the start date.
/// </summary>
/// <value>The start date.</value>
DateTime StartDate { get; set; } DateTime StartDate { get; set; }
/// <summary>
/// Gets or sets the prod version.
/// </summary>
/// <value>The prod version.</value>
string ProdVersion { get; set; } string ProdVersion { get; set; }
/// <summary>
/// Gets or sets the stable version.
/// </summary>
/// <value>The stable version.</value>
string StableVersion { get; set; } string StableVersion { get; set; }
/// <summary>
/// Gets or sets the testing version.
/// </summary>
/// <value>The testing version.</value>
string TestingVersion { get; set; } string TestingVersion { get; set; }
/// <summary>
/// Gets or sets the web site.
/// </summary>
/// <value>The web site.</value>
string WebSite { get; set; } string WebSite { get; set; }
} }
} }

View File

@ -7,13 +7,20 @@ using Yavsc.Model.Blogs;
namespace Npgsql.Web.Blog namespace Npgsql.Web.Blog
{ {
/// <summary>
/// Npgsql blog provider.
/// </summary>
public class NpgsqlBlogProvider : BlogProvider public class NpgsqlBlogProvider : BlogProvider
{ {
string applicationName; string applicationName;
string connectionString; string connectionString;
#region implemented abstract members of BlogProvider #region implemented abstract members of BlogProvider
/// <summary>
/// Tag the specified postid and tag.
/// </summary>
/// <param name="postid">Postid.</param>
/// <param name="tag">Tag.</param>
public override long Tag (long postid, string tag) public override long Tag (long postid, string tag)
{ {
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
@ -24,7 +31,10 @@ namespace Npgsql.Web.Blog
return (long) cmd.ExecuteScalar (); return (long) cmd.ExecuteScalar ();
} }
} }
/// <summary>
/// Removes the tag.
/// </summary>
/// <param name="tagid">Tagid.</param>
public override void RemoveTag (long tagid) public override void RemoveTag (long tagid)
{ {
using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString))
@ -34,10 +44,22 @@ namespace Npgsql.Web.Blog
cmd.ExecuteNonQuery (); cmd.ExecuteNonQuery ();
} }
} }
/// <summary>
/// Gets the post identifier.
/// </summary>
/// <returns>The post identifier.</returns>
/// <param name="username">Username.</param>
/// <param name="title">Title.</param>
public override long GetPostId (string username, string title) public override long GetPostId (string username, string title)
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
/// <summary>
/// Gets the comments.
/// </summary>
/// <returns>The comments.</returns>
/// <param name="postid">Postid.</param>
/// <param name="getHidden">If set to <c>true</c> get hidden.</param>
public override Comment[] GetComments (long postid, bool getHidden) public override Comment[] GetComments (long postid, bool getHidden)
{ {
List<Comment> cmts = new List<Comment> (); List<Comment> cmts = new List<Comment> ();
@ -68,6 +90,13 @@ namespace Npgsql.Web.Blog
} }
return cmts.ToArray(); return cmts.ToArray();
} }
/// <summary>
/// Updates the post.
/// </summary>
/// <param name="postid">Postid.</param>
/// <param name="title">Title.</param>
/// <param name="content">Content.</param>
/// <param name="visible">If set to <c>true</c> visible.</param>
public override void UpdatePost (long postid, string title, string content, bool visible) public override void UpdatePost (long postid, string title, string content, bool visible)
{ {
using (NpgsqlConnection cnx = new NpgsqlConnection(connectionString)) using (NpgsqlConnection cnx = new NpgsqlConnection(connectionString))
@ -89,12 +118,20 @@ namespace Npgsql.Web.Blog
cnx.Close(); cnx.Close();
} }
} }
/// <summary>
/// Removes the post.
/// </summary>
/// <param name="postid">Postid.</param>
public override void RemovePost (long postid) public override void RemovePost (long postid)
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
/// <summary>
/// Comment the specified from, postid and content.
/// </summary>
/// <param name="from">From.</param>
/// <param name="postid">Postid.</param>
/// <param name="content">Content.</param>
public override long Comment (string from, long postid, string content) public override long Comment (string from, long postid, string content)
{ {
if (from == null) if (from == null)
@ -121,12 +158,20 @@ namespace Npgsql.Web.Blog
return (long) cmd.ExecuteScalar(); return (long) cmd.ExecuteScalar();
} }
} }
/// <summary>
/// Validates the comment.
/// </summary>
/// <param name="cmtid">Cmtid.</param>
public override void ValidateComment (long cmtid) public override void ValidateComment (long cmtid)
{ {
throw new NotImplementedException (); throw new NotImplementedException ();
} }
/// <summary>
/// Updates the comment.
/// </summary>
/// <param name="cmtid">Cmtid.</param>
/// <param name="content">Content.</param>
/// <param name="visible">If set to <c>true</c> visible.</param>
public override void UpdateComment public override void UpdateComment
(long cmtid, string content, bool visible) (long cmtid, string content, bool visible)
{ {
@ -134,7 +179,10 @@ namespace Npgsql.Web.Blog
} }
private bool autoValidateComment = true; private bool autoValidateComment = true;
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Npgsql.Web.Blog.NpgsqlBlogProvider"/> auto validate comment.
/// </summary>
/// <value><c>true</c> if auto validate comment; otherwise, <c>false</c>.</value>
public override bool AutoValidateComment { public override bool AutoValidateComment {
get { get {
return autoValidateComment; return autoValidateComment;
@ -144,7 +192,11 @@ namespace Npgsql.Web.Blog
} }
} }
/// <summary>
/// Blogs the title.
/// </summary>
/// <returns>The title.</returns>
/// <param name="username">Username.</param>
public override string BlogTitle public override string BlogTitle
(string username) (string username)
{ {
@ -152,7 +204,11 @@ namespace Npgsql.Web.Blog
} }
#endregion #endregion
/// <summary>
/// Initialize the specified name and config.
/// </summary>
/// <param name="name">Name.</param>
/// <param name="config">Config.</param>
public override void Initialize public override void Initialize
(string name, System.Collections.Specialized.NameValueCollection config) (string name, System.Collections.Specialized.NameValueCollection config)
{ {
@ -165,6 +221,11 @@ namespace Npgsql.Web.Blog
base.Initialize (name, config); base.Initialize (name, config);
} }
#region implemented abstract members of BlogProvider #region implemented abstract members of BlogProvider
/// <summary>
/// Gets the post.
/// </summary>
/// <returns>The post.</returns>
/// <param name="postid">Postid.</param>
public override BlogEntry GetPost (long postid) public override BlogEntry GetPost (long postid)
{ {
BlogEntry be = null; BlogEntry be = null;
@ -190,6 +251,11 @@ namespace Npgsql.Web.Blog
} }
return be; return be;
} }
/// <summary>
/// Removes the comment.
/// </summary>
/// <returns>The comment.</returns>
/// <param name="cmtid">Cmtid.</param>
public override long RemoveComment (long cmtid) public override long RemoveComment (long cmtid)
{ {
long postid = 0; long postid = 0;
@ -202,6 +268,12 @@ namespace Npgsql.Web.Blog
} }
return postid; return postid;
} }
/// <summary>
/// Gets the post.
/// </summary>
/// <returns>The post.</returns>
/// <param name="username">Username.</param>
/// <param name="title">Title.</param>
public override BlogEntry GetPost (string username, string title) public override BlogEntry GetPost (string username, string title)
{ {
BlogEntry be = null; BlogEntry be = null;
@ -239,7 +311,13 @@ namespace Npgsql.Web.Blog
} }
return be; return be;
} }
/// <summary>
/// Post the specified username, title, content and visible.
/// </summary>
/// <param name="username">Username.</param>
/// <param name="title">Title.</param>
/// <param name="content">Content.</param>
/// <param name="visible">If set to <c>true</c> visible.</param>
public override long Post (string username, string title, string content, bool visible) public override long Post (string username, string title, string content, bool visible)
{ {
if (username == null) if (username == null)
@ -264,7 +342,15 @@ namespace Npgsql.Web.Blog
return (long) cmd.ExecuteScalar(); return (long) cmd.ExecuteScalar();
} }
} }
/// <summary>
/// Finds the post.
/// </summary>
/// <returns>The post.</returns>
/// <param name="pattern">Pattern.</param>
/// <param name="searchflags">Searchflags.</param>
/// <param name="pageIndex">Page index.</param>
/// <param name="pageSize">Page size.</param>
/// <param name="totalRecords">Total records.</param>
public override BlogEntryCollection FindPost (string pattern, FindBlogEntryFlags searchflags, int pageIndex, int pageSize, out int totalRecords) public override BlogEntryCollection FindPost (string pattern, FindBlogEntryFlags searchflags, int pageIndex, int pageSize, out int totalRecords)
{ {
BlogEntryCollection c = new BlogEntryCollection (); BlogEntryCollection c = new BlogEntryCollection ();
@ -313,7 +399,11 @@ namespace Npgsql.Web.Blog
} }
return c; return c;
} }
/// <summary>
/// Removes the post.
/// </summary>
/// <param name="username">Username.</param>
/// <param name="title">Title.</param>
public override void RemovePost (string username, string title) public override void RemovePost (string username, string title)
{ {
using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString)) using (NpgsqlConnection cnx=new NpgsqlConnection(connectionString))
@ -330,7 +420,13 @@ namespace Npgsql.Web.Blog
int defaultPageSize = 10; int defaultPageSize = 10;
/// <summary>
/// Lasts the posts.
/// </summary>
/// <returns>The posts.</returns>
/// <param name="pageIndex">Page index.</param>
/// <param name="pageSize">Page size.</param>
/// <param name="totalRecords">Total records.</param>
public override BlogEntryCollection LastPosts(int pageIndex, int pageSize, out int totalRecords) public override BlogEntryCollection LastPosts(int pageIndex, int pageSize, out int totalRecords)
{ {
BlogEntryCollection c = new BlogEntryCollection (); BlogEntryCollection c = new BlogEntryCollection ();

View File

@ -8,6 +8,7 @@ using System.Configuration.Provider;
using System.Collections.Generic; using System.Collections.Generic;
using Yavsc.Model.FrontOffice; using Yavsc.Model.FrontOffice;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Web.Security;
namespace WorkFlowProvider namespace WorkFlowProvider
{ {
@ -16,22 +17,12 @@ namespace WorkFlowProvider
/// </summary> /// </summary>
public class NpgsqlContentProvider: ProviderBase, IContentProvider public class NpgsqlContentProvider: ProviderBase, IContentProvider
{ {
/// <summary>
/// Gets the stock status.
/// </summary>
/// <returns>The stock status.</returns>
/// <param name="productReference">Product reference.</param>
public virtual StockStatus GetStockStatus (string productReference)
{
return StockStatus.NonExistent;
}
/// <summary> /// <summary>
/// Registers the command. /// Registers the command.
/// </summary> /// </summary>
/// <returns>The command id in db.</returns> /// <returns>The command id in db.</returns>
/// <param name="com">COM.</param> /// <param name="com">COM.</param>
public long RegisterCommand (Commande com) public long RegisterCommand (Command com)
{ {
long id; long id;
using (NpgsqlConnection cnx = CreateConnection ()) { using (NpgsqlConnection cnx = CreateConnection ()) {
@ -47,6 +38,56 @@ namespace WorkFlowProvider
} }
return id; return id;
} }
/// <summary>
/// Gets the commands.
/// </summary>
/// <returns>The commands.</returns>
/// <param name="username">Username.</param>
public CommandSet GetCommands (string username )
{
// Check the user's authorisations
MembershipUser user = Membership.GetUser ();
if (user.UserName != username)
if (!Roles.IsUserInRole ("Admin"))
if (!Roles.IsUserInRole ("FrontOffice"))
throw new Exception ("Not allowed");
CommandSet cmds = new CommandSet ();
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"select id,prdref,creation,params from commandes where @user = clientname and applicationname = @app";
cmd.Parameters.Add ("@user", username);
cmd.Parameters.Add ("@app", this.ApplicationName);
cnx.Open ();
using (NpgsqlDataReader rdr = cmd.ExecuteReader ()) {
while (rdr.Read ()) {
Command ycmd = new Command();
ycmd.Id = rdr.GetInt64(0);
ycmd.CreationDate = rdr.GetDateTime(1);
ycmd.ProductRef = rdr.GetString(2);
ycmd.Parameters = JsonConvert.DeserializeObject(rdr.GetString(3)) as StringDictionary;
cmds.Add (ycmd);
}
}
}
cnx.Close ();
}
return cmds;
}
/// <summary>
/// Gets the stock status.
/// </summary>
/// <returns>The stock status.</returns>
/// <param name="productReference">Product reference.</param>
public virtual StockStatus GetStockStatus (string productReference)
{
return StockStatus.NonExistent;
}
/// <summary> /// <summary>
/// Gets the writting status changes. /// Gets the writting status changes.
/// </summary> /// </summary>

View File

@ -40,6 +40,8 @@
<HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll</HintPath> <HintPath>..\..\..\..\..\usr\lib\mono\4.5\System.Net.Http.Formatting.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />

View File

@ -7,7 +7,6 @@ using System.Web.Http;
using Yavsc.Model.WorkFlow; using Yavsc.Model.WorkFlow;
using System.Collections.Specialized; using System.Collections.Specialized;
using Yavsc.Model.FrontOffice; using Yavsc.Model.FrontOffice;
using System.Web.SessionState;
namespace Yavsc.ApiControllers namespace Yavsc.ApiControllers
{ {
@ -37,12 +36,10 @@ namespace Yavsc.ApiControllers
/// Gets the current basket, creates a new one, if it doesn't exist. /// Gets the current basket, creates a new one, if it doesn't exist.
/// </summary> /// </summary>
/// <value>The current basket.</value> /// <value>The current basket.</value>
protected Basket CurrentBasket { protected CommandSet CurrentBasket {
get { get {
HttpSessionState session = HttpContext.Current.Session; CommandSet b = wfmgr.GetCommands (Membership.GetUser ().UserName);
Basket b = (Basket) session ["Basket"]; if (b == null) b = new CommandSet ();
if (b == null)
session ["Basket"] = b = new Basket ();
return b; return b;
} }
} }
@ -55,7 +52,7 @@ namespace Yavsc.ApiControllers
public long Create(NameValueCollection cmdParams) public long Create(NameValueCollection cmdParams)
{ {
// HttpContext.Current.Request.Files // HttpContext.Current.Request.Files
Commande cmd = new Commande(cmdParams, HttpContext.Current.Request.Files); Command cmd = new Command(cmdParams, HttpContext.Current.Request.Files);
CurrentBasket.Add (cmd); CurrentBasket.Add (cmd);
return cmd.Id; return cmd.Id;
} }
@ -65,7 +62,7 @@ namespace Yavsc.ApiControllers
/// </summary> /// </summary>
/// <param name="itemid">Itemid.</param> /// <param name="itemid">Itemid.</param>
[Authorize] [Authorize]
Commande Read(long itemid){ Command Read(long itemid){
return CurrentBasket[itemid]; return CurrentBasket[itemid];
} }

View File

@ -15,15 +15,13 @@ namespace Yavsc.Controllers
/// </summary> /// </summary>
public class FileSystemController : Controller public class FileSystemController : Controller
{ {
private string usersDir = "~/users";
/// <summary> /// <summary>
/// Gets the users base directory. /// Gets the users base directory.
/// </summary> /// </summary>
/// <value>The users dir.</value> /// <value>The users dir.</value>
public string UsersDir { public string RootDir {
get { get {
return usersDir; return mgr.Prefix;
} }
} }
@ -36,7 +34,8 @@ namespace Yavsc.Controllers
protected override void Initialize (System.Web.Routing.RequestContext requestContext) protected override void Initialize (System.Web.Routing.RequestContext requestContext)
{ {
base.Initialize (requestContext); base.Initialize (requestContext);
mgr = new FileSystemManager (UsersDir); mgr = new FileSystemManager (
string.Format("~/users/{0}",Membership.GetUser().UserName));
} }
/// <summary> /// <summary>
@ -45,7 +44,7 @@ namespace Yavsc.Controllers
[Authorize] [Authorize]
public ActionResult Index (string id) public ActionResult Index (string id)
{ {
return View (mgr.GetFiles (Membership.GetUser().UserName+"/"+id)); return View (mgr.GetFiles (id));
} }
/// <summary> /// <summary>
@ -63,9 +62,9 @@ namespace Yavsc.Controllers
return RedirectToAction ("Index"); return RedirectToAction ("Index");
} }
} }
string fpath = Path.Combine (UserBaseDir, id); FileInfo fi = mgr.FileInfo (id);
ViewData ["Content"] = Url.Content (fpath);
FileInfo fi = new FileInfo (fpath); ViewData ["Content"] = Url.Content (fi.FullName);
return View (fi); return View (fi);
} }
@ -78,16 +77,15 @@ namespace Yavsc.Controllers
[Authorize] [Authorize]
public ActionResult Create (string id) public ActionResult Create (string id)
{ {
string path=Membership.GetUser().UserName+"/"+id; mgr.Put ( id, Request.Files);
mgr.Put ( path, Request.Files); return View ("Index",mgr.GetFiles(id));
return View ("Index",mgr.GetFiles(path));
} }
/// <summary> /// <summary>
/// Gets the user's base dir. /// Gets the user's base dir.
/// </summary> /// </summary>
/// <value>The base dir.</value> /// <value>The base dir.</value>
public string UserBaseDir { get { return Path.Combine (UsersDir, Membership.GetUser ().UserName); } } public string UserBaseDir { get { return Path.Combine (RootDir, Membership.GetUser ().UserName); } }
/// <summary> /// <summary>
/// Edit the specified id. /// Edit the specified id.

View File

@ -181,19 +181,14 @@ namespace Yavsc.Controllers
} }
/// <summary> /// <summary>
/// Command this instance. /// Basket this instance.
/// </summary> /// </summary>
public ActionResult Command () [Authorize]
public ActionResult Basket ()
{ {
return View (); return View (wfmgr.GetCommands(Membership.GetUser().UserName));
} }
private Basket GetBasket ()
{
if (Session ["Basket"] == null)
Session ["Basket"] = new Basket();
return Session ["Basket"] as Basket;
}
/// <summary> /// <summary>
/// Command the specified collection. /// Command the specified collection.
@ -204,29 +199,9 @@ namespace Yavsc.Controllers
public ActionResult Command (FormCollection collection) public ActionResult Command (FormCollection collection)
{ {
try { try {
// get files from the request
string fnre = "[A-Za-z0-9~\\-.]+";
HttpFileCollectionBase hfc = Request.Files;
// TODO mime-magic on content, and file name filter
foreach (String h in hfc.AllKeys) {
if (!Regex.Match (hfc [h].FileName, fnre).Success) {
ViewData ["Message"] = "File name refused";
ModelState.AddModelError (
h,
string.Format (
"The file name {0} dosn't match an acceptable file name {1}",
hfc [h].FileName, fnre));
return View (collection);
}
}
string usersdir = Server.MapPath("~/users");
FileSystemManager fsmgr = new FileSystemManager(usersdir);
foreach (String h in hfc.AllKeys) {
// TODO Limit with hfc[h].ContentLength
hfc [h].SaveAs (Path.Combine (usersdir, hfc [h].FileName));
}
// Add specified product command to the basket, // Add specified product command to the basket,
GetBasket().Add (new Commande(collection,HttpContext.Request.Files)); // saves it in db
new Command(collection,HttpContext.Request.Files);
ViewData ["Message"] = LocalizedText.Item_added_to_basket; ViewData ["Message"] = LocalizedText.Item_added_to_basket;
return View (collection); return View (collection);
} catch (Exception e) { } catch (Exception e) {

View File

@ -103,13 +103,13 @@ namespace Yavsc.Helpers.Google
try { try {
using (WebResponse resp = webreq.GetResponse ()) { using (WebResponse resp = webreq.GetResponse ()) {
using (Stream respstream = resp.GetResponseStream ()) { using (Stream respstream = resp.GetResponseStream ()) {
try { try {
res = (CalendarEntryList) new DataContractJsonSerializer(typeof(CalendarEntryList)).ReadObject (respstream); res = (CalendarEntryList) new DataContractJsonSerializer(typeof(CalendarEntryList)).ReadObject (respstream);
} catch (Exception ex) { } catch (Exception ex) {
respstream.Close (); respstream.Close ();
resp.Close (); resp.Close ();
webreq.Abort (); webreq.Abort ();
throw new GoogleErrorException(ex); throw ex;
} }
} }
resp.Close (); resp.Close ();

View File

@ -0,0 +1,26 @@
<%@ Page Title="Basket" Language="C#" Inherits="System.Web.Mvc.ViewPage<Basket>" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
<% Title = Title +" "+ Model.Count+" article(s)"; %>
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" ID="mainContent" runat="server">
<ul>
<% foreach (Commande cmd in Model.Values) { %>
<li>
<%= cmd.Id %>
<%= cmd.CreationDate %>
<%= cmd.Status %>
<%= cmd.ProductRef %>
<ul>
<% foreach (string key in cmd.Parameters.Keys) { %>
<li><%=key%>: <%=cmd.Parameters[key]%></li>
<% } %>
</ul>
</li>
<% } %>
</ul>
</asp:Content>

View File

@ -673,6 +673,7 @@
<Content Include="Scripts\jquery.googlemaps.js" /> <Content Include="Scripts\jquery.googlemaps.js" />
<Content Include="Scripts\jquery.googlemaps.min.js" /> <Content Include="Scripts\jquery.googlemaps.min.js" />
<Content Include="Views\Account\MyProfile.aspx" /> <Content Include="Views\Account\MyProfile.aspx" />
<Content Include="Views\FrontOffice\Basket.aspx" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" /> <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

View File

@ -56,9 +56,9 @@ namespace Yavsc.Model.FileSystem
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.FileSystemManager"/> class. /// Initializes a new instance of the <see cref="Yavsc.Model.FileSystem.FileSystemManager"/> class.
/// </summary> /// </summary>
public FileSystemManager (string usersDirectory="~/files", char dirSep = '/') public FileSystemManager (string rootDirectory="~/files", char dirSep = '/')
{ {
prefix = usersDirectory; prefix = rootDirectory;
DirectorySeparator = dirSep; DirectorySeparator = dirSep;
} }
@ -150,8 +150,19 @@ namespace Yavsc.Model.FileSystem
} }
DirectoryInfo di = new DirectoryInfo (path); DirectoryInfo di = new DirectoryInfo (path);
FileInfoCollection res = new FileInfoCollection (di.GetFiles ()); FileInfoCollection res = new FileInfoCollection (di.GetFiles ());
// TODO define an Owner
return res; return res;
} }
/// <summary>
/// Files the info.
/// </summary>
/// <returns>The info.</returns>
/// <param name="id">Identifier.</param>
public FileInfo FileInfo(string id)
{
checkSubDir (id);
return new FileInfo(Path.Combine (Prefix, id));
}
} }
} }

View File

@ -27,12 +27,12 @@ namespace Yavsc.Model.FrontOffice
/// <summary> /// <summary>
/// Basket. /// Basket.
/// </summary> /// </summary>
public class Basket: Dictionary<long,Commande> public class CommandSet: Dictionary<long,Command>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Yavsc.Model.FrontOffice.Basket"/> class. /// Initializes a new instance of the <see cref="Yavsc.Model.FrontOffice.CommandSet"/> class.
/// </summary> /// </summary>
public Basket () public CommandSet ()
{ {
} }
/// <Docs>The item to add to the current collection.</Docs> /// <Docs>The item to add to the current collection.</Docs>
@ -43,7 +43,7 @@ namespace Yavsc.Model.FrontOffice
/// Add the specified cmd. /// Add the specified cmd.
/// </summary> /// </summary>
/// <param name="cmd">Cmd.</param> /// <param name="cmd">Cmd.</param>
public void Add(Commande cmd) public void Add(Command cmd)
{ {
Add (cmd.Id, cmd); Add (cmd.Id, cmd);
} }

View File

@ -22,13 +22,34 @@ using System;
namespace Yavsc.Model.FrontOffice namespace Yavsc.Model.FrontOffice
{ {
/// <summary>
/// Command status.
/// </summary>
public enum CommandStatus:int public enum CommandStatus:int
{ {
/// <summary>
/// The inserted.
/// </summary>
Inserted, Inserted,
/// <summary>
/// The user validated.
/// </summary>
UserValidated, UserValidated,
/// <summary>
/// The user canceled.
/// </summary>
UserCanceled, UserCanceled,
/// <summary>
/// The execution pending.
/// </summary>
ExecutionPending, ExecutionPending,
/// <summary>
/// The satisfied.
/// </summary>
Satisfied, Satisfied,
/// <summary>
/// The refunded.
/// </summary>
Refunded Refunded
} }
} }

View File

@ -11,24 +11,32 @@ namespace Yavsc.Model.FrontOffice
/// <summary> /// <summary>
/// Commande. /// Commande.
/// </summary> /// </summary>
public class Commande public class Command
{ {
/// <summary> /// <summary>
/// Gets or sets the creation date. /// Gets or sets the creation date.
/// </summary> /// </summary>
/// <value>The creation date.</value> /// <value>The creation date.</value>
public DateTime CreationDate { get; set; } public DateTime CreationDate { get; set; }
/// <summary> /// <summary>
/// Gets or sets the identifier. /// Gets or sets the identifier.
/// </summary> /// </summary>
/// <value>The identifier.</value> /// <value>The identifier.</value>
public long Id { get; set; } public long Id { get; set; }
/// <summary> /// <summary>
/// Gets or sets the product reference. /// Gets or sets the product reference.
/// </summary> /// </summary>
/// <value>The prod reference.</value> /// <value>The prod reference.</value>
public CommandStatus Status { get; set; } public CommandStatus Status { get; set; }
/// <summary>
/// Gets or sets the product reference.
/// </summary>
/// <value>The product reference.</value>
public string ProductRef { get; set; } public string ProductRef { get; set; }
/// <summary> /// <summary>
/// The parameters. /// The parameters.
/// </summary> /// </summary>
@ -39,30 +47,46 @@ namespace Yavsc.Model.FrontOffice
return GetFSM().GetFiles (Id.ToString()); return GetFSM().GetFiles (Id.ToString());
} }
} }
/// <summary> /// <summary>
/// Create a command using the specified collection /// Initializes a new instance of the <see cref="Yavsc.Model.FrontOffice.Command"/> class.
/// as command parameters, handles the request files. /// </summary>
public Command()
{
}
/// <summary>
/// Froms the post.
/// </summary> /// </summary>
/// <param name="collection">Collection.</param> /// <param name="collection">Collection.</param>
/// <param name="files">Files.</param> /// <param name="files">Files.</param>
public Commande (NameValueCollection collection, NameObjectCollectionBase files) public void FromPost(NameValueCollection collection, NameObjectCollectionBase files)
{ {
// string catref=collection["catref"]; // Catalog Url from which formdata has been built // string catref=collection["catref"]; // Catalog Url from which formdata has been built
ProductRef=collection["ref"]; // Required product reference ProductRef=collection["ref"]; // Required product reference
CreationDate = DateTime.Now; CreationDate = DateTime.Now;
Status = CommandStatus.Inserted; Status = CommandStatus.Inserted;
// stores the parameters: // stores the parameters:
Parameters.Clear ();
foreach (string key in collection.AllKeys) { foreach (string key in collection.AllKeys) {
if (key!="ref") if (key!="ref")
Parameters.Add (key, collection [key]); Parameters.Add (key, collection [key]);
} }
WorkFlowManager wfm = new WorkFlowManager (); WorkFlowManager wfm = new WorkFlowManager ();
wfm.RegisterCommand (this); // sets this.Id wfm.RegisterCommand (this); // overrides this.Id
string strcmdid = Id.ToString (); string strcmdid = Id.ToString ();
GetFSM().Put (strcmdid, files); GetFSM().Put (strcmdid, files);
} }
/// <summary>
/// Creates a command using the specified collection
/// as command parameters, handles the files upload.
/// </summary>
/// <param name="collection">Collection.</param>
/// <param name="files">Files.</param>
public Command (NameValueCollection collection, NameObjectCollectionBase files)
{
FromPost (collection, files);
}
private FileSystemManager GetFSM() { private FileSystemManager GetFSM() {
return new FileSystemManager ("~/commands"); return new FileSystemManager ("~/commands");
} }

View File

@ -1,24 +0,0 @@
using System;
using Yavsc;
using System.Collections.Specialized;
using Yavsc.Model.WorkFlow;
using Yavsc.Model.FileSystem;
using System.Web;
using System.Collections.Generic;
namespace Yavsc.Model.FrontOffice
{
public class WebFileInfoCollection: List<WebFileInfo>
{
public WebFileInfoCollection (
HttpContextBase context, string prefix)
{
}
}
}

View File

@ -119,8 +119,13 @@ namespace Yavsc.Model.WorkFlow
/// </summary> /// </summary>
/// <returns>The command id in db.</returns> /// <returns>The command id in db.</returns>
/// <param name="com">COM.</param> /// <param name="com">COM.</param>
long RegisterCommand (Commande com); long RegisterCommand (Command com);
/// <summary>
/// Gets the commands.
/// </summary>
/// <returns>The commands.</returns>
/// <param name="username">Username.</param>
CommandSet GetCommands (string username);
/// <summary> /// <summary>
/// Gets the stock status. /// Gets the stock status.
/// </summary> /// </summary>

View File

@ -25,7 +25,7 @@ namespace Yavsc.Model.WorkFlow
/// </summary> /// </summary>
/// <returns>The command.</returns> /// <returns>The command.</returns>
/// <param name="com">COM.</param> /// <param name="com">COM.</param>
public long RegisterCommand(Commande com) public long RegisterCommand(Command com)
{ {
return ContentProvider.RegisterCommand (com); return ContentProvider.RegisterCommand (com);
} }
@ -183,7 +183,15 @@ namespace Yavsc.Model.WorkFlow
{ {
ContentProvider.SetEstimateStatus (estid, status, username); ContentProvider.SetEstimateStatus (estid, status, username);
} }
/// <summary>
/// Gets the commands.
/// </summary>
/// <returns>The commands.</returns>
/// <param name="username">Username.</param>
public CommandSet GetCommands(string username)
{
return ContentProvider.GetCommands (username);
}
} }
} }

View File

@ -96,7 +96,6 @@
<Compile Include="Google\GoogleErrorMessage.cs" /> <Compile Include="Google\GoogleErrorMessage.cs" />
<Compile Include="RssFeeds.cs" /> <Compile Include="RssFeeds.cs" />
<Compile Include="FrontOffice\Commande.cs" /> <Compile Include="FrontOffice\Commande.cs" />
<Compile Include="FrontOffice\Basket.cs" />
<Compile Include="FrontOffice\Catalog\Brand.cs" /> <Compile Include="FrontOffice\Catalog\Brand.cs" />
<Compile Include="FrontOffice\Catalog\Catalog.cs" /> <Compile Include="FrontOffice\Catalog\Catalog.cs" />
<Compile Include="FrontOffice\Catalog\CheckBox.cs" /> <Compile Include="FrontOffice\Catalog\CheckBox.cs" />
@ -136,8 +135,8 @@
<Compile Include="FileSystem\InvalidDirNameException.cs" /> <Compile Include="FileSystem\InvalidDirNameException.cs" />
<Compile Include="FileSystem\WebFileInfo.cs" /> <Compile Include="FileSystem\WebFileInfo.cs" />
<Compile Include="Google\CalendarEntryList.cs" /> <Compile Include="Google\CalendarEntryList.cs" />
<Compile Include="FrontOffice\WebFileInfoCollection.cs" />
<Compile Include="FrontOffice\CommandStatus.cs" /> <Compile Include="FrontOffice\CommandStatus.cs" />
<Compile Include="FrontOffice\CommandSet.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>