Thursday, August 26, 2010

.Net Studio Trick - How to check out only modified source files when rebinding the project to the source control

Commonly software is developed in a source controlled environment such as team foundation server, but sometime its not applicable , the classic scenario is when two developers are working simultaneously with the same source files for two different projects which takes a while to finish , agreeably or not , one of them will need to develop his project offline and unbind from the source control server , after the project completion he binds it back the source control then check out the modified files and merge the source code then checks in his project changes - mission accomplished!
I have been there , and the problem I faced in this process is to remember what files to check out after binding the project , its not always easy to remember when its a big project when you have modified 8 source files out of 220 , if you missed one you are risking checking in partial source or worse you may override and lose your modified sources when syncing your machine with the source control as it replaces your sources with server's ones.
I found a quick way to checkout only the modified source files when rebinding the project to the source control without remembering the files names ,i will illustrate how to do it using the following example project :


Step I: Bind the project and checkout all the files


Step II: On the project file Right click and choose to "Undo Pending Changes.."


Step III: A dialog pops up warning about discarding changes , press "No to All"

The result :


Vaulla !  only my modified files is checked out , you can do this trick to entire project solution containing lots of projects and source file !

Please be aware to choose the "No to All " in the undo pending changes pop up and not any other option which may override your changes.

Enjoy :)

Monday, August 16, 2010

C# How to add distance and calculate new location from Lat\Lon

In one of my geo spatial projects I faced the need to calculate new Lat \ Lon location based on other Lat \ Lon Location , distance and bearing , for example what is the location that is 300 meters NE of a particular location as described in this illusrtartion :

Here is the formula that for given a start point, initial bearing, and distance it calculates the destination point and final bearing travelling along a (shortest distance) great circle arc

lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))

lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))

Where d is the distance travelled and R is the earth’s radius , d/R is the angular distance (in radians)
Here is the a function written in C# that applies the formula :

const double EarthRadius = 6378137.0;
const double DegreesToRadians = 0.0174532925;
const double RadiansToDegrees = 57.2957795;
/// <summary>
/// Calculates the new-point from a given source at a given range (meters) and bearing (degrees). .
/// </summary>
/// <param name="source">Orginal Point</param>
/// <param name="range">Range in meters</param>
/// <param name="bearing">Bearing in degrees</param>
/// <returns>End-point from the source given the desired range and bearing.</returns>

public LatLon CalculateDerivedPosition(LatLon source, double range, double bearing)

{
double latA = source.Lat * DegreesToRadians;
double lonA = source.Lon * DegreesToRadians;
double angularDistance = range / EarthRadius;
double trueCourse = bearing * DegreesToRadians;

double lat = Math.Asin(Math.Sin(latA) * Math.Cos(angularDistance) +Math.Cos(latA) * Math.Sin(angularDistance) * Math.Cos(trueCourse));

double dlon = Math.Atan2(Math.Sin(trueCourse) * Math.Sin(angularDistance) * Math.Cos(latA),Math.Cos(angularDistance) - Math.Sin(latA) * Math.Sin(lat));
double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;

return new LatLon(lat * RadiansToDegrees,lon * RadiansToDegrees);

}

Thursday, August 12, 2010

Step by Step - How to Host .Net Win Forms User Control in IE

If you ever wandered if its possible to use your Internet Explorer as hosting shell to your.NET Win Forms user control component - the answer is YES! and its easy ! In this post i will show how to do it step by step  :

Step I: Have a user control
Build up a simple user control that has a label , calendar and progress bar :

The user control i'm going to use
Step II : Move Binaries of the user control to the  IIS
Copy the binaries or configure the solution  project of the user control to output the binaries to the virtual directory of the IIS diretory  e.g.  C:\inetpub\wwwroot  .

Step III : Create web page and create instance of the user control
create HTML page with the following code and name it Host.html then save it in the virtual directory :

<html>
<head><title>Host My User Control</title><head>
<body>
<div id ="container">
<object id="MyUserControl" classid="http://localhost/MySmallControl.dll#MySmallControl.MyUserControl"</object>
</div>
</body>
</html>

where as;
MySmallControl.dll stands for the binary name
MySmallControl stands for the namespace of the project
MyUserControl stands for the class name of the user control


Step IV : Surf to the Host.html

open Internet Explorer and surf to  http://localhost/Host.html and you good to go !


The user control hosted in Internet Expolrer !

 
Related Topics i'm gonig to release soon:

  • How to interact between Javascript code and host user control C# code

  • How to give access to the host user control to the client's resources ,e.g. the Hard Disk