* Web.csproj:

* LocalizedText.resx:
* SimpleFormatter.cs:
* TemplateException.cs:
* ErrorHtmlFormatter.cs:
* LocalizedText.Designer.cs:
* WorkFlowManager.cs: 

* Makefile: refactoring

* FrontOfficeApiController.cs: nice html error response in case of
  error at rendering a tex or pdf document 

* LocalizedText.fr.resx: Gives as title at rendering a template
  processing error
vnext
Paul Schneider 10 years ago
parent e847248366
commit 2f6146c0f7
10 changed files with 163 additions and 13 deletions

@ -3,8 +3,8 @@ VERSION=1.1
CONFIG=Debug CONFIG=Debug
DESTDIR=build/web/$(CONFIG) DESTDIR=build/web/$(CONFIG)
COPYUNCHANGED="false" COPYUNCHANGED="false"
PREPRODHOST=yavsc.localdomain PREPRODHOSTDIR=localhost:/srv/www/yavsc
PRODHOSTDIR=localhost:/srv/www/lua
all: deploy all: deploy
ddir: ddir:
@ -25,13 +25,10 @@ clean:
rm -rf $(DESTDIR) rm -rf $(DESTDIR)
rsync-preprod: deploy rsync-preprod: deploy
rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOST):/srv/www/yavsc rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOSTDIR)
rsync-prod: deploy rsync-prod: deploy
rsync -ravu build/web/$(CONFIG)/ root@$(PREPRODHOST):/srv/www/lua rsync -ravu build/web/$(CONFIG)/ root@$(PRODHOSTDIR)
rsync-local:
rsync -ravu build/web/$(CONFIG)/ root@localhost:/srv/www/yavsc
sourcepkg: sourcepkg:
git archive --format=tar --prefix=yavsc-$(CONFIG)/ $(CONFIG) | bzip2 > yavsc-$(CONFIG).tar.bz2 git archive --format=tar --prefix=yavsc-$(CONFIG)/ $(CONFIG) | bzip2 > yavsc-$(CONFIG).tar.bz2

@ -22,6 +22,7 @@ using Yavsc.Formatters;
using System.Text; using System.Text;
using System.Web.Profile; using System.Web.Profile;
using System.Collections.Specialized; using System.Collections.Specialized;
using Yavsc.Model;
namespace Yavsc.ApiControllers namespace Yavsc.ApiControllers
{ {
@ -102,9 +103,28 @@ namespace Yavsc.ApiControllers
[AcceptVerbs("GET")] [AcceptVerbs("GET")]
public HttpResponseMessage GetEstimTex(long estimid) public HttpResponseMessage GetEstimTex(long estimid)
{ {
string texest = getEstimTex (estimid); string texest = null;
try {
texest = getEstimTex (estimid);
}
catch (TemplateException ex) {
return new HttpResponseMessage (HttpStatusCode.OK){ Content =
new ObjectContent (typeof(string),
ex.Message, new ErrorHtmlFormatter(HttpStatusCode.NotAcceptable,
LocalizedText.DocTemplateException
))};
}
catch (Exception ex) {
return new HttpResponseMessage (HttpStatusCode.OK){ Content =
new ObjectContent (typeof(string),
ex.Message, new SimpleFormatter("text/text")) };
}
if (texest == null) if (texest == null)
throw new HttpRequestValidationException ("Not an estimation id:"+estimid); return new HttpResponseMessage (HttpStatusCode.OK) { Content =
new ObjectContent (typeof(string),
"Not an estimation id:" + estimid, new SimpleFormatter ("text/text"))
};
return new HttpResponseMessage () { return new HttpResponseMessage () {
Content = new ObjectContent (typeof(string), Content = new ObjectContent (typeof(string),
texest, texest,
@ -121,11 +141,11 @@ namespace Yavsc.ApiControllers
Profile prpro = new Profile(ProfileBase.Create(e.Responsible)); Profile prpro = new Profile(ProfileBase.Create(e.Responsible));
if (!prpro.IsBankable) if (!prpro.IsBankable)
throw new Exception ("NotBankable:"+e.Responsible); throw new TemplateException ("NotBankable:"+e.Responsible);
Profile prcli = new Profile(ProfileBase.Create(e.Client)); Profile prcli = new Profile(ProfileBase.Create(e.Client));
if (!prcli.IsBillable) if (!prcli.IsBillable)
throw new Exception ("NotBillable:"+e.Client); throw new TemplateException ("NotBillable:"+e.Client);
tmpe.Session.Add ("from", prpro); tmpe.Session.Add ("from", prpro);
tmpe.Session.Add ("to", prcli); tmpe.Session.Add ("to", prcli);
tmpe.Init (); tmpe.Init ();

@ -0,0 +1,40 @@
using System;
using Yavsc;
using SalesCatalog;
using SalesCatalog.Model;
using System.Web.Routing;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Web.Http;
using System.Net.Http;
using System.Web;
using System.Linq;
using System.IO;
using System.Net;
using WorkFlowProvider;
using System.Web.Security;
using Yavsc.Model.WorkFlow;
using System.Reflection;
using System.Collections.Generic;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Controllers;
using Yavsc.Formatters;
using System.Text;
using System.Web.Profile;
using System.Collections.Specialized;
namespace Yavsc.ApiControllers
{
class TemplateException : Exception
{
public TemplateException(string message):base(message)
{
}
public TemplateException(string message,Exception innerException):base(message,innerException)
{
}
}
}

@ -0,0 +1,74 @@
//
// ErrorHtmlFormatter.cs
//
// Author:
// paul <${AuthorEmail}>
//
// Copyright (c) 2015 paul
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Web.Mvc;
using System.Net;
namespace Yavsc.Formatters
{
public class ErrorHtmlFormatter:SimpleFormatter {
public string Title { get ; set; }
public HttpStatusCode ErrorCode { get ; set; }
string doctype="<!DOCTYPE html>";
public ErrorHtmlFormatter
(HttpStatusCode errorCode, string title):base("text/html")
{
ErrorCode = errorCode;
Title = title;
}
public override void WriteToStream (Type type, object value, Stream stream, HttpContentHeaders contentHeaders)
{
// TODO create a type containing T4 parameters, and generate from them
using (var writer = new StreamWriter(stream))
{
string message = value as string;
TagBuilder doc = new TagBuilder ("html");
TagBuilder body = new TagBuilder ("body");
TagBuilder h1 = new TagBuilder ("h1");
TagBuilder p = new TagBuilder ("p");
TagBuilder head = new TagBuilder ("head");
head.InnerHtml = "<meta http-equiv=\"Content-Type\" " +
"content=\"text/html; charset=utf-8\"/>" +
"<link rel=\"stylesheet\" " +
"href=\"/Theme/style.css\" />" +
"<link rel=\"icon\" type=\"image/png\"" +
" href=\"/favicon.png\" />";
p.InnerHtml = MvcHtmlString.Create (message).ToHtmlString();
h1.InnerHtml = MvcHtmlString.Create (Title).ToHtmlString();
body.InnerHtml = h1.ToString()+p.ToString ();
doc.InnerHtml = head.ToString()+"\n"+body.ToString ();
writer.WriteLine (doctype);
writer.Write (doc.ToString());
}
}
}
}

@ -24,6 +24,8 @@ using System.Net.Http.Headers;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Web.Mvc;
using System.Net;
namespace Yavsc.Formatters namespace Yavsc.Formatters
{ {
@ -63,5 +65,6 @@ namespace Yavsc.Formatters
} }
} }
} }

@ -172,6 +172,8 @@
<Compile Include="Helpers\Google\EntityQuery.cs" /> <Compile Include="Helpers\Google\EntityQuery.cs" />
<Compile Include="Helpers\Google\ApiClient.cs" /> <Compile Include="Helpers\Google\ApiClient.cs" />
<Compile Include="Helpers\Google\Calendar.cs" /> <Compile Include="Helpers\Google\Calendar.cs" />
<Compile Include="Controllers\TemplateException.cs" />
<Compile Include="Formatters\ErrorHtmlFormatter.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Views\Web.config" /> <Content Include="Views\Web.config" />
@ -639,7 +641,7 @@
<Policies> <Policies>
<DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedFlat" ResourceNamePolicy="FileFormatDefault" /> <DotNetNamingPolicy DirectoryNamespaceAssociation="PrefixedFlat" ResourceNamePolicy="FileFormatDefault" />
</Policies> </Policies>
<XspParameters Port="8080" Address="127.0.0.1" SslMode="None" SslProtocol="Default" KeyType="None" CertFile="" KeyFile="" PasswordOptions="None" Password="" Verbose="True" /> <XspParameters Port="8080" Address="192.168.0.47" SslMode="None" SslProtocol="Default" KeyType="None" CertFile="" KeyFile="" PasswordOptions="None" Password="" Verbose="True" />
</Properties> </Properties>
</MonoDevelop> </MonoDevelop>
</ProjectExtensions> </ProjectExtensions>

@ -154,6 +154,12 @@ namespace Yavsc.Model {
} }
} }
public static string DocTemplateException {
get {
return ResourceManager.GetString("DocTemplateException", resourceCulture);
}
}
public static string Description { public static string Description {
get { get {
return ResourceManager.GetString("Description", resourceCulture); return ResourceManager.GetString("Description", resourceCulture);

@ -39,4 +39,6 @@
<data name="MaxDate"><value>Date maximale du rendez-vous</value></data> <data name="MaxDate"><value>Date maximale du rendez-vous</value></data>
<data name="Date_search"><value>Demande de rendez-vous</value></data> <data name="Date_search"><value>Demande de rendez-vous</value></data>
<data name="Remember_me"><value>Se souvenir du mot de passe</value></data> <data name="Remember_me"><value>Se souvenir du mot de passe</value></data>
<data name="DocTemplateException"><value>Une erreur est survenue à la génération de votre document</value></data>
</root> </root>

@ -39,4 +39,6 @@
<data name="MaxDate"><value>Maximal date for the rendez-vous</value></data> <data name="MaxDate"><value>Maximal date for the rendez-vous</value></data>
<data name="Date_search"><value>Rendez-vous query</value></data> <data name="Date_search"><value>Rendez-vous query</value></data>
<data name="Remember_me"><value>Remember me</value></data> <data name="Remember_me"><value>Remember me</value></data>
<data name="DocTemplateException"><value>Exception occured when rendering your document</value></data>
</root> </root>

@ -20,7 +20,11 @@ namespace Yavsc.Model.WorkFlow
{ {
ContentProvider.UpdateEstimate (estim); ContentProvider.UpdateEstimate (estim);
} }
/// <summary>
/// Gets the estimate.
/// </summary>
/// <returns>The estimate.</returns>
/// <param name="estid">Estid.</param>
public Estimate GetEstimate (long estid) public Estimate GetEstimate (long estid)
{ {
return ContentProvider.GetEstimate (estid); return ContentProvider.GetEstimate (estid);

Loading…