268
I Use This!
Very Low Activity

News

Analyzed about 3 hours ago. based on code collected 1 day ago.
Posted about 16 years ago
Today I moved from Castle Project RC3 to Trunk there were a couple changes that I needed to make. The IFilter interface has changed, The ExecuteEnum has changed to ExecuteWhen. The IRailsEngineContext name has changed to IEngineContext. I think ... [More] there's been a fair amount of refactoring around the Controller, I think the IController interface is new and there is now an IControllerContext interface. The EngineContextModule has been removed, so I needed to remove that from the web.config. and the Windsor integration facility name has changed from RailsFacility to MonoRailFacility, which also required a web.config change. The upgrade seems to be working well. [Less]
Posted about 16 years ago
Templates When sending an email using RenderMessageAndSend the following will be parsed for the message and removed what's left is sent as the body. from: name <address> or address to: address,address cc: address,address bcc: address,address ... [More] subject: value X-header: value body text If the body text contains '<html>' it will be sent as html. By default layouts will not be applied. It looks for views stored in Common if the view name starts with a /. Otherwise it looks for views in the Mail folder. /MailTemplate.brail should be stored in views/common/MailTemplate.brail MailTemplate.brail should be stored in views/mail/MailTemplate.brail Testing The test support doesn't currently render the message, but you can check for the number of message sent and the template name and properties. Assert.That(MessagesSent.Length, Is.EqualTo(2)); Assert.That(RenderedEmailTemplates[0].Name, Is.EqualTo("MailTemplate")); Assert.That(RenderedEmailTemplates[0].Parameters["to"], Is.EqualTo(emails[0])); In the MessageSent Collection all the messages are hard coded as new Message("from", "to", "subject", "body"); Also added to using.castleproject.org Sending Email With RenderViewAndSend [Less]
Posted about 16 years ago
Opps, I guess there's already some documentation on Testing Filters here. There is a lot of good info on the using.castleproject.org site, I'll be checking and adding info there.
Posted about 16 years ago
I'm really liking the unit test support in the Castle Monorail project. Here's an example to create a simple test for testing filters. [TestFixture] public class AdminAuthorizationFilterTest : BaseControllerTest { private Controller _controller; ... [More] [SetUp] public void Setup() { _controller = new TestController(); PrepareController(_controller); } [Test] public void Perform_No_User_Expect_False() { AdminAuthorizationFilter filter = new AdminAuthorizationFilter(); bool perform = filter.Perform(ExecuteEnum.BeforeAction, Context, _controller); Assert.That(perform, Is.False); Assert.That(Response.WasRedirected, Is.True); } } internal class TestController : Controller {} Setup is the same as testing a controller, but I needed to create an basic test controller. I attempted to use Rhino Mocks to partial mock the controller, but that disconnected the BaseControllerTest resulting in things like checking the Response object not working. Creating the class is one less line of code anyway. More on test support here. And Here. [Less]
Posted about 16 years ago
I finally spent two minutes to create a view.brail VS template today. It's really basic, but at least I won't end up with a class definition every time I try to add a new view. Below is the zip file, just drop in into My Documents\Visual Studio 2005\Templates\ItemTemplates. View.zip (5.12 KB)
Posted about 16 years ago
I spent some time today setting up OpenId in Monorail using ExtremeSwank OpenId consumer library. I went with a view component that can be on every page and a login controller to handle the authenticate and logout functions. This code is mostly a mix ... [More] of the ExtremeSwank sample code and monorail sample code and probably shouldn't be used in a production environment. Anyway, we'll start with the controller. It has three methods, Index, Authenticate, and Logout. The Index is just an empty action to explain OpenId to those who may not have experience with it. Authenticate takes the OpenId URL provided by the user to authenticate.  We store that in the session and pass to the consumer. Then we call BeginAuth which will process the request as long as the URL is correct. If not I render the Index view. public void Authenticate(string openIdUrl) { try { OpenIDConsumer consumer = new OpenIDConsumer(); consumer.Identity = openIdUrl; Session[OPENID_LOGIN] = consumer.Identity; consumer.ReturnURL = Context.UrlReferrer; consumer.BeginAuth(); } catch (Exception e) { PropertyBag["message"] = "Login attempt failed."; } RenderView("Index"); } Lastly, I have the Logout method which just removes the OpenIdUser object from the session. public void Logout() { Session[OPENID_USEROBJECT] = null; RedirectToReferrer(); } Next I have the ViewComponent which checks to see if the user is authenticating, authenticated, or not. I check for the OpenIDUser in the session first, if it finds that, then the user is authenticated. Otherwise, it creates a OpenIdConsumer object which looks at the state of authentication and executes accordingly, rendering either the default URL box or the logout link. public override void Render() { OpenIDUser user = Session[LoginController.OPENID_USEROBJECT] as OpenIDUser; if (user != null) { RenderLoggedIn(user); } else { OpenIDConsumer consumer = new OpenIDConsumer(); switch (consumer.RequestedMode) { case RequestedMode.IdResolution: consumer.Identity = (string)Session[LoginController.OPENID_LOGIN]; if (consumer.Validate()) { user = consumer.RetrieveUser(); Session[LoginController.OPENID_USEROBJECT] = user; RenderLoggedIn(user); } else { RenderLoginFailed(); } break; case RequestedMode.CancelledByUser: RenderLoginCancelled(); break; default: base.Render(); break; } } } I needed to add the appropriate views, but thats mostly all that's needed for this simple setup. [Less]
Posted about 16 years ago
Looking back, it should have been an obvious thing to not do, but it wasn't. I wanted to get access to the container and so I made IContainerAccessor a dependency for my class. The I added that to the container. The Main problem was that the ... [More] IContainerAccessor interface was implemented on the class that also created the container. So, after startup I had two containers, one I created for the application and one that container created when the IContainerAccessor was created. Okay, there are other ways to implement the IContainerAccessor, but is that what I really needed? No, I really needed a way to create a specific kind of component. Maybe like a factory of some sort. Oh, yea the factory pattern is already sitting around waiting to be used. And it was a good solution here. That makes me think, for most cases where you want the container directly, there is a better solution waiting to be used. [Less]
Posted over 16 years ago
One of the really nice things about using the NHibernate / Active Record stack is that there are so many extensions points. One of the more fun things is the ability to do runtime modifications of the mapping. Here is a simple ... [More] example:ActiveRecordStarter.ModelsCreated+=delegate(ActiveRecordModelCollection models, IConfigurationSource source) { foreach (ActiveRecordModel model in models) { if(model.Type == typeof(User)) { model.ActiveRecordAtt.Table = "MyUsers"; } } }; Here we are re-writing the table that the User entity will go to. We can get much more complex, since we have all the knowledge of the structure of the code and can apply things like naming convention, validation, etc. It is also a fast way to translate between database/conventions. NHibernate has a similar concept, INamingStrategy, which can be used to some of the same purposes, but I like this approach better, since it gives me more semantic information. [Less]
Posted over 16 years ago by [email protected] (mausch)
Some months ago, at work I was facing the need to send faxes from the main application server. "No problem", you might say, "just use Windows Fax Services". But the fax server was far, far away, only to be accessed through the internet. So I wrote a ... [More] wrapper Castle facility around the fax API and published it as a SOAP-WS. Interfaces and implementation are in separate assemblies, so the ws-client doesn't have to depend on fxscomex.dll et al (the Windows Fax DLLs). It is also possible to send faxes via email, by setting up a couple of components outside the facility. These components periodically check an IMAP account for the destination fax number from the subject and the actual fax as an attachment. Usually you would send a TIF or PDF for faxing. Plain text also works, but I guess nobody would use that... Ok, here's a more formal documentation: Usage The facility (Castle.Facilities.WindowsFax.dll) should be installed and configured on the machine that is the direct client of the fax server. Required assemblies: Castle.Facilities.WindowsFax.dll Castle.Components.Fax.WindowsFaxService.dll Castle.Components.Fax.dll Castle.Core.dll Castle.MicroKernel.dll Interop.FAXCOMEXLib.dll Windows Fax installed Those are the bare minimum assemblies required, however you probably already have also Castle.Windsor, so I'm going to assume that for the rest of this documentation. If you don't have Windsor for some reason, you'll have to configure it manually using MicroKernel or provide your own configuration. Configuration <facility id="fax" type="Castle.Facilities.WindowsFax.WindowsFaxFacility, Castle.Facilities.WindowsFax"> <serverName>localhost</serverName> </facility> <serverName> refers to the machine that has the actual Windows Fax Service running, the one with the actual fax hardware. If not specified, localhost is assumed. To make a fax operation, ask the Windsor container for Castle.Components.Fax.IFaxService, it has all the operations. Scenario 1: Local fax server If your fax server is on the web server's network, just drop the configuration above in your windsor config, setup the fax server name and you're good to go. Scenario 2: Fax server is on another network Here you can use the SOAP web services provided (client proxy here) or alternatively use remoting, WCF, etc. Leaving firewalls aside, it looks like this:     Required assemblies on "Web App Server": Castle.Components.Fax.dll Castle.Components.Fax.WebServiceClient.dll On "Fax Web Server", just install the web service provided. Sending faxes by email The web service miniapp also comes with the optional components to send faxes via mail. It works by periodically polling an IMAP account for mails with subject with the format "<fax number>, <fax subject>" IMAPClientWrapper is just a wrapper around Lumisoft's excellent IMAP Client. MailFaxSender is the one that does the actual work of checking the mail account and sending any pending faxes found. This component takes the following configuration: Username, Password: to access the IMAP account Server, ServerPort: to the IMAP server FolderInbox: IMAP folder where to look for new faxes FolderError: IMAP folder where faxes processed with errors are stored. FolderSent: IMAP folder where sent faxes are stored. FolderNotFax: IMAP folder where mails not related to the fax service (ie doesn't comply with the subject format specified above) are stored. These IMAP folders are automatically created when needed. MailSenderScheduler is a basic scheduler that executes the IMAP polling every x minutes. It relies on the startable facility to be...er... started. Configuration: SleepingMinutes: pretty much self explanatory. Troubleshooting Problem: I can't perform any fax operation, I always get some COM Operation Failed exception. Solution: Make sure the fax service is running. If it's not that, it's probably a matter of permissions. Open the Fax Console, Tools -> Fax Service Manager, right-click on Fax (Local), Properties, Security tab, allow all operations to the user running the facility (probably NETWORK SERVICE or ASPNET). Also check the permissions on the fax printer: from the Fax Console, Tools -> Fax Printer Configuration, Security tab, etc. Problem: I can't send PDF files. Solution: Install Acrobat 4, then modify the path on the registry file acrobat_printto.reg, then apply that reg. UPDATE: also try HKCR\AcroExch.Document.x\shell\Printto\command (where x is the acrobat version) Explanation: Windows fax services sends different file types by printing them internally to the fax printer. This registry modification tells Windows to use Acrobat 4 to print the PDF. Why Acrobat 4 and not the latest version? Because Adobe has removed the support in Reader to directly print a PDF. UPDATE: turns out this still works with Acrobat 8.1. Couldn't get it working with Acrobat 9 though. Problem: I can't send DOC (Word) files. Solution: DOC files are not supported (if you find something to print docs on the server reliably (ie NOT Microsoft Word) please tell me) TODO Generalize it to support Hylafax and other fax providers. Support POP3 Project homepage at SourceForge. SVN repository. [Less]
Posted over 16 years ago by [email protected] (Markus Zywitza)
Recently I discovered some behaviour of .NET that I couldn't explain. I still wonder whether this is an error or "ByDesign". I found it when I tried to call ActiveRecordMediator's Exists method, which threw out an unexpected exception. Minutes later ... [More] , I stared unbelievingly to the screen: A complete different method overload was called. I sat down and created a short example that doesn't use ActiveRecord, so it can be understood from any .NET-developer: public interface IString { string Content{ get;} } public class DString:IString { private readonly string content; public string Content { get { return content; } } public DString(string content) { this.content = content; } } public static class Class1 { public static void Foo(params IString[] bars) { foreach (IString s in bars) { Console.WriteLine(s.Content); } } public static void Foo<T>(T bar) { throw new NotImplementedException(); } } [TestFixture] public class Tester { [Test] public void CallBar() { Class1.Foo(new DString("baz")); } } So what would you expect when running the unit test? That's what I got: TestCase 'ClassLibrary2.Tester.CallBar' failed: System.NotImplementedException : The method or operation is not implemented. What happens here? If you add exactly one optional parameter, the compiler somehow thinks, you meant Foo<istring>() instead of Foo(). This happens only if the type parameter is an interface. I tried with string and that worked like expected, calling Foo(). So, is this a bug or a documented behaviour. Do you know ressources that document it? I didn't find any... [Less]