Tuesday, January 21, 2014

A custom exception class with Log flag

A class to re-thrown Exception with property if the Exception is already logged.

[Serializable()] public class ExceptionLog : Exception { private bool isLogged; public bool IsLogged { get { return isLogged; } } protected ExceptionLog() : base() { } public ExceptionLog(bool value) : base() { isLogged = value; } public ExceptionLog(bool value, string message) : base(message) { isLogged = value; } public ExceptionLog(bool value , string message , Exception innerException) : base(message, innerException) { isLogged = value; } protected ExceptionLog(SerializationInfo info , StreamingContext context) : base(info, context) { } }

Share/Bookmark

Friday, January 3, 2014

Split Camel Case "string" To Human Readable

private string SplitCamelCaseToHumanReadable(string strCamelCase) { var rgx = new Regex( @"(?<=[A-Z])(?=[A-Z][a-z]) | (?<=[^A-Z])(?=[A-Z]) | (?<=[A-Za-z])(?=[^A-Za-z])" , RegexOptions.IgnorePatternWhitespace); return rgx.Replace(strCamelCase, " "); }

Share/Bookmark

Tuesday, December 31, 2013

Firebug Net panel - HTTP Traffic Monitoring

Needed to collect info around request URL, request header, response status, and response value of REST service calls, I utilized Net panel of Firebug which provided me a lot of details to verify the service calls processes in the web application.

The goal of using the Net panel was monitoring the HTTP traffic initiated by a web page which simply revealed all the collected and computed information in a graphical and intuitive interface.





introduction of Firebug by Rob Campbell


Share/Bookmark

IIS 7.5 Advanced Logging

To be able to capture all requests URLs and status of them in a real-time manner during a load test I added IIS Advanced Logging and customized it by defining the log, setting, and activating it.

It helped to monitor the sequence of requests and status of service responses during a load test.




Share/Bookmark

Trace listener and logging trace in a file

Possible to create and use a trace listener in code or by using a configuration file, as it’s easier to change configuration file without touching the code I tried to add it for a WebApi REST service by the following code for Telerik reports:

<system.diagnostics> <trace autoflush="false" indentsize="4"> <listeners> <add name="WebApiRESTListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="Services.Reporting.REST.Tracing.log" /> <remove name="Default" /> </listeners> </trace> </system.diagnostics>

Share/Bookmark

Friday, December 20, 2013

{System.Data.EntityException: The underlying provider failed on Open.

Entity Framework 5.0 with DbContext in the code tried to have access data as data Access layer code of a WCF service, the following error happened:

{System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired. The time out period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=50; handshake=1215; [Login] initialization=0; authentication=14; [Post-Login] complete=13022; ---> System.ComponentModel.Win32Exception: The wait operation timed out

It didn't have Transaction around the code, if I had a TransactionScope around the code then it treat connections as multiple ones using a distributed transaction which force open/close connections with each call. But without the transaction I needed to add opening connection code.

using (MyEntities ctx = new MyEntities()) { #region Added to work when Transaction is not around ctx.Database.Connection.Open(); #endregion courseList = ctx.MyMethod(MyParam).ToList(); }

Share/Bookmark

Friday, December 6, 2013

jQuery - replace html element by .remove()

.remove()
Remove the set of matched elements from the DOM.

You could remove an element from DOM but it doesn't get eliminated from wrapper set and this feature allows you remove an element, operate on that element, and then place that element back into the DOM, all within a single jQuery chain.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<title></title> </head> <body> <div id="ItemToBeRelaced">remove it!</div>
<script> (function ($) { $('#ItemToBeRelaced') .remove() .html('<a href="http://greyknots.com/">GreyKnots</a>') .appendTo('body'); })(jQuery); </script>
</body> </html>

Share/Bookmark

jQuery - difference between closest() and parents()

closest() stops traversing once it finds a match.
closest() can only return a maximum of one element.
closest() will actually include the currently selected element in its filtering.
parents() gets all parents and then filters on your optional selector.

Try the following example:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<title></title> </head> <body> <!-- Nested Div(s) --> <div id="parent3"> <div id="parent2"> <div id="parent1"> <div id="parent0"> <div id="LastInChain"></div> </div> </div> </div> </div>
<script> (function ($) { alert($('#LastInChain').parents().length); alert($('#LastInChain').parent().attr('id')); alert($('#LastInChain').parents('#parent0').attr('id')); alert($('#LastInChain').parents()[0].id);
alert($('#LastInChain').closest('#parent1').length); alert($('#LastInChain').closest('#parent1').length); alert($('#LastInChain').closest('#parent1').attr('id')); })(jQuery); </script>
</body> </html>

Share/Bookmark

Friday, November 29, 2013

Automating package restore in Visual Studio, don’t keep NuGet Packages in source control

When developers install NuGet packages and set references to those assemblies then it would be necessary to keep them available during build. On the other side down the road maybe the NuGet packages in your projects need to be upgraded and also keeping more and more binaries in repositories will just consume more space in your local disk and in repository especially for Git or Distributed version control systems (DCVS) which include every version of every file within the repository.

The best way is to enable package restore during build, the feature added since NuGet 2.0 and improved as of NuGet 2.7.

By automating package restore in Visual Studio the build events can handle installing the missing packages which eliminate the necessity of keeping them in repository.

There are two levels which should be set, simply go for ToolsOptions and then try to choose Package Manager 1. Visual Studio is configured to 'Allow NuGet to download missing packages' 2. Visual Studio is configured to 'Automatically check for missing packages during build in Visual Studio'



It’s done, but there is other options too like [MSBuild-Integrated Package Restore] which I’ll point to that in next blog entry.

Share/Bookmark

Friday, November 22, 2013

Adding external assemblies to load with Visual Studio at startup

Needed to add user defined methods for Telerik Reporting to be able to call the methods in expression builder of report, then it was necessary that Visual Studio loads the assembly at startup to make it ready for Telerik Report designer in VS.

Looked into VS configuration file:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe.config

Found the probing tag points to PublicAssemblies & PrivateAssemblies:
<probing privatePath="PublicAssemblies;PrivateAssemblies;..."/>

The above paths allows to have access to assemblies other than GAC, in this case, I needed to drop the custom coded assembly in a path which is known for VS.

Also assemblies deployed in PublicAssemblies path appear in the Add Reference dialog box, if you don't like to make them available in the Add Reference list but be known for VS, it should be deployed in PrivateAssemblies path.

Simply found the paths as following:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies

in this special case, I added the following parts in devenv.exe.config

<configSections> ... <section name="Telerik.Reporting" type="Telerik.Reporting.Configuration.ReportingConfigurationSection , Telerik.Reporting , Version=7.2.13.1016 , Culture=neutral , PublicKeyToken=a9d7983dfcc261be" allowLocation="true" allowDefinition="Everywhere"/> </configSections>

and then added the following part in devenv.exe.config to introduce the external methods functionality to Telerik.Reporting designer.
<Telerik.Reporting> <AssemblyReferences> <add name="MyAssembly" version="1.0.0.0" /> </AssemblyReferences> </Telerik.Reporting>

Now VS loads the assembly and it gets available for Telerik.Reporting as extended methods inside designer.
Share/Bookmark