Tech ED – Windows 7 embedded

image I had the pleasure of attending the DEMO MANIA session on Windows Embedded Standard 2011, also called “Quebec” or plain Windows 7 Embedded.

Due to the fact that it was a DEMO session, the amount information given were minimal and the visual presentation was in focus.

The embedded team has come up with a treat for all of us technical guys. They have prepared Windows 7 for embedded devices, and in such a way that when you boot up for the first time, a menu appears to let you chose which Device drivers you need for the system (the ones it did not find it self). After this, the system let’s you pick and chose your desired configuration, meaning that you now have a chance to deselect IE, or just the parts of IE you don’t want… And off course not only IE, but every little piece of Windows 7 you select and deselect as of your likings (That is WOW!). In Short it is a full Windows 7 with all features, (silverlight etc.) where you deselect features to make it fit your device and wishes.

I got a hold of an early preview version of Windows Standard 2011 and when I got home, I immediately started to install the version onto my Asus Eee 901 just to see the how it worked! And you can really optimize a laptop with this kind of version :-)

But…. It was brought to my attention that it was illegal to install Windows Embedded Standard on a Notebook, and therefore I have now erased it, and cannot show any pictures of my progress with the adventure (I will not even explain about it).

Windows 7 Embedded Standard 2011 as OS for Windows Mobile?

But with all of this power at your hands, and the statements from Microsoft that the future of their mobile phones will run on at least 1GHz processors…. Hmmm wouldn’t be weird if Microsoft didn’t use this as a new operating system (OS) for Their Mobile products too?? Let me answer that! Yes it would.. With this product at their hands, Microsoft is finallly able to have – One Operating System For All platforms – A vision they had for years, and a vision Mr. Steve Balmer talked about on his last visit in Denmark.

And here is the more technical information:

Processor Architecture
Support for multiple processor architectures
· x86
· x64

Tools
Improved developer experiences:
· Wizard experience with Image Build Wizard (IBW)
· Advanced experience with Image Configuration Editor (ICE)

Componentization
The right level of granularity to build special-purpose devices
· Hundreds of feature packages based on latest innovations for Windows 7
· Embedded enabling features such as Enhanced Write Filter, File Based Write Filter, Registry Filter, Hibernate Once Resume Many, and Custom Shell to fulfill embedded-specific requirements
· Large number of driver sets for compatibility with growing set of device hardware and peripherals

Application Compatibility
Applications and drivers for Windows 7 can work on Windows Embedded Standard 2011 without difficult, expensive, and time-consuming porting effort

Enterprise Connectivity and Manageability
Support for Active Directory, Domain Join, Group Policies, Network Access Protection, and IPv6 to enable connectivity and manageability with Windows Server, System Center Configuration Manager, System Center Operations Manager, and Windows Server Update Services

User Experiences
Rich, interactive user experiences with Windows Aero and Windows Touch and Gesture. A stable framework Windows Presentation Foundation for building new and innovative experiences.

Video resources

image http://channel9.msdn.com/posts/Charles/Windows-Embedded-Past-Present-and-Future/

Websites

image http://windowsembedded.com

imagehttp://msdn.microsoft.com/en-us/windowsembedded/ce/default.aspx

imagehttp://msdn.microsoft.com/en-us/windowsembedded/standard/default.aspx

Blogs

image Olivier Bloch - http://blogs.msdn.com/obloch/

imagehttp://blogs.msdn.com/mikehall

imagehttp://blogs.msdn.com/jcoyne

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 12/5/2009 at 4:24 PM
Tags: , , ,
Categories: Embedded | OS | Tech ED | Windows 7
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Tech Ed experience

At the Tech ED Conference

We started our journey to Tech ED Europe, on Sunday the 8th of November. All of the Danish Microsoft Student Partners had agreed on, meeting at the airport, because we were on the same flight. But as the plane was going into the air we were missing one of our MSP’s. He had unfortunately missed the flight, and had to wait until Monday morning to get the next flight down to Berlin.

clip_image002

Picture 1 - First day at Tech ED, Jacob Korsgaard and Martin Esmann

Welcome to Tech ED

The first day of Tech ED came, and we started with a check in – to get our access passes – and thereafter headed directly to the SWAG hand out area to collect a brand new bag, that could hold our laptops, and of course the bag had even more goodies in the form of a Windows 7 ultimate etc. After this it was a matter of finding the sessions that you had put in your calendar from home. One thing that I hadn’t calculated into my schedule was the 7200 other conference attendees! And the fact that finding things among so many people would not be easy. But luckily that turned out alright and I found all my sessions (and on time). After this first day, we headed back to the hotel, ready to put the day’s experiences and newly acquired knowledge onto our blogs….. But, the hotel did not have free internet!? In fact the hotel wanted us to pay 4 euro per half hour of internet usage!? I’ll let that hang for awhile….. That’s 6 Dollars or 32 Danish kr. FOR HALF AN HOUR!!!! So if you go to Berlin and need internet, please keep away from - Hotel Grand City Excelsior, or you will lose money! That’s the main reason why most of our post to our blogs, are being done after the Tech ED event, and not during the event. When attending the event, you don’t have the time to, attend sessions, be social, post on blog and do some coding, if you don’t have the possibility to do some blogging from the hotel... (If you want to be serious with your blog posts, internet access is necessary to check up on facts before posting).

The next thing about going to Tech ED as a Microsoft Student Partner is, that there are MSP’s from all over Europe gathered at this event, and we were all put together on Tuesday in an event just for us Microsoft Student Partners. At this event we were given some of the top speakers at Tech ED at our disposal, so we could ask them any questions we might have, and get top of the line expert answers to the questions. To name a few of the speakers we could talk to: Rob Miles, Microsoft Most Valuable Professional and lecturer in the Department of Computer Science at the University of Hull (he also gave an exclusive talk on building games with XNA, and he took some awesome pictures of us! See his version of the event here http://www.robmiles.com/journal/2009/11/10/student-session-fun.html), Don Syme, Microsoft Research and developer of F#, Olivier Bloch, Embedded Systems Engineer at Microsoft and many others…

clip_image004

Picture 2 - The panel of speakers at our disposal

This event did indeed bring us MSP’s closer together, and we began talking to one another on daily basis, exchanging contact information and knowledge. We had a meeting point at the conference, which was called The Community Lounge, where we all hanged out whenever we had time. And as it turned out so did some of the top speakers which gave us MSP’s opportunity to ask even more questions and get quality answers.

On Thursday, all the MSP’s were gathered again (after the sessions had ended) and now it was time for us to see some of Berlin’s culture. We went to a restaurant and had dinner (all 77 MSP’s), and after dinner, we went out to see the Berlin underground, how it looked from medieval time till now, and why things had changed (of course did had something to do with breweries and us drinking a few beers while taken the tour). This tour lasted for one and a half hour, after which we went back to the restaurant and held a party.

clip_image006

Picture 3 - At the Comunity Lounge

At one point a fellow MSP named Jacob Korsgaard and I decided to enter a contest, where we should develop artificial intelligence for an ant colony. We could create as many ant personalities we wanted to, and deploy these ants to collect foods and sugar while avoiding other teams ant and bugs that wanted to kill our ants. This turned out as a very fun challenge, and we actually won the daily contest as well as the final. Whoo hoo ;-)

As a Microsoft Student Partner you always travel to Tech ED with a hope to get to talk to specific speakers, and my hope was to catch Harry Pierson who is a Senior Program Manager in the Visual Studio Languages-team, with focus on IronPython. And I was not disappointed! A was able to catch by the Visual Studio stall, where he took his time to talk about IronPython and Dynamics languages in general. This was really awesome to be able to get to talk to him at the Tech ED, and of course I was attending his session on the DLR (dynamic language runtime).

clip_image008

Picture 4 - Harry Pierson geting ready for session on DLR

But that wasn’t it! While I was resting in the Community Lounge, I suddenly saw Harry Pierson and Don Syme getting ready for a live stage talk on programming languages. I went over and sat on a chair, and I was in for a treat! Harry and Don gave us all a good debate talk on IronPython, F# and C# (to name a few), and afterwards we could ask them questions to our liking… They really gave all of us an in dept insight into their opinions on the differences and forces of the languages and the DLR.

clip_image010

Picture 5 - Harry Pierson and Don Syme talking about languages

The experience as a Microsoft Student Partner at the Tech ED is one of the best ones I’ve had in a long time. I have used this Tech ED to gain a stronger knowledge base, and to create a large network af other MSP’s and other delegates. And I hope that you too one day get to experience this technical highway of knowledge at your disposal.

Oh and of course!

The last night in Berlin, we were a couple of MSP’s going into the streets of Berlin to see if we could find some of their famous beer, and we did!

clip_image012

Picture 6 - Green apple beer and red raspberry beer

These are the funniest tasting beer I’ve ever tasted, but they were not bad! The bar had as different beers as Banana beer, ginger beer, beer with coca cola, raspberry beer, cherry beer and many others. If you ever go to Berlin, don’t miss out on their beer ;-)

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 11/15/2009 at 6:12 PM
Tags:
Categories: Tech ED
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Tech ED – Top 10 mistakes made by Web developers and how to avoid them

At this Tech ED Session Pete LePage Talked about top 10 mistakes that web developers do, when creating a website. This has for a long time been a problem, although standards are there, too aid the developer in designing/developing the website (and apparently this is very much still an issue.

  • The use of colors on websites 
  • Not optimizing websites for search engines
  • Over extended use of Flash, Silverlight and Rich Media in general
  • Not giving the ?tab? key any thought when using forms
  • Inconsistent website design
  • No easy navigation of the website
  • Errors in the code 
  • Extreme use of ads on websites, and sticking them in everywhere
  • Having non designers, design the websites

Web developers have to pay close attention to the use of colors on their sites. There are many great resources out there to help finding those ?websafe? or ?websmart? colors. When building a site using a lot of colors, we tend to forget about the millions of colorblind people out there not being able to use the sites due to web developers use of colors that suck! And because of the developer being a little to creative with the use of colors like yellow background with blue text etc?

There are also a lot of developers, that do not make use of the meta tag keyword in their websites. This meaning that search engines will categorize the websites using their <h1> tags (So please also make sure that this tag gives a meaningful interpretation of what this page has to offer!). An search engine rank a website by their use of meta tags:

<head> <title>meta - HTML 4.01 dokumentation</title> <meta name="description" content="Description of site.">
<meta name="keywords" content="meta, html, css, xhtml, xml">
<meta name="title" content="meta - HTML 4.01 dokumentation">
<meta name="language" content="dan"> <meta name="date" content="20-10-00">
<meta name="robots" content="index, follow">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head>

their <h1>, <h2> tags and the text used to describe the <h1>, <h2> tags.. (Think about his before making everything as a picture on the site!).

When designing a website there are trends moving towards using a Flash only website?? Please open up a browser and take a look at this awesome car site

 http://www.miniusa.com/ 

Looks really cool right? Now open up your browser and disable JavaScript and browse the site again! If you click on a few links, you even get an 404 error!!  Be aware of using to much flash will cut some people from using your site. And if it?s a products site trying to sell something, then you?re cutting potential buyers from buying your product?

A basic an simple thing to keep in mind when using forms on the website is to have a tab order index, and have that index match what you would expect when filling out a form.

When creating a web site, one of the most important things to keep in mind is to design/develop the site consistently. Every page on the site most have the same look and feel to it (when ever possible). There are a lot of sites on the web, which do not have consistent look and feel to them, and honestly it look ridiculous and un-professional.  For example look at these two sites:

http://www.wsdot.wa.gov/traffic/seattle/flowmaps/bridges.htm

http://wsdot.wa.gov/traffic/
It is the same site, just different views of traffic information, but the two pages doesn?t have the same look!

Links on a web page is the most important thing to have! But some sites really makes you guess what are links and aren?t.

http://www.samanzerin.com/

It?s graphically a really cool site, but it makes the users have to guess what the links are? Too much ?Glam? in a site, will ruin what the site is actually supose to say? Hey we want to sell you something, and that something is?.. Remember that the users have to be able to use the navigation, let alone find the navigation on your website.

Be aware of using to many automated tools, without knowing what they do! Make sure you know what DOCTYPE your using when developing your site. When developing your site, the architecture must be designed with DOCTYPE in mind. Otherwise you will end up having HTML code tags that are not supported by the given DOCTYPE, and the web browser engines will not render your site correctly. This tend to leave even more hacks in the HTML code just to make the site function as intended. When web site is designed with a specific DOCTYPE in mind, you will ? in advance ? know what tags you?re able to utilize, and in the architecture design fase, how to implement it?..

A quick word on ads on your site!

http://www.barcelona.com/

What are they trying to tell me? Is this an website promoting ads? Are they selling ads, or do they just like lots of ads? Too many ads, in ?weird? places ruins the site entirely, and the user will click away!

In the end, find out what you want your site to state! And be aware of too much information on the website (not too little, and not too much) . This web page gives a good example of ? what not to do!

http://www.havenworks.com/

What just happened here!?

Also, when putting up a website, developers are very often not the right persons to get to write the content on the website! In general, people with deep knowledge of the subject is very often the wrong ones to write the information made availeble on the site. They tend to use specific language terms etc. in the text, that end-users will not understand? Get someone to read through the text, sugesting normal langu<ge terms, and please?? Check the spelling! ;-)

And again, because you can do something, it doesn?t mean it?s a good idea!?

http://web.archive.org/web/20060613061524/http:/moire.ch/

Try hovering over the links?

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 11/10/2009 at 5:44 AM
Tags: ,
Categories: Tech ED
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Attending Tech ED Berlin 2009

TechED

“All my bags are packed, I’m ready to go……”

I’m am very exited to get to Tech ED Berlin 2009 (which is now sold out!). I’ve been trying to wrap my head around what track and sessions I should attend, because there are MANY! to chose from. As a person I believe it’s importent to focus on the fact that this is a unique opportunity to evolve your knowledge. Therefore I have chosen to expand my choice of sessions to not just include areas of immediate focus, but to also include areas of common interest.

I spend a few hours on the track & sessions page, figuring out pros and cons on sessions that unfortunately collided on day and hours. But I think I hit an amazing agenda for the entire week:

TechEd Europe Keynote - Welcome to the New Efficiency
Enabling Rich Business Clients with Windows Presentation Foundation
Top 10 Design Mistakes Made By Web Developers and How to Avoid Them
Windows 7 Demo Mania
Embedding Windows 7 into Devices
Tips and Tricks for Building High Performance Web Applications and Sites
Pumping Iron: Dynamic Languages on the Microsoft .NET Framework
F# for Parallel and Asynchronous Programming
Microsoft Visual Studio Team System 2010 Team Foundation Server: Become Productive in 30 Minutes
Unit Testing Best Practices
The Windows API Code Pack: How Managed Code Developers Can Easily Access Exciting New Windows Vista and Windows 7 Features
Windows 7 and Windows Server 2008 R2 Kernel Changes (*PDC at TechEd)
Windows 7: The Power Management Workout!
Building High Performance Parallel Software
Windows Embedded: "Demos Only"
Parallel Computing for Managed Developers
Achieve new levels of desktop optimization with Intel Core™ 2 processors with vPro™ technology and Windows* 7
Case of the Unexplained... Windows Troubleshooting with Mark Russinovich

The one session that I look really forward to is Windows 7 and Windows Server 2008 R2 Kernel Changes!! I’ve been following the discussion on the internet, and following the videos from Channel 9 on Windows 7.

The official note on the session leaves me with the impression that this is going to be really good:

“This session goes beneath the hood of Windows 7 and Windows Server 2008 R2 to describe and demonstrate the key changes in the kernel. Topics include: scalability improvements such as removal of the global scheduler lock, support for more than 64 logical processors, and user mode scheduling, virtual service accounts, core parking and timer coalescing for power efficiency, trigger-started services, core architecture changes to modularize Windows ("Minwin") and more.”

And the embedded part with demo’s are also something to be looking forward to:

“This demo-packed session presents all sorts of devices, tools, and technologies used in today's and tomorrow's embedded projects. If you want to learn how Windows Embedded can be used to build stunning devices or if you are just a geek, you can't miss this session.”

And yes, I’m a geek!

I’m really looking forward to this mix of Desktop, embedded, web technology and architechture sessions. And not forgetting all the demo presentations that makes this Tech ED a must-see event.

Appart from all of these sessions, I will be on the lookout for the expo areas, where I will get a chance to have a look at what all other developers are doing right now.

I’m also loking forward to meeting all the other Microsoft Student Partners from all over the world. And this will ofcourse introduce them to my network, and me to theirs.

If you find the subjects listet above interesting, then I will attempt to blog on every single one of them, and hopefully provide you with awesome pictures from the whole event. If you find subjects of interests missing in my list, I will suggest that you have a look at some of the other Microsoft Student Partner blogs. We are well represented at the Tech ED event, and maybe they will attend more convenient subjects. You can find links to there blogs on the left column.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 10/31/2009 at 5:14 PM
Tags:
Categories: C# | Embedded | F# | FMOD | IronPython | OS | Programming | Tech ED | Velkommen | Windows 7
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Send email with PDF attachment in NAV 2009

Are you using Microsoft Dynamics Nav 2009

Here is a brilliant post explaining how to create an email from the Role Tailored client and attach an invoice as a PDF file to the email. (Including the source code for download).

Microsoft Dynamics Nav team Blog

 

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 10/16/2009 at 4:35 AM
Tags:
Categories: Dynamic Nav
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Win a book on IronPython or F#

Here is a little contest that will run for 14 days (until the 29-09-2009), where every developer should have a chance of winning!

The Contest has ended, and the winner was Yoni Holman! Congratulations!

I?ve created 7 questions, in different programming languages such as C#, F#, Ironpython, C++, Java and off course the well known and liked true or false. The questions are designed to give a number of points, where the maximum number of points given can be read in the text of the assignment. The rules are simple, the one with the highest score on points, will win. Points will be given for correctness and effort. An assignment might give 6 point, but if not entirely correct, it will be given some points for effort.

What can you win?

The winner gets Office 2007 Student version, and gets to choose one of two books ? Foundation of F# or IronPython in Action - and the runner-up gets the book that the winner did not choose.

FSharp ironpythoninaction OFF2007STUKEY

What to do now?

If you want to try out for the books, all you have to do is:

  • Leave a comment on this blog-post (in case that when you submit, and your assignment gets in my spam-mail-box, I?ll know to look for it here if its not in my usual mailbox.
  • Submit your answers (as a txt file) to my mail address (ajp at clug.dk)
  • Everyone is allowed to solve all the questions (if you can), or just some of them.
  • When mailing me, please leave ? if you have ? your Twitter name, and I will also post the winner and runner-up on twitter (if the winner and runner-up has a Twitter name).

Here are the questions

Question number 1.

6 point

The following code compiles and runs without problems, but everything is not as it should be. When a user enters the input as shown below, what is the output? And more important, why is the output as it is?

#include <iostream>

using namespace std;

char string1[2]; char string2[2]; char string3[7]; char string4[7];  char string5[8];

int main (){
    cout<< "\n Read 1. text (length 2)";
    cin>> string1;
    cout<< "\n Read 2. text (length 2)";
    cin>> string2;
    cout<< "\n Read 3. text (length 7)";
    cin>> string3;
    cout<< "\n Read 4. text (length 7)";
    cin>> string4;
    cout<< "\n Read 5. text (length 8)";
    cin>> string5;
    cout << "\n 1.: "<< string1;
    cout << "\n 2.: "<< string2;
    cout << "\n 3.: "<< string3;
    cout << "\n 4.: "<< string4;
    cout << "\n 5.: "<< string5;
    return 0;
}

Read 1. text (length 2) - F#
Read 2. text (length 2) - C#
Read 3. text (length 7) - ASP.NET
Read 4. text (length 7) - IronRuby
Read 5. text (length 8) ? IronPython

Answer:

1. F#C#ASP.NETIronRubIronPython
2. C#ASP.NETIronRubIronPython
3. ASP.NETIronRubIronPython
4. IronRubIronPython
5. IronPython

In C++ the strings are null terminated. This means that space must be preserved for null termination character. In the assignment above, the null character is overwritten, and therefor the output is as shown.

This example does have some issues regarding compiler dependencies, and yes this was also part of the assignment ;-)

Question number 2.

9 point.

The following is an application made with the .NET Micro Framework, but the code is missing two lines! The missing parts are an Output port, and an Input port. Implement these two line to complete the code.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace MicroFramework
{
   public class Light
   {
     public static void Main()
     {
       Cpu.Pin pin = Cpu.Pin.GPIO_Pin1;
       Cpu.Pin switch = Cpu.Pin.GPIO_Pin2;
       //missing line
       //missing line

       while (true)
       {
         YourOutputPort.Write(YourInputPort.Read());
       }
      }
     }
}

Answer:

OutputPort YourOutputPort = new OutputPort(pin, false);
InputPort YourInputPort = new InputPort(switch, false);

Question number 3.

3 point.

The following code is F#, and it represents an array. Finish the code, so that every item in the array is printed out to the screen.

#light
let colors = [| "Blue"; "Green"; "Yellow"; "Black"; "White"; "Red"; |]

//iterate over the array, and print out the items within the array.

Answer (There are multiple ways of doing this) :

for color in colors do
    print_endline color

Question number 4.

4 point.

The following code is an array written in C#. create a LINQ query that selects the items that are less than 15 and do this:

  1. Using standard LINQ query
  2. Without the use of keyword "var" (without implicit typing).

int[] numbers = {5, 2, 10, 12, 16, 35, 20, 100};

//Create query

//iterate and print out items

Answer:

1.
var query = from i in numbers where i < 15 select i;

foreach(var i in query)
  Console.WriteLine("Number: {0}", i);

2.  
IEnumerable<int> query = from i in numbers where i < 15 select i;
foreach(int i in query)
  Console.WriteLine("Number: {0}", i);

Question number 5.

6 point.

Implement a function in IronPython that takes one parameter, and calculates and returns the Fibonacci series. Then call your function with the number 200.
shown here in pseudocode:

FibonacciFunction(aNumber)

calculate fibonacci

return number

call function
print output

Answer:

def fibonacci(number):
        result = []
        a, b = 0, 1
        while b < number:
             result.append(b)
             a, b = b, a+b
        return result

fib = fibonacci(200)   
fib

Question number 6.

8 point.

The following code is in Java, and it is a sorting algorithm. Two lines are missing, and you are to implement the missing lines.

public class HeapSort
{

    public void heapSort (int [] A)
    {
        printArray(A);
        makeHeap(A);
        printArray(A);
        for (int i = A.length-1;i >0 ;i--)
        {           
            int temp =0;
            temp = A[i];
            //Line missing
            A[0] = temp;
            reheap(A,0, i-1);
            printArray(A);
        }
    }
    public void makeHeap(int [] A)
    {
        for (int j = ((A.length / 2)-1);j>=0;j--)
        {
            reheap(A, j, A.length-1);
        }
    }
    public void reheap(int [] A, int current, int last)
    {
        int leftChild = 2* current +1;
        int rightChild = 2* current +2;
        int largest;
        int tempA=0;
        if (leftChild <= last && A[leftChild] > A[current])
        {
            largest = leftChild;
        }
        else
        {
            //Line missing
        }
        if (rightChild <= last && A[rightChild] > A[largest])
        {
            largest = rightChild;
        }
        if (largest != current)
        {
            tempA = A[current];
            A[current] = A[largest];
            A[largest] = tempA;
            reheap (A , largest, last);
        }
    }
    public void printArray(int [] A)
    {
        System.out.print("Array: ");
        for (int i = 0; i < A.length ; i++)
        {
            System.out.print( A[i] + ", ");
        }
        System.out.println("\n");
    }
    public static void main(String[] args)
    {
        int A [] = {10,23,75,24,98,87,27,11,34,28,17,13,31,37};
        HeapSort heap = new HeapSort();
        heap.heapSort(A);

    }

}

Answer:

A[i] = A[0];
largest = current;

Question 7.

Each correct answer will give 1 point each. (max point is 21).

In this assignment you should answer "true" or "false" to the following questions:

  1. IronPython is the .NET version of Python.
  2. IronPython is a functional programming language.
  3. There is nothing called IronRuby from Microsoft.
  4. IronPython does not work in a web browser.
  5. IronPython is a dynamic programming language.
  6. IronPython can interact with the C# programming language.
  7. IronPython is an OpenSource language.
  8. F# is a dynamic programming language.
  9. F# does not work with WPF (Windows Presentation Foundation).
  10. F# only works with math and formulas.
  11. F# works with Windows Forms.
  12. F# only runs on Windows Computers.
  13. F# is an OpenSource language.
  14. C# is the only programming language in .NET family.
  15. C# can only be used on Windows computers.
  16. The .NET MicroFramework is used for embedded systems.
  17. ASP.NET is a Java version of PHP.
  18. ASP.NET can only be used on Windows computers.
  19. ASP.NET, C#, F# and Silverlight all run on Linux.
  20. Moonlight on Linux is the same as C# on Windows.
  21. Mono is the same as F# on Windows.
Answer:

1. true
2. false
3. false
4. false
5. true
6. true
7. true
8. true
9. false
10. false
11. true
12. false
13. true
14. false
15. false
16. true
17. false
18. false
19. true
20. false
21. false

The text in small print

Everyone from every country is allowed to participate in this contest. The winner and runner-up will be notified by me personally, and I will personally send the books to their home address. If the winner and runner-up will allow it, their names will be posted on this website after I have talked to them.

All I can say now is good luck, and I hope you find this fun :-)

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 9/15/2009 at 6:48 AM
Categories: C# | IronPython | Programming | F# | Contest
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (8) | Post RSSRSS comment feed

IronPython

 

I had the pleasure of attending Harry Piersons TechTalk at Microsoft Development Center Copenhagen (MDCC) on IronPython.

IronPython is a new member of the .NET family, based on the programming language Python. The Iron part has become known as It-Runs-On-.NET.

IronPython is a dynamic programming language (as Perl, PHP, Ruby and JavaScript - Although Perl and PHP never truly was Object oriented at heart, but they are moving in that direction now), which means that execution happens at runtime and not at compiletime. Dynamic languages make it easy to quickly manipulate data, which often is collected from networks, user interfaces and devices, and are extremely powerful when it comes to manipulating meta-data, whereas static languages (eg. C#, C++, and Java) often prove its strengths in creating complex data structures and algorithms and so on. It’s said that Dynamic languages focus on the code, rather than the structure or “architecture”.

With IronPython in the .NET family the developers now have a perfect opportunity to combine the forces of static languages as C# with a dynamic language namely IronPython.

In Harry Piersons own words “Dynamic languages are easier to learn and therefore teach”. And then he gave a small example where he compared a “Hello World” program from C# with the same in IronPython:

// C# version of "Hello World"
class Program
{
static void Main()
{
System.Console.WriteLine("Hello, World");
}
}


// IronPython version of "Hello World"
print "Hello, World"

Now wait a second! What about C# 4.0?

C# version 4.0 now comes with a new keyword called “dynamic” which can be used to dynamically invoke methods, but I’ll let it be up to the reader to dig in deeper with the new version of C# coming out.

Is IronPython opensource?

YES it is! Microsoft has two licenses that have been approved by the Open Source Initiative(OSI), which means that developers can be confident that the licenses meet the terms of the Open Source Definition. And yes, the IronPython team is taking in contributions from the community, and for that – Microsoft I salute you. Thank you for showing initiative to promote things via opensource.

The roadmap for the IronPython project is, that in December 2008 it was shipped in version 2.0, and Microsoft hopes to release version 2.6 (Microsoft has decided to end confusions, and name the versions after Python release conventions ) in the near future. They are also planning to release IronPython for .NET version 4.0, (with release shortly after version 4.0), which will work with C# Dynamics and be compatible with Python version 2.6 and 3.1. The intention is not to have a release cycle like the one on Visual Studio, but rather have it be a plug-in for Visual Studio, so that the IronPython team can maintain a release cycle of ca. 10 months.

For more resources:

 

 


Just an update! You can view the video, and download the slides from the Tech Talk on Channel 9

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 9/14/2009 at 4:42 AM
Tags: ,
Categories: IronPython
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Tech ED 2009 in Berlin

The time has come, this November 9 -13 there will be Tech ED in Berlin.

The Tech ED is a really great place to get in- deep coverage of technical material from Microsoft,
but that's the only thing! You will have the ability to certified on the spot! And Microsoft Partner solutions
will also be presented.... Cool!

I've taken a snapshot to show which Topics will be presented at Tech ED 2009 Berlin:

 

273

The Windows Client track e.g. contains sessions on adoption, deployment, management,
and virtualisation of the Windows® Desktop Environment, including a technical introduction 
into Windows® 7 and Windows® Internet Explorer® 8.


The Web and Internet Application track contains sessions on Microsoft® Expression® Studio, Microsoft® 
Silverlight™, Microsoft® Internet Information Services (IIS), ASP.NET, ASP.NET AJAX,
Windows® Internet Explorer®, Windows Live™ Platform and more.

So as you can see it's an action packed Tech ED, covering the whole week:

 

And you can spend hours on their website just planning what to see!


For more information go to The TechED 2009 Berlin Website

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 9/1/2009 at 3:50 AM
Tags:
Categories: Tech ED
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Windows 7 and security

One of the big issues with Windows Vista was that the system was too strict on security, and always popped up with notifications regarding security issues. This became a big problem, because a big part of the Windows Vista users chose to completely turn off the notification feature, leaving the system vulnerable.  To address this problem, Windows 7 introduces 2 new security levels (see figure bellow) in the User Account Control Settings (UACS). The first - which is default in Windows 7 - is called: Notify me only when programs try to make changes to my computer, which is a level where you no longer see notifications regarding you messing with the settings in the Control panel, but only if a third-party program tries to. The second is called: Notify me only when programs try to make changes to my computer (do not dim desktop). This level will further stop the UACS from utilizing the "safe desktop" and the desktop light will not dim, and you will be able to run other programs while UACS messages pop up. It is no longer possible to turn off the UACS completely, but you can tell the UACS to never ever inform you of anything. 
 
 
 
 
In Windows 7, the Security center has been replaced with the Action Center, which now contains the functionality of Computer Maintenance and Security. Here you are now able to adjust the notifications according to a given subject, e.g. if you no longer wish to see information regarding virus protection or network firewall, you just uncheck the subject from the list. Off course this doesn't improve security, but it removes the hassle of administrating the system. In fact, Windows 7 has pushed even more security settings in, when compared to Windows Vista, but it also introduces problem solving tools, which is problem solving wizards which check your program and security settings for problems, and tell you what they find. 
 
AppLocker is a new feature to Windows 7, which easily lets you which programs different users are allowed to run. E.g. You can tell AppLocker to trust all software coming from Microsoft (or others) and AppLocker will run all software signed by Microsoft, and you can stretch this into also telling AppLocker that newer version of a give piece of software is trusted, and these will also run without problems. This feature though is only provided with the Windows 7 Ultimate edition.
PC Safe Guard - or as I like to call it; Annoy-Your-Teen - is essentially a kind of sandbox account. It lets you create a user account and set it up with the software you want, and then activate PC Safe Guard. PC Safe Guard then makes sure that all software (and spyware or viruses) installed after activations is deleted when the user logs out, and this way the user account returns to the state of first-install. Files created in an PC Safe Guard activated User Account, must be saved on another partition of the hard drive, where PC Safe Guard will not touch them. 
 
BitLocker is a feature that was also present in Windows XP and Windows Vista. In these versions though it was not always easy to find, but all this has changed in Windows 7. Now all you have to do, is right-click the hard drive and select "turn on BitLocker", and an easy guide will follow you through the process. This feature is only available in Windows 7 Ultimate, which I find rather disturbing. Microsoft has a portal called MSDNAA where students from around the world (if the university they attend to has signed up for MSDNAA) can download Microsoft products for free (while being students). This portal gives the Windows 7 pro. Version to students and faculty teachers. With this in mind, there is lots of research going on at these universities, where encrypting of hard drives could be a nice feature. So why not make BitLocker available to lower versions of Windows 7?

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 8/31/2009 at 8:12 AM
Tags: ,
Categories: Windows 7
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

IronPython is TechTalk

Get an introduction to Python on the .NET Platform, from Harry Pierson.

At the Microsoft development center copenhagen... (sorry guys, this one is in Denmark)

About Harry Pierson
Harry Pierson is a Senior Program Manager on the Visual Studio Languages team, primarily focused on IronPython. A ten year Microsoft veteran, Harry has worked all over the company from Microsoft Consulting Services and Architecture Evangelism in the field to being an architect in Microsoft IT. He has been writing his blog DevHawk (http://devhawk.net) for just over six years and has written articles for MSDN and CoDe Magazines.

He will be talking at variuos universities around Denmark, I just don't have the dates yet, but for more information look here http://www.computerworld.dk/blog/studblog/1931?cid=6&a=cid&i=6&o=1&pos=2

 

 

 

Currently rated 3.0 by 1 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 8/24/2009 at 7:04 AM
Tags:
Categories: Programming
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

P/Invoke, InteropServices, C# and FMOD

Making music with C#, P/Invoke, InteropServices and FMOD

I've been trying to give a glimse of how one could make a media player, but I'm not the kind of person who gives the whole answer until the absolute end. This post will be no different from the others. I'm going to present an outline as to making a media player using the FMOD library. The beaty of this library is that you can use it cross-platform so this code will also work for Linux in Mono (Linux version of C#)

Download the FMOD Library for Win32, for Windows CE, Windows CE small, Linux or MacOS

And inside you will find the reference manual, which is the place to start to get familiar with the functionallity of the library. In this little post I will focus on using C#, but as you might have guessed one can utilize every known language to programme against the FMOD library. On a quick notice; the FMOD library is primarily used in game development, but works just fine as a mediaplayer library. It is legal to use the FMOD library, without paying anything, just as long as you don't start selling your code as a product.

Now, the FMOD library is written in C++, and this means that it is written in unmanaged code contra the C# language which is a mannaged language. Therefore we need to have a look at the C# - System.Runtime.InteropServices; where we will find the DllImport attribute, which will call the unmanaged code from the C++ FMOD library (There is very much more going on in the CLI to call unmanaged code, but I will leave this for later post). As far as managed code is concerned, unmanaged code is invoked merely by invoking a method with an associated DllImport attribute.

[DllImport("My_CPP_Library.dll", EntryPoint="Function_in_CPP_Library", CallingConvention=CallingConvention.Winapi)]
public static extern Boolean Self_chosen_function_name(The parameters from the Function_in_CPP_Library);

Here's what I did to get the functionallity up and running:

[DllImport("fmod.dll", EntryPoint="FSOUND_Init",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_Init(int mixRate, int maxSoftwareChannel, int flags);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Open",
CallingConvention=CallingConvention.Winapi)]
public static extern IntPtr fmod_Open(string data, int mode, int offset, int lenght);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Play",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_Play(int channel, IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_SetVolume",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_Setvolume(IntPtr fstream, int volume);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_GetLength",
CallingConvention=CallingConvention.Winapi)]
public static extern int fmod_getLenght(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_GetPosition",
CallingConvention=CallingConvention.Winapi)]
public static extern UInt32 fmod_getPos(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_SetPosition",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_setPos(IntPtr fstream, UInt32 pos);

[DllImport("fmod.dll", EntryPoint="FSOUND_Stream_Stop",
CallingConvention=CallingConvention.Winapi)]
public static extern Boolean fmod_stop(IntPtr fstream);

[DllImport("fmod.dll", EntryPoint="FSOUND_Close",
CallingConvention=CallingConvention.Winapi)]
public static extern void fmod_close();


Function (and therefore names) defined in the FMOD library.

The function names that I define, and the names that I will use in my C# code.

And now off to test if it works!

public static void Main()
{
//initialize
fmod_Init(44100, 16, 0);
//load the mp3 into a soundhandle that we can use
IntPtr soundHandle = fmod_Open("C:\\Path\\To\\Song\\gone.mp3", 0 , 0, 0);
//Set the volume on the song fmod_Setvolume(soundHandle, 255);
//Play the song
fmod_Play(0, soundHandle);

Application.Init();
//Create the Window
Window myWin = new Window("My Player");
myWin.Resize(200,200);
Button playButton = new Button("Play");
myWin.Add(playButton);
//Show Everything
myWin.ShowAll();
myWin.DeleteEvent += new DeleteEventHandler(myWin_DeleteEvent);
Application.Run();
//Stop the song
fmod_stop(soundHandle);
//Close the stream
fmod_close();
}
public static void myWin_DeleteEvent(object o, DeleteEventArgs args)
{
Application.Quit();
args.RetVal = true;
}

And that's actually about it! In this example I've tried to use GTK+ so that the GUI part will work for both Windows and Linux.

I'll let you fiddle around with it a while before showing the full code including the ID3Tag etc. You're more than welcome to send me a mail or comment and I will respond as soon as possible.

Currently rated 3.0 by 4 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 8/16/2009 at 6:25 AM
Categories: C# | FMOD
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

FenixOS: a research operating system

It's been a while since I've been updating my blogwith posts, and for that I'm truely sorry! The reason is my involvement in aresearch project where we are trying to design a new operating system for thefuture!

The common operating systems of today are based ontechnology developed many years ago when topics as scalability, security andpower consumption was not a major concern in computing, like it is today.

This is the primary motivation for developing a newoperating system from the bottom with the aforementioned issues.taken intoaccount from the start.This leads to the FenixOS which is a research operatingsystem, which is aimed at the hardware specifications of computers today – thatbe Desktop, Laptop, Notebooks, and Embedded devices (Smartphones etc.)-  But even more at fact that computer systems ofthe future will contain even more CPU's than currently computers. This fact andthe fact that current operating systems all have a creation date ranging fromthe 70's through the 90's where uni-core systems where common, has made it duetime to refactor  the architecture ofoperating systems. FenixOS supports an arbitrary number of CPU's and focuses onstability, security and the need for less power usage. It is based onmicrokernel architecture to enhance stability issues, and enforces securitythrough access control lists - among others. A complete rewrite of theunderlying system structure is made in C++, to clean up the disorderlystructure seen in many current operating systems. Although everything is newand cleaned up, FenixOS is still set to be compatible with current applicationsrunning on current operating systems, this meaning that applications that runon Linux, MacOS and Windows is aimed to be able to run on FenixOS. FenixOS doesdistinct itself  from Linux by eg. Havingseparate notions of threads and processes.

 

 

How this will be achieved is still on the researchstage, but initial ideas are on the drawing board. The easiest approach toobtaining compatibility with the Unix variations of operating systems, is toport the EGLIBC library to the FenixOS platform, while off course stillupholding the POSIX’s standard. EGLIBC (embedded GLIBC) is a variant of the GNU C Library (GLIBC). GLIBCis the C library used by most Linux kernel based operating systems.

We had to start off there-designing of the operating system structure, by considering which systemcalls are necessary for an operating system to compile itself. In this phase wehad to – in order to maintain compatibility with current operating systems –examine how current systems conduct their system calls, and thoroughly considerthe impact on security, stability and power consumption. We examined Linux,MacOS, Solaris, FreeBSD, Windows, and Singularity,paying especially attention to the thoughts and design of the researchoperating system Singularity, to see how these ideas would be suitable inFenixOS, without breaking the POSIX standard and the compatibility with otheroperating systems. The one major problem of looking at the Singularity researchproject is that Singularity uses managed code language to enforce securitybetween processes (among others) called SIPS. FenixOS is implemented in C++programming language, and therefore cannot utilize the security of managedcode.  We have reasoned that thefollowing system calls would be necessary for a basic new operating system:  

 

For self compiling:

Fork(), Execve(), Exit(), CreateThread(),ExitThread(), Wait(), Futex(),

 

For  file operations:

Open(), Close(), Read(), Write(),Stat(), Seek(), Link(), Unlink(), Ioctl(),

 

Message passing:

Send(), Receive(),

 

Memory management:

Malloc(), Free()

 

I will not be going through allthe systemcalls here, as this is just an introduction, but I can give a glanceof what we did with wait() systemcall.

By looking through source codeson the GLIBC we found that there are different versions of the wait() systemcall, all with different functionality, and by further examining thedocumentation on the different libraries, GLIBC, EGLIBC and such, we found thatthey all could be combined into one single system call, without breakingcompatibility with existing operating systems. This is done by keeping theexisting functions – wait(), waitpid(), wait3(), waitid() and wait4(), buthaving all of the aforementioned functions calling our newly created do_waitid().

 

It appears that over time newwait() calls with new features has been invented and added to the differentUNIX like operating systems (Linux, BSD, Mac OS, etc.) but not all of the oldwait() calls has been removed. The most powerful of the wait system calls arecalled waitid(), this system call takes a total of four parameters and withthose it can replace the old system calls wait() and waitpid(). If we add afifth parameter, the waitid() system call can also replace wait3() and wait4().In our EGLIBC code we call this system call with five arguments do_waitid(). Becauseof this we decided to just implement one wait system call in the FenixOS kernelwhich will just be called wait() and act similar to the described waitid()call. It will then be up to the C library to map the four other system calls tothis one existing in the kernel. The system call interface looks as follows:

 

pid_twaitid(idtype_t idtype, id_t id,              siginfo_t* infop, int options, struct              rusage*usage)

 

The first argument idtype can hold 3 different values whichindicates how the second argument idshould be interpreted. If idtypeholds the value P_PID then it meanswait for the child process with the process id that matches the second argumentid. If the value is P_PGID then it means wait for any childprocess which has a process group id that matches id. Finally if idtype is P_ALL then id is ignored and there will be waited for any child process. Thethird argument is a pointer to a structure which holds information about howthe child process stopped execution. With the fourth argument options it is possible to tell when thesystem call should return. It could return when the child exits of course butalso if the child changes from one state to another, for example if the childis blocked or when it wakes up. The last argument usage is the one added to support wait3() and wait4() system callswhich are the only ones using this type of argument. The structure holdsinformation about which resources the child held and which therefore should beavailable. The trickiest part of mapping the four system calls to waitid() isthat only waitid() is using the aforementioned structure siginfo which holds information about how the child terminated. Theother four system calls uses a pointer to an integer to get information abouthow the child process terminated. EGLIBC has some build in macros that userapplications can use for interpreting this status code. So the EGLIBC code hasto translate from the siginfostructure to the status code. Luckily EGLIBC also has some build in macros forcreating these status codes which simplifies the translation part a bit (Can befound in libc/bits/waitstatus.h). Another thing we had to be aware ofwhen mapping the system calls was that not all options in the options argument could be used for allsystem calls. Therefore we added error checking for this in the EGLIBC code andreturned error code EINVAL (Error:Illegal argument) before the kernel would be bothered with the system call. As wementioned earlier we have created two different waitid() system calls in theEGLIBC code. One takes the five arguments mentioned in this section and doesthe actual call down the the FenixOS kernel. This function is calleddo_waitid(). The other is called waitid() and takes the four argumentsoriginally intended for waitid() and maps those to do_waitid() (Leaving usage with value NULL).The latter is meant for user applications wishing to call waitid(). Thefirst should only be used by the EGLIBC code for mapping the other systemcalls. By creating this mapping between the wait system calls in the EGLIBCcode we cut down the number of wait system calls in the kernel to one. Butstill we are able to support already existing applications which may make useof the older wait system calls.

This off course just give a smallinsight in to a very big subject, where we to this date haven’t been able totest our system yet. As stated earlier, it’s a research system, and the designis a subject to change…. J

 

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 7/13/2009 at 6:44 AM
Tags:
Categories: OS
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

Touching the Surface

surface

In Denmark we've got three of these Surface tables, but only one is currently up and running.

A couple of weeks ago me and my fellow Microsoft Student Partners where given the opportunity to play with a Windows Surface table. Now by playing I don't just mean that we could look and feel, but we could also make our own software and run it on the Surface table... Now that was cool!! We divided ourselves in small groups and started developing some applications for the Surface table.

IMG_1280

As can be seen from the pictures one of the MSP's made an XNA game for the Surface table, which wad an asteroid game where multiple players had to touch the asteroid before they hide the spacestation in the center of the Surface table.. We had lots of fun with that...

IMG_1279

The cool thing about Windows Surface is that you are able to program it using WPF and/or XNA, which is unleashing a lot of power. As of writing I don't belive that there is a SurfaceSDK available for download just yet, but it is on the way :-) and therefore I am not going to show you any of the code we made for the Surface table just yet, but when the SDK is released, I will put up some example code..

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 3/31/2009 at 2:45 PM
Tags: , ,
Categories: C# | Surface
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

Windows Phone Video

Just an appitizer for you all.....

 

 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 2/25/2009 at 3:13 PM
Tags:
Categories: Embedded
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

ID3 Tag version 2.3.0

Now I've tried to make a simple version of how too get the tags out of ID3v2.3.0 tags, but I think I failed..... 

It's was not easy to do.... On purpose I haven't gotten into the part about flags, and extended headers (allthough its not too hard to implement now), because it would cloud the bigger picture... So without further delay, here is the code... (please mail me if it simply dosn't make any sense, I've rewritten the code a few times, so a couple of mistakes can be present, but the code works though Wink )

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.IO;

using System.Drawing;

 

namespace Id3

{

    class test

    {        

        private long startPosition = 0;

        private byte[] byteArray = new byte[6];             

        private string path;

        public Bitmap bmp;

        // Method to do the bute parsing so we can calculate the size of the header

        private static int GetLengthOfTag(byte[] calcByteArray)

        {   // now this is kind of long haired so just take it as it is 

            /* Basically, every 8th bit is filled with a 0 (zero) which means that the bits look like this:

                0xxxxxxx 0xxxxxxx 0xxxxxxx 0xxxxxxx

               which again means that a bit pattern (2 bytes) looking like this:

                00100011 10110011 (35 and 179)

               will look like this:

                01000111 00110011 (71 and 51)

               So a need for bit crunching......

             * if calByteArray[3] = 25 and calcByteArray[2] = 30, then its going look like this:

             * bytes[3] = 25 + (30 << 7), which is 25 + 3840 and in bits:

             * bytes[3] = 11001 + (11110 << 7)

             * bytes[3] = 11001 +  111100000000 and the final number is:

             * bytes[3] = 111100011001 (3865)..... Now taking a closer look at this number...

             * bytes[3] = 11110 (30) 0011001 (25), its pure magic, don't forget, every 8th bit is zero'ed and therefore ignored....

             */

            int lenght = 0; 

            int[] bytes = new int[4];

            bytes[3] =   calcByteArray[3]             + ((calcByteArray[2] * 1) << 7);

            bytes[2] = ((calcByteArray[2] >> 1) * 63) + ((calcByteArray[1] * 3) << 6);

            bytes[1] = ((calcByteArray[1] >> 2) * 31) + ((calcByteArray[0] * 7) << 5);

            bytes[0] = ((calcByteArray[0] >> 3) * 15);            

 

            lenght = (10 + bytes[3] + (bytes[2] << 8) + (bytes[1] << 16) + (bytes[0] << 24));            

            return lenght;

        }

 

        public void RecurseDirectories(string myPath)

        {

            path = myPath;

            string[] dirs = Directory.GetDirectories(myPath);

 

            if (dirs.Length > 0)

            {

 

                foreach (string subDir in dirs)

                {                    

                    RecurseDirectories(subDir);

                }

            }            

 

            //This point will be reached after the current directory has been checked for other directories... 

            string[] fileNames = Directory.GetFiles(myPath);

            

            foreach (string fileName in fileNames)

            {

                using (System.IO.FileStream fs = System.IO.File.OpenRead(fileName))

                {

                    fs.Read(byteArray, 0, 6); // read the first 6 bytes of "main" header

                    // Read in the first three bytes to check for ID3, if its there we have a tag, otherwise we don't

                    string startOfID3 = ((char)byteArray[0]).ToString() + ((char)byteArray[1]).ToString() + ((char)byteArray[2]).ToString();

                    if (startOfID3.Equals("ID3"))

                    {

                        int versionMajor = byteArray[3]; //The version of the IDTAG is placed at the fourth byte

                        int versionMinor = byteArray[4]; //Not used right now, but will be used later

                        Console.WriteLine("MajorVersion = {0}", versionMajor);

                        Console.WriteLine("MinorVersion = {0}", versionMinor);

                        if (versionMajor == 2)

                        {   // at present time, only ID3v2.3 is supported

                            Console.WriteLine("ID3v2.2 not supported yet");

                        }

 

                        int frameIdSize; //ID3v2.2 uses 3 charecters xx xx xx while ID3v2.3 uses 4 charecters xx xx xx xx 

                        int flagSize; 

 

                        frameIdSize = (versionMajor > 2) ? 4 : 3;

                        Console.WriteLine("frameIdSize = {0}", frameIdSize);

                        flagSize = (versionMajor > 2) ? 2 : 0;

                        Console.WriteLine("flagSize = {0}", flagSize);

 

                        // parse the header

                        fs.Read(byteArray, 0, 4); // read the last 4 bytes of "main" header which containes the size

                        // of the header (header total = 10 bytes)                        

                        int lenghtOfHeader = GetLengthOfTag(byteArray); // Going on to calculate the length of the header 

                        

                        byteArray = new byte[lenghtOfHeader];

                        fs.Read(byteArray, 0, lenghtOfHeader); /* read the main header into our byteArray*/

                        startPosition = fs.Position;

 

                        int currentPosition = 0;

                        byte[] tag = new byte[frameIdSize];

                        byte[] lenghtArray = new byte[frameIdSize];

                        byte[] stringFrameContent;

                        string frameID;

                        int lengthOfTag = 0;

                        // Now looping through the tags

                        do

                        {

                            if ((currentPosition + 10) > lenghtOfHeader)

                            {

                                Console.WriteLine("Ups!");

                                break;

                            }

 

                            frameID = "";

                            // Copy contents of byteArray to tag

                            Array.Copy(byteArray, currentPosition, tag, 0, frameIdSize);

                            currentPosition += frameIdSize; // keep track of position

                            // Copy contents of byteArray to lenghtArray

                            Array.Copy(byteArray, currentPosition, lenghtArray, 0, frameIdSize);

                            currentPosition += frameIdSize; // keep track of position

 

                            

                            if (flagSize > 0)

                            {

                                

                                currentPosition += 2; 

                            }

 

                            lengthOfTag = 0;

 

                            

                            for (int i = frameIdSize - 1; i >= 0; i--)

                            {

                                int ml = 1;

                                for (int j = i; j < frameIdSize - 1; j++)

                                {

                                    ml *= 256;

                                }

                                lengthOfTag += lenghtArray[i] * ml;

                            }

 

                            stringFrameContent = new byte[lengthOfTag];

                            // Copy contents of byteArray to stringContent

                            Array.Copy(byteArray, currentPosition, stringFrameContent, 0, lengthOfTag);

                            currentPosition += lengthOfTag;

 

 

                            frameID = System.Text.Encoding.ASCII.GetString(tag);

 

                            string contentOfFrame = "";

 

                            if (frameID.Equals("TPE1"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Artist: {0}", contentOfFrame);

 

                            }

                            if (frameID.Equals("TIT2"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Song Title: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TALB"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Album: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TRCK"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Tracknumber: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TYER"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Year: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("TCON"))

                            {

                                contentOfFrame = System.Text.Encoding.ASCII.GetString(stringFrameContent);

                                Console.WriteLine("Genre: {0}", contentOfFrame);

                            }

                            if (frameID.Equals("APIC"))

                            {

                                Console.WriteLine("PICTURE");                                                   

 

                            }

                        }

                        while (lengthOfTag > 0);

                    }

                    else 

                    { 

                        Console.WriteLine("No tags present"); 

                    }

                }//end using

 

                Console.ReadLine();

            }//end foreach

        }//end method RecurseDirectories

    }

 

 

I've tried to comment the code as good as possible, but hey, I'm only human... Send me a mail if something is wrong, or not understanderble.... 

This code may be revisited a few times to make modifications....... 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: AllanJP
Posted on: 2/4/2009 at 1:21 PM
Tags: ,
Categories: C#
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed