maandag 14 november 2011

Silverlight Developers are worried

It kind of feels like another episode of a dramatic television soap.  If you’ve been in a coma for the previous 5 months let me refresh your memory:


Then in episode 2 we then saw that HTML and Javascript will be technologies that you can use in Windows 8 but you can still write your everyday XAML and use the WinRT API’s for your metro apps.  You can even still use .NET for your 'legacy' applications.

In episode 3 Microsoft announced that they’ll be ditching browser plugins in the metro version of IE and will only make them available in legacy desktop mode.  Another sad episode indeed, the part that made allot of people cry was quote:

For what these sites do, the power of HTML5 makes more sense, especially in Windows 8 apps.

Now for the cliffhanger of this seasons ‘bye bye silvy’ rumors are going that Silverlight 5 will be the last Silverlight version released.  Will this turn out to be true?



Since the release of this rumor my blog visitors have spiked and one post in particular received allot of views.  Based on this and the ranting that’s going on several forums I think it’s safe to say that allot of Silverlight developers are worried for their future.

But should you be worried?  After all the technology isn’t likely to go away the next couple of years, Silverlight 5 still has to be released.  But what company is going to invest in a project that makes use of a technology that is already deprived of its future?  Wouldn’t it make more sense to switch to HTML 5 instead?

Then again Silverlight will still be used in Windows Phone 7 and Xbox…. not really useful if you’re a corporate developer (unless you work at a company that uses Xbox's for their business apps).  Okay granted that there will certainly be a future for Silverlight in Windows Phone 7, but how long will it take for Microsoft to merge their desktop OS with their Phone OS, seeing that we already have quad core mobile CPU’s.

I don’t think Silverlight developers should worry just yet, the transition will go smoothly and there are still a ton of Silverlight applications that need to be maintained (or rewritten).  Though it won’t hurt you to start refreshing that good old HTML and Javascript as it looks that you’ll be needing it in the near future…

donderdag 10 november 2011

Remote Control your PC with Windows Phone 7

I just wanted to share a cool app with you.  It’s called cool remote and it allows you to remote control the desktop of your PC from iPhone or Windows Phone 7.  I’ve installed it this weekend and been trying it out since then and it just works great.  Even on 3G, the connection is stable and good enough to use. 

Default the application tries to use port 80 or 81 but I had to switch it to a custom port (in my case 1222) that I’ve had to open on my router.  Once that was done it was just a matter of connecting to the PC.

Another great thing about this app is that it’s free!

Here are the download links:


Have fun!

vrijdag 4 november 2011

Wordprocessing Serialization: move content between wordprocessing files

At the moment I’m working on a couple of side projects (which explains why I forgot to close last month off with a funny post). I’ll be blogging about them a bit more in the couple of weeks or months ahead.  A small one-man’s project I’m working on has to do with OpenXml.  For those that have been following my blog, it won’t sound much of a surprise that I’m pretty fond of doing document generation with OpenXml.  I wanted to make it a bit easier though.

A recurring requirement I’ve been confronted with is the copying of content from one document to another.  It can even go so far that you must be able to store this content and be able to inject it into multiple documents at a later moment.  One might think that this is an easy think to do but think again.  If you’re document is crammed with custom style, numbering and tables you’ll soon notice that a simple copy of the paragraphs won’t do the trick.  

So what I’ve done is create a library that allows you to transfer content between 2 wordprocessing documents and keep the format of the table and styles.  Not only can you transfer the content between documents, you can also save the content as a blob to your database or any other file.  The way that you can mark the content that you want to serialize is by bookmarks.  You place two bookmarks in the source document to determin the start and end of the content, and one bookmark in the target document to indicate where to insert the copied content.

So how does it work? There are basically 3 main objects to the library that you need to know about.

  • ContentSerializer
  • ContentDeserializer
  • ContentInserter

ContentSerializer

The content serializer will serialize OpenXmlElements between the two bookmarks that you specify.  Here is a small example:

var memoryStream = new MemoryStream();

IContentSerializer serializer = new ContentSerializer("c:\\temp\\Test.docx");
serializer.SerializeElementsFullBetweenBookmarks(memoryStream,
                                                "profielstart",
                                                "profieleind");

As you can see the ContentSerializer accepts a string that points to the location of where the document resides.  You can then call the SerializeElementsFullBetweenBookmarks.  This method accepts 3 parameters:

  • The stream to which it will serialize to
  • The bookmark indicating the start of the text
  • The bookmark indicating the end of the text

The ContentSerializer will then serialize all OpenXmlElements between the two bookmarks together with their styles and numbering definition.  You can use the data in the stream to save the objects to a database or a binary file.

There is also a SerializeElementsBetweenBookmark function available which will only serialize the paragraphs between two bookmarks.  Yet for this example I want to be able to serialize everything.

ContentDeserializer

The ContentDeserializer will simply deserialize the serialized content into a format usable to inject into a document.  Depending on whether you serialized only the paragraphs or the full content with styles and numbering you can call one of the two following methods:

  • DeserializeContent: This will deserialize only paragraphs
  • DeserializeContentWithNumberingAndStyles: This method will deserialize the paragraphs together with the numbering and styles.

A small demonstration:

IContentDeserializer deserializer = new ContentDeserializer();
var contentWithNumbering = deserializer.DeserializeContentWithNumberingAndStyles(memoryStream);

This method will return an object that contains an IEnumerable of paragraphs, an IEnumerable of styles and a numbering definition. 

ContentInserter

When you have the content deserialized you might want to insert it into another docx file.  The ContentInserter will do just this for you.  All you need to do is provide it with the location of the wordprocessing document and then call the InsertElementsWithNumberingInDocument method to insert the deserialized content at the provided bookmark.

IContentInserter contentInserter = new ContentInserter("c:\\temp\\InsertInDocument.docx");
                contentInserter.InsertElementsWithNumberingInDocument(contentWithNumbering, "Paste");

So the InsertElementsWithNumberingInDocument method accepts the following parameters:

  • An ElementsFull element which contains the deserialized content
  • The name of the bookmark in which it will insert after.

There are a few things that you should take note to:

  • When the document is under revision control, all revisions will be accepted prior to serializing or inserting content!
  • The bookmarks are case sensitive
  • This projects uses the OpenXml Power tools, it’s a cool open source project so be sure to take a look at: http://powertools.codeplex.com/
  • The content that will be serialized between the two bookmarks currently only consists of Parargraphs and all their children (run, text, runproperties, etc.) and tables and all their children (tablecell, etc.).

Some things that I might improve in the future are:
  • Include the serialization of Images
  • Include the serialization of more elements like drawings and graphs
  • Optimize the serialization of the styles and numbering part, at the moment there is no filter

 
Make any adjustments as you like, until next time ;)