I can't find any example on the web for this, so i guess it could be helpful.
This is a simple example to show a way to read the system.serviceModel configuration section in application/web configuration file.
Something like for
ConnectionString, there is a straightforward class for that,
ConfigurationManager.ConnectionStrings["keyname"].ConnectionString
Codes snippet below
ServiceModelSectionGroup group = ServiceModelSectionGroup.GetSectionGroup(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));
//suppose if there is only one endpoint
if(group.Client.Endpoints.Count < 0)
{
uri = group.Client.Endpoints[0].Address.AbsoluteUri;
}
Monday, November 30, 2009
Monday, November 23, 2009
Stop Symantec Endpoint Protection Weekly Scheduled Scan Momentary
The intention of weekly scheduled scan is good, it helps to safeguard and diagnose your computer from malware. It is a setting set by the most system administrator that any computer with endpoint protection installed would need to oblige this and have it scan every week. It is a centralized setting where users can't change it at the user end.
However, for an advanced user like myself who know how to take care of my computer, running a PC scanning even on my peak hours are really intrusive. Therefore, after some trial and error, i notice if I use process explorer to kill the rtvscan.exe while it is running, it would force the scanning to terminate itself. And the best thing is antivirus would still be up and running and no restart required. Probably you would need to enable back the protection at the setting where it would prompt you too. That is all you need to do.
(this is my backdoor trick, use it at your own risk.)
However, for an advanced user like myself who know how to take care of my computer, running a PC scanning even on my peak hours are really intrusive. Therefore, after some trial and error, i notice if I use process explorer to kill the rtvscan.exe while it is running, it would force the scanning to terminate itself. And the best thing is antivirus would still be up and running and no restart required. Probably you would need to enable back the protection at the setting where it would prompt you too. That is all you need to do.
(this is my backdoor trick, use it at your own risk.)
Thursday, July 30, 2009
Visual Studio .NET 2008 - Some conditional breakpoints not getting triggered and workaround.
If you read some debugging tips or reference on conditional breakpoint. You would notice that what is in the text should be straightforward and there is no reason why it won't work when you try it out.
However, there are times when you set conditional breakpoint , a very simple one like
say in you code,
string a[] = {"21", "123", "32", "1234", "sds"};
foreach (string myString in stringArray)
{
Console.WriteLine("myString = " + myString); //conditional breakpoint set here.
}
conditional breakpoint set as myString == "1234" but to your surprise, it would not break and stop there.
It is a very simple thing you would do but it just seems not working. For most people, they would just set normal breakpoint there and run a few more iterations and bypass the use of the conditional breakpoints but this is not my liking. This is a VS.NET function that I would really like it to work. It is afterall a very productive debugging function.
And after some trial and error. It seems like the == operator is not correctly recognized as the ordinary C# syntax in the case of string in the conditonal breakpoint expression. It would work on most type like int, float but not on string. I suspect it would not work on most reference type variable (my reckon, though i have not tested it).
So, to cut story short. In the case when some occassion when expression in conditional breakpoints not working because of some operator like == or >.
Use the equivalent function. So, in the case of string. That would be String.Equals.
So, use Equals in the expression of the conditional breakpoint instead.
However, there are times when you set conditional breakpoint , a very simple one like
say in you code,
string a[] = {"21", "123", "32", "1234", "sds"};
foreach (string myString in stringArray)
{
Console.WriteLine("myString = " + myString); //conditional breakpoint set here.
}
conditional breakpoint set as myString == "1234" but to your surprise, it would not break and stop there.
It is a very simple thing you would do but it just seems not working. For most people, they would just set normal breakpoint there and run a few more iterations and bypass the use of the conditional breakpoints but this is not my liking. This is a VS.NET function that I would really like it to work. It is afterall a very productive debugging function.
And after some trial and error. It seems like the == operator is not correctly recognized as the ordinary C# syntax in the case of string in the conditonal breakpoint expression. It would work on most type like int, float but not on string. I suspect it would not work on most reference type variable (my reckon, though i have not tested it).
So, to cut story short. In the case when some occassion when expression in conditional breakpoints not working because of some operator like == or >.
Use the equivalent function. So, in the case of string. That would be String.Equals.
So, use Equals in the expression of the conditional breakpoint instead.
Technorati Tags: VS.NET Debugger
Wednesday, June 03, 2009
C# 2.0 syntax reference
readonly - member variable of class where can only be initialized once in constructor.
yield - contruct return for IEnumerable
e.g.
IEnumerable GetNumbers()
{
yield return 1;
yield return 2;
yield return 3;
yield return 4;
yield break;
}
This is return a 1,2,3,4 list.
this() - calling class constructor
this[] - [] operator override
e.g
public int this[int i]
{
get
{
return 1;
}
}
generic programming
//where TbaseClass is use for T calling function
class C1<T>:D1 where T:TbaseClass
class B1 : C1<myInherittedTbaseClass>
yield - contruct return for IEnumerable
e.g.
IEnumerable
{
yield return 1;
yield return 2;
yield return 3;
yield return 4;
yield break;
}
This is return a 1,2,3,4 list.
this() - calling class constructor
this[] - [] operator override
e.g
public int this[int i]
{
get
{
return 1;
}
}
generic programming
//where TbaseClass is use for T calling function
class C1<T>:D1 where T:TbaseClass
class B1 : C1<myInherittedTbaseClass>
C# pass-by-value and reference type
If you are coming from C/C++ programming background. You would be accustomed with heavy use of pass by reference (or pass by pointer) as a way to improve the performance, update the variable passed in and reducing memory consumption. It is so common, that most C/C++ function written to be efficient would be passing by constant reference (if they do not wish to allow variable passed in get updated)
Like
void myFunction(const MyClass & param)
So, you are rest assured that variable pass in would not get updated.
For C#, there is no such thing as const reference. But, there is pass-by-ref, unsafe pointer and pass-by-value.
So, to ensure that your variable passed in to function not get updated. You would naturally think of using pass-by-value.
However, there is a catch for pass-by-value if your object is of reference type (class, interface, delegate, objet, string)
Value type variable store value but reference type variable store references to object. So, even the reference is passed by value in the function. The method can still use the reference it receive to
update the original object stored in the memory.
So,
MyClass o = new MyClass();
myFunction(o);
Debug.Assert(o.MyName != “123”) ; //assertion get thrown because object has been updated by function
Public void myFunction(MyClass o)
{
o.MyName = “123”
}
So, in short, do not update the variable pass in to the function if you do not intend to. Or simply, write a Clone function for your object and pass in clone object instead.
Like
void myFunction(const MyClass & param)
So, you are rest assured that variable pass in would not get updated.
For C#, there is no such thing as const reference. But, there is pass-by-ref, unsafe pointer and pass-by-value.
So, to ensure that your variable passed in to function not get updated. You would naturally think of using pass-by-value.
However, there is a catch for pass-by-value if your object is of reference type (class, interface, delegate, objet, string)
Value type variable store value but reference type variable store references to object. So, even the reference is passed by value in the function. The method can still use the reference it receive to
update the original object stored in the memory.
So,
MyClass o = new MyClass();
myFunction(o);
Debug.Assert(o.MyName != “123”) ; //assertion get thrown because object has been updated by function
Public void myFunction(MyClass o)
{
o.MyName = “123”
}
So, in short, do not update the variable pass in to the function if you do not intend to. Or simply, write a Clone function for your object and pass in clone object instead.
Sunday, April 26, 2009
Smart Thinking & Lateral Thinking (Edward De Bono)
(These are just my own "personal" summary to Edward De Bono smart thinking & lateral thinking materials where I have came across some of his books lately. (for my own reference)
Please visit authorized Edward De Bono web sites if you are interested on these topics. http://www.edwdebono.com/)
Lateral Thinking - 6 thinking hats
White Hat - Based on hard data, facts, figures and numbers
Red Hat - Based on hunch, gut feeling emotional point of view
Black Hat - Pessimistic, sad & negative view but logical.
Yellow Hat - Glad and possitive but logical view.
Green Hat - Alternative, creative and sprouting new idea.
Blue Hat - Step back and take care of process of thinking. Deciding hats to be used and summarize what have been thought.
Critical Thinking - A way to minimize mistake in thinking.
Creative Thinking
Provocative Operation - Come up with an absurd idea. Then, think of "movement".
Movement - Think of ways to make provocative operation / random words possible.
Random Words - Random nouns, then think of "movement"
Focus - Set hit list (focus point for the creative thiking or where to improve).
Please visit authorized Edward De Bono web sites if you are interested on these topics. http://www.edwdebono.com/)
Lateral Thinking - 6 thinking hats
White Hat - Based on hard data, facts, figures and numbers
Red Hat - Based on hunch, gut feeling emotional point of view
Black Hat - Pessimistic, sad & negative view but logical.
Yellow Hat - Glad and possitive but logical view.
Green Hat - Alternative, creative and sprouting new idea.
Blue Hat - Step back and take care of process of thinking. Deciding hats to be used and summarize what have been thought.
Critical Thinking - A way to minimize mistake in thinking.
Creative Thinking
Provocative Operation - Come up with an absurd idea. Then, think of "movement".
Movement - Think of ways to make provocative operation / random words possible.
Random Words - Random nouns, then think of "movement"
Focus - Set hit list (focus point for the creative thiking or where to improve).
Friday, March 27, 2009
DOS prompt batch
Was trying out something on batch file, quite interesting though has limited features. But would be a quick way to delivery some solutions. Always check what batch can do before want to write a program for it.
Good place to start on batch programming at -> http://www.allenware.com/icsw/icswidx.htm
SET MYLOCATION = C:\Folder
REM A reversible CD command where you can go back where you
REM came from.
pushd %MYLOCATION%
REM check for file existent
if not exist *.txt goto ERROR
for %%file in (*txt) do type "%%file" >> mySingleFile.txt
IF ERRORLEVEL 1 goto ERROR
popd
:ERROR
echo Error occurredEXIT /B 1
Good place to start on batch programming at -> http://www.allenware.com/icsw/icswidx.htm
SET MYLOCATION = C:\Folder
REM A reversible CD command where you can go back where you
REM came from.
pushd %MYLOCATION%
REM check for file existent
if not exist *.txt goto ERROR
for %%file in (*txt) do type "%%file" >> mySingleFile.txt
IF ERRORLEVEL 1 goto ERROR
popd
:ERROR
echo Error occurredEXIT /B 1
Monday, March 09, 2009
XSL - Altering child attribute with original parent attribute
XML
<?xml version="1.0" encoding="utf-8"?> <Items xmlns="http://www.abc.com"
xmlns:myns="http://www.abc.com"> <Item attr="1"> <field1>My Content 1</field1>
</Item> <Item attr="2"> <field1>My Content 1</field1> </Item> <Item attr="3">
<field1>My Content 1</field1> <field2 innerAttr="a">My Content 2</field2>
</Item> </Items>
XSL
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns="http://www.abc.com"
xmlns="http://www.abc.com" > <xsl:output omit-xml-declaration="no"
indent="yes"/> <xsl:namespace-alias stylesheet-prefix="#default"
result-prefix="#default"/> <xsl:template match="@* | node()"> <xsl:copy>
<xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
<xsl:template match="/myns:Items/myns:Item"> <xsl:variable name="OriginalAttr"
select="@attr"/> <xsl:choose> <xsl:when test="./myns:field2/@innerAttr">
<xsl:copy> <xsl:apply-templates select="@*"/> <xsl:for-each select="*"> <xsl:if
test="local-name()='field1'"> <xsl:copy> <xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/> </xsl:copy> </xsl:if> <xsl:if
test="local-name()='field2'"> <xsl:copy> <xsl:attribute name="innerAttr"> <!--
copy from parent attribute to child attribute--> <xsl:value-of
select="$OriginalAttr"/> </xsl:attribute> <xsl:apply-templates select="
node()"/> </xsl:copy> </xsl:if> </xsl:for-each> </xsl:copy> </xsl:when>
<xsl:otherwise> <xsl:copy> <xsl:apply-templates select="@* | node()"/>
</xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
<?xml version="1.0" encoding="utf-8"?> <Items xmlns="http://www.abc.com"
xmlns:myns="http://www.abc.com"> <Item attr="1"> <field1>My Content 1</field1>
</Item> <Item attr="2"> <field1>My Content 1</field1> </Item> <Item attr="3">
<field1>My Content 1</field1> <field2 innerAttr="a">My Content 2</field2>
</Item> </Items>
XSL
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:myns="http://www.abc.com"
xmlns="http://www.abc.com" > <xsl:output omit-xml-declaration="no"
indent="yes"/> <xsl:namespace-alias stylesheet-prefix="#default"
result-prefix="#default"/> <xsl:template match="@* | node()"> <xsl:copy>
<xsl:apply-templates select="@* | node()"/> </xsl:copy> </xsl:template>
<xsl:template match="/myns:Items/myns:Item"> <xsl:variable name="OriginalAttr"
select="@attr"/> <xsl:choose> <xsl:when test="./myns:field2/@innerAttr">
<xsl:copy> <xsl:apply-templates select="@*"/> <xsl:for-each select="*"> <xsl:if
test="local-name()='field1'"> <xsl:copy> <xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/> </xsl:copy> </xsl:if> <xsl:if
test="local-name()='field2'"> <xsl:copy> <xsl:attribute name="innerAttr"> <!--
copy from parent attribute to child attribute--> <xsl:value-of
select="$OriginalAttr"/> </xsl:attribute> <xsl:apply-templates select="
node()"/> </xsl:copy> </xsl:if> </xsl:for-each> </xsl:copy> </xsl:when>
<xsl:otherwise> <xsl:copy> <xsl:apply-templates select="@* | node()"/>
</xsl:copy> </xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet>
Subscribe to:
Posts (Atom)