Thursday, March 12, 2009

Windows Media Center

I dont know how may of you out there are using Windows Media Center for your TV viewing needs, but I have to say http://www.secondrun.tv/ is the best add-on that I have come across yet!
I have completely dropped my Dish Network and almost exclusively use this to watch my favorite shows.

Friday, February 13, 2009

The underlying connection was closed: A connection that was expected to be kept alive was closed by the server

Well the bad news is that this worked for some time but then started to not work again. Looks like i am back to the drawing board.


Ok it took me 2 days to track this down but I think I have solved it.

I have 2 different .net 2.0 libraries in the same application that both access the same third-party Java web service. Oh by the way this worked no problem in .net 1.0

Well this was throwing an System.Net.WebException "The underlying connection was closed:" randomly.

InnerException: System.IO.IOException
Message="Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Source="System"
StackTrace:
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead)
InnerException: System.Net.Sockets.SocketException
Message="An existing connection was forcibly closed by the remote host"
Source="System"
ErrorCode=10054
NativeErrorCode=10054
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)


I spent forever searching the net looking for a solution to this, with little to no success.
Well I finally came across this link. To resolve this problem you need to disable the keep-alive feature.

In the .NET Framework, you need to set the HttpWebRequest.KeepAlive property to FALSE.
To do this I created a web service reference then modified the generated Reference.cs class and added

protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}

now I know this will probably add a little over-head to my application but so what it solved my devastating error :-)

Labels: , ,

Wednesday, December 10, 2008

My new HTPC

Ok I just created a new HTPC (Home Theater PC) and let me just say how the hell did I live with out this before. I actually was able to drop my Dish Network service since most of what I was watching is offered online.
When I get a chance I hope to list everything I went thru in creating it.

Labels:

Tuesday, September 9, 2008

.net Exception list

Jeff Atwood wrote a great little block of code to list all the exceptions in .net. I just needed the most common ones so I posted them here.

System.AppDomainUnloadedException
System.ApplicationException
System.ArgumentException
System.ArgumentNullException
System.ArgumentOutOfRangeException
System.ArithmeticException
System.ArrayTypeMismatchException
System.BadImageFormatException
System.CannotUnloadAppDomainException
System.ComponentModel.Design.CheckoutException
System.ComponentModel.Design.Serialization.CodeDomSerializerException
System.ComponentModel.InvalidEnumArgumentException
System.ComponentModel.LicenseException
System.ComponentModel.WarningException
System.ComponentModel.Win32Exception
System.Configuration.ConfigurationException
System.ContextMarshalException
System.Data.ConstraintException
System.Data.DataException
System.Data.DBConcurrencyException
System.Data.DeletedRowInaccessibleException
System.Data.DuplicateNameException
System.Data.EvaluateException
System.Data.ExprException
System.Data.InRowChangingEventException
System.Data.InvalidConstraintException
System.Data.InvalidExpressionException
System.Data.MissingPrimaryKeyException
System.Data.NoNullAllowedException
System.Data.Odbc.OdbcException
System.Data.OleDb.OleDbException
System.Data.ReadOnlyException
System.Data.RowNotInTableException
System.Data.SqlClient._ValueException
System.Data.SqlClient.SqlException
System.Data.SqlTypes.SqlNullValueException
System.Data.SqlTypes.SqlTruncateException
System.Data.SqlTypes.SqlTypeException
System.Data.StrongTypingException
System.Data.SyntaxErrorException
System.Data.TypedDataSetGeneratorException
System.Data.VersionNotFoundException
System.DivideByZeroException
System.DllNotFoundException
System.Drawing.Printing.InvalidPrinterException
System.DuplicateWaitObjectException
System.EntryPointNotFoundException
System.Exception
System.ExecutionEngineException
System.FieldAccessException
System.FormatException
System.IndexOutOfRangeException
System.InvalidCastException
System.InvalidOperationException
System.InvalidProgramException
System.IO.DirectoryNotFoundException
System.IO.EndOfStreamException
System.IO.FileLoadException
System.IO.FileNotFoundException
System.IO.InternalBufferOverflowException
System.IO.IOException
System.IO.IsolatedStorage.IsolatedStorageException
System.IO.PathTooLongException
System.Management.ManagementException
System.MemberAccessException
System.Messaging.MessageQueueException
System.MethodAccessException
System.MissingFieldException
System.MissingMemberException
System.MissingMethodException
System.MulticastNotSupportedException
System.Net.CookieException
System.Net.ProtocolViolationException
System.Net.Sockets.SocketException
System.Net.WebException
System.NotFiniteNumberException
System.NotImplementedException
System.NotSupportedException
System.NullReferenceException
System.ObjectDisposedException
System.OutOfMemoryException
System.OverflowException
System.PlatformNotSupportedException
System.RankException
System.Reflection.AmbiguousMatchException
System.Reflection.CustomAttributeFormatException
System.Reflection.InvalidFilterCriteriaException
System.Reflection.ReflectionTypeLoadException
System.Reflection.TargetException
System.Reflection.TargetInvocationException
System.Reflection.TargetParameterCountException
System.Resources.MissingManifestResourceException
System.Runtime.InteropServices.COMException
System.Runtime.InteropServices.ExternalException
System.Runtime.InteropServices.InvalidComObjectException
System.Runtime.InteropServices.InvalidOleVariantTypeException
System.Runtime.InteropServices.MarshalDirectiveException
System.Runtime.InteropServices.SafeArrayRankMismatchException
System.Runtime.InteropServices.SafeArrayTypeMismatchException
System.Runtime.InteropServices.SEHException
System.Runtime.Remoting.MetadataServices.SUDSGeneratorException
System.Runtime.Remoting.MetadataServices.SUDSParserException
System.Runtime.Remoting.RemotingException
System.Runtime.Remoting.RemotingTimeoutException
System.Runtime.Remoting.ServerException
System.Runtime.Serialization.SerializationException
System.Security.Cryptography.CryptographicException
System.Security.Cryptography.CryptographicUnexpectedOperationException
System.Security.Policy.PolicyException
System.Security.SecurityException
System.Security.VerificationException
System.Security.XmlSyntaxException
System.ServiceProcess.TimeoutException
System.StackOverflowException
System.SystemException
System.Threading.SynchronizationLockException
System.Threading.ThreadAbortException
System.Threading.ThreadInterruptedException
System.Threading.ThreadStateException
System.Threading.ThreadStopException
System.TypeInitializationException
System.TypeLoadException
System.TypeUnloadedException
System.UnauthorizedAccessException
System.UriFormatException
System.Web.HttpApplication+CancelModuleException
System.Web.HttpCompileException
System.Web.HttpException
System.Web.HttpParseException
System.Web.HttpRequestValidationException
System.Web.HttpUnhandledException
System.Web.Services.Discovery.InvalidContentTypeException
System.Web.Services.Discovery.InvalidDocumentContentsException
System.Web.Services.Protocols.SoapException
System.Web.Services.Protocols.SoapHeaderException
System.Windows.Forms.AxHost+InvalidActiveXStateException
System.Xml.Schema.XmlSchemaException
System.Xml.XmlException
System.Xml.XPath.XPathException
System.Xml.Xsl.XsltCompileException
System.Xml.Xsl.XsltException

Labels: ,

Wednesday, July 9, 2008

Xsl function to testing if text only contains footnote marks

The situation come up were I had a table of data and in on of the columns it had just footnote marks. Well I had to merge these footnote marks over to the previous column, but in order to do this I needed to know if the only value in the cell were marks. So I realize there are many ways to do this but I thought this was a cool way. It reads in an external xml file with all the footnote refs I want to search for the ref value is a regex.
<footnotes>
<footnote ref="\*"/>
<footnote ref="\+"/>
<footnote ref="†"/>
<footnote ref="\([a-z]\)"/>
<footnote ref="\([1-9]\)"/>
</footnotes>

I then concat the refs together with a | and do a replace on the string value. If nothing is left then it is a footnote ref.


<!-- Reads all possible footnote ref marks from a footnotes.xml file and if pText only contains footnote marks returns true otherwise false -->
<xsl:function name="txt:IsFootnoteRef" as="xs:boolean">
<xsl:param name="pText" as="xs:string"/>
<xsl:variable name="vFootnotes" select=" document('./footnotes.xml')/footnotes/footnote"/>
<xsl:choose>
<xsl:when test="not($vFootnotes)">
<xsl:value-of select="false()"/>
</xsl:when>
<xsl:when test="not($pText)">
<xsl:value-of select="false()"/>
</xsl:when>
<xsl:when test="normalize-space($pText) = '' ">

<xsl:value-of select="false()"/>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="vFootnoteRef">
<xsl:value-of select="$vFootnotes/@ref" separator="|"/>
</xsl:variable>

<xsl:choose>
<xsl:when test=" normalize-space(replace($pText, $vFootnoteRef , '' , 'i')) = '' ">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:function>

Labels: , ,

Tuesday, March 4, 2008

Comparing XML attributes with parents attributes

I had a need to test if all/most of the attributes of a child node were equal to its parent and strip out the child node if true.

My XML structure was basically:

<PARAGRAPH style='heading1' emphasis='true' font='arial' number='30' indent=’10’>

<SPECIALTEXT style='heading1' emphasis='true' font='arial' number='31'>

Helloworld

</SPECIALTEXT>

</PARAGRAPH>

Output needed to be:

<PARAGRAPH style='heading1' emphasis='true' font='arial' number='30'>

Helloworld

</PARAGRAPH>

Now this only works on the first level after the PARAGRAPH but that’s all I needed, and it could be changed to do this recursively I guess. Basically I am matching on any paragraph that contains a child element SPECIALTEXT with the same style attribute and calling the template CompareKeyAttributes.
PARAGRAPH has more attributes than SPECIALTEXT in most cases so I compare only the ones that exist in SPECIALTEXT.

CompareKeyAttributes will return a string of all the
attributes that don’t match so then I just check if I care that the attribute
is different and output accordingly.

<xsl:template match="PARAGRAPH[SPECIALTEXT[@Style=./@Style] ] ">

<xsl:copy>

<xsl:apply-templates select="@*"/>

<xsl:for-each select=" child::*">

<xsl:variable name="RESULT">

<xsl:call-template name="CompareKeyAttributes">

<xsl:with-param name="PARA" select=".."/>

<xsl:with-param name="SPEC" select="."/>

</xsl:call-template>

</xsl:variable>

<xsl:choose>

<xsl:whentest="$RESULT='number' ">

<xsl:apply-templates select="child::node()"/>

</xsl:when>

<xsl:otherwise>

<xsl:copy>

<xsl:apply-templates select="@*|node()"/>

</xsl:copy>

</xsl:otherwise>

</xsl:choose>

</xsl:for-each>

</xsl:copy>

</xsl:template>

<xsl:template name="CompareKeyAttributes">

<xsl:param name="PARA"/>

<xsl:param name="SPEC"/>

<xsl:for-each select="$SPEC/@*">

<xsl:variable name="SPEC_ATT" select="name()"/>

<xsl:variable name="PARA_ATT" select="$PARA/@*[name()= $SPEC_ATT]"/>

<xsl:choose>

<xsl:when test="$PARA_ATT != .">

<xsl:value-of select="name()"/>

</xsl:when>

</xsl:choose>

</xsl:for-each>

</xsl:template>

Let me know if you find this useful or have anyway to make it better. Enjoy

Labels: , , ,

Tuesday, February 19, 2008

Upgrading MOSS2007 to SP1

Jason had some good references for upgrading MOSS07 to SP1. I have tried the upgrade on my development server with out any issues, but that is a single server env. I will try the upgrade next week on QA servers but anyway here is the link http://blogs.informationhub.com/jnadrowski/archive/2008/01/11/24045.aspx

Labels: