refactoring

vnext
Paul Schneider 10 years ago
parent 347ffc8a5a
commit b5d19c5da6
38 changed files with 149 additions and 117 deletions

@ -30,12 +30,6 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="Configuration\BlogProviderConfigurationElement.cs" />
<Compile Include="Configuration\BlogProvidersConfigurationCollection.cs" />
<Compile Include="Configuration\BlogProvidersConfigurationSection.cs" />
<Compile Include="BlogHelper.cs" />
<Compile Include="BlogManager.cs" />
<Compile Include="BlogProvider.cs" />
<Compile Include="NpgsqlBlogProvider.cs" />
<Compile Include="AssemblyInfo.cs" />
</ItemGroup>

@ -31,9 +31,7 @@
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77">
<Package>nunit</Package>
</Reference>
<Reference Include="nunit.framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

@ -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,6 +35,7 @@ namespace SalesCatalog.XmlImplementation
}
private void LoadCatalog ()
{
try {
FileInfo fi = new FileInfo (fileName);
if (!fi.Exists)
throw new Exception (
@ -50,6 +54,11 @@ namespace SalesCatalog.XmlImplementation
fileName = fi.FullName;
lastModification = fi.LastWriteTime;
}
catch (Exception e) {
lastModification = new DateTime (0);
throw e;
}
}
}
}

@ -38,10 +38,6 @@
<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>
@ -50,7 +46,4 @@
<Name>YavscModel</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration\" />
</ItemGroup>
</Project>

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

@ -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)
public ActionResult Index ()
{
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 Estimate*/
}
}

@ -42,7 +42,7 @@ namespace Yavsc.ApiControllers
[Authorize]
public Estimate[] YourEstimates()
{
return WorkFlowProvider.WFManager.GetEstimates (
return WorkFlowManager.GetEstimates (
Membership.GetUser().UserName);
}

@ -73,7 +73,7 @@ namespace Yavsc.ApiControllers
/// <param name="estid">Estid.</param>
public Estimate GetEstimate (long estid)
{
Estimate est = WFManager.ContentProvider.GetEstimate (estid);
Estimate est = WorkFlowManager.ContentProvider.GetEstimate (estid);
return est;
}

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

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

@ -2,7 +2,7 @@
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<%= Html.ValidationSummary() %>
<% using(Html.BeginForm("DoAddRole", "Account")) %>
<% using(Html.BeginForm("DoAddRole")) %>
<% { %>
Nom du rôle :
<%= Html.TextBox( "RoleName" ) %>

@ -17,7 +17,7 @@
</h2>
<p><%= Html.ValidationSummary() %> </p>
<% using ( Html.BeginForm("Admin", "Account") ) { %>
<% using ( Html.BeginForm("Admin", "Admin") ) { %>
<%= Html.LabelFor(model => model.UserName) %> :
<%= Html.DropDownListFor(model => model.UserName, (List<SelectListItem>)ViewData["useritems"] ) %>

@ -1,6 +1,6 @@
<%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<%=Html.ActionLink("Create a database backup", "CreateBackup", "BackOffice")%><br/>
<%=Html.ActionLink("Restaurations", "Restore", "BackOffice")%><br/>
<%=Html.ActionLink("Create a database backup", "CreateBackup")%><br/>
<%=Html.ActionLink("Restaurations", "Restore")%><br/>
</asp:Content>

@ -1,7 +1,7 @@
<%@ Page Title="Backup creation" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.ValidationSummary("CreateBackup") %>
<% using (Html.BeginForm("CreateBackup","BackOffice")) { %>
<% using (Html.BeginForm("CreateBackup")) { %>
<%= Html.LabelFor(model => model.Host) %>:
<%= Html.TextBox( "Host" ) %>

@ -1,4 +1,4 @@
<%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.ActionLink("Backups","Backups","BackOffice") %>
<%= Html.ActionLink("Backups","Backups") %>
</asp:Content>

@ -7,7 +7,7 @@
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<div>
<%= Html.ValidationSummary() %>
<% using ( Html.BeginForm("RemoveUser","Account") ) { %>
<% using ( Html.BeginForm("RemoveUser") ) { %>
Supprimer l'utilisateur
<%= Html.Encode( ViewData["usertoremove"] ) %> ?
<br/>

@ -1,7 +1,7 @@
<%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<DataAccess>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
<%= Html.ValidationSummary("Restore a database backup") %>
<% using (Html.BeginForm("Restore","BackOffice")) { %>
<% using (Html.BeginForm("Restore")) { %>
<% string [] bckdirs = Model.GetBackupDirs(); %>
<select name="backupName">

@ -0,0 +1,12 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>

@ -1,4 +1,4 @@
<%@ Page Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection collection>" %>
<%@ Page Title="Commande" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage<FormCollection collection>" %>
<asp:Content ID="MainContentContent" ContentPlaceHolderID="MainContent" runat="server">
</asp:Content>

@ -1,6 +1,6 @@
<%@ Page Title="Catalog" Language="C#" Inherits="System.Web.Mvc.ViewPage<Service>" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="init" ID="init1" runat="server">
<%= Title = ViewData ["BrandName"] + " " + Model.Name; %>
<% Title = ViewData ["BrandName"] + " " + Model.Name; %>
</asp:Content>
<asp:Content ContentPlaceHolderID="header" ID="headerContent" runat="server">
<h2> <%=ViewData ["ProdCatName"]%> - <%= Html.ActionLink( Model.Name, "Product", new { id = ViewData ["BrandName"], pc = ViewData ["ProdCatRef"] , pref = Model.Reference } ) %></h2>

@ -20,10 +20,10 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
</sectionGroup>
</sectionGroup>
<sectionGroup name="system.web">
<section name="blog" type="Npgsql.Web.Blog.Configuration.BlogProvidersConfigurationSection, NpgsqlBlogProvider" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
<section name="blog" type="Yavsc.Model.Blogs.Configuration.BlogProvidersConfigurationSection, YavscModel" 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" />
<section name="workflow" type="Yavsc.Model.WorkFlow.Configuration.WorkflowConfiguration, YavscModel" allowLocation="true" requirePermission="false" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
<!-- <runtime>

@ -103,6 +103,7 @@
<Folder Include="Views\FileSystem\" />
<Folder Include="CatExts\" />
<Folder Include="Views\WorkFlow\" />
<Folder Include="Views\Admin\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
@ -147,10 +148,7 @@
<Content Include="Views\Account\ChangePassword.aspx" />
<Content Include="Views\Account\ChangePasswordSuccess.aspx" />
<Content Include="Views\Account\Index.aspx" />
<Content Include="Views\Account\UserList.aspx" />
<Content Include="Views\Account\Login.aspx" />
<Content Include="Views\Account\RoleList.aspx" />
<Content Include="Views\Account\Admin.aspx" />
<Content Include="images\Banner.png" />
<Content Include="images\noavatar.png" />
<Content Include="images\apache_pbw.png" />
@ -161,9 +159,6 @@
<Content Include="Views\Blogs\UserPosts.aspx" />
<Content Include="Views\Blogs\UserPost.aspx" />
<Content Include="Views\Blogs\Edit.aspx" />
<Content Include="Views\Account\RemoveUserQuery.aspx" />
<Content Include="Views\Account\RemoveRoleQuery.aspx" />
<Content Include="Views\Account\AddRole.aspx" />
<Content Include="Views\Blogs\Error.aspx" />
<Content Include="Views\Account\RegistrationPending.aspx" />
<Content Include="Views\Account\Validate.aspx" />
@ -172,15 +167,9 @@
<Content Include="Views\Blogs\TitleNotFound.aspx" />
<Content Include="Views\FrontOffice\ProductCategory.aspx" />
<Content Include="Views\FrontOffice\Product.aspx" />
<Content Include="Views\BackOffice\BackupCreated.aspx" />
<Content Include="Views\BackOffice\Index.aspx" />
<Content Include="Views\BackOffice\Restore.aspx" />
<Content Include="Views\Home\AOEMail.aspx" />
<Content Include="errors\GeneralError.aspx" />
<Content Include="errors\PageNotFound.aspx" />
<Content Include="Views\BackOffice\Restored.aspx" />
<Content Include="Views\BackOffice\Backups.aspx" />
<Content Include="Views\BackOffice\CreateBackup.aspx" />
<Content Include="Views\FrontOffice\Service.aspx" />
<Content Include="Views\FrontOffice\ReferenceNotFound.aspx" />
<Content Include="Views\FileSystem\Delete.aspx" />
@ -193,6 +182,19 @@
<Content Include="Views\WorkFlow\NewProject.aspx" />
<Content Include="Views\WorkFlow\Index.aspx" />
<Content Include="Views\Blogs\RemovePost.aspx" />
<Content Include="Views\Admin\Admin.aspx" />
<Content Include="Views\Admin\AddRole.aspx" />
<Content Include="Views\Admin\UserList.aspx" />
<Content Include="Views\Admin\RemoveRoleQuery.aspx" />
<Content Include="Views\Admin\RemoveUserQuery.aspx" />
<Content Include="Views\Admin\RoleList.aspx" />
<Content Include="Views\BackOffice\Estimate.aspx" />
<Content Include="Views\Admin\CreateBackup.aspx" />
<Content Include="Views\Admin\BackupCreated.aspx" />
<Content Include="Views\Admin\Backups.aspx" />
<Content Include="Views\Admin\Restore.aspx" />
<Content Include="Views\Admin\Restored.aspx" />
<Content Include="Views\Admin\Index.aspx" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

@ -2,10 +2,9 @@ using System;
using System.Configuration;
using System.Reflection;
using System.Collections.Specialized;
using Npgsql.Web.Blog.Configuration;
using Yavsc.Model.Blogs;
using Yavsc.Model.Blogs.Configuration;
namespace Npgsql.Web.Blog
namespace Yavsc.Model.Blogs
{
public static class BlogHelper
{

@ -2,7 +2,7 @@ using System;
using Yavsc.Model.Blogs;
namespace Npgsql.Web.Blog
namespace Yavsc.Model.Blogs
{
public static class BlogManager
{

@ -2,7 +2,7 @@ using System;
using System.Configuration;
using System.ComponentModel;
namespace Npgsql.Web.Blog.Configuration
namespace Yavsc.Model.Blogs.Configuration
{
public class BlogProviderConfigurationElement : ConfigurationElement

@ -2,7 +2,7 @@ using System;
using System.Configuration;
using System.ComponentModel;
namespace Npgsql.Web.Blog.Configuration
namespace Yavsc.Model.Blogs.Configuration
{
public class BlogProvidersConfigurationCollection : ConfigurationElementCollection
{

@ -2,7 +2,7 @@ using System;
using System.Configuration;
using System.ComponentModel;
namespace Npgsql.Web.Blog.Configuration
namespace Yavsc.Model.Blogs.Configuration
{
public class BlogProvidersConfigurationSection : ConfigurationSection
{

@ -1,7 +1,7 @@
using System;
using System.Configuration;
namespace WorkFlowProvider.Configuration
namespace Yavsc.Model.WorkFlow.Configuration
{
public class WFProvider:ConfigurationElement
{

@ -1,7 +1,7 @@
using System;
using System.Configuration;
namespace WorkFlowProvider.Configuration
namespace Yavsc.Model.WorkFlow.Configuration
{
public class WFProviderCollection : ConfigurationElementCollection
{

@ -1,7 +1,7 @@
using System;
using System.Configuration;
namespace WorkFlowProvider.Configuration
namespace Yavsc.Model.WorkFlow.Configuration
{
public class WorkflowConfiguration : ConfigurationSection
{

@ -1,21 +1,30 @@
using System;
using Yavsc.Model.WorkFlow;
using System.Configuration;
using WorkFlowProvider.Configuration;
using Yavsc.Model.WorkFlow.Configuration;
using System.Collections.Specialized;
namespace WorkFlowProvider
namespace Yavsc.Model.WorkFlow
{
public static class WFManager
/// <summary>
/// Work flow manager.
/// It takes orders store them and raise some events for modules
/// It publishes estimates and invoices
/// </summary>
public static class WorkFlowManager
{
public static event EventHandler NewOrder;
public static Estimate GetEstimate (long estid)
{
return ContentProvider.GetEstimate (estid);
}
public static Estimate [] GetEstimates (string client)
{
return ContentProvider.GetEstimates (client);
}
public static void UpdateWritting (Writting wr)
{
ContentProvider.UpdateWritting (wr);

@ -8,7 +8,7 @@
<ProjectGuid>{68F5B80A-616E-4C3C-91A0-828AA40000BD}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>yavscModel</RootNamespace>
<AssemblyName>yavscModel</AssemblyName>
<AssemblyName>YavscModel</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -67,6 +67,16 @@
<Compile Include="IModule.cs" />
<Compile Include="WorkFlow\BasketImpact.cs" />
<Compile Include="WorkFlow\Commande.cs" />
<Compile Include="Blogs\BlogManager.cs" />
<Compile Include="Blogs\BlogProvider.cs" />
<Compile Include="WorkFlow\WorkFlowManager.cs" />
<Compile Include="WorkFlow\Configuration\Provider.cs" />
<Compile Include="WorkFlow\Configuration\ProviderCollection.cs" />
<Compile Include="WorkFlow\Configuration\WorkflowConfiguration.cs" />
<Compile Include="Blogs\BlogHelper.cs" />
<Compile Include="Blogs\Configuration\BlogProviderConfigurationElement.cs" />
<Compile Include="Blogs\Configuration\BlogProvidersConfigurationCollection.cs" />
<Compile Include="Blogs\Configuration\BlogProvidersConfigurationSection.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>

Loading…