Skip to content

Instantly share code, notes, and snippets.

View ArnisL's full-sized avatar
🦊

Arnis Lapsa ArnisL

🦊
View GitHub Profile
@ArnisL
ArnisL / after.cs
Created October 19, 2011 22:02
refactoring == joy
namespace Interreg.App.Audit.Application{
using Domain.Model.Applications;
public class ApplicationAudit:Audit{
public override void AttachHandlers(){
On<AttachmentAdded>(e=>e.Source.LogEvent(
"Attachment named '{0}' added".With(e.Attachment.Name)));
On<AttachmentRemoved>(e=>e.Source.LogEvent(
"Attachment named '{0}' removed".With(e.Attachment.Name)));
@ArnisL
ArnisL / gist:742085
Created December 15, 2010 15:27
word_interop.cs
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
public class WordTemplateFiller{
private readonly Zipper _zipper=new Zipper();
private const string _pathToCustomPropXml="docprops\\custom.xml";
/// <returns>path to filled docx</returns>
public FileInfo FillTemplate(string templatePath,Dictionary<string,string> props){
var docPath=Path.GetTempFileName();
@ArnisL
ArnisL / gist:742040
Created December 15, 2010 14:59
temp_directory.cs
using System;
using System.IO;
public class TempDirectory:IDisposable{
private readonly string _path;
public TempDirectory(){
var path=Path.Combine(Path.GetTempPath(),Path.GetRandomFileName());
Directory.CreateDirectory(path);
_path=path;
}
public void Dispose(){
@ArnisL
ArnisL / gist:634190
Created October 19, 2010 13:30
globalasax.cs
namespace Interreg.Web{
using System;
using System.Security.Principal;
using System.Web.Security;
using MvcExtensions.StructureMap;
public class MvcApplication:StructureMapMvcApplication{
//ignore this bullshit code...
protected void Application_AuthenticateRequest(Object sender,EventArgs e){
var authCookie=Context.Request.Cookies[FormsAuthentication.FormsCookieName];
if(authCookie==null||authCookie.Value=="") return;
@ArnisL
ArnisL / gist:634186
Created October 19, 2010 13:27
userSession.cs
public class UserSession:IUserSession{
private readonly IAuthenticationService _authenticationService;
private readonly ICryptographer _crypto;
private readonly IUserRepository _repository;
public UserSession(IUserRepository repository,IAuthenticationService authenticationService,ICryptographer crypto){
Guard.AgainstNull(repository);
Guard.AgainstNull(authenticationService);
Guard.AgainstNull(crypto);
_repository=repository;
_crypto=crypto;
namespace Interreg.Infra.Forms{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Excel;
public interface IExcelReader:IDisposable{
void Open(string path);
string Get(string key);
void ChangeSheet(string key);
using Map=BudgetPerPartnersMap;
//you all going to die down here!
public static class BudgetPerPartnersReader{
public static void Read(IExcelReader r,ApplicationForm f){
r.ChangeSheet(SheetMap.BudgetPerPartners);
var b=f.BudgetPerPartners;
var fillCostsType=new Action<CostsType,string[,]>(
(costsType,map)=>{
costsType.AllPartnersTotal=r.Get(Map.AllPartnersTotal[0]);
for(var i=0;i<map.GetUpperBound(0);i++)
//class Application {
public virtual void ReceivePaperVersion(DateTime sendDate,DateTime arrivalDate){
if(Statuses.ApplicationStatus!=ApplicationStatus.ReceivedElectronically)
throw new ApplicationException
("Paper version can be received only right after electronic version is received.");
var d=Call.ApplicationDeadlines;
if(sendDate>d.PaperVersionSendDeadline)
throw new ApplicationException("Send date exceeds call deadline");
if(arrivalDate>d.PaperVersionArrivalDeadline)
throw new ApplicationException("Arrival date exceeds call deadline");
[HttpPost]
public ActionResult ReceivePaperVersion(Application a,ReceivePaperVersionInput inp){
var r=new Func<ActionResult>(()=>RedirectToAction("Details",new {a.Id}));
return this.Do(
()=>{
a.ReceivePaperVersion(inp.PaperVersionSendDate.Value,inp.PaperVersionArrivalDate.Value);
this.Flash("Application paper version received!");
return r();
},r); //1st arg==happy path, 2nd arg==onFail
}
if ((sTemp.IndexOf(".") == -1) && (sTemp.Length >= 1) &&
(sTemp.ToUpper().IndexOf("N") == -1) && (sTemp.IndexOf("-") == -1))
{
invRow.AT13 = true;
}
else
{
invRow.AT13 = false;
}
sTemp =