Monday, December 31, 2012

Simple Exif Viewer using C++ and Exiv2

Exif or Exchangeable image file format is a variation of JPEG, used by almost all digital cameras to record extra interchange information to image files as they are taken. Camera settings and scene information are recorded by the camera into the image file. Examples of stored information are shutter speed, date and time a photo was taken, focal length, exposure compensation, metering pattern and if a flash was used.

I have build a simple Exif Viewer using Exiv2 and C++ (I have wrote about Exiv2 in a previous post). Since Exiv2 supports command line, from my application I am invoking the Exiv2 commands through the command line and getting the output back to my application. The one of the nicest things in Exiv2 is, it has the capability to read set of commands from a text file and execute those commands on the command line.
image
Simple Exif Viewer
You can download the source and expand the application using various features Exiv2 supports.

Happy Coding.

Regards,
Jaliya

Saturday, December 22, 2012

Building and Installing Exiv2 on Visual Studio 2010

Exiv2 is a C++ library and a command line utility to manage image metadata. It provides fast and easy read and write access to the Exif (Exchangeable image file format), IPTC and XMP metadata of images in various formats. Exiv2 is available as free software and with a commercial license, and is used in many projects.

I have spent more than 2 hours to build this library on Visual Studio 2010. So I think it's better if I wrote the steps that I have followed to build the libraries.

Exiv2 has two main dependencies. One is expat and the other is zlib. The important thing here is finding the suitable versions of these two dependencies. To successfully compile Exiv2 we need following versions of expat and zlib.
Steps:
  • First create a folder in any place you like. I have created a folder named “gnu” in “C:\” drive.
  • Put all three folders which you got from extracting and put them inside the folder “gnu”.
image
My Folder : "C:\gnu"
image
C:\gnu\exiv2
image
C:\gnu\expat-2.0.1
image
C:\gnu\zlib-1.2.3
  • Open the “expat.dsw” inside the folder “expat-2.0.1”. Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything.
  • Go to Batch Build and select the following and Build. Please note that if you try to build the whole solution you will get many errors. So you should only build the following.
    • expat-Debug
    • expat-Release
    • expat_static-Debug
    • expat_static-Release
image
Batch Build
image
Batch Build Selection
image
Build
  • Open the “zlib.dsw” inside the folder “zlib-1.2.3\projects\visualc6”. Again Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything.
  • Go to Batch Build and select the following and Build. Please note that if you try to build the whole solution you will get many errors. So you should only build the following.
    • zlib-DLL Debug
    • zlib-DLL Release
    • zlib-LIB Debug
    • zlib-LIB Release
image
Batch Build Selection
image
Build
  • Now open the “exiv2.sln” inside the folder “exiv2\msvc”. Again Visual Studio 2010 will convert everything to latest project files and say "Yes" to everything. when Visual Studio has completed converting, select the project “exiv2lib”. Right click on it and select properties.
image
exiv2lib
image
exiv2lib Properties
image
exiv2lib Properties -> General
  • Only for this project, target name should changed as follows.
    • Debug           - exiv2sd
    • DebugDLL    - exiv2d
    • Release         - exiv2s
    • ReleaseDLL  - exiv2
image
Debug -> exiv2sd
image
DebugDLL -> exiv2d
image
Release -> exiv2s
image
ReleaseDLL -> exiv2
  • Now you can build the project without any errors.
image
Build
I have uploaded all the needed files to my skydrive and you can download it from there.


Happy Coding.

Regards,
Jaliya

Tuesday, December 18, 2012

ASP.NET Web Site in Windows 8 Metro Style

Have you ever wanted to create an ASP.NET web site in Windows 8 Metro Style? But you might already know that, to get started writing Metro style apps you need Windows 8 and Visual Studio 2012.

If you want to create Metro style using Visual Studio 2010, you will have to use third party libraries. I  have came across such a solution which is Metro UI CSS. Metro UI CSS a set of styles to create a site with an interface similar to Windows 8 Metro UI. This set of styles was developed as a self-contained solution. I have already tested it out and it’s really amazing.

image
Sample Metro Style Web App
I have created a sample web application, you can download and see for yourself the beauty of these css files.



Happy Coding.

Regards,
Jaliya

Friday, December 7, 2012

Presentation : Windows Communication Foundation (Part 2)

Continued my previous session at iOM World about Windows Communication Foundation (WCF) and today we spent some time learning how to create WCF services and how to configure the endpoints with different bindings etc.



I have uploaded the slide deck and demo source code to my SkyDrive. Do check it out.
     Download

Happy Coding.

Regards,
Jaliya

Wednesday, December 5, 2012

Forms Authentication with MS Access Database

I recently had a requirement to provide Forms Authentication to a web application which has a Microsoft Access database. If you are thinking that Forms authentication only supports with Microsoft SQL Server databases, No it’s not. ASP.NET supports variety of custom Membership and Roles providers including,
  • SQL Database Support for ASP.NET Membership, Roles and Personalization
  • Access Database Support for ASP.NET Membership, Roles and Personalization
  • MySQL Support for ASP.NET Membership and Roles
  • SQLLite3 Support for ASP.NET Membership and Roles
  • Oracle Support for ASP.NET Membership, Roles and Personalization
Today I am going to show you how to configure Forms Authentication with Microsoft Access. If you have used Forms Authentication with Microsoft SQL Server, you know that we run following command to create “aspnetdb” database in the SQL Server first.

image
Create aspnetdb in SQL Server
But since here we are using MS Access database, we should have some kind of a access database similar to “aspnetdb”. So for that Microsft has provided us a MS Access .mdb file and some set of classes to implement Forms Authentication with the provided MS Access database file. So let’s see how this works. (I am hoping to upload a sample project to SkyDrive, so you can get all the database files and class files.)

First I will create a new web application and I will add a new class library to the solution.

image
Solution Explorer : Add Class Library Project
In the class library I will add a folder called “AccessProviders” and I will add the Microsoft provided class files to that folder. Then I am building “MyAccessProvides” class library and to compile I need to add following references to the class library project.
  • System.Web
  • System.Web.ApplicationServices
  • System.configuration
image
Solution Explorer : AccessProviders
Now I am moving to my Web Application project and in that project I am adding a reference to my class library project. Then to the “App_Data” folder, I am adding the MS Access .mdb file.

image
Add Project Reference
image
Solution Explorer : App_Data Folder
Then I am modifying the web.config file as follows.

I am adding new a connection string which will point to the Access .mdb file.
<connectionStrings>
  <add name="AccessFileName" connectionString="~/App_Data/ASPNetDB.mdb" providerName="System.Data.OleDb"/>
</connectionStrings>

Then I am further modifying the web.config file as follows.
<membership defaultProvider="AccessMembershipProvider" >
    <providers>
    <clear/>
    <add name="AccessMembershipProvider"
        type="MyAccessProviders.AccessProviders.AccessMembershipProvider,MyAccessProviders"
        connectionStringName="AccessFileName" requiresQuestionAndAnswer="false"/>
    </providers>
</membership>

<profile enabled="true" defaultProvider="AccessProfileProvider">
    <providers>
    <add name="AccessProfileProvider" type="MyAccessProviders.AccessProviders.AccessProfileProvider,MyAccessProviders"
        connectionStringName="AccessFileName" />
    </providers>
    <properties>
    </properties>
</profile>

<roleManager enabled="true" defaultProvider="AccessRoleProvider">
    <providers>
    <clear/>
    <add name="AccessRoleProvider"
        type="MyAccessProviders.AccessProviders.AccessRoleProvider,MyAccessProviders"
        connectionStringName="AccessFileName" />
    </providers>
</roleManager>


Now that’s it. A can create a new account and I can see it in the “ASPNetDB.mdb”.

image
Create New Account
image
Logged In
image
User created in the database
I have uploaded a sample of all the class files and the database to SkyDrive. Do check it out and hope this helps.
     Download the Sample

Happy Coding.

Regards,
Jaliya

Tuesday, December 4, 2012

SharePoint 2010 : How to Create a Custom List Definition and a Instance

I will start by creating an Empty SharePoint project and I am going to deploy it as a Farm solution.
Untitled1
Empty SharePoint Project
Untitled2
Trust Level - Farm Solution
Then I am adding a SharePoint Mapped Folder to Images and I am adding a image to use as Feature Image Url.
Untitled3
SharePoint "Images" Mapped Folder
Untitled4
SharePoint "Images" Mapped Folder created
Then I am right clicking on my Project and add a new item which is a “List Definition”.
image
Add List Definition
Now I am setting the Display name of my list definition and setting up the list type as a “Custom List”.
Untitled5
List Display Name & Type

A Feature will be created in addition to my list definition. I am double clicking on the feature and in the properties I am setting up the Image Url.
Untitled6
Feature Image Url

Now I am modifying the Schema.xml file in the list definition. I am adding fields which should be included in my list.

Schema.xml
<Fields>
        <Field Name="EmpId" DisplayName="Employee Id" Type="Text"></Field>
        <Field Name="EmpName" DisplayName="Employee Name" Type="Text"></Field>
</Fields>


Since I have created an instance of my list, I am going to put some default values. I am modifying the Elements.xml of the instance.

Elements.xml
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="MySharePointProject - MyListInstance"
                OnQuickLaunch="TRUE"
                TemplateType="10000"
                Url="Lists/MySharePointProject-MyListInstance"
                Description="My List Instance">
      <Data>
          <Rows>
              <Row>
                  <Field Name="EmpId">1</Field>
                  <Field Name="EmpName">Jaliya Udagedara</Field>
              </Row>

              <Row>
                  <Field Name="EmpId">2</Field>
                  <Field Name="EmpName">John Doe</Field>
              </Row>

              <Row>
                  <Field Name="EmpId">3</Field>
                  <Field Name="EmpName">Jane Doe</Field>
              </Row>
          </Rows>
      </Data>
  </ListInstance>
</Elements>


Now I am deploying the solution and once it is activated, I can see my List definition is available.
Untitled12
Create New List

And I can see a quick launch item is created.
Untitled7
Created List Instance

I am getting the default view of the list instance. But as you can see the two fields I have added is not displaying here. So I am again modifying the Schema.xml file in the list definition as follows. I am deploying the solution again and now the fields are displaying.

Schema.xml
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
    <ViewFields>
      <FieldRef Name="Attachments"></FieldRef>
      <FieldRef Name="LinkTitle"></FieldRef> <!--if you don’t want to see title, comment this line-->
      <FieldRef Name="EmpId"></FieldRef>
      <FieldRef Name="EmpName"></FieldRef>
    </ViewFields>
    <Query>
      <OrderBy>
        <FieldRef Name="ID"></FieldRef>
      </OrderBy>
    </Query>
    <ParameterBindings>
      <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
      <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
    </ParameterBindings>
</View>


Untitled9
Created List Instance
Now when I click on Add new item, only Title field is displayed and not my created fields.
Untitled8
Created List Instance
For that, I am commenting the following part in the Schema.xml file in the list definition as follows.

Schema.xml
<!--<ContentTypes>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>-->


Now I can see the fully completed output.
Untitled11
Created List Instance
Happy Coding.

Regards,
Jaliya