Transform System.Drawing.ContentAlignment property to System.Drawing. StringFormat Alignment property

Recently we had the need to transform System.Drawing.ContentAlignment property to System.Drawing. Stringformat alignment property for creating a Graphic object with text drawn on it inside a given rectangle.  Assuming that you want the text printed from left to right, you can use the ContentAlignment Enum values to obtain the desired StringAlignment Enum value.  For example:
   1: public StringFormat TransformProperty(ContentAlignment alignment)

   2:         {

   3:             StringFormat myStringFromat  = new StringFormat();

   4:             switch(alignment)

   5:             {

   6:                 case ContentAlignment.MiddleLeft:

   7:                     myStringFromat.Alignment = StringAlignment.Near;

   8:                     break;

   9:                 case ContentAlignment.MiddleRight:

  10:                     myStringFromat.Alignment = StringAlignment.Far;

  11:                     break;

  12:                 default:

  13:                     myStringFromat.Alignment = StringAlignment.Center;

  14:                     break;

  15:             }

  16:             return myStringFromat;

  17:         }

Craig

General

Comments (0)

Permalink

Adding SQLite to a Windows Mobile Application

Using SQLite in a Windows Mobile Application provides a simple way to add pre-populated data for consumption by the application.  There are a couple of configuration considerations when adding the database to the project.

1. Adding reference to SQLite.dll. After installing SQLite there will be a Compact Framework folder in the following path :C:\ProgramFiles\SQLite.NET\bin.  This folder contains the System.Data.SQLite.dll that needs to be referenced.

2 The same path will also contain the dll which Windows Mobile will need to invoke the methods contained in the SQLite.dll.  The following file needs to be added to the project which contains the main executable,  SQLite.Interop.065.DLL.

Once the interop dll is in the project you can start using SQLite in the Mobile Application just as you would for any other application.

Craig

General

Comments (0)

Permalink

Could not load file or assembly ‘AjaxControlToolkit’ or one of its dependencies. Access is denied.

Problem: Recently i came across this problem while switching to a new Windows 7 64 bit m/c. The web site at hand was working fine on my previous m/c Windows 7 64 bit RC1. The error and the event log were basically not very helpful either.

Resolution:

So here is what I did to fix the issue (to get it to work using IIS):

1. Make sure that the dll in question is either set to “Copy to: Local). Go to References, right click on AjaxControlToolkit and select properties. In my case it was already set to Copy Local. So that was not the issue

2. Open IIS Manager, browse to the AppPool (in my case it was the DefaultAppPool… it is just a Dev box, ok!). Go to Advanced Settings, and set Enable 32-bit Applications to true. Now that did fix the problem I was having.

For Cassini:

1. I had to give modify rights on the asp.net temp folder  to the Apppool identity (in my case IIS users group).

Discussion

  • On further research (i.e. “google”), I came to the conclusion that it was a permissions error related to the Temporary ASP.NET Files folder (C:\Windows\Microsoft.NET\Framework64\v2.0.50727). Some of the other fixes for this problem can be found on other blogs. They relate to the access permissions on the ASP.NET folder, Trust level Settings on the Website, and Anti-virus settings. Here is a link to some of them:
  • What I found was that the main focus while resolving this error should be on the later part of the error that says ‘Access is denied’ or “Invalid Argument’ etc.. that will help you in attacking the issue. In my case it was the fact that I was running a 32 bit app on a 64 bit mc and a permissions issue as well on the Temporary ASP.NET folder.
  • If you get an ‘Access Denied’..try checking the permissions on the Temp ASP.NET folder.
  • If you get ‘Invalid Argument’ try cleaning the temp asp.net folder and restarting the web site.

http://lichao.net/eblog/fix-access-is-denied-exception-from-hresult-0×80070005-e_accessdenied-on-local-machines-200905307.html

http://weblogs.asp.net/joshuajohnson/archive/2008/12/22/could-not-load-file-or-assembly-ajaxcontroltoolkit-or-one-of-its-dependencies-the-parameter-is-incorrect-exception-from-hresult-0-215-80070057-e-invalidarg.aspx

http://msforums.ph/forums/t/46678.aspx

.NET Framework
General

Comments (1)

Permalink

WCF Exception Shielding Error

While using the WCF Exception Shielding policy in Enterprise Library’s Exception Handler Block to shield exceptions and return Fault Contracts I came across an error. I named the shielding policy “WCF Shielding Policy” and implemented a FaultContract for each type of desired or expected exception.

While testing the policy, we were unable to return a proper FaultContract from the WCF Service.  The only error that we received was the generic Communication Error:

System.ServiceModel.CommunicationException: An error occurred while receiving the HTTP response to (path of service).
 This could be due to the service endpoint binding not using the HTTP protocol.
This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down).
See server logs for more details. --->  System.Net.WebException: The underlying connection was closed:
An unexpected error occurred on a receive.
  System.IO.IOException: Unable to read data from the transport connection: An existing connection was
forcibly closed by the remote host.
 System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.

This error is incredibly deceiving and led to many dead ends while trying to track down the root cause of the error. I re-wrote the app.config file and removed and re-added the service references, all to no avail.

The cause of the problem was simply in the name of the policy. If you don’t name your shielding policy “WCF Exception Shielding” verbatim then the policy will not be found and the error above will be thrown.  If you do name your policy something different or you implement different policies for different types of exceptions then you have to explicitly state in the ExceptionShielding attribute the name of the policy as follows:

C#:[ExceptionShielding("MyPolicy")]
VB: <ExceptionShielding ("MyPolicy")>

I renamed the policy to the default name and started receiving the Fault Contracts as expected.

Hope this helps eliminate some headaches for someone.

-Craig

General

Comments (0)

Permalink

Write iPhone Applications in C# using MonoTouch

The mono project has released a new Mono edition for Apple’s iPhone and iPod Touch.  This allows you to write full featured applications for the iPod touch using C#. 

This is not a JIT Compiler, but is a static compiler that turns .NET executables into native applications. 

For more information, check out the project at : http://www.mono-project.com/MonoTouch

General

Comments (0)

Permalink

Spring and Functional Tests

Recently on our project we created a “functional” unit test for some services. The test was designed to check the entire call stack from the service layer to the DAO and return some expected results. We are using Spring for dependency injection through our entire application. This functional test initially only referenced the service DLL’s as this is all we thought that had to be referenced.  Upon execution, the test was failing due to “null or empty Context”. We knew that we had referenced the context in the configuration file correctly, but were perplexed at how the spring context were not loading.

We finally realized that it was an issue with Resharper and how the tests were executed differently then when run is Visual Studio using default run (ctrl + r, t)

Once this was solved, we were getting reference exceptions.

To solve this error, it is necessary to reference in your test project all of the DLL’s that are referenced in your Spring xml file. It will not work unless you do so.

-Craig

General

Comments (0)

Permalink

RESTFul Services in Silverlight - CT Code Camp June 2009

Downloade the Presentation and Code 

The Connecticut User Group organized a full day code camp event in Bloomfield, CT. The topic I presented on was “RESTFul Services and Silverlight”. The presentation was organized around the following main topics:

  • Web Services via SOAP
  • RESTFul Services
  • Creating a WCF RESTFul Service
  • Consuming a Custom WCF RESTFul Service in Silverlight

The attached slide deck will provide you with highlights on each topic. The code samples revolve around the AdventureWorks Database. I have partitioned the code into Data Access, Service Layer and a UI Layer.

  • Database: AdventureWorksDB from code plex. You can download it from here: http://www.codeplex.com/MSFTDBProdSamples
  • Data Access: Used Nettiers and Codesmith to Generate the CRUD methods to access Adventure Works.
  • Service Layer: WCF, ASMX and WCF REST service examples. I have also included a sample service from John Papa’s Data Services with Silverlight book. I would recommend this book for who ever is working with Siverlight
  • UI Layer: Consists of a ASP.NET web site that houses the silverlight controls and the silverlight controls themselves. The services are conusmed by silverlight.

During the actual presentation, i also created a simple WCF Service and demo’ed how to use a simple SOAP WCF service in a silverlight client using the Asynchronous pattern.

Check the samples out!

Happy coding

Reddy (reddy.kadasani@tallan.com)

.NET Framework
Presentations
User Groups
WCF

Comments (0)

Permalink

Content from LINQ Code Camp Presentation (6/13/09)

On June 13, 2009 I was privileged to give a presentation at the Hartford Code Camp at New Foundations in Bloomfield, CT.   The event was a great success, with 29 presenters,  35 sessions, and more than 150 people in attendance.  I’d like to say thank you to anyone who was able to attend my session on LINQ, my group was great and had a lot of insightful and pointed questions.

As promised, I’m posting the content from the presentation including the PowerPoint files and Demo Code.

If anyone has any questions about the content, please feel free to e-mail me at mgerety@tallan.com

Presentation and Content Files: LINQ Presentation And Files

.NET Framework
Presentations

Comments (0)

Permalink

Convert Multi-page image to Collection of Bitmaps

Recently on a project, we had the need to convert a saved multi-page tiff to a collection of bitmaps for viewing in a UI using standard GDI+ methods. These bitmaps also needed to be printed in a high quality way for submission to a government agency.  This method ensures that no quality will be lost from the creation of the new bitmap objects.

/////////////////////////////////////////
// by Craig Vallee
// Consultant
// Tallan, Inc.
/////////////////////////////////////////

private static List<Bitmap> ImageToBitmap()
{
    //Create and Image object from file path and name
    Image originalImage = Image.FromFile(@"C:\Temp\Your_File.tif");

    //Create a collection of Bitmap objects 
    List<Bitmap> bitmapList = new List<Bitmap>();

    //Place holders for setting resolution of new Bitmap objects
    var xResolution = originalImage.HorizontalResolution;
    var yResolution = originalImage.VerticalResolution;

    //Create FrameDimesion for iteration through file frames
    FrameDimension frameDimension = new FrameDimension(originalImage.FrameDimensionsList[0]);

    //Framecount of image for iteration through file frames
    int frameCount = originalImage.GetFrameCount(FrameDimension.Page);

    //Simple iteration through file frames
    for (int i = 0; i < frameCount; ++i)
    {
        //Create bitmap to hold individual frame
        Bitmap bmp;

        //Moves active frame pointer to next frame in iteration
        originalImage.SelectActiveFrame(frameDimension, i);

        //Cast image frame to Bitamp holder
        bmp = (Bitmap)originalImage;

        //Create new Bitmap from placeholder
        Bitmap temp = new Bitmap(bmp);

        //Set bitmap resolution based on original resolution
        temp.SetResolution(xResolution, yResolution);

        //Add Bitmap to Bitmap collection
        bitmapList.Add(temp);
    }
    return bitmapList;

}

-Craig

.NET Framework
General

Comments (0)

Permalink

Windows Worfklow: Error 1342 Activity X validation failed: Can not find the condition Y

This is just a small tip for anyone doing any WWF work:  The workflow’s name property MUST MATCH file workflow filename or rules and conditions will not be found, and the workflow will not be instantiated.

Example:

Create a sequential workflow.  Call it WorkflowA.cs.

Click the workflow in the designer mode, and change the name of the workflow in the property window to WkflwA.  Add any activity that takes conditions (i.e., if/then/else). 

Add a valid condition to this activity.

Attempt to start the workflow.

 

You will get a WorkflowValidationFailedException saying that the Workflow failed validation.  To correct this issue, rename the workflow back to “WorkflowA” and restart.  The workflow will instantiate without issue.

.NET Framework
General

Comments (0)

Permalink