Tuesday, December 23, 2008

WPF Dispatcher using PriorityQueue

I am sure everyone using WPF know about Dispacther and how it works but i was more curious to see how it implementes the work prioritization. So i opened the Reflector and disassembled the System.Windows.Threading dll.

private PriorityQueue PriorityQueue();

For people who do not know about PriorityQueues please visit http://en.wikipedia.org/wiki/PriorityQueue

The best part about the priority queues is that user can tell execution of which workitem is more important than the other.

Microsoft should have exposed the PriorityQueue they have implemented to the developers in the collections namespace, reason being lot of realtime systems use priority queues.

Dispacther class uses following enumeration for prioritization.


public enumDispatcherPriority
{
ApplicationIdle = 2,
Background = 4,
ContextIdle = 3,
DataBind = 8,
Inactive = 0,
Input = 5,
Invalid = -1,
Loaded = 6,
Normal = 9,
Render = 7,
Send = 10,
SystemIdle = 1
}

Friday, December 19, 2008

MGrammer : My first languange

During my browsing i found the PDC 2008 video's and was so excited to see new microsoft products like OSLO SDK and M language family. Finally i decided to give a try of my own using the MGrammer for writing my first language.

Presently we are using the UI below for search using dropdown's and TextBox's for criteria and also it was limited to only two search criteria becuase of real estate issue.










Finally i was enlighted by MGrammer that why not have my own language which would allow user to write there query. Here is what i got :)



The only reason i posted the example above is to show how MGrammer is helpful for simple problems. I have been part of various projects in past where power users of the application wanted to perform some operation which is simply not possible with conventional UI e.g. once a user asked for capability to write Select statement in the UI which was not possible because user can delete or update the data by mistake. Also DBA's would not allow write access in the hands of application user's.

If i am faced with the same problem again i would write my small language which would allow minimum operations from the UI and let the user write subset of SQL queries.


Finally the MGrammer for the above implementation.

module PDC {

@{CaseSensitive[false]}

language Contacts

{

syntax Main = Search;
syntax Search = SearchToken Clause WhereToken Args;
syntax Clause = "PolicyHolder" "Associate" "AccountManager";
syntax Args = (Arg isToken value)*;
syntax value = ('A'..'Z' 'a'..'z' '0'..'9')*;

syntax Arg = "Policy" "Name" "SSN";
@{Classification["Keyword"]}

final token isToken = "is";
@{Classification["Keyword"]}

final token andToken = "and";
@{Classification["Comment"]}

token Comment = "/" ^("\r" "\n")*;
interleave TokensIHate = Comment " " "\r" "\n";
@{Classification["Keyword"]}

final token SearchToken = "Search";
@{Classification["Keyword"]}

final token WhereToken = "Where";

}

}