Web hosting mysql - CHAPTER 5 PERMUTATIONS PATTERN 131 public void
CHAPTER 5 PERMUTATIONS PATTERN 131 public void WriteRedirection(HttpRequest request) string[] elements = (string[])request.AcceptTypes.Clone() Array.Sort( elements, new CompareMimeTypes()) Regex semiColon = new Regex(”;”) foreach (string type in elements) String[] buffers = semiColon.Split(type) if (_defaultRewriter.WriteRedirection(buffers[0])) break; When implementing step 1 in the method IsResource, the challenge is to figure out whether the URL is a resource or a file reference. A file reference, simply put, would have an extension in the URL indicating the referencing of a specific file type. The decision chosen by the URLRewriterASPNet implementation is to test whether the absolute path of the URL refers to a directory. If a directory is referenced, the URL is a resource; otherwise, the URL is something else. In other IURLRewriter implementations, other logic might be used. Maybe a regular expression is used to validate the URL to see whether a reference to a file exists. Whatever logic is used, a true is returned to indicate a URL resource, and false is used to indicate the URL is something else. If there are multiple IURLRewriter implementations, they are wired together and called by using the Chain of Responsibility pattern. E B V N If the URL needs to be rewritten as per step 2, the method WriteRedirection is called. In the implementation of WriteRedirection, which executes steps 3 and 4, the Accept headers are sorted from highest priority to lowest priority. The sorting is carried out by cloning the Accept headers (request.AcceptTypes) and then calling the method Array.Sort. The default algorithm used by Array.Sort will not work, and therefore the class CompareMimeTypes is used. I will explain that class in a moment. After the Accept identifiers have been sorted, they are iterated, and for each one the method defaultRewriter.WriteRedirection is called. As each identifier is called from highest to lowest priority, the IRewriter implementation tests to see whether the URL can be rewritten. If the test returns a true value, an identifier is found and the URL is rewritten. If the URL has been rewritten, defaultRewriter.WriteRedirection returns true and all processing stops. The sorting of the individual Accept identifiers will now be discussed. When using a custom sorting routine with Array.Sort, the custom sorting routine would have to implement the IComparer interface. The IComparer interface has a single method that compares two values from the list to be sorted. The single method implementation returns a positive, negative, or zero integer value indicating which value is greater than the other. Following is the implemen tation of CompareMimeTypes: class CompareMimeTypes : IComparer { Regex _wildcard = new Regex(@”/*”); Regex _semiColon = new Regex(”;”); public void CalculateValue(string val, out int level, out double qvalue) { String[] buffers = _semiColon.Split(val); double multiplier = 1.0;
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.