Click here to Skip to main content
15,884,237 members
Articles / Code generation

Semi generated crawler

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
22 Jun 2012CPOL4 min read 21.5K   599   10  
Leverage Visual studio Web Test Framework for your crawling needs...
using System;
using System.Globalization;
namespace LightWebTestFramework.Rules
{
	[LocalizableDescription("ConditionalRuleDescriptionProbabilityRule"), LocalizableDisplayName("ConditionalRuleNameProbabilityRule")]
	public class ProbabilityRule : ConditionalRule
	{
		private string m_contextParameterName;
		private double m_percentage;
		private static Random s_random = new Random();
		[LocalizableDescription("PropertyDescriptionProbabilityContextParameterName"), LocalizableDisplayName("PropertyNameContextParameterName"), IsContextParameterName(true)]
		public string ContextParameterName
		{
			get
			{
				return this.m_contextParameterName;
			}
			set
			{
				this.m_contextParameterName = value;
			}
		}
		[LocalizableDescription("PropertyDescriptionPercentage"), LocalizableDisplayName("PropertyNamePercentage")]
		public double Percentage
		{
			get
			{
				return this.m_percentage;
			}
			set
			{
				this.m_percentage = value;
			}
		}
		public override void CheckCondition(object sender, ConditionalEventArgs e)
		{
			if (this.m_percentage < 0.0 || this.m_percentage > 100.0)
			{
				e.IsMet = false;
				string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorInvalidPercentageValues, new object[]
				{
					this.m_contextParameterName
				});
				throw new ConditionalRuleException(message);
			}
			double num = ProbabilityRule.s_random.NextDouble() * 100.0;
			if (e.WebTest.Context.ContainsKey(this.m_contextParameterName))
			{
				e.WebTest.Context[this.m_contextParameterName] = num;
			}
			else
			{
				e.WebTest.Context.Add(this.m_contextParameterName, num);
			}
			if (num < this.m_percentage)
			{
				e.IsMet = true;
				return;
			}
			e.IsMet = false;
		}
		public override string StringRepresentation()
		{
			return string.Format(CultureInfo.CurrentCulture, Resources.StringRepresentationProbabilityRule, new object[]
			{
				this.m_percentage
			});
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Software Developer Freelance
France France
I am currently the CTO of Metaco, we are leveraging the Bitcoin Blockchain for delivering financial services.

I also developed a tool to make IaaS on Azure more easy to use IaaS Management Studio.

If you want to contact me, go this way Smile | :)

Comments and Discussions