Wednesday, May 28, 2008

Creating Objects that Support Edit Cancellation via IEditableObject

This blog is from - http://blogs.infragistics.com/blogs/joshs/archive/2008/05/08/creating-objects-that-support-edit-cancellation-via-ieditableobject.aspx
Creating Objects that Support Edit Cancellation via IEditableObject

The IEditableObject interface provides controls with a way to allow a data source to react intelligently to being edited. This might seem superfluous, until you consider that complex controls, such as a data grid, allow the user to cancel an editing session via the Escape key.

For example, suppose the user is editing a row in the UltraGrid or XamDataGrid, and then realizes that he has been editing the wrong row. If he presses the Escape key once, the grid automatically reverts the active cell to the value it had before editing began. If the user hits Escape again, the entire row reverts to the values it had before the user started to edit its cells.

If the grid is bound to an ADO.NET container, such as DataTable, all of this magic happens for us automatically. However, if the grid is bound to a collection of your own objects, such as custom business objects, this will not happen by default. Your business objects will need to implement that logic, just as the ADO.NET containers do. Perhaps your business objects will not implement that functionality, since it is not part of any business domain, but Presentation Model objects might, instead. Regardless of the lingo, at the end of the day you will need to implement this logic somewhere!

Fortunately, this is quite easy to do. The IEditableObject interface is all you need to implement, as seen below:

private BinaryFormatter _formatter = new BinaryFormatter();
private MyData _myState;
private MemoryStream _snapshot;


void IEditableObject.BeginEdit()
{
if (_snapshot != null)
return;

_snapshot = new MemoryStream();
_formatter.Serialize(_snapshot, _myState);
}

void IEditableObject.CancelEdit()
{
if (_snapshot == null)
return;

// Restore our state to the snapshot taken when the editing session began.
_snapshot.Position = 0;
_myState = _formatter.Deserialize(_snapshot) as MyData;
this.ThrowAwaySnapshot();
}

void IEditableObject.EndEdit()
{
this.ThrowAwaySnapshot();
}

void ThrowAwaySnapshot()
{
if (_snapshot != null)
{
_snapshot.Dispose();
_snapshot = null;
}
}

This code assumes the MyData type (and all of its ancestor types) is decorated with the Serializable attribute, since it is serialized by the BinaryFormatter.

The BeginEdit method starts with a check to see if we are already in an editing session. If so, it immediately returns since there can only be one editing session at a time. There is no guarantee regarding when and how often that method will be invoked, so this precautionary step is necessary. When a new editing session begins, a snapshot of the object's state is taken and stored in a MemoryStream.

If the user cancels the editing session, the CancelEdit method executes. That method deserializes the snapshot taken in BeginEdit, and applies the saved values to the editable object. If the IEditableObject instance contains the various fields being edited, instead of having a reference to one object that contains all the values, your CancelEdit method will include code that sets all of those fields to whatever values were saved in the BeginEdit method.

When the user completes an editing session (i.e. finishes editing a row in the grid) the EndEdit method is invoked. That gives us a chance to dispose of the snapshot data. Once the snapshot is removed, a subsequent call to BeginEdit will cause a new editing session to begin.

Monday, May 19, 2008

Doing a Planet transformation to a Pano foto.

1. Make the foto into a square using 'image size' by putting in the same number of pixels in the vertical axis.. uncheck constrain proportions..the image now looks a bit funky

2. Now flip 180

3 Go to filter effects and choose 'Distort......polar co-ordinates and press o.K and hey presto

this tip was given by one of the members in the Fredmiranda forum.

Friday, May 16, 2008

GPS Loggers - RBT 2300 and Holux M241 Reviewed in depth

Here is a details review of both the GPS logger models and read on to see which one is a clear winner over the other.

So I purchased the RBT-2300 and had some issues with the signal fix and one of my friend suggested to try the new Holux-M241, later realised the fix is due to the low signal level inside my apartment and its an issue with all GPS units.

My main use is for Geotagging photographs and also to be used as GPS with my Nokia N73.

Here are my observations on both the devices on a test I did this weekend.

Specs:
RoyalTek RBT-2300 with Nokia battery fully charged
Holux M-241 with Energiser lithium battery fully charged

Time to Acquire first fix:
Tried both inside my flat and first fix was difficult, so moved both the devices to my Balcony, RBT-2300 acquired the fix in approx 12 minutes and the Holux took 15 minutes.

Lock:
The RBT-2300 was able to lock to the signals more easily than the holux M-241 when i moved inside my apartment, Royaltek lost signal one in 10 compared to Holux losing 4 times in 10.

Logging:
RBT starts logging the moment you switch it on and the GPS is fixed, no hassles to wait for the fix and then press the start button to start logging.
Holux needs to get the fix first and then need to press the enter button to start logging.

Log size:
RBT : 180 days worth data or approx half million way points
Holux : 130,000

Battery life:
RBT using a Nokia batterly (860mAh) ran very good for 9 hours until the unit totally died.
Holux using the new Energiser lithium battery (approx 2800mAh) ran for 6 hours till it totally died.

Connecting to Smartphone:
Both the devices were very easy to connect to my Nokia N73 using bluetooth, got connected immediately without any problems.

Connecting to computer:
RBT provides only bluetooth and connected pretty well,
Holux uses both USB and bluetooth and connection was good.

Software:
RBT software is better then the Holux, remembers the selected Com port and also the folder location where GPS log file was last downloaded.

Downloading LOG files:
This is the main part where I started hating the Holux M-241, both took the same time to download using bluetooth, however the Holux files were empty without any log info in a previous test.

Reliability:
For any geotagging and logging purposes reliability of the data is more important, RBT has delivered proper ones till now and had no issues, but with the Holux, I was not able to download the data, this might be due to the fact that the battery got over and the unit switched off without stopping the log, now am not able to see the data in Holux, using the download tool, it crashes whenever I try to get the file.

Verdict:

Eventhough the looks of the Holux is better then the RBT, and the Holux has an attractive LCD display and many modes, it is clearly not a winner in the Geotagging scenario, may be it can be used as a GPS device for smartphones, but definitely never a reliable one for Geotagging, the reasons below.

1. For geotagging, i would prefer to switch on the device and start logging by default and if I dont want it, then I can switch it off, its ridiculous to wait for a signal and then to switch the logging on.

2. If the unit dies of low battery charge, I should atleast be able to get the proper log files from it, here Holux fails to impress.

Overall the new Holux M-241 is just a beauty with absolutely no brains and does not seem to be very useful for logging and Geotagging world with a highly unreliable performance.

Even though the RBT is simple and does not have any fancy display, it exactly does the job its claimed to do.

so anybody planning to buy the Holux M-241, please assess these facts and base your decision on what you mainly intend to use the GPS for, if visual display of the GPS details is not much of a bother to you, better go with the RBT-2300.

The Winner:

[b]RBT-2300 is a clear winner[/b] compared to the Holux M-241.