Wednesday, July 29, 2009

How to fix AssemblyVersion number but auto-increment AssemplyFileVersion number

Why need it?

A quote from Microsoft (http://support.microsoft.com/kb/556041):

If you release new version of assembly very frequently, say once every day, and if assemblies are strong named, Developers will have to change the reference every time you release new assembly. This can be quite cumbersome and may lead to wrong references also.
But unfortunately that link doesn't show how to make AssemblyFileVersion auto-increment as we do need a version control feature, so i started to search around over internet and finally found a solution (well.. not quite nice)


Solution

1. Download and install the AssemblyInfoTask package, you can find it from here
http://code.msdn.microsoft.com/AssemblyInfoTaskvers/Release/ProjectReleases.aspx?ReleaseId=232

2. Reboot your PC after installation (I know ... but trust me, it's needed)

3. Then you should be able to find a help chm file here
C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask\AssemblyInfoTask.chm

4. Open it and follow what it suggests in "Getting Started" page

5. You can modify the Microsoft.VersionNumber.targets file to customize the format of version number based on your need

P.S it doesn't support TEAM FOUNDATION or Source Safe quite well, as you will get an access error when you build the project if the AssemblyInfo source file is locked (read-only)

Hope it helps someone

Labels: , ,

Thursday, December 11, 2008

paypal transaction

These are some information I searched over internet, which they are very useful. Basically you can set up your own paypal transaction recorder after read them though

1.PayPal IPN handler - free script to handle PayPal IPN

2.Getting Payment Data from PayPal: Auto Return, PDT, IPN Demystified

3.PayPal Script Generator

4.Donation Button Examples

Labels: , ,

THE SOLUTION OF HOW TO CONVERT UK POSTCODE TO VALUE OF EASTING AND NORTHING BY USING JAVASCRIPT

The main idea



1. Use Goolge public map API - GlocalSearch (do not use GClientGeocoder, because GClientGeocoder doesn't support very well) to get the value in LanLong.
2. Use the following functions below to convert LanLong to value of easting and northing

A Javascript I wrote up to implement the mechanism





/***
The part of this script uses Google' map API, so it is necessary to apply a Google map Key before use it
***/

/*
* construct a LatLon object: arguments in numeric degrees
*
* note all LatLong methods expect & return numeric degrees (for lat/long & for bearings)
*/
function LatLon(lat, lon) {
this.lat = lat;
this.lon = lon;
}

// extend Number object with methods for converting degrees/radians

Number.prototype.toRad = function() { // convert degrees to radians
return this * Math.PI / 180;
}

Number.prototype.toLat = function() { // convert numeric degrees to deg/min/sec latitude
return this.toDMS().slice(1) + (this<0 ? 'S' : 'N'); // knock off initial '0' for lat!
}

/*
* pad a number with sufficient leading zeros to make it w chars wide
*/
Number.prototype.padLZ = function(w) {
var n = this.toString();
for (var i=0; i<w-n.length; i++) n = '0' + n;
return n;
}


function GetPointFromPostcode(postcode, callbackFunction) {
var localSearch = new GlocalSearch();
localSearch.setSearchCompleteCallback(null,
function() {
if (localSearch.results[0]) {
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;

point = new LatLon(parseFloat(resultLat),parseFloat(resultLng));
var coor = gridrefNumeric(LatLongToOSGrid(point));

/********************************
TAKE YOUR COORDINATE HERE
coor[0] - EASTING
coor[1] - NORTHING
********************************/
callbackFunction(coor);
}else{
alert("Postcode not found!");
return false;
}
});

localSearch.execute(postcode + ", UK");
}

/*
* convert standard grid reference ('SU387148') to fully numeric ref ([438700,114800])
*
* note that northern-most grid squares will give 5-digit northings
* no error-checking is done on gridref (bad input will give bad results or NaN)
*/
function gridrefNumeric(gridref) {
// get numeric values of letter references, mapping A->0, B->1, C->2, etc:
var letE = gridref.toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0);
var letN = gridref.toUpperCase().charCodeAt(1) - 'A'.charCodeAt(0);
// shuffle down letters after 'I' since 'I' is not used in grid:
if (letE > 7) letE -= 1;
if (letN > 7) letN -= 1;

// convert grid letters into 100km-square indexes from false origin (grid square SV):
var e = ((letE+3)%5)*5 + (letN%5);
var n = (19-Math.floor(letE/5)*5) - Math.floor(letN/5);

// skip grid letters to get numeric part of ref, stripping any spaces:
gridref = gridref.slice(2).replace(/ /g,'');

// append numeric part of references to grid index:
e += gridref.slice(0, gridref.length/2);
n += gridref.slice(gridref.length/2);

// normalise to 1m grid:
switch (gridref.length) {
case 6: e += '00'; n += '00'; break;
case 8: e += '0'; n += '0'; break;
// 10-digit refs are already 1m
}

return [e, n];
}

/*
* convert geodesic co-ordinates to OS grid reference
*/
function LatLongToOSGrid(p) {
var lat = p.lat.toRad(), lon = p.lon.toRad();

var a = 6377563.396, b = 6356256.910; // Airy 1830 major & minor semi-axes
var F0 = 0.9996012717; // NatGrid scale factor on central meridian
var lat0 = (49).toRad(), lon0 = (-2).toRad(); // NatGrid true origin
var N0 = -100000, E0 = 400000; // northing & easting of true origin, metres
var e2 = 1 - (b*b)/(a*a); // eccentricity squared
var n = (a-b)/(a+b), n2 = n*n, n3 = n*n*n;

var cosLat = Math.cos(lat), sinLat = Math.sin(lat);
var nu = a*F0/Math.sqrt(1-e2*sinLat*sinLat); // transverse radius of curvature
var rho = a*F0*(1-e2)/Math.pow(1-e2*sinLat*sinLat, 1.5); // meridional radius of curvature
var eta2 = nu/rho-1;

var Ma = (1 + n + (5/4)*n2 + (5/4)*n3) * (lat-lat0);
var Mb = (3*n + 3*n*n + (21/8)*n3) * Math.sin(lat-lat0) * Math.cos(lat+lat0);
var Mc = ((15/8)*n2 + (15/8)*n3) * Math.sin(2*(lat-lat0)) * Math.cos(2*(lat+lat0));
var Md = (35/24)*n3 * Math.sin(3*(lat-lat0)) * Math.cos(3*(lat+lat0));
var M = b * F0 * (Ma - Mb + Mc - Md); // meridional arc

var cos3lat = cosLat*cosLat*cosLat;
var cos5lat = cos3lat*cosLat*cosLat;
var tan2lat = Math.tan(lat)*Math.tan(lat);
var tan4lat = tan2lat*tan2lat;

var I = M + N0;
var II = (nu/2)*sinLat*cosLat;
var III = (nu/24)*sinLat*cos3lat*(5-tan2lat+9*eta2);
var IIIA = (nu/720)*sinLat*cos5lat*(61-58*tan2lat+tan4lat);
var IV = nu*cosLat;
var V = (nu/6)*cos3lat*(nu/rho-tan2lat);
var VI = (nu/120) * cos5lat * (5 - 18*tan2lat + tan4lat + 14*eta2 - 58*tan2lat*eta2);

var dLon = lon-lon0;
var dLon2 = dLon*dLon, dLon3 = dLon2*dLon, dLon4 = dLon3*dLon, dLon5 = dLon4*dLon, dLon6 = dLon5*dLon;

var N = I + II*dLon2 + III*dLon4 + IIIA*dLon6;
var E = E0 + IV*dLon + V*dLon3 + VI*dLon5;
//alert(E + ' : ' + N)
return gridrefNumToLet(E, N, 8);
}

/*
* convert numeric grid reference (in metres) to standard-form grid ref
*/
function gridrefNumToLet(e, n, digits) {
// get the 100km-grid indices
var e100k = Math.floor(e/100000), n100k = Math.floor(n/100000);

if (e100k<0 || e100k>6 || n100k<0 || n100k>12) return '';

// translate those into numeric equivalents of the grid letters
var l1 = (19-n100k) - (19-n100k)%5 + Math.floor((e100k+10)/5);
var l2 = (19-n100k)*5%25 + e100k%5;

// compensate for skipped 'I' and build grid letter-pairs
if (l1 > 7) l1++;
if (l2 > 7) l2++;
var letPair = String.fromCharCode(l1+'A'.charCodeAt(0), l2+'A'.charCodeAt(0));

// strip 100km-grid indices from easting & northing, and reduce precision
e = Math.floor((e%100000)/Math.pow(10,5-digits/2));
n = Math.floor((n%100000)/Math.pow(10,5-digits/2));

var gridRef = letPair + e.padLZ(digits/2) + n.padLZ(digits/2);

return gridRef;
}





Useful References



1. Introducing Google's Geocoding Service
2. Introducing Google's Geocoding USNaviguide / Maps.Huge.Info Example Pages
3. Calculate distance and bearing between two OS National Grid Reference points

Labels: , , , , , ,

Saturday, December 06, 2008

Asp.net Web Administrator tool Workarround in Windows Vista

How did I get my Web Administrator tool(WAT) running under Windows Vista

The development environment I am working on is:

  1. VS 2005,
  2. Windows Vista
  3. SQL Server Management Studio Express

The Problem

The problem I had was that I got an error message when I clicked on AspNetSqlProvider Test click, as following:

"Could not establish a connection to the database.If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider."

How I fix it:

The valid steps I made to fix the problem were:

  1. First of all, make sure that run the VS2005 as administrator.
  2. As what the Microsoft suggest, use aspnet_regsql command-line to create and configure the database, but unfortunately it doesn't tell us where the utility is, which is quite frustrating. so I have to google a bit over Internet, and finally found the path to it is C:\Windows\Microsoft.NET\Framework\. After I run the command, just followed the guide to create the aspnet membership database that holds idenditiy details.

    Sometimes, things just don't go smooth as you expect. During the progress of installing aspnetdb, I got a permission issue, saying that I don't have enough permission to use master database. The fix is that

    go to SQL Server Surface Area Configuration -> Click on "Add new administrator" -> grant the avaiable privileges to specified account-> click "Ok"
  3. Now I can see I got a new database called "aspnetdb" in Sql server Express that contains serval tables that are needed for aspnet Membership system, but when I went back to WAT, the message was still there.
  4. Go to event viewer, it will tell you more information such as any error or warning. one of errors I got was

    Generating user instances in SQL Server is disabled. Use sp_configure 'user instances enabled' to generate user instances. [CLIENT:
    the fix was

    > Open a SQL Server 2005 Management Studio Express.
    > Connect to the default instance of that server (PC-Name\SQLEXPRESS)
    > Open a New Query Window, ensure that you are connecting to the master database
    > Type: exec sp_configure 'user instances enabled', 1
    > Type: RECONFIGURE
    > Restart the SQL Server


    After fixed this problem, I got another one here:

    Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed. [CLIENT: ]

    Most of articles suggest that delete C:\Users\<accountname>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS, (in WinXP the path is different - C:\Documents and Settings\USERNAME\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS) folder, my magic was to make sure the SQL server express service is running as Local system account.
  5. and sometimes you can't see the error in the eventviewer, but you still keep getting the error message. then you need to check out the error.log file which under this path (in window vista) C:\Users\<accountname>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS

and eventually, after 1 day, i got my WAT work.

Labels: , , , , , , ,

Thursday, February 14, 2008

Interesting Data Type of DataColumn generated from Excel data source

I generated a DataTable from an excel file by using ADO.NET, which the excel file includes two columns "notes","id". like:


Excel file:
ID        NOTES (ignore the rest of columns ...)
201      FunnytEST
202      78
203      Interesingtest2
204      90
205      67
...



After I got my DataTable, I wrote up a piece of codes to loop through the 'NOTES' column, and find out something which is quite interesting!

In this case above, apart from 78,90,67, supprisingly I got 2 NULLs instead of "FunnytEST" and "Interesingtest2"! and the DataTable.Column("NOTES").DataType is equal to String.Double

and then I changed the data of excel file to :


ID         NOTES (ignore the rest of columns ...)
201      FunnytEST
202      ChangeNumberToString
203      Interesingtest2
204      90
205     67


then the DataTable.Column("NOTES").DataType was changed to System.String the last two cells (90 and 67) of column NOTES can not be read.

OK, that makes sence, because if the data type of that column has been declared with System.String, so any data in Double or Int can not be read.

it seems like ADO.Net creates data type for DataColumn based on how many cells in Double type that column have and how many cells in String type. After comparaison, the ADO.NET chooses the one that is used mostly by cells to be the final data type for that column.(do you know wat I try to explain? ... well.. in fact, I don't know wat I talk about :-))


And so that must be something wrong with the excel file itself then. I opened the excel file right click NOTES column ->choose Cell Format, on Category changed General to Text, click OK.

Now tried again. Problem solved!


PS:
This bloody problem caused my fucking whole day (and my lovely lunch hour!) on it. Fuck!

Labels: , , ,

Friday, January 04, 2008

Interesting Sessioin timeout issue

Q:Clients frequently got timeout in an uncertainty point.

A:Apart from asp.net Session.Timeout and the settingstate mark in the web.config, inproper IIS settings will result in trigger timeout as well
helpful details:
click here

In order to keep session state based on a stateless protocol - HTTP, web application keep the session detail in a process called w3wp.exe, if any events trigger w3wp.exe recyle then the session state stored in the proccess will be lost as well

Labels: , , , ,

Tuesday, December 11, 2007

Strange experience of permission changed

Under WinXP, I made a copy of some of web application files to another folder, and copied them back to the folder where the web application is in.

Supprisely, the permission for the webapplicaiton folder was changed!! then you got a access denied error:


Access is denied.
Description: An error occurred while accessing the resources required to serve this request. You might not have permission to view the requested resources.

Error message 401.3: You do not have permission to view this directory or page using the credentials you supplied (access denied due to ACLs). Ask the Web server's administrator to give you access to 'C:\Websites\globalGateway2\bespoke\ISA\Forms\frmLogin.aspx'.

Labels: , ,

Monday, October 23, 2006

创建了新的Workgroup Information File后,为了与ACCESS数据库建立连接,应当如何编写连接字符串?

当尝试连接 Access数据库时,Jet 数据库引擎将查找默认的Workgroup Information File(system.mdw,

system1.mdw,或system2.mdw,)。若再创建了新的Workgroup Information File后(例如Secured.mdw)没有

在连接字符串中指明其绝对路径,Jet 数据库引擎将仍然查找默认的Workgroup Information File,最终导致

"无法启动应用程序。工作组信息文件丢失,或是已被其它用户以独占方式打开。"的错误。

因此正确的连接字符串书写应为:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\BlueBamboo\database\db.mdb;Jet OLEDB:System

Database=E:\BlueBamboo\database\Secured.mdw;User Id=PubUser;Password=123"

Labels: , , , , ,