/// <summary> /// Add a new prototype. /// </summary> internal void Add(JsPrototype prototype) { if (!Prototypes.Contains(prototype)) { Prototypes.Add(prototype); } }
//-------------------------------------------// /// <summary> /// Update the form with children elements. /// </summary> protected void Update() { _update = false; _forms.Clear(); _input.Clear(); // iterate the elements HashSet <Element> hashSet = new HashSet <Element>(_elements.TakeItem()); _elements.Release(); foreach (var element in hashSet) { if (element.Tag == Tag.Input) { Element parent = element.Parent; while (parent != null && parent != this && parent.Tag != Tag.Form) { parent = parent.Parent; } if (parent == this) { var input = element as ElementInput; if (input == null || input["name"] == null) { continue; } if (!_input.ContainsKey(input["name"])) { _input.Add(input["name"], input); } } } else if (element.Tag == Tag.Form) { Element parent = element.Parent; while (parent != null && parent != this && parent.Tag != Tag.Form) { parent = parent.Parent; } if (parent == this) { var form = element as ElementForm; if (form != null && !_forms.Contains(form)) { _forms.Add(form); } } } } }
/// <summary> /// Resolve the path using redirects. No authentication. /// </summary> protected virtual string ResolvePath(string path) { HttpRedirect redirect = null; string[] sections; int index; if (path[0] == '/') { // split the request path into directory sections sections = path.Split(Chars.ForwardSlash); index = -1; } else { sections = path.Split(Chars.ForwardSlash); index = -2; } // persistance of the current path path = "/"; // the first iteration? bool first = true; // redirected path is absolute? bool absolute = false; // iterate the request path sections while (++index < sections.Length) { // is the first iteration? if (!first) { // is the redirect absolute? yes, end the redirects if (absolute) { break; } // is the section empty? yes, skip the section if (sections[index].Length == 0) { continue; } // append the section path = path + Chars.ForwardSlash + sections[index]; } // should the path be redirected? if (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; int iteration = 1; // while the current path is to be redirected while (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; // have there been an excessive number of redirects? if (++iteration == 20) { // yes, start maintaining a collection of redirected paths ArrayRig <string> redirects = new ArrayRig <string>(); redirects.Add(path); // while the current path is to be redirected while (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; // has the redirect path already been hit? if (redirects.Contains(path)) { // yes, return false, a redirect loop was hit Log.Warning("Redirect loop detected. Request denied."); return(null); } // add to the redirected collection redirects.Add(path); } break; } } first = false; } else if (first) { path = string.Empty; first = false; } } // return the authentication value return(path); }
/// <summary> /// Check if the WebRequest should be redirected and authenticate the /// web request. Returns if the request path was resolved successfully. /// </summary> protected virtual bool ResolvePath(HttpRequest request) { HttpRedirect redirect = null; HttpRequirement auth; // split the request path into directory sections var sections = request.RequestPath.Split(Chars.ForwardSlash); // persistance of the current path string path = "/"; // the first iteration? bool first = true; // redirected path is absolute? bool absolute = false; // is the request path authenticated? bool authentication = true; // iterate the request path sections for (int i = 0; i < sections.Length; ++i) { // is the first iteration? if (!first) { // is the redirect absolute? yes, end the redirects if (absolute) { break; } // is the section empty? yes, skip the section if (sections[i].Length == 0) { continue; } // append the section path = path + Chars.ForwardSlash + sections[i]; } // does authentication exist for the request path? if (Authentication.TryGetValue(path, out auth)) { // update the authentication authentication = auth.Allow(request); } // should the path be redirected? if (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; // does authentication exist for the request path? if (Authentication.TryGetValue(path, out auth)) { // update the authentication authentication = auth.Allow(request); } int iteration = 1; // while the current path is to be redirected while (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; // does authentication exist for the request path? if (Authentication.TryGetValue(path, out auth)) { // update the authentication authentication = auth.Allow(request); } // have there been an excessive number of redirects? if (++iteration == 20) { // yes, start maintaining a collection of redirected paths ArrayRig <string> redirects = new ArrayRig <string>(); redirects.Add(path); // while the current path is to be redirected while (Redirects.TryGetValue(path, out redirect)) { // update the current path path = redirect.Target; absolute = redirect.Absolute; // has the redirect path already been hit? if (redirects.Contains(path)) { // yes, return false, a redirect loop was hit Log.Warning("Redirect loop detected. Request denied."); request.RequestPath = null; return(false); } // add to the redirected collection redirects.Add(path); // does authentication exist for the request path? if (Authentication.TryGetValue(path, out auth)) { // update the authentication authentication = auth.Allow(request); } } break; } } first = false; } else if (first) { path = string.Empty; first = false; } } // has a redirect occured? if (!request.RequestPath.Equals(path)) { // has the redirect method been assigned? if (OnRedirect != null) { OnRedirect.ArgA = request; OnRedirect.ArgB = path; OnRedirect.Run(); } // update the web request path request.RequestPath = path; } // return the authentication value return(authentication); }
/// <summary> /// Add the specified styles properties to this instance and return a style /// that is a compilation of the differences between this and the specified /// style. /// </summary> public Style AddAndGetDifferences(Style other) { Style differences = new Style(); // iterate the style entries foreach (var entry in other._properties) { string value; if (_properties.TryGetValue(entry.Key, out value)) { if (!StyleKeys.Inherited.Contains(entry.Key) || !entry.Value.Equals(value, StringComparison.Ordinal)) { differences[entry.Key] = entry.Value; _properties[entry.Key] = entry.Value; } } else { differences[entry.Key] = entry.Value; _properties[entry.Key] = entry.Value; } } if (other._params != null) { _params = new Dictionary <string, string>(); // iterate the custom parameters foreach (var entry in other._params) { string value; if (_params.TryGetValue(entry.Key, out value)) { if (!entry.Value.Equals(value, StringComparison.Ordinal)) { differences[entry.Key] = entry.Value; _params[entry.Key] = entry.Value; } } else { differences[entry.Key] = entry.Value; _params[entry.Key] = entry.Value; } } } // iterate children if (other._children != null) { if (_children == null) { for (int i = 0; i < other._children.Count; ++i) { differences.Add(new Style(other._children[i])); } } else { for (int i = 0; i < other._children.Count; ++i) { if (_children.Contains(other._children[i])) { continue; } differences.Add(new Style(other._children[i])); } } } return(differences); }