Sunday, January 22, 2012
Hashtable v. Dictionary
The Dictionary(Of TKey, TValue) and ConcurrentDictionary(Of TKey, TValue)classes have the same functionality as the Hashtable class. A Dictionary(Of TKey, TValue) of a specific type (other than Object) provides better performance than a Hashtable for value types. This is because the elements of Hashtable are of type Object; therefore, boxing and unboxing typically occur when you store or retrieve a value type. The ConcurrentDictionary(Of TKey, TValue)class should be used when multiple threads might be accessing the collection simultaneously.
Saturday, January 14, 2012
WCF Notes
The Svcutil.exe tool can be used only with XML Schema (XSD) files that support data contracts. If data contracts cannot be generated, you must use the Xsd.exe tool to generate XML-based data types from the XSD file.
Use SVCUtil.exe and not XSD.exe. Must read article:
http://blog.shutupandcode.net/?p=761
Validate XML with SoapExtension:
http://msdn.microsoft.com/en-us/magazine/cc164115.aspx
Use SVCUtil.exe and not XSD.exe. Must read article:
http://blog.shutupandcode.net/?p=761
Validate XML with SoapExtension:
http://msdn.microsoft.com/en-us/magazine/cc164115.aspx
Thursday, January 12, 2012
SQL Notes
Find all references of a given stored proc or a given string.
syscomments has the body text for all user stored procs in the system.
So you may search all stored procs that contain a given text.
Suppose you want to see all references for a stored proc named up_MyProc.
You may accomplish this as follows:
declare @keyword nvarchar(100)
set @keyword = 'up_MyProc' -- Enter the key word here like 'OptInInd'
SELECT distinct 'sp_helptext ' + o.name
FROM syscomments s, sys.objects o
where s.id = o.object_id
and o.type = 'P'
and charindex(@keyword, s.text) > 0
******
syscomments has the body text for all user stored procs in the system.
So you may search all stored procs that contain a given text.
Suppose you want to see all references for a stored proc named up_MyProc.
You may accomplish this as follows:
declare @keyword nvarchar(100)
set @keyword = 'up_MyProc' -- Enter the key word here like 'OptInInd'
SELECT distinct 'sp_helptext ' + o.name
FROM syscomments s, sys.objects o
where s.id = o.object_id
and o.type = 'P'
and charindex(@keyword, s.text) > 0
******
The syntax for using an alias in an update statement on SQL Server is as follows:
UPDATE QSET Q.TITLE = 'TEST'
FROM HOLD_TABLE QWHERE Q.ID = 101;
So one could write and update based on selected rows:
update pv
set pv.[LocalizedText]= (Select [LocalizedText] from [Np2n.v2.eCoCommon].[dbo].[LocalizationItem] as nv
where nv.[LocalizationItemID]='NP_Review_ShipMethod_Header' and
nv.cultureid=pv.cultureid) from [Np2n.v2.eCoCommon].[dbo].[LocalizationItem] pv where pv.[LocalizationItemID]='GG_Review_ShipMethod_Header'
******Mutliple insert from another source:INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information
WHERE Year(Date) = 1998
Saturday, June 11, 2011
Rebooting With remote desktop
You remote Windows computer appears hung and can't even bring up the Start Menu. How do you log off or reboot the machine?
Do a CTL-ALT-END this brings up the Task Manager allowing you to reboot or log off.
Do a CTL-ALT-END this brings up the Task Manager allowing you to reboot or log off.
Tuesday, May 3, 2011
Modifying HTML content before on Render
You could modify the HTML that is about to be rendered to a page using the ASP.NET Render event. For example, below we add an onclick event to every a href tag on the page:
///
/// Add an onclick handler to each link. Allows omniture to trace user clicks and navigation with s_objectID.
/// Exceptions: if onclick exists do not override or add another one to the chain.
///
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter);
base.Render(htmlWriter);
string html = stringWriter.ToString();
// get to the first a tag and start processing from there
int startPoint = html.IndexOf("
// is there already an onclick handler on some tag in this page
bool hasOnclick = html.IndexOf("onclick=", StringComparison.InvariantCultureIgnoreCase) > -1;
// get to the href and add an onclick handler unless one already exists
startPoint = html.IndexOf("href=\"", startPoint);
int ihref2 = 0;
string link;
// distniguishes links within different pages
string linkExtension;
string[] pathseg = Request.Url.Segments;
if (pathseg.Length > 0)
{
linkExtension = pathseg[pathseg.Length - 1];
linkExtension = linkExtension.Replace(".", "");
}
else
linkExtension = String.Empty;
while (startPoint > -1)
{
if (hasOnclick)
{
int idx1 = html.IndexOf(" int idx2 = html.IndexOf(">", idx1 + 1);
string atag = html.Substring(idx1, idx2 - idx1);
// is this an if (atag.IndexOf("onclick", StringComparison.InvariantCultureIgnoreCase) > -1)
{
// move to the next tag. Do not override existing onclick
startPoint = startPoint + 7;
startPoint = html.IndexOf("href=\"", startPoint);
continue;
}
}
startPoint = startPoint + 7;
ihref2 = html.IndexOf("\"", startPoint);
if (ihref2 > -1 && ihref2 > startPoint)
{
link = html.Substring(startPoint, ihref2 - startPoint).Replace("http", "").Replace("\\", "").Replace(@"/", "").Replace("\"", "").Replace("'", "").Replace(".", "").Replace("(", "").Replace(")", "").Replace(":", "");
ihref2++;
html = html.Substring(0, ihref2) + " onclick=\"s_objectID='" + link + linkExtension + "'\" " + html.Substring(ihref2);
startPoint = html.IndexOf("href=\"", ihref2); // get the next href - ihref2 is > startPoint
}
else
startPoint = -1;
}
writer.Write(html);
}
Friday, October 10, 2008
return key event processing in javascript
function retkey(ev) {
if (ev == null)
ev = window.event;
var key = null;
if (ev.keyCode)
key = ev.keyCode;
else if (ev.which)
key = ev.which;
if (key != null && key == 13)
return ClientValidate();
return true;
}
if (ev == null)
ev = window.event;
var key = null;
if (ev.keyCode)
key = ev.keyCode;
else if (ev.which)
key = ev.which;
if (key != null && key == 13)
return ClientValidate();
return true;
}
Thursday, September 25, 2008
Calculating absolute position
// here is a Javascript routine that calculates the absolute position of an html
// element by recursively traversing the parent dom elements
// (works in IE, Firefox, Safari , etc.)
Map.Drawing.Point.prototype.addAbsolutePosition = function(obj) {
var X, Y;
var cur;
if (!obj) {
return this;
}
else
{
X=parseInt("0" + this.x);
Y=parseInt("0" + this.y);
var o = obj;
if (o.offsetParent) //then this object has a container that affects its position
{
while (o.offsetParent)
{
X += parseInt(o.offsetLeft);
Y += parseInt(o.offsetTop);
o = o.offsetParent; //traverse the hierarchy upward
}
}
else if (o.x || o.y) //no container but an absolute position
{
if (o.x) X += parseInt(o.x);
if (o.y) Y += parseInt(o.y);
}
this.x = X;
this.y = Y;
return this;
}
};
// element by recursively traversing the parent dom elements
// (works in IE, Firefox, Safari , etc.)
Map.Drawing.Point.prototype.addAbsolutePosition = function(obj) {
var X, Y;
var cur;
if (!obj) {
return this;
}
else
{
X=parseInt("0" + this.x);
Y=parseInt("0" + this.y);
var o = obj;
if (o.offsetParent) //then this object has a container that affects its position
{
while (o.offsetParent)
{
X += parseInt(o.offsetLeft);
Y += parseInt(o.offsetTop);
o = o.offsetParent; //traverse the hierarchy upward
}
}
else if (o.x || o.y) //no container but an absolute position
{
if (o.x) X += parseInt(o.x);
if (o.y) Y += parseInt(o.y);
}
this.x = X;
this.y = Y;
return this;
}
};
Subscribe to:
Posts (Atom)