From b5d19c5da63f08d8e5658ee9cec44fa147d47df0 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Wed, 8 Oct 2014 10:47:40 +0200 Subject: [PATCH] refactoring --- NpgsqlBlogProvider/NpgsqlBlogProvider.csproj | 6 -- SalesCatalog/SalesCatalog.csproj | 4 +- .../XmlImplementation/XmlCatalogProvider.cs | 13 ++++- WorkFlowProvider/WorkFlowProvider.csproj | 7 --- web/Controllers/AdminController.cs | 57 +++++++++++++++++++ web/Controllers/BackOfficeController.cs | 55 +----------------- web/Controllers/BasketController.cs | 2 +- web/Controllers/FrontOfficeApiController.cs | 2 +- web/Controllers/FrontOfficeController.cs | 2 +- web/Controllers/WorkFlowController.cs | 10 ++-- web/Views/{Account => Admin}/AddRole.aspx | 2 +- web/Views/{Account => Admin}/Admin.aspx | 2 +- .../{BackOffice => Admin}/BackupCreated.aspx | 0 web/Views/{BackOffice => Admin}/Backups.aspx | 4 +- .../{BackOffice => Admin}/CreateBackup.aspx | 2 +- web/Views/{BackOffice => Admin}/Index.aspx | 2 +- .../{Account => Admin}/RemoveRoleQuery.aspx | 0 .../{Account => Admin}/RemoveUserQuery.aspx | 2 +- web/Views/{BackOffice => Admin}/Restore.aspx | 2 +- web/Views/{BackOffice => Admin}/Restored.aspx | 0 web/Views/{Account => Admin}/RoleList.aspx | 0 web/Views/{Account => Admin}/UserList.aspx | 0 web/Views/BackOffice/Estimate.aspx | 12 ++++ web/Views/FrontOffice/Command.aspx | 2 +- web/Views/FrontOffice/Service.aspx | 2 +- web/Web.config | 4 +- web/Web.csproj | 26 +++++---- .../Blogs}/BlogHelper.cs | 5 +- .../Blogs}/BlogManager.cs | 2 +- .../Blogs}/BlogProvider.cs | 0 .../BlogProviderConfigurationElement.cs | 2 +- .../BlogProvidersConfigurationCollection.cs | 2 +- .../BlogProvidersConfigurationSection.cs | 2 +- .../WorkFlow}/Configuration/Provider.cs | 2 +- .../Configuration/ProviderCollection.cs | 2 +- .../Configuration/WorkflowConfiguration.cs | 2 +- .../WorkFlow/WorkFlowManager.cs | 15 ++++- yavscModel/YavscModel.csproj | 12 +++- 38 files changed, 149 insertions(+), 117 deletions(-) rename web/Views/{Account => Admin}/AddRole.aspx (89%) rename web/Views/{Account => Admin}/Admin.aspx (94%) rename web/Views/{BackOffice => Admin}/BackupCreated.aspx (100%) rename web/Views/{BackOffice => Admin}/Backups.aspx (58%) rename web/Views/{BackOffice => Admin}/CreateBackup.aspx (94%) rename web/Views/{BackOffice => Admin}/Index.aspx (79%) rename web/Views/{Account => Admin}/RemoveRoleQuery.aspx (100%) rename web/Views/{Account => Admin}/RemoveUserQuery.aspx (93%) rename web/Views/{BackOffice => Admin}/Restore.aspx (95%) rename web/Views/{BackOffice => Admin}/Restored.aspx (100%) rename web/Views/{Account => Admin}/RoleList.aspx (100%) rename web/Views/{Account => Admin}/UserList.aspx (100%) create mode 100644 web/Views/BackOffice/Estimate.aspx rename {NpgsqlBlogProvider => yavscModel/Blogs}/BlogHelper.cs (92%) rename {NpgsqlBlogProvider => yavscModel/Blogs}/BlogManager.cs (98%) rename {NpgsqlBlogProvider => yavscModel/Blogs}/BlogProvider.cs (100%) rename {NpgsqlBlogProvider => yavscModel/Blogs}/Configuration/BlogProviderConfigurationElement.cs (96%) rename {NpgsqlBlogProvider => yavscModel/Blogs}/Configuration/BlogProvidersConfigurationCollection.cs (93%) rename {NpgsqlBlogProvider => yavscModel/Blogs}/Configuration/BlogProvidersConfigurationSection.cs (95%) rename {WorkFlowProvider => yavscModel/WorkFlow}/Configuration/Provider.cs (94%) rename {WorkFlowProvider => yavscModel/WorkFlow}/Configuration/ProviderCollection.cs (90%) rename {WorkFlowProvider => yavscModel/WorkFlow}/Configuration/WorkflowConfiguration.cs (94%) rename WorkFlowProvider/WFManager.cs => yavscModel/WorkFlow/WorkFlowManager.cs (89%) diff --git a/NpgsqlBlogProvider/NpgsqlBlogProvider.csproj b/NpgsqlBlogProvider/NpgsqlBlogProvider.csproj index 70a0e7bf..6992eeee 100644 --- a/NpgsqlBlogProvider/NpgsqlBlogProvider.csproj +++ b/NpgsqlBlogProvider/NpgsqlBlogProvider.csproj @@ -30,12 +30,6 @@ - - - - - - diff --git a/SalesCatalog/SalesCatalog.csproj b/SalesCatalog/SalesCatalog.csproj index ed2eb8bd..84c1e97f 100644 --- a/SalesCatalog/SalesCatalog.csproj +++ b/SalesCatalog/SalesCatalog.csproj @@ -31,9 +31,7 @@ - - nunit - + diff --git a/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs b/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs index bd410b76..95b18e5d 100644 --- a/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs +++ b/SalesCatalog/XmlImplementation/XmlCatalogProvider.cs @@ -15,13 +15,16 @@ namespace SalesCatalog.XmlImplementation { // Assert fileName != null FileInfo fi = new FileInfo (fileName); + if (!fi.Exists) + throw new ConfigurationErrorsException( + string.Format("No catalog found ({0})",fileName)); if (fi.LastWriteTime > lastModification) LoadCatalog (); return catInstance; } protected XmlCatalog catInstance = null; - protected DateTime lastModification; + protected DateTime lastModification = new DateTime(0); protected string fileName = null; #endregion @@ -32,8 +35,9 @@ namespace SalesCatalog.XmlImplementation } private void LoadCatalog () { + try { FileInfo fi = new FileInfo (fileName); - if (!fi.Exists) + if (!fi.Exists) throw new Exception ( string.Format ("Le fichier Xml decrivant le catalogue n'existe pas ({0})", fi.FullName)); XmlSerializer xsr = new XmlSerializer (typeof(XmlCatalog),new Type[]{ @@ -49,6 +53,11 @@ namespace SalesCatalog.XmlImplementation } fileName = fi.FullName; lastModification = fi.LastWriteTime; + } + catch (Exception e) { + lastModification = new DateTime (0); + throw e; + } } } } diff --git a/WorkFlowProvider/WorkFlowProvider.csproj b/WorkFlowProvider/WorkFlowProvider.csproj index a202af3c..c8f6968e 100644 --- a/WorkFlowProvider/WorkFlowProvider.csproj +++ b/WorkFlowProvider/WorkFlowProvider.csproj @@ -38,10 +38,6 @@ - - - - @@ -50,7 +46,4 @@ YavscModel - - - \ No newline at end of file diff --git a/web/Controllers/AdminController.cs b/web/Controllers/AdminController.cs index 311d3e01..985f1fcc 100644 --- a/web/Controllers/AdminController.cs +++ b/web/Controllers/AdminController.cs @@ -6,11 +6,68 @@ using System.Web.Mvc; using System.Web.Mvc.Ajax; using System.Web.Security; using Yavsc.Model.RolesAndMembers; +using Yavsc.Model.Admin; namespace Yavsc.Controllers { public class AdminController : Controller { + [Authorize(Roles="Admin")] + public ActionResult Index(DataAccess model) + { + return View (model); + } + + [Authorize(Roles="Admin")] + public ActionResult Backups(DataAccess model) + { + return View (model); + } + + [Authorize(Roles="Admin")] + public ActionResult CreateBackup(DataAccess datac) + { + if (datac != null) { + if (ModelState.IsValid) { + if (string.IsNullOrEmpty (datac.Password)) + ModelState.AddModelError ("Password", "Invalid passord"); + DataManager ex = new DataManager (datac); + Export e = ex.CreateBackup (); + if (e.ExitCode > 0) + ModelState.AddModelError ("Password", "Operation Failed"); + return View ("BackupCreated", e); + } + } else { + datac = new DataAccess (); + } + return View (datac); + } + + [Authorize(Roles="Admin")] + public ActionResult CreateUserBackup(DataAccess datac,string username) + { + throw new NotImplementedException(); + } + + [Authorize(Roles="Admin")] + public ActionResult Upgrade(DataAccess datac) { + throw new NotImplementedException(); + } + + [Authorize(Roles="Admin")] + public ActionResult Restore(DataAccess datac,string backupName,bool dataOnly=true) + { + ViewData ["BackupName"] = backupName; + if (ModelState.IsValid) { + DataManager mgr = new DataManager (datac); + ViewData ["BackupName"] = backupName; + ViewData ["DataOnly"] = dataOnly; + TaskOutput t = mgr.Restore (backupName,dataOnly); + return View ("Restored", t); + } + return View (datac); + } + [Authorize(Roles="Admin")] public ActionResult RemoveFromRole(string username, string rolename, string returnUrl) { diff --git a/web/Controllers/BackOfficeController.cs b/web/Controllers/BackOfficeController.cs index ede9f896..85ba60ee 100644 --- a/web/Controllers/BackOfficeController.cs +++ b/web/Controllers/BackOfficeController.cs @@ -4,69 +4,18 @@ using System.Linq; using System.Web; using System.Web.Mvc; using Yavsc.Admin; -using Yavsc.Model.Admin; namespace Yavsc.Controllers { public class BackOfficeController : Controller { - [Authorize(Roles="Admin")] - public ActionResult Index(DataAccess model) + public ActionResult Estimate() { - return View (model); - } - [Authorize(Roles="Admin")] - public ActionResult Backups(DataAccess model) - { - return View (model); - } - - [Authorize(Roles="Admin")] - public ActionResult CreateBackup(DataAccess datac) - { - if (datac != null) { - if (ModelState.IsValid) { - if (string.IsNullOrEmpty (datac.Password)) - ModelState.AddModelError ("Password", "Invalid passord"); - DataManager ex = new DataManager (datac); - Export e = ex.CreateBackup (); - if (e.ExitCode > 0) - ModelState.AddModelError ("Password", "Operation Failed"); - return View ("BackupCreated", e); - } - } else { - datac = new DataAccess (); - } - return View (datac); - } - - [Authorize(Roles="Admin")] - public ActionResult CreateUserBackup(DataAccess datac,string username) - { - throw new NotImplementedException(); } - [Authorize(Roles="Admin")] - public ActionResult Upgrade(DataAccess datac) { - throw new NotImplementedException(); - } - - [Authorize(Roles="Admin")] - public ActionResult Restore(DataAccess datac,string backupName,bool dataOnly=true) + public ActionResult Index () { - ViewData ["BackupName"] = backupName; - if (ModelState.IsValid) { - DataManager mgr = new DataManager (datac); - ViewData ["BackupName"] = backupName; - ViewData ["DataOnly"] = dataOnly; - TaskOutput t = mgr.Restore (backupName,dataOnly); - return View ("Restored", t); - } - return View (datac); } - - /*[Authorize(Roles="Admin")] - public ActionResult Estimate*/ } } diff --git a/web/Controllers/BasketController.cs b/web/Controllers/BasketController.cs index 8dd99552..2b74b7a7 100644 --- a/web/Controllers/BasketController.cs +++ b/web/Controllers/BasketController.cs @@ -42,7 +42,7 @@ namespace Yavsc.ApiControllers [Authorize] public Estimate[] YourEstimates() { - return WorkFlowProvider.WFManager.GetEstimates ( + return WorkFlowManager.GetEstimates ( Membership.GetUser().UserName); } diff --git a/web/Controllers/FrontOfficeApiController.cs b/web/Controllers/FrontOfficeApiController.cs index 830f65b3..0b3a0e75 100644 --- a/web/Controllers/FrontOfficeApiController.cs +++ b/web/Controllers/FrontOfficeApiController.cs @@ -73,7 +73,7 @@ namespace Yavsc.ApiControllers /// Estid. public Estimate GetEstimate (long estid) { - Estimate est = WFManager.ContentProvider.GetEstimate (estid); + Estimate est = WorkFlowManager.ContentProvider.GetEstimate (estid); return est; } diff --git a/web/Controllers/FrontOfficeController.cs b/web/Controllers/FrontOfficeController.cs index 1518e7e2..43b011d4 100644 --- a/web/Controllers/FrontOfficeController.cs +++ b/web/Controllers/FrontOfficeController.cs @@ -22,7 +22,7 @@ namespace Yavsc.Controllers { if (ModelState.IsValid) { if (e.Id > 0) { - Estimate f = WFManager.GetEstimate (e.Id); + Estimate f = WorkFlowManager.GetEstimate (e.Id); if (e.Owner != f.Owner) if (!Roles.IsUserInRole ("FrontOffice")) throw new UnauthorizedAccessException ("You're not allowed to modify this estimate"); diff --git a/web/Controllers/WorkFlowController.cs b/web/Controllers/WorkFlowController.cs index 6e06f6c4..80d85b03 100644 --- a/web/Controllers/WorkFlowController.cs +++ b/web/Controllers/WorkFlowController.cs @@ -29,7 +29,7 @@ namespace Yavsc.ApiControllers [Authorize] public long CreateEstimate (string title) { - return WFManager.CreateEstimate ( + return WorkFlowManager.CreateEstimate ( Membership.GetUser().UserName,title); } @@ -37,20 +37,20 @@ namespace Yavsc.ApiControllers [Authorize] public void DropWritting(long wrid) { - WFManager.DropWritting (wrid); + WorkFlowManager.DropWritting (wrid); } [HttpGet] [Authorize] public void UpdateWritting(Writting wr) { - WFManager.UpdateWritting (wr); + WorkFlowManager.UpdateWritting (wr); } [HttpGet] [Authorize] public void DropEstimate(long estid) { - WFManager.DropEstimate (estid); + WorkFlowManager.DropEstimate (estid); } [HttpGet] [Authorize] @@ -68,7 +68,7 @@ namespace Yavsc.ApiControllers 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); + return WorkFlowManager.Write(estid, desc, ucost, count, productid); } diff --git a/web/Views/Account/AddRole.aspx b/web/Views/Admin/AddRole.aspx similarity index 89% rename from web/Views/Account/AddRole.aspx rename to web/Views/Admin/AddRole.aspx index 772712ac..a4a0003c 100644 --- a/web/Views/Account/AddRole.aspx +++ b/web/Views/Admin/AddRole.aspx @@ -2,7 +2,7 @@ <%= Html.ValidationSummary() %> -<% using(Html.BeginForm("DoAddRole", "Account")) %> +<% using(Html.BeginForm("DoAddRole")) %> <% { %> Nom du rôle : <%= Html.TextBox( "RoleName" ) %> diff --git a/web/Views/Account/Admin.aspx b/web/Views/Admin/Admin.aspx similarity index 94% rename from web/Views/Account/Admin.aspx rename to web/Views/Admin/Admin.aspx index a50a8f0a..36e5186a 100644 --- a/web/Views/Account/Admin.aspx +++ b/web/Views/Admin/Admin.aspx @@ -17,7 +17,7 @@

<%= Html.ValidationSummary() %>

-<% using ( Html.BeginForm("Admin", "Account") ) { %> +<% using ( Html.BeginForm("Admin", "Admin") ) { %> <%= Html.LabelFor(model => model.UserName) %> : <%= Html.DropDownListFor(model => model.UserName, (List)ViewData["useritems"] ) %> diff --git a/web/Views/BackOffice/BackupCreated.aspx b/web/Views/Admin/BackupCreated.aspx similarity index 100% rename from web/Views/BackOffice/BackupCreated.aspx rename to web/Views/Admin/BackupCreated.aspx diff --git a/web/Views/BackOffice/Backups.aspx b/web/Views/Admin/Backups.aspx similarity index 58% rename from web/Views/BackOffice/Backups.aspx rename to web/Views/Admin/Backups.aspx index a11783cd..45f6437f 100644 --- a/web/Views/BackOffice/Backups.aspx +++ b/web/Views/Admin/Backups.aspx @@ -1,6 +1,6 @@ <%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> -<%=Html.ActionLink("Create a database backup", "CreateBackup", "BackOffice")%>
-<%=Html.ActionLink("Restaurations", "Restore", "BackOffice")%>
+<%=Html.ActionLink("Create a database backup", "CreateBackup")%>
+<%=Html.ActionLink("Restaurations", "Restore")%>
diff --git a/web/Views/BackOffice/CreateBackup.aspx b/web/Views/Admin/CreateBackup.aspx similarity index 94% rename from web/Views/BackOffice/CreateBackup.aspx rename to web/Views/Admin/CreateBackup.aspx index c9d9ab6e..0f2f22c1 100644 --- a/web/Views/BackOffice/CreateBackup.aspx +++ b/web/Views/Admin/CreateBackup.aspx @@ -1,7 +1,7 @@ <%@ Page Title="Backup creation" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> <%= Html.ValidationSummary("CreateBackup") %> -<% using (Html.BeginForm("CreateBackup","BackOffice")) { %> +<% using (Html.BeginForm("CreateBackup")) { %> <%= Html.LabelFor(model => model.Host) %>: <%= Html.TextBox( "Host" ) %> diff --git a/web/Views/BackOffice/Index.aspx b/web/Views/Admin/Index.aspx similarity index 79% rename from web/Views/BackOffice/Index.aspx rename to web/Views/Admin/Index.aspx index 4840f5bd..a97e5e3a 100644 --- a/web/Views/BackOffice/Index.aspx +++ b/web/Views/Admin/Index.aspx @@ -1,4 +1,4 @@ <%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> -<%= Html.ActionLink("Backups","Backups","BackOffice") %> +<%= Html.ActionLink("Backups","Backups") %> diff --git a/web/Views/Account/RemoveRoleQuery.aspx b/web/Views/Admin/RemoveRoleQuery.aspx similarity index 100% rename from web/Views/Account/RemoveRoleQuery.aspx rename to web/Views/Admin/RemoveRoleQuery.aspx diff --git a/web/Views/Account/RemoveUserQuery.aspx b/web/Views/Admin/RemoveUserQuery.aspx similarity index 93% rename from web/Views/Account/RemoveUserQuery.aspx rename to web/Views/Admin/RemoveUserQuery.aspx index 8e5fd740..235d212d 100644 --- a/web/Views/Account/RemoveUserQuery.aspx +++ b/web/Views/Admin/RemoveUserQuery.aspx @@ -7,7 +7,7 @@
<%= Html.ValidationSummary() %> -<% using ( Html.BeginForm("RemoveUser","Account") ) { %> +<% using ( Html.BeginForm("RemoveUser") ) { %> Supprimer l'utilisateur <%= Html.Encode( ViewData["usertoremove"] ) %> ?
diff --git a/web/Views/BackOffice/Restore.aspx b/web/Views/Admin/Restore.aspx similarity index 95% rename from web/Views/BackOffice/Restore.aspx rename to web/Views/Admin/Restore.aspx index ce2c1ba4..2e6853b2 100644 --- a/web/Views/BackOffice/Restore.aspx +++ b/web/Views/Admin/Restore.aspx @@ -1,7 +1,7 @@ <%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> <%= Html.ValidationSummary("Restore a database backup") %> -<% using (Html.BeginForm("Restore","BackOffice")) { %> +<% using (Html.BeginForm("Restore")) { %> <% string [] bckdirs = Model.GetBackupDirs(); %>