Recently I had a task to translate exisiting website using Microsoft Translator Widget. One of the tasks was to display something that will indicate that translation is in progress.
Sunday, March 24, 2013
Friday, December 16, 2011
Stopping save operation from Silverlight control inside CRM 2011
CRM 2011 allows to insert Silverlight controls inside forms. And when control is not just to show data, but to interact with user sometimes you may need to prevent form being saved until user finished some operation. It is quite easy to achieve in javascript, but not that obvious in Silverlight.
Let’s start. CRM 2011 SDK help gives us first clue – Xrm.Page.data.entity has addOnSave method. That’s exactly what we need. But how can we attach event to that object?
First thing to do is to get that object. As CRM 2011 SDK and Training Kit recommend us following way:
Next step is to call addOnSave method. Handlers of OnSave method returns boolean value so lets attach some method returning boolean like this
But just returning bool is not enough to stop save operation. And again SDK helps us here: ExecutionObj.getEventArgs().preventDefault(). It ‘Cancels the save operation, but all remaining handlers for the event will still be executed’. ExecutionObj is something passed to the save event handler. Since we don’t know exact type of this object we will use dynamic:
And after this event handler looks like this:
That’s it.
P.S. You may choose to return true instead of false when stopping save operation depending on whether you need other handlers to be executed or not. But usually false is enough
P.P.S. When your Silverlight control is inside html webresource that is after that placed on crm 2011 form, you will have to change way how you are getting Xrm reference to something like this
Let’s start. CRM 2011 SDK help gives us first clue – Xrm.Page.data.entity has addOnSave method. That’s exactly what we need. But how can we attach event to that object?
First thing to do is to get that object. As CRM 2011 SDK and Training Kit recommend us following way:
Xrm.Page.data.entity
- dynamic Xrm = HtmlPage.Window.GetProperty( "Xrm" ) as ScriptObject;
- dynamic entity = Xrm.Page.data.entity as ScriptObject;
Next step is to call addOnSave method. Handlers of OnSave method returns boolean value so lets attach some method returning boolean like this
- entity.Invoke( "addOnSave", new Func<bool>( OnSave ) );
But just returning bool is not enough to stop save operation. And again SDK helps us here: ExecutionObj.getEventArgs().preventDefault(). It ‘Cancels the save operation, but all remaining handlers for the event will still be executed’. ExecutionObj is something passed to the save event handler. Since we don’t know exact type of this object we will use dynamic:
Attach event
- entity.Invoke( "addOnSave", new Func<dynamic, bool>( OnSave ) );
And after this event handler looks like this:
Event handler
- private bool OnSave( dynamic eventData )
- {
- if( !IsReadyToSave )
- {
- eventData.getEventArgs().preventDefault();
- return false;
- }
- return true;
- }
That’s it.
P.S. You may choose to return true instead of false when stopping save operation depending on whether you need other handlers to be executed or not. But usually false is enough
P.P.S. When your Silverlight control is inside html webresource that is after that placed on crm 2011 form, you will have to change way how you are getting Xrm reference to something like this
- dynamic parent = ( ScriptObject )HtmlPage.Window.GetProperty( "parent" );
- Xrm = parent.Xrm;
Labels:
.Net,
.Net Framework,
addOnSave,
C#,
CRM,
CRM 2011,
Silverlight
Thursday, October 20, 2011
Internet Synchronized Clock using C#. Part 2
In previous part we got some methods just to get time from internet. But this may be not enough for the real clock. Let’s tell us current UTC time and will synchronize with internet servers from time to time to ensure accuracy.
First of all, lets put all methods from previous part inside some class, let it be called InternetTimeGetter.
We want to have clock which is synchronized with internet. Since synchronization may take some time or even fail we don’t want our application to freeze while performing synchronization. This means that we need background thread for this. We may use Task class for this. Also we will need some variables to keep current time value and last synchronization time. Let’s start
First of all, lets put all methods from previous part inside some class, let it be called InternetTimeGetter.
We want to have clock which is synchronized with internet. Since synchronization may take some time or even fail we don’t want our application to freeze while performing synchronization. This means that we need background thread for this. We may use Task class for this. Also we will need some variables to keep current time value and last synchronization time. Let’s start
Labels:
.Net,
.Net Framework,
C#,
sync time,
time from internet,
UTC time
Friday, July 1, 2011
Internet Synchronized clock using C#. Part 1
Task – show clock that is synchronized with some internet time server.
In this part I’ll just try to get UTC time from the server and in Part 2 I’ll use this code to create simple clock.
Some search pointed me to the http://tf.nist.gov/tf-cgi/servers.cgi page. It contains list of servers placed in US which provide UTC time on demand. Another page from that site (http://www.nist.gov/pml/div688/grp40/its.cfm) gives information about supported protocols. One of the is Network Time Protocol (RFC-1305) and another one is Daytime Protocol (RFC-867). Network Time Protocol (NTP) is a little bit more complicated and it provides more features. Daytime Protocol is simpler, but it should be just enough for this task.
In this part I’ll just try to get UTC time from the server and in Part 2 I’ll use this code to create simple clock.
Some search pointed me to the http://tf.nist.gov/tf-cgi/servers.cgi page. It contains list of servers placed in US which provide UTC time on demand. Another page from that site (http://www.nist.gov/pml/div688/grp40/its.cfm) gives information about supported protocols. One of the is Network Time Protocol (RFC-1305) and another one is Daytime Protocol (RFC-867). Network Time Protocol (NTP) is a little bit more complicated and it provides more features. Daytime Protocol is simpler, but it should be just enough for this task.
Labels:
.Net,
.Net Framework,
C#,
daytime protocol,
sync time,
time from internet,
UTC time
Tuesday, May 17, 2011
Writing into Visual Studio Output Window. Part 2
In Part 1 we set up OutputWindowWriter class which performs writing to the Visual Studio output window. What else can we add here?
It would be great if everything worked fine from the first attempt, but this not always happens, especially when dialing with someone’s else code. In our situation we have problem - when output window is initially hidden (by auto hide option at the top right corner of the window next to the cross) and we are writing something there we may get something like this
Sunday, May 1, 2011
Selecting first item in WPF ListView and keyboard navigation
I have been playing with WPF ListView recently and I’ve met its following not quite
comfortable behavior – when ListView is focused and I’m trying to navigate inside it using keyboard (in my case it was down arrow) I had to press down key twice to move to the second item and then once for each next item. My goal was to fix that twice pressing (and also enable correct navigation when some other item is selected, not the first one). I thought that it can be archieved by some simple property like SelectedIndex, but despite setting it to necessary value it still didn’t work.
comfortable behavior – when ListView is focused and I’m trying to navigate inside it using keyboard (in my case it was down arrow) I had to press down key twice to move to the second item and then once for each next item. My goal was to fix that twice pressing (and also enable correct navigation when some other item is selected, not the first one). I thought that it can be archieved by some simple property like SelectedIndex, but despite setting it to necessary value it still didn’t work.
Labels:
focus ListViewItem,
ListView,
twice,
visual studio,
wpf
Tuesday, April 12, 2011
Writing into Visual Studio Output Window. Part 1
Lets assume that we have some Visual Studio 2010 Isolated Shell application (I suppose everything mentioned here should be valid for ordinary vspackages, but didn’t test, so cannot be sure). It may perform some operations (actually it is usually written to perform some operation, isn’t it?) and our task is to put log of these operations somewhere. Visual Studio has such nice feature like output window. And it is perfect candidate for such log, so post creates simple class to make it easy to write anything into log.
Subscribe to:
Posts (Atom)