Saturday, November 7, 2009

In search for .Net 4.0 Features - dynamic.

If you are an edgy developer then you should be already knowing about the new version of .Net and about the keyword ‘dynamic’. C# 4.0 is adding support for the dynamic keyword, which introduces some aspects of dynamic languages to C#. I was reading on the some early bird posts pushed by some geeky folks upon the topic, and was sort of looking for a good opportunity to squeeze it into coding. After doing some research I found some scenarios which I thought it would work great with the dynamic type and also some areas it didn’t worked as expected.

Note:
Root is a public static property I used in sample which points to textbox in the main window.

1 - Hello World in dynamic.

This example demonstrates a ‘Hello World’ in dynamic.

class SimpleDynamic

{

public SimpleDynamic()

{

dynamic customer = new Customer();

customer.First = "Hello ";

customer.Last = "World";

customer.ID = 2009;

Root.Text = customer.HelloWorld();

}

}

public class Customer

{

public string First { get; set; }

public string Last { get; set; }

public int ID { get; set; }

public string HelloWorld()

{

return First + Last + ID.ToString();

}

}

2 - Convertions:

Dynamic eliminates the use of unboxing completely. We don’t require the value to be Casted if we do an assignment from a higher grade to lower grade.

class Convertions

{

public Convertions()

{

dynamic d1 = 7;

dynamic d2 = "a string";

dynamic d3 = System.DateTime.Today;

dynamic d4 = System.Diagnostics.Process.GetProcesses();

int i = d1;

string str = d2;

DateTime dt = d3;

System.Diagnostics.Process[] procs = d4;

Root.Text = "Check my code";

}

}

3 - COM Interop with Office.

The above feature creates the flexibility for dynamic to use it with COM interop.

// Without dynamic.

((Microsoft.Office.Interop.Excel.Range)excel.Cells[1, 1]).Value2 = "Name";

Excel.Range range = (Excel.Range)excel.Cells[1, 1];

// With dynamic.

excel.Cells[1, 1].Value = "Name";

Excel.Range range = excel.Cells[1, 1];

And here is another example.

public class CallMSO

{

//requires MSoffice to be installed.

public CallMSO()

{

var bankAccounts = new List<Account>

{

new Account { ID = 345678,Balance = 541.27 },new Account { ID = 1230221,Balance = -127.44}

};

CreateIconInWordDoc();

}

static void CreateIconInWordDoc()

{

var wordApp = new Word.Application();

wordApp.Visible = true;

wordApp.Documents.Add();

//check the arguments which contains dynamic

wordApp.Selection.PasteSpecial(Link: true, DisplayAsIcon: true);

}

}

public class Account

{

public int ID { get; set; }

public double Balance { get; set; }

}

4 - Using dynamic with Reflection:

This was the best part I liked while trying with this new syntax. Dynamic did a wonderful job here which helped me bypass some steps and of course result in some level of performance improvement.

dynamic mytype = Assembly.LoadFile(System.IO.Directory.GetCurrentDirectory() + @"\UnknownLib.dll").CreateInstance("UnKnownLib.UnkownClass");

MessageBox.Show(mytype.GetvaluePlus25(28).ToString());

If you think in old way you need to do something like to this.

Assembly myassm = Assembly.LoadFile(System.IO.Directory.GetCurrentDirectory() + @"\UnknownLib.dll");

Type mytype = myassm.GetType("UnKnownLib.UnkownClass");

System.Reflection.MethodInfo method = mytype.GetMethod("GetvaluePlus25", new Type[] { typeof(int) });

method.Invoke(myassm.CreateInstance("UnKnownLib.UnkownClass"),new object[] {20});

Unreferenced Remote Assembly.

namespace UnKnownLib

{

public class UnkownClass

{

public UnkownClass()

{

}

public int GetvaluePlus25(int val)

{

if (val + 25 <= int.MaxValue)

return val + 25;

else

return val;

}

}

}

5 - Using dynamic syntax to map an xml file:

XElement xel = XElement.Load(System.IO.Directory.GetCurrentDirectory() + @"\MyXml.xml");

dynamic del = new DynamicElement(xel);

dynamic textbox = textBox1;

textbox.Text = del.channel.title.ToString();

textbox.Text = textbox.Text + " - " + System.Environment.NewLine + del.channel.description;

foreach (var item in del.channel.items)

textbox.Text = textbox.Text + " - " + System.Environment.NewLine + item;

textbox.Focus();

Class Implmentation

public class DynamicElement : DynamicObject

{

private XElement actualElement;

public DynamicElement(XElement actualElement)

{

this.actualElement = actualElement;

}

public override bool TryGetMember(GetMemberBinder binder, out object result)

{

string name = binder.Name;

var elements = actualElement.Elements(name);

int numElements = elements.Count();

if (numElements == 0)

return base.TryGetMember(binder, out result);

if (numElements == 1)

{

if (elements.First().Attributes().Count() > 0 && elements.First().Attribute("IsCollection").Value == "True")

{

List<DynamicElement> list = new List<DynamicElement>();

for (int i = 0; i <>

{

list.Add(new DynamicElement(elements.First().Elements().ElementAt(i)));

}

result = list;

}

else

{

result = new DynamicElement(elements.First());

}

return true;

}

result = from e in elements select new DynamicElement(e);

return true;

}

public override string ToString()

{

return actualElement.Value;

}

}

6 - Call for static method – Do not work.

And here is some exception which comes with dynamic. This is something found not to be working with dynamic and it looks like Microsoft is planning to give support for this only on next version.

public class DynamicwithStaticObj

{

public DynamicwithStaticObj()

{

try

{

Root.Text = Addvalue(new Class1());

Root.Text += Addvalue(new Class2());

Root.Text += GetTransformString(new Class1().GetType());

Root.Text += GetTransformString(new Class2().GetType());

}

catch(Exception ex)

{

System.Windows.MessageBox.Show(ex.Message);

}

}

static string GetTransformString(dynamic mytype)

{

return mytype.AddValuefromstring("Hello World");

}

static string Addvalue(dynamic type)

{

return type.AddValue("Hello World");

}

}

Case N:

Well, you guys can also add the comments here and links to new cases where we can use dynamic. This would definitely help people who are new into C# 4.0.

Example:

Here is the sample which I worked available for download.

Dynamic_Sample

External Links/ References:

I found some folks who already did the paper work for me which I avoided the theory part. You can see the dynamic and .Net 4.0 Insides here in these links.

C# 4.0: Dynamic Programming - Explains the basics and layers of DLR –Dynamic Language Runtime.

Video Cast from MS DLR Development Team – Video explains the challenges and some technical insides for DLR.

MSDN References:

dynamic (C# Reference)

Dynamic Language Runtime Overview

Office Interop

Using Type dynamic

Dynamic Method Bags

Cross References:

http://weblogs.asp.net/bleroy/archive/2009/09/17/fun-with-c-4-0-s-dynamic.aspx

http://blogs.msdn.com/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx

http://www.codeproject.com/KB/cs/dynamicfun.aspx

http://www.codeproject.com/KB/cs/CSharp4_Features.aspx

http://amazedsaint.blogspot.com/2009/09/fun-with-dynamic-objects-and-mef-in-c.html

Cross Blogs:

Programming Gallery Article: http://www.programminggallery.com/article_details.php?article_id=126

Monday, April 7, 2008

Virgle - The Adventure of Many Lifetimes


Everyone related to technology and computer knows what is Google. Probably a few among them may know the wonderful ideas, projects and products funded by Google. Google's prestigious search engine, Orkut, Google Earth, Blogger.. the list goes on... But the most amazing project plan I have been ever heard from Google came on early hours of this month. Here the story goes...

On the 2nd or 3rd of this month, I get a forwarded mail from one of my friend with a web link in it. The name in mail is completely new for me. Never heard about such a project or product name from Google or any other company. Just because it starts with the main domain Google.com, I assured myself that it is the one from Google itself. I navigate through the specified link and reach the homepage referring to the project plan details. The project is named Virgle - The Adventure of Many Lifetimes.

Here is the link for your reference: http://www.google.com/virgle/index.html

In search for the details
Let me guess; you have already gone through the link above. Noticed the 100 year plan given in the left side of homepage? Google team narrates their 100 year plan starting from 2010 through 2108.

One video by Larry Page and Sergey Brin on Virgle

The next section, 'Become a Pioneer' explains the benefits and dangers involved in joining the project. Yeah!! everyone is welcome to apply... Just what you need to do is to explain why you want to live on Mars and you could win a coveted slot on the earliest, most uncomfortable and dangerously untested manned space flights to the new New World - or a fabulous prize!






One button is provided to 'Apply' or 'To be a Pioneer' and it continues to an Application Form, the page with a bundle of questions and further asks to publish a you-tube video from the applicant. Next two sections explains the Google's ideas about the planet and founders messages.

Still you have some clarifications? AFAQ section is also provided. Go through the commonly asked questions and it's answers.

Ok ok. No more secrets...I think you got the point (if you have already gone though the site). Best April fool I have ever seen. 'Location, location, location.' hehe...hardly escaped!!

They designed it almost perfect with a lot of external references.
Blog - http://googleblog.blogspot.com/2008/04/announcing-project-virgle.html
Jobs - http://www.google.com/jobs/lunar_job.html
Discussion Board - http://groups.google.com/group/virgle/
A lot of you-tube videos which is posted by poor April fools..etc...

Wednesday, March 12, 2008

Microsoft Research – The World-Wide Telescope, an Archetype for Online Science

For a long period, after seeing one of the most wonderful desktop application from google, which I think could be useful to our mordern day-to-day life going forward, I was thinking what is next after Google Earth. Last week while going through one of my favorite sites under Microsoft domain, I found something new, which virtually made my heart stop with astonishment, after looking out for the details in web. I never expected such a technology is ever possible with in my lifetime.

Yeah, it is all about existence and Competition. Like most of the successful enterprises having a potential for growth and innovative ideas that adds value to its goodwill, Microsoft is always one-step forward in its ideas. Now another technology is rising from Microsoft labs, World Wide Telescope. The shadow of the product is so cool that it already started spreading in the news.


What is all about?


As per Microsoft definition, World Wide Telescope is a rich visualization environment that functions as a virtual telescope, bringing together imagery from the best ground and space telescopes and terabytes of images, data, and stories from multiple sources over the Internet into a media-rich, immersive experience. World Wide Telescope, which is powered with Microsoft’s high-performance Visual Experience Engine, enables seamless panning and zooming across the night sky for guided explorations of the universe.

The WWT isn’t available yet, but you can see a demo below


TED talk - Microsoft World Wide Telescope - Video Demo

Seeing this everyone can get a clear understanding about what this project can do. Viewing the TED talk, it’s like a Google Earth for the sky, seamlessly integrating pictures and information in a single platform.


Microsoft plans to release this desktop product by spring 2008. At present, the homepage of WWT you can find in this link - http://worldwidetelescope.org/.

References:

Microsoft World Wide Telescope - Video Demo - http://www.labnol.org/software/download/video-demo-microsoft-
worldwide-telescope-universe/2434/


A PDF document from Jim Gray; Alexander S. Szalay & End Bracket
ftp://ftp.research.microsoft.com/pub/tr/tr-2002-75.pdf
http://msdn2.microsoft.com/en-us/magazine/cc163629.aspx

FAQ -
http://www.worldwidetelescope.org/buzz/FAQ.aspx

Wednesday, November 7, 2007

Hmm...Better Guys are ther!!!!

Yesterday, while going through the daily newspaper I noticed one advertisement in Times of India. Hmm....an Xplod Car Stereo Player advertisement from Sony.



The same technology integration which I was talking about in one of my last blog. ideas@technology. It looks like this technology integration is going to be the next trend in market.

Thursday, November 1, 2007

ideas @ Technology


This picture of an Mp3 player I took from Big Bazaar this evening. They were demonstrating an Mp3 player using songs stored in a USB storage media. It means a complete USB sub-system is integrated into this MP3 player electronics. Using USB as standalone device for playing songs and video is not a new thing. But I was wondering about the way technology integration goes. One more storage device coming to general public after Audio Tapes, CDs, DVDs, and Blue Ray disks. It is USB Storage Drives. MP3 Players are in market which can use USB Storage devices instead of CDs or DVDs. To next level just think about a situation where in a DVD rendering shop, we will be giving a 4 GB USB device to get a film copied, or plugging in USB device into an MP3 player and copy all files from the DVD Rom inserted. This is what we can expect tomorrow....

Wednesday, September 5, 2007

Windows Vista is “Out” - Welcome to the world of Windows 7


With Windows Vista finally behind us, it's time to turn our attention to the next Windows client release, which is currently codenamed Windows "7", though Microsoft has used other code-names, like “Blackcomb”, "Vienna" and "Windows Seven" in the past.

The countdown clock of the next generation OS after Windows Vista has already started ticking officially. Microsoft is preparing for Windows 7, which is the next version of OS. Initially codenamed as “Blackcomb” and then renamed to "Vienna" and then to "Windows Seven" and now it is changed to “Windows 7”. As per sources the stage for Windows 7 is set to 2009. Searches in web reaches to information published even on first days of 2007. Guess… even I am a late informer in this area.

Windows Vista, the much delayed most recent release of Windows, shipped to businesses in November and to consumers in January after more than five years of development. Vista's gestation period was marked by shifting product details as internal priorities changed and problems arose with development.

Like Vista, Windows 7 will ship in consumer and business versions, and in 32-bit and 64-bit versions. Company sources also confirmed that it is considering a subscription model to complement Windows, but did not provide specifics or a time frame.

As to words according to the representative, "Microsoft is scoping Windows 7 development to a three-year time frame, and then the specific release date will ultimately be determined by meeting the quality bar". Windows Vista was a major release, and it seems like Windows 7 will also be a major update. Microsoft is currently on a development path where every other Windows version is a major release, so it's possible that we'll see a minor OS update between Vista and Windows 7?

Features Overview:

Explicitly saying Microsoft hasn't publicly committed to any features for Windows 7 and the company is still deciding upon what this next Windows release will look like. I got only little information about Windows 7. Also It looks like many Microsoft consultants are now giving out a policy of not to give much hope to customers about the features which ends up in damaging the reputation of the company itself. Anyway I am giving some features that we can expect.

Internet Explorer 9:
We can expect a new version of Windows Explorer that is being built by the same team that designed the Ribbon user interface in Office 2007.

Thoughts for a new UI component:
When Microsoft first drew up plans for Windows 7 (back when it was codenamed Blackcomb), there were rumors that the current UI will be replaced with an entirely new one, with some reference to a sort of radial-dial. Where there are no chances for a complete overhaul of the current interface, Microsoft has been working on several new UI ideas, some of which may slip into Windows 7. Indeed, this might be a way to transition us from the current UI to the new one in future Windows releases.

Virtual Desktops:
Mac OSX already has it, and Linux had it for a long time, so it would only make sense that Microsoft will be implementing virtual desktops into Windows 7.

System Restore:
With OSX Leopard's Time Machine making such an impression with the general public, it can be expected that Windows 7 will improve upon its own backup tool.

Paint.NET:
So far this has been an independent project that was under the guidance of Microsoft, but Microsoft has always acknowledged that Paint.NET with one day replace the current 'Paint' application in Windows.

Windows Hypervisor:
It will likely include some form of the "Hypervisor" technologies that will ship shortly after Windows Server 2008. Microsoft is currently working on a new hypervisor system codenamed "Viridian" with OS integration at the lowest level, and already Windows Vista includes extensions to boost performance when running on top of the Viridian hypervisor. We can expect Windows 7 to have a higher level of interaction with Viridian.

File system:
It may also include the much expected but aborted file system in windows Vista, WinFS (Windows Future Storage) technologies, though they won't be packaged or branded as WinFS.

Licensing:
Microsoft says it might also make a subscription-based version of the OS available to consumers, but that's still in flux.

Better User Experience:
Windows 7 will make it easier for users to find and use information. Local, network and Internet search functionality will converge. Intuitive user experiences will be further advanced. Automated application provisioning and cross-application data transparency will be integrated.

Windows Security:
Windows 7 will include improved security and legislative compliance functionality. Data protection and management will be extended to peripheral devices. Windows 7 will advance role-based computing scenarios and user-account management, and bridge the inherent conflicts between data protection and robust collaboration. It will also enable enterprise-wide data protection and permissions.

Universal devices connectivity:
Windows 7 will further enable the mobile workforce. It may deliver anywhere, anytime, any device access to data and applications. Wireless connectivity, management and security functionality will be expanded. The performance and functionality of current and emerging mobile hardware will be optimized. The multiple device sync, management and data protection capabilities in Windows will be extended. Finally, Windows 7 will enable flexible computing infrastructures including rich, thin and network-centric models.

Versions:
Though I had expected Windows 7 to ship only in 64-bit versions(http://apcmag.com/6121/windows_server_gets_vista_version_itis), some Microsoft sources now says it will be the final Windows version to ship in both 32-bit and 64-bit versions.

Conclusion:
There is also a slight possibility that Microsoft will be integrating Windows Live services much more strongly into Windows 7, although it might raise allegations of anti-competitive business strategies. But there might be certain unique Live services that make it into Windows 7, such as Live Drive. Other Microsoft services such as MSN Soapbox might also be a significant part of applications such as Windows Media Center.

It is still too early to tell what shape Windows 7 may take, but we can hope that the recent wave of innovations we have been seeing from Microsoft will carry on into the next two years.

Some references:

http://en.wikipedia.org/wiki/Windows_7
http://news.com.com/2100-1016_3-6197943.html
http://blogs.zdnet.com/microsoft/?p=592

Sunday, June 17, 2007

Betas and CTPs - Microsoft Acropolis, Crossbow, .Net Framework 3.5


Two important IT/Developer Products from Microsoft are growing behind the curtains.
First one is the next version of .Net Framework .Net 3.5 and the next important one is AcropolisNext Generation of Smart Client Applications from Microsoft.

Acropolis – Revolutionizing Smart Client Development

Next Generation tool for Smart client Applications "Acropolis" is a toolkit for creating modular, business-focused Windows client applications. Acropolis is build up on the.NET Framework, and includes a run-time framework, design-time tools, and out-of-the-box functionality. In a nutshell it provides a better environment and tools to create Smart client applications.

Microsoft Smart Client Solutions offers an ocean of benefits in flexibility and usability over thin client solutions, at the same time retaining some of their manageability capabilities. These benefits can be substantial and can include an increase in user efficiency, a reduction in development and training costs, and corresponding improvements in the overall Total cost of ownership and Rate of Investment of the solutions.

Unfortunately, developing smart client solutions can be challenging. Hurdles like lack of a good application model, supporting infrastructure, and out-of-the-box implementations for commonly used client-side services forces each developer to address these sometimes complex issues themselves.

Acropolis targets at a solution by providing an application framework and tools to support the development of smart client line-of-business solutions. Acropolis is based on the composite smart client approach where solutions are constructed from a number of loosely coupled ‘parts’. Each part provides a unit of self-contained functionality that can be independently tested and developed and re-used in many different solutions.

Acropolis builds on the rich capabilities of Microsoft Windows and the .NET Framework, including Windows Presentation Foundation (WPF), by providing tools and pre-built components that help developers quickly assemble applications from loosely-coupled parts and services.

With Acropolis you will be able to:

1) Quickly create WPF enabled user experiences for your client applications.
Build client applications from reusable, connectable, modules that allow you to easily create complex, business-focused applications in less time.
2) Integrate and host your modules in applications such as Microsoft Office, or quickly build stand-alone client interfaces.
3) Change the look and feel of your application quickly using built-in themes, or custom designs using XAML.
4) Add features such as workflow navigation and user-specific views with minimal coding. 5) Manage, update, and deploy your application modules quickly and easily.

Valuable points of Reference:

http://windowsclient.net/Acropolis/


Crossbow -
Windows Forms and WPF Interoperability

If you choose to write a WPF application from the ground up, you may need to augment the feature set of WPF by utilizing Windows Forms controls, Windows Forms-based User Controls and/or ActiveX controls. Many customers need a rich DataGrid control and since WPF will not ship a DataGrid control in the first release, customers want to use the Windows Forms 2.0 DataGridView control.

Crossbow the code name for the interoperability layer between Windows Forms and Windows Presentation Foundation (WPF). Crossbow is all about the ability to leverage your existing investments in Windows Forms and infuse your application with WPF functionality at your pace and without having to re-write your entire application.

And, just peeping from the back door, interesting things are happening. There is one more "Crossbow" project at Microsoft. It is the next version of the Windows Mobile OS, commonly referred to by Microsoft watchers as "Windows Mobile 6.0."

Microsoft .NET Framework 3.5 – Beta 1


















The first Beta of .Net 3.5 was released on 27th April 2007.

Here is the link for it's download.

http://www.microsoft.com/downloads/details.aspx?
FamilyId=E3715E6F-E123-428B-8A0F-028AFB9E0322&displaylang=en


This one is a preview release(CTP) of the latest version of the .NET Framework. It seems like Microsoft is planning to continue to invest more in the .NET Framework developer platform and support the existing users. This new version of framework will be having minimal number of code breaking changes, so that existing applications built for .NET Framework 2.0 or .NET Framework 3.0 should continue to run without requiring changes in assembly or configurations.

The .NET Framework has a bunch of new interesting features, like LINQ support and integration of ASP.NET AJAX into the framework, especially in the areas of WCF and WF. Functionally .NET Framework 3.5 integrates new features in several major technology areas.

1 - Deep integration of Language Integrated Query (LINQ) (System.Data.Linq.dll), XLINQ (System.Xml.Linq.dll) and data awareness and LinqDataSource (System.Web.Extensions.dll).
2 - ASP.NET AJAX.
3 - New web protocol support for building WCF services including AJAX, JSON, REST, POX, RSS, ATOM and several new WS-* standards.
4 - Full tooling support for WF, WCF and WPF including the new workflow-enabled services technology.
5 - New classes in the base class library (BCL) for the .NET Framework 3.5 address the most common customer requests.
6 - Deeper Support for the Web like Syndication, webHttpBinding, ASP.NET AJAX Integration, Partial Trust etc.
7 - Added support for all the new WS-* protocols that are coming out of OASIS - WS-ReliableMessaging, WS-AtomicTransaction, and WS-Trust/WS-SecurityPolicy, to make sure WCF continues to be a good WS-* citizen.
8) - New AddIn (plug-in) model(System.AddIn.dll).
9) - Peer to Peer APIs (
System.Net.dll).
10) - Wrapper for Active Directory APIs (System.DirectoryServices.AccountManagement.dll ).
11) - WMI 2.0 managed provider (
System.Management.Instrumentation.dll combined with System.Management namespace in System.Core.dll).
12) - System.WorkflowServices.dll and System.ServiceModel.Web.dll – WF and WCF enhancements (for more on WF + WCF in v3.5 follow links from here).
13) - The implementation for ASP.NET AJAX (for more web enhancements, follow links from here) plus also the implementation of Client Application Services.
14) - In addition to the LINQ to Objects implementation, this assembly includes the following: HashSet, TimeZoneInfo, Pipes, ReaderWriteLockSlim, System.Security.*, System.Diagnostics.Eventing.* and System.Diagnostics.PerformanceData (
System.Core.dll).

It looks like .NET Framework 3.5 is planned to release at the end of 2007.

For more detail about the features being introduced in .NET Framework 3.5 and Visual Studio code name “Orcas”, click here
http://msdn2.microsoft.com/en-us/vstudio/aa700830.aspx

Some reference links:

http://blogs.msdn.com/brada/archive/2007/06/12/net-framework-3-5.aspx
http://www.danielmoth.com/Blog/2007/06/net-framework-35.html
http://www.danielmoth.com/Blog/2007/06/visual-studio-2008-stack.html
https://www.gazitt.com/blog/PermaLink,guid,a8383226-a0dd-48c5-9fea-33d5da159d17.aspx


Bookmark