Click here to Skip to main content
15,886,578 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.6K   599   10  
Leverage Visual studio Web Test Framework for your crawling needs...
using System;
using System.ComponentModel;
using System.Globalization;
namespace LightWebTestFramework.Rules
{
	[LocalizableDescription("ConditionalRuleDescriptionForLoopRule"), LocalizableDisplayName("ConditionalRuleNameForLoopRule"), ConditionalRuleType(ConditionalRuleType.LoopOnly)]
	public class ForLoopRule : ConditionalRule
	{
		private string m_contextParameterName;
		private ForLoopComparisonOperator m_comparisonOperator;
		private double m_terminatingValue;
		private double m_initialValue;
		private double m_incrementValue;
		[LocalizableDescription("PropertyDescriptionContextParameterName"), LocalizableDisplayName("PropertyNameContextParameterName"), IsContextParameterName(true)]
		public string ContextParameterName
		{
			get
			{
				return this.m_contextParameterName;
			}
			set
			{
				this.m_contextParameterName = value;
			}
		}
		[LocalizableDescription("PropertyDescriptionComparisonOperator"), LocalizableDisplayName("PropertyNameComparisonOperator"), DefaultValue(ForLoopComparisonOperator.LessThan)]
		public ForLoopComparisonOperator ComparisonOperator
		{
			get
			{
				return this.m_comparisonOperator;
			}
			set
			{
				this.m_comparisonOperator = value;
			}
		}
		[LocalizableDescription("PropertyDescriptionTerminatingValue"), LocalizableDisplayName("PropertyNameTerminatingValue")]
		public double TerminatingValue
		{
			get
			{
				return this.m_terminatingValue;
			}
			set
			{
				this.m_terminatingValue = value;
			}
		}
		[LocalizableDescription("PropertyDescriptionInitialValue"), LocalizableDisplayName("PropertyNameInitialValue")]
		public double InitialValue
		{
			get
			{
				return this.m_initialValue;
			}
			set
			{
				this.m_initialValue = value;
			}
		}
		[LocalizableDescription("PropertyDescriptionIncrementValue"), LocalizableDisplayName("PropertyNameIncrementValue")]
		public double IncrementValue
		{
			get
			{
				return this.m_incrementValue;
			}
			set
			{
				this.m_incrementValue = value;
			}
		}
		public override void Initialize(object sender, ConditionalEventArgs e)
		{
			if (e.WebTest.Context.ContainsKey(this.m_contextParameterName))
			{
				e.WebTest.Context[this.m_contextParameterName] = this.m_initialValue - this.m_incrementValue;
				return;
			}
			e.WebTest.Context.Add(this.m_contextParameterName, this.m_initialValue - this.m_incrementValue);
		}
		public override void CheckCondition(object sender, ConditionalEventArgs e)
		{
			double num;
			if (!double.TryParse(e.WebTest.Context[this.m_contextParameterName].ToString(), out num))
			{
				e.IsMet = false;
				string message = string.Format(CultureInfo.CurrentCulture, Resources.ErrorCPContentNotANumber, new object[]
				{
					this.m_contextParameterName
				});
				throw new ConditionalRuleException(message);
			}
			num += this.m_incrementValue;
			e.WebTest.Context[this.m_contextParameterName] = num;
			switch (this.m_comparisonOperator)
			{
			case ForLoopComparisonOperator.LessThan:
				e.IsMet = (num < this.m_terminatingValue);
				return;
			case ForLoopComparisonOperator.LessThanOrEqual:
				e.IsMet = (num <= this.m_terminatingValue);
				return;
			case ForLoopComparisonOperator.GreaterThan:
				e.IsMet = (num > this.m_terminatingValue);
				return;
			case ForLoopComparisonOperator.GreaterThanOrEqual:
				e.IsMet = (num >= this.m_terminatingValue);
				return;
			default:
				e.IsMet = false;
				return;
			}
		}
		public override string StringRepresentation()
		{
			string text = TypeDescriptor.GetConverter(typeof(ForLoopComparisonOperator)).ConvertToString(this.m_comparisonOperator);
			return string.Format(CultureInfo.CurrentCulture, Resources.StringRepresentationForLoopRule, new object[]
			{
				this.m_initialValue,
				this.m_incrementValue,
				this.m_contextParameterName,
				text,
				this.m_terminatingValue
			});
		}
	}
}

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