Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Measuring and Monitoring WCF Web Service Performance

, 4 Oct 2012 GPL3
Using ServiceMon to obtain performance statistics for web services
ServiceMonExtensionExample-noexe.zip
ServiceMonExtensionExample
ServiceMonExtensions
Properties
Service References
TempConvertWebService
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
tempconvert.wsdl
Tests
Properties
ServiceMonExtensionExample.zip
bin
Kaleida.ServiceMonitor.Framework.dll
configuration.svcinfo
configuration91.svcinfo
Reference.svcmap
tempconvert.wsdl
ServiceMon_v1.0.0_Source-noexe.zip
ServiceMon v1.0.0 Source
BuildTools
antlr-3.2.jar
nUnit
Failure.jpg
Ignored.jpg
NUnitTests.nunit
Success.jpg
tempfile.tmp
Everything.build
Kaleida.ServiceMonitor.CodePlexUploader
Kaleida.ServiceMonitor.Framework
Properties
Responses
Kaleida.ServiceMonitor.Model
Email
Layout
Parsing
ScriptGrammar.g
Properties
Runtime
ScriptDirectives
Statistics
StructuredSource
Kaleida.ServiceMonitor.Operations
PreparedRequests
Properties
ResponseHandlers
Kaleida.ServiceMonitor.UI
Application.ico
Icons
Application.ico
Error.ico
Running.ico
Stopped.ico
Kaleida.ProductBuilder.ServiceMonitor.csproj.DotSettings
Kaleida.ProductBuilder.ServiceMonitor.csproj.DotSettings.user
Kaleida.ProductBuilder.ServiceMonitor.csproj.ReSharper
NotificationPanels
Properties
Settings.settings
Scripts
Introductory Examples.mscr
More Examples.mscr
Kaleida.ServiceMonitor.UnitTests
Framework
Model
Email
Layout
Parsing
Runtime
Statistics
Operations
Scripts
Setup
DialogBackround.bmp
DialogBackround.pdn
DialogTopBanner.bmp
GPLv3License.rtf
Product.wxs
Setup.wixproj
ServiceMon_v1.0.0_Source.zip
bin
Antlr3.Runtime.dll
CodePlex.WebServices.Client.dll
JetBrains.Annotations.dll
log4net.dll
antlr-3.2.jar
Failure.jpg
fit.dll
Ignored.jpg
loadtest-assembly.dll
mock-assembly.dll
nonamespace-assembly.dll
notestfixtures-assembly.dll
nunit-console-runner.dll
nunit-console-x86.exe
nunit-console.exe
nunit-console.tests.dll
nunit-gui-runner.dll
nunit-gui.exe
nunit-gui.tests.dll
nunit-test-server.dll
nunit-x86.exe
nunit.core.dll
nunit.core.extensions.dll
nunit.core.interfaces.dll
nunit.core.tests.dll
nunit.exe
nunit.extensions.tests.dll
nunit.fixtures.dll
nunit.fixtures.tests.dll
nunit.framework.dll
nunit.framework.extensions.dll
nunit.framework.tests.dll
nunit.mocks.dll
nunit.mocks.tests.dll
nunit.testutilities.dll
nunit.uikit.dll
nunit.uikit.tests.dll
nunit.util.dll
nunit.util.tests.dll
NUnitTests.nunit
runFile.exe
Success.jpg
tempfile.tmp
test-assembly.dll
test-utilities.dll
timing-tests.dll
WixFileVersionExtension.dll
Everything.build
ScriptGrammar.g
Application.ico
Application.ico
Error.ico
Running.ico
Stopped.ico
Kaleida.ProductBuilder.ServiceMonitor.csproj.DotSettings
Kaleida.ProductBuilder.ServiceMonitor.csproj.DotSettings.user
Kaleida.ProductBuilder.ServiceMonitor.csproj.ReSharper
Settings.settings
Introductory Examples.mscr
More Examples.mscr
DialogBackround.bmp
DialogBackround.pdn
DialogTopBanner.bmp
GPLv3License.rtf
Product.wxs
Setup.wixproj
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Mail;
using System.Text;
using System.Linq;

namespace Kaleida.ServiceMonitor.Framework
{
    public static class StringExtensions
    {
        public static TimeSpan ToTimeSpan(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");

            return DurationParser.ParseTimeSpan(text);
        }

        public static Duration ToDuration(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");

            return DurationParser.ParseDuration(text);
        }

        public static TimeSpan ToTimeSpan(this Duration duration)
        {
            if (duration == null) throw new ArgumentNullException("duration");

            return duration.ToString().ToTimeSpan();
        }

        public static bool IsTimeSpan(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");

            return DurationParser.CanParse(text);
        }

        public static bool IsDuration(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");

            return DurationParser.CanParse(text);
        }

        public static bool IsDecimal(this string value)
        {
            if (value == null) throw new ArgumentNullException("value");

            decimal result;
            return decimal.TryParse(value, out result);
        }

        public static bool IsInteger(this string value)
        {
            if (value == null) throw new ArgumentNullException("value");

            int result;
            return int.TryParse(value, out result);
        }

		public static ScheduledTime ToScheduledTime(this string value)
		{
			if (value == null) throw new ArgumentNullException("value");

			var components = value.Split(':');

			if(components.Count() != 2)
				throw new FormatException(string.Format("Cannot parse '{0}' as a ScheduledTime. Expected string to be in HH:MM format. E.g. 09:32", value));

			int hour;
			if (!int.TryParse(components[0], out hour))
				throw new FormatException(string.Format("Cannot parse '{0}' as a ScheduledTime. Expected hour to be a number", value));

			int minute;
			if (!int.TryParse(components[1], out minute))
				throw new FormatException(string.Format("Cannot parse '{0}' as a ScheduledTime. Expected minute to be a number", value));

			return new ScheduledTime(hour, minute);
		}

    	public static string SurroundWith(this string text, string enclosingText)
        {
            if (text == null) throw new ArgumentNullException("text");
            if (enclosingText == null) throw new ArgumentNullException("enclosingText");

            return enclosingText + text + enclosingText;
        }

        public static string ToFormattedString(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");
            return text.SurroundWith("'");
        }

        public static string ToFormattedString(this int text)
        {
            return text.ToString(CultureInfo.InvariantCulture);
        }

        public static string ToFormattedString(this decimal text)
        {
            return text.ToString(CultureInfo.InvariantCulture);
        }

        public static string ToFormattedString(this TimeSpan timeSpan)
        {
            var duration = timeSpan.Duration();

            var formatted = new StringBuilder();

            if(timeSpan.Ticks < 0)
                formatted.Append("-");

            formatted.Append("[");
            if(duration.Days != 0)
                formatted.AppendFormat("{0} ", duration.Days);

            formatted.AppendFormat("{0:00}:{1:00}:{2:00}", duration.Hours, duration.Minutes, duration.Seconds);

            if (duration.Milliseconds != 0)
                formatted.AppendFormat(".{0:000}", duration.Milliseconds);

            formatted.Append("]");
            return formatted.ToString();
        }

        public static List<KeyValuePair<string, string>> SplitIntoKeyValuePairs(this string argumentsString)
        {
            if (argumentsString == null) throw new ArgumentNullException("argumentsString");

            if (argumentsString == "")
                return new List<KeyValuePair<string, string>>();

            var argumentStrings = argumentsString.Split(',');
            return argumentStrings.Select(BuildKeyValuePair).ToList();
        }

		public static IList<MailAddress> ToMailAddressList(this string text)
		{
			if (text == null) throw new ArgumentNullException("text");

			var emailAddresses = text.Split(';').Select(i => i.Trim()).Where(i => i != "").ToList();

			if (!emailAddresses.Any())
				throw new InvalidOperationException("Must provide at least one email address (multiple addresses can be specified using a semicolon. e.g. \"me@example.com;someone@example.com\")");

			return emailAddresses.Select(BuildMailAddress).ToList();
		}

		private static MailAddress BuildMailAddress(string text)
		{
			try
			{
				return new MailAddress(text);
			}
			catch (FormatException e)
			{
				throw new InvalidOperationException(e.Message + " (multiple addresses can be specified using a semicolon. e.g. \"me@example.com;someone@example.com\")");
			}
		}

        public static IList<ScheduledTime> ToScheduledTimeList(this string text)
        {
            if (text == null) throw new ArgumentNullException("text");

            var timeStrings = text.Split(';').Select(i => i.Trim()).Where(i => i != "").ToList();

            if (!timeStrings.Any())
                throw new InvalidOperationException("Must provide at least one scheduled time (multiple addresses can be specified using a semicolon. e.g. \"14:30; 17:15\")");

            return timeStrings.Select(BuildScheduledTime).ToList();
        }

        private static ScheduledTime BuildScheduledTime(string text)
        {
            try
            {
                return text.ToScheduledTime();
            }
            catch (FormatException e)
            {
                throw new InvalidOperationException(e.Message + " (multiple times can be specified using a semicolon. e.g. \"14:30; 17:15\")");
            }
        }

        private static KeyValuePair<string, string> BuildKeyValuePair(string argumentString)
        {
            var components = argumentString.Split('=');

            if (components.Length != 2)
                throw new InvalidOperationException(String.Format("Expected argument '{0}' to be specified as ARG=VAL", argumentString));

            return new KeyValuePair<string, string>(components[0], components[1]);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Stuart Wheelwright
Architect BlackJet Software Ltd
United Kingdom United Kingdom
Stuart Wheelwright is the Principal Architect and Software Developer at BlackJet Software Ltd.
 
He has over 16 years commercial experience producing robust, maintainable, web-based solutions and bespoke systems for Microsoft platforms.
 
His latest project is Shopping UK, an elegantly simple shopping list for iPhone.
Follow on   Twitter   Google+   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Oct 2012
Article Copyright 2012 by Stuart Wheelwright
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid