Tagged: C# RSS

  • John 12:34 am on March 28, 2010 Permalink | Reply
    Tags: C#, Castle, Medium Trust, NHibernate   

    Running NHibernate in Medium Trust 

    After deploying a NHibernate to a shared host I started running into a number of issues. Whilst developing we were running in full trust not in medium trust whilst the majority of shared hosts use. After hours and hours of searching I finally come across a post on the Castle Project mailing list which detailed how to get a nhibernate working under medium trust. Here is the steps I followed to get it working.

    I am using NHibernate 2.1.2 and C# .NET 3.5 in Visual Studio 2008.

    Step 1

    Download Castle.Core from gitbhub
    git://github.com/castleproject/Castle.Core.git

    Step 2

    Enable Castle to allow partially trusted callers.
    Open buildscripts/CommonAssemblyInfo.cs and enable the library to enable partially trusted callers

    Step 3

    Disable generation of debug information for the projects Castle.Core and Castle.DynamicProxy.

    Step 4

    Build the projects

    Step 5

    Download Nhibernate source code from source forge.

    http://sourceforge.net/projects/nhibernate/files/

    Step 6

    Open Nhibernate.Everything.sln and update the references for the NHibernate.ByteCode.Castle project so that the references for Castle.Core and Castle.DynamicProxy2 are the libraries build in step 4. Disable generation of debug information for the projects NHibernate, Iesi.Collections and NHibernate.ByteCode.Castle, similar to what was done in step 3.

    Step 7

    Copy the outputted library files from NHibernate.ByteCode/bin/Release to your shared libs folder of your project.

    Step 8

    Update the references in your project to point to the new libraries. Next turn off reflection optimization. This needs to be done in code before you create the configuration object. Configuring this in the hibernate.cfg.xml does not work. Update all your projects assemblies to set allow partially trusted callers, similar to step 2. Update your web.config to set requirePermission=”false” in the nhibernate section delceration

    NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
    Configuration = new Configuration();
    Configuration.Configure();
    
    
    

    You can now run your site in medium trust using lay loading.

    Links

    Related Reading

     
  • John 8:02 pm on January 1, 2010 Permalink | Reply
    Tags: C#, , NAnt   

    NAnt.ToDo a NAnt Plugin 

    This simple plugin for NAnt parses your source code and creates a report of all the TODO and comment tags in your source code. The code is hosted over at google code.

    Comments

    The task automatically identify comments in the following style

    //TODO: First Test to do Item
    //FIXME: First Fix me Item
    //HACK: First Hack Item
    

    Additional matches can be made by adding in Token elements to the NAnt task.

    Sample

    <ToDo source="path/to/source" output="report.xml" searchpattern="*.cs;*.txt">
     <Tokens>
     <Tokens Value="BUGFIX" />
     </Tokens>
    </ToDo>
    

    Output

    <ToDo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <Items>
     <Item>
     <Message>First Test to do Item</Message>
     <File>NAnt.ToDo\ToDoTask.cs</File>
     <Line>0</Line>
     <Type>TODO</Type>
     </Item>
     <Item>
     <Message>First Hack Item</Message>
     <File>NAnt.ToDo\ToDoTask.cs</File>
     <Line>0</Line>
     <Type>HACK</Type>
     </Item>
     <Item>
     <Message>First Fix me Item</Message>
     <File>NAnt.ToDo\ToDoTask.cs</File>
     <Line>0</Line>
     <Type>FIXME</Type>
     </Item>
     </Items>
    </ToDo>
    

    Cruise Control Xsl

    Below is a basic xsl style sheet that can be used with CruiseControl.NET to display the output from NAnt.ToDo.

    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
     <xsl:output method="html"/>
     <xsl:param name="applicationPath"/>
     <xsl:template match="/">
     <div id="ToDo">
     <h1>ToDo List</h1>
     <div id="Summary">
     <h3>To Do</h3>
     <table>
     <tbody>
     <xsl:for-each select="//ToDo/Items/Item">
     <tr>
     <td>
     <xsl:value-of select="Type/text()"/>
     </td>
     <td>
     <xsl:value-of select="Message/text()"/>
     </td>
     <td>
     <xsl:value-of select="File/text()"/>
     </td>
     </tr>
     </xsl:for-each>
     </tbody>
     </table>
     </div>    
     </div>
     </xsl:template>
    </xsl:stylesheet>
    
     
  • John 10:06 pm on September 26, 2009 Permalink | Reply
    Tags: C#, , , , ,   

    jqRunner Snapshot – Running Javascript Unit test with NUnit 

    One of the nice things about unit tests is that you can use continuous integration so that you don’t have to run them yourself. At work we use CruiseControl.NET to automate our builds and run our unit tests. Now as a number of our projects are web based we use a fair amount of javascript, mainly jQuery, though in-house plugins. In order to test these we use jqunit, this works great and allows us to use TDD when writing javascript. However as development goes on the unit tests get forgotten about as they are not automatically ran.

    In order so solve this I decided to experiment to find a method of getting cruise control to run our jqunit tests for me. To run the tests I looked at wrapping the jqunit tests with nunit tests.

    jqRunner

    jqRunner is designed so that you can us your existing jqunit tests in their existing location without changing them. jqRunner required that all the scripts that are needed to run are registered. The full path to the file is required. jqRunner then executes the tests and returns the results, which are then parsed by nunit as tests using the TestCaseSource attribute.

    var sampleTestCase = new jqUnit.TestCase('Sample Test Case', function() {
        /*setup*/
        // this.yep(1);
    }, function() {
        /*teardown*/
        // this.ok(1)
    });
    sampleTestCase.test('Sample Test 1', function() {
        this.ok(1);
    });
    sampleTestCase.test('Sample Test 2', function() {
        this.ok(0);
    });
    
    using System;
    using System.Collections.Generic;
    using NUnit.Framework;
    using jqRunner;
    using System.IO;
    using System.Reflection;
    
    namespace jqRunner.Tests
    {
        [TestFixture,RequiresSTA]
        public class TestCaseSourceTests
        {
            [Test, TestCaseSource("GetTestResults"), RequiresSTA]
            public void CheckTest(ITestResult result)
            {
                Assert.IsTrue(result.Pass, result.Name);
            }
    
            private static ITestResult[] GetTestResults()
            {
                string jsFile = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase) + @"\jqUnitTests\SampleUnitTest.js";
                TestBed target = new TestBed();
                target.RegisterScript(jsFile);
                return target.Execute().ToArray();
            }
        }
    }
    

    This is an initial development snapshot and is bound to have plenty of problems.

    Download
    http://static.yeticode.co.uk/blog/downloads/jqRunner-snapshot.zip

    Related Reading

     
  • John 8:34 pm on August 24, 2009 Permalink | Reply
    Tags: C#, , , ,   

    More Django Plugin Stuff 

    MonoDevelop Django

    So I’ve been working more on the support for django within monodevelop. Heres some screenshots of it.

    MonoDevelop Django

    MonoDevelop Django

     
    • Aledr 8:47 pm on December 16, 2009 Permalink | Reply

      I’ve just installed MonoDevelop 2.2 and started a new Django project but is no option to create a new App there. Is your code already integrated?

      Thanks.

      • John 11:11 am on December 17, 2009 Permalink | Reply

        I never got round to getting the code into a stable state, and submittting a patch. However I have a couple of weeks of work so I’ll see if have anytime to look at it again.

  • John 7:21 pm on June 28, 2009 Permalink | Reply
    Tags: ASP.NET, C#, MVC,   

    Professional ASP.NET MVC 1.0 

    At work we have been looking at the ASP.NET MVC, model-view-controller, framework. After looking around at various different tutorials and articles we found a sample chapter from the wrox book Professional ASP.NET MVC 1.0. The sample chapter took the hello world example and create a full application. The application, NerdDinner is an application that allows you to create dinner parties and RSPV to them. The sample covers a lot of the functionality that is within ASP.NET MVC. The sample chapter can be found online at Wrox’s website with the source code hosted at codeplex.


    Professional ASP.NET MVC 1.0

    Reading though the sample chapter is a good way to get started with ASP.NET MVC as the chapter explains what it is doing in a easy to understand manor, but more importantly it explains why they are being done. The chapter is a comprehensive walk through of how to create the NerdDinner application. Throughout the chapter the authors provide titbits of useful information, for example the use of the repository pattern and dependency injection. Throughout the chapter the authors trying to enforce good coding practice and often make reference to test driven development which in a later chapter they go into more detail about, discussing different development techniques.

    The sample chapter is more than enough to get anyone started with ASP.NET MVC and follows the development process from start to finish including a section on unit testing the application. The following chapters delve into more detail about specific areas of the ASP.NET MVC framework. The second and third chapters go into detail about the MVC pattern, detailing its background and its use on the web. The chapter also provides an overview, albeit brief, of other frameworks that are available. Although their coverage was brief they were not mentioned as either superior or inferior rather just as alternatives to the ASP.NET MVC framework. This tone was subsequently repeated in the third chapter when the authors compare ASP.NET with WebForms to ASP.NET MVC. They often mention that MVC is not a replacement for WebForms rather it is a different approach. These two chapters are extremely useful as they allow you to make an informed decision whether ASP.NET MVC is the right choice for you.

    I’ve still to finish reading the rest of this book so I’ll update this post the more I read of it.

     
  • John 8:14 pm on May 24, 2009 Permalink | Reply
    Tags: C#, nmock, nunit   

    NUnit and NMock 

    Whist working on a piece of course work for uni I started using NMock as part of some unit tests written using nunit. Having mainly used MSTests for unit tests at work I decided to use nunit as everyone has said that they are very similar. I’m extremely impressed with the potential power that NMock has given me during testing. For the assignment I wrote a small spider application that crawly a site and stores all the link. Using NMock it allowed me to test the structure of the site without requiring internet access. During this assignment I also tried to use the test driven development approach, opposed to my normal sit down and hack away. Not only were there less bugs at the end, the overall quality of my code was noticeable higher. This was largely due to the fact that I had tests already created for what it was meant to do, which required me to put more effort into the implementation. Hopefully I’ll keep this style of programming up, and not just forget it as soon as I get back to work.

    Here’s a sample nunit test that uses nmock. The nmock object mocks the calls that request specific urls and loads the data for local files.

    [Test()]
    public void MockLinkFinderTest()
    {
    	IMock mockWebClient = new DynamicMock(typeof(IWebClient));
    	mockWebClient.ExpectAndReturn("GetPage",File.ReadAllText("HTML/1.htm"),new object[]{"http://domain.example/1.htm"});
    	mockWebClient.ExpectAndReturn("GetPage",File.ReadAllText("HTML/2.htm"),new object[]{"http://domain.example/2.htm"});
    	mockWebClient.ExpectAndReturn("GetPage",File.ReadAllText("HTML/3.htm"),new object[]{"http://domain.example/3.htm"});
    
    	string domain = "domain.example";
    	string url = "http://domain.example/1.htm";
    
    	LinkFinder linkFinder = new LinkFinder();
    	LinkItemCollection linkCollection = linkFinder.Find(url,domain,(IWebClient)mockWebClient.MockInstance);
    
    	int expected = 3;
    	Assert.AreEqual(expected,linkCollection.Count);
    }
    
     
  • John 1:59 am on May 13, 2009 Permalink | Reply
    Tags: C#, , ,   

    New GTK# Project 

    I’ve started a new project, RssNotify, to try and learn more about developing applications using GTK. I’ll still be developing cctray-gtk as this project is useful, but the RssNotify is more of a project to satisfy my curiosity.

    The RssNotify project aims to provide an easy way for a user to receive notifications when an rss feed has been updated. the idea is to use notify-sharp to display the new news items. The rest of the interface will be used to try to explore the features widgets that GTK# offers.

     
  • John 8:15 pm on May 6, 2009 Permalink | Reply
    Tags: C#, , , ,   

    CCTray updates and Mono musings 

    Impleneted some more to the CCTray-gtk project with the ability to add build servers that communicate over HTTP. This did involve commenting out some of the code in the CCTrayLib project, which was unavoidable. The issue occurred as the library added a delegate to the Service point manager

    ServicePointManager.ServerCertificateValidationCallback = delegate{ return true; }
    

    These were causing an exception to be thrown as it is currently not implemented in mono. This so far is the only part of mono that I’ve found that has caused any problems.

    https://bugzilla.novell.com/show_bug.cgi?id=346561

    I’ve also started to implement the ability to remove a project, at the moment it removes the project from the preferences window but does not yet remove the associated project monitor or remove it from the main window’s treeview.

    Once this has been implemented I will create a release or something for testing.

     
  • John 3:09 pm on April 9, 2009 Permalink | Reply
    Tags: C#,   

    C# Style for lstinputlisting 

    After getting latex to format my code nicely I noticed that it did not have build in support for C#, which read of the manual and knocked one up. Share and Enjoy

    \lstdefinelanguage{cs}
      {morekeywords={abstract,event,new,struct,as,explicit,null,switch
    		base,extern,object,this,bool,false,operator,throw,
    		break,finally,out,true,byte,fixed,override,try,
    		case,float,params,typeof,catch,for,private,uint,
    		char,foreach,protected,ulong,checked,goto,public,unchecked,
    		class,if,readonly,unsafe,const,implicit,ref,ushort,
    		continue,in,return,using,decimal,int,sbyte,virtual,
    		default,interface,sealed,volatile,delegate,internal,short,void,
    		do,is,sizeof,while,double,lock,stackalloc,
    		else,long,static,enum,namespace,string, },
    	  sensitive=false,
    	  morecomment=[l]{//},
    	  morecomment=[s]{/*}{*/},
    	  morestring=[b]",
    }
    

    Usage

    \lstinputlisting[language=cs]{test-class.cs}
    
     
  • John 4:01 am on March 24, 2009 Permalink | Reply
    Tags: C#, , , ,   

    Cruise Control Tray For Linux Update 

    Basic functionality has been implemented with the ability to add project to monitor and receive notifications of the build as and when they occur. At the moment there is not the ability to delete a project that is being monitor this will be implemented next. There is also the ability to force a build of a project, however there is not the ability to abort the build, this will also been implemented in the next couple of days hopefully. Here are some more screen shots of what it currently looks like. The build notification have also been attached to the tray icon.



     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
esc
cancel

Powered by Web Design Company Plugins