Dijelite putem


Storing Your Autoscaling Rules

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

On this page:
Saving and Loading Rules from an XML Rules Store

You can configure the Autoscaling Application Block to use one of the two XML-based rules store implementations included with the block: the BlobXmlFileRulesStore class for storing the rules in Microsoft Azure or the LocalXmlFileRulesStore class for storing the rules in a file on the local file system. You can also use your own custom rules store by implementing the IRuleStore interface.

Both of the provided XML-based rules store implementations expect the rules to conform to the XML schema defined in the https://schemas.microsoft.com/practices/2011/entlib/autoscaling/rules namespace. If you installed the Autoscaling Application Block in your Visual Studio project by using NuGet, you can find the AutoscalingRules.xsd schema file in the root folder of the project.

Note

Many XML editors allow you to use an XML schema file to provide validation and other support when you edit a document that is bound to the schema. If these schemas are in the same Visual Studio solution as the XML documents that you are editing, Visual Studio will provide IntelliSense and real-time validation automatically.

If you are using the BlobXmlFileRulesStore class, you should save the XML document with your rules to the Azure blob that you specified in your configuration settings. If you are using the LocalXmlFileRulesStore class, you should save the XML document with your rules as the local file that you specified in your configuration settings.

For a description of the AutoscalingRules.xsd schema, see the topic "Rules Schema Description."

Saving and Loading Rules from an XML Rules Store

To facilitate saving and loading rules from the rules store in your application, the Autoscaling Application Block includes the RuleSetSerializer class. The Deserialize and Serialize methods enable you to deserialize from a TextReader instance to a RuleSetElement instance and serialize to a TextWriter instance from a RuleSetElement instance.

// Deserialize from a reader.
var ruleSetElement = this.serializer.Deserialize(reader);

// Serialize to a writer.
this.serializer.Serialize(writer, ruleSetElement);

The RuleSetElement class enables you to manipulate a set of rules in code.

[XmlRoot("rules", Namespace = Constants.Namespace)]
public class RuleSetElement
{
    ...
    [XmlArray("constraintRules")]
    [XmlArrayItem("rule")]
    public List<ConstraintRuleElement> ConstraintRules { get; set; }

    ...
    [XmlArray("reactiveRules")]
    [XmlArrayItem("rule")]
    public List<ReactiveRuleElement> ReactiveRules { get; set; }

    ...
    public List<ParameterElement> Parameters { get; set; }

    public RuleSet CreateRuleSet()
    {
        ...
    }
}

You should examine the other classes in the Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling.Rules.Configuration namespace, and the AutoscalingRules.xsd schema for information about the child elements of the ConstraintRuleElement, ReactiveRuleElement, and ParameterElement classes.

For an example of one approach to providing a UI for editing and saving rules, see the section "Editing and Saving Rules" in Chapter 5, "Making Tailspin Surveys More Elastic," in the Developer's Guide.

For a description of the AutoscalingRules.xsd schema, see the topic "Rules Schema Description."

Note

The content of the store should always be encoded using UTF-8 (with or without the byte order mark (BOM)).

Next Topic | Previous Topic | Home

Last built: June 7, 2012