| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Sockets;
- using System.Text;
- using System.Threading;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace System.Net.ApiService {
- public class RouteElements {
- private object _instance;
- private Route _route;
- private MethodInfo _method;
- private Type _t;
- private string _baseRoute;
- private Regex _pattern;
- public RouteElements(object instance, MethodInfo mi, Route r) {
- this._instance = instance;
- this._route = r;
- this._method = mi;
- this._t = instance.GetType();
- this._baseRoute = "";
- this.createPattern();
- }
- public RouteElements(Type instance, MethodInfo mi, Route r) {
- this._t = instance;
- this._route = r;
- this._method = mi;
- this._baseRoute = "";
- this.createPattern();
- }
- public RouteElements(object instance, MethodInfo mi, Route r, string BaseRoute) {
- this._instance = instance;
- this._route = r;
- this._method = mi;
- this._t = instance.GetType();
- this._baseRoute = BaseRoute;
- this.createPattern();
- }
- public RouteElements(Type instance, MethodInfo mi, Route r, string BaseRoute) {
- this._t = instance;
- this._route = r;
- this._method = mi;
- this._baseRoute = BaseRoute;
- this.createPattern();
- }
- private void createPattern() {
- string x = this.Path;
- string fin = "";
- int round = 0;
- int eckig = 0;
- int geschweift = 0;
- bool bIsEscaped = false;
- for (int i = 0; i < x.Length; i++) {
- if (!bIsEscaped) {
- switch (x.Substring(i, 1)) {
- case "{":
- geschweift++;
- fin += "{";
- break;
- case "}":
- geschweift--;
- fin += "}";
- break;
- case "(":
- round++;
- fin += "(";
- break;
- case ")":
- round--;
- fin += ")";
- break;
- case "[":
- eckig++;
- fin += "[";
- break;
- case "]":
- eckig--;
- fin += "]";
- break;
- case ".":
- case "/":
- if (eckig == 0 && geschweift == 0 && round == 0) {
- fin += "\\" + x.Substring(i, 1);
- } else {
- fin += x.Substring(i, 1);
- }
- break;
- default:
- fin += x.Substring(i, 1);
- break;
- }
- }
- bIsEscaped = x.Substring(i, 1) == "\\";
- }
- this._pattern = new Regex(fin, RegexOptions.Singleline);
- }
- public object Instance {
- get {
- return this._instance;
- }
- }
- public Type Type {
- get {
- return this._t;
- }
- }
- public Route Route {
- get {
- return this._route;
- }
- }
- public MethodInfo Function {
- get {
- return this._method;
- }
- }
- public string Path {
- get {
- if (this._baseRoute == "") {
- return (this._route.Path.StartsWith("/") ? "" : "/") + this._route.Path;
- } else {
- return (this._baseRoute.StartsWith("/") ? "" : "/") + this._baseRoute + (!this._baseRoute.EndsWith("/") && !this._route.Path.StartsWith("/") ? "/" : "") + this._route.Path;
- }
- }
- }
- public Regex Pattern {
- get {
- return this._pattern;
- }
- }
- public HttpMethod Method {
- get {
- return this._route.Method;
- }
- }
- public string BaseRoute {
- get {
- return this._baseRoute;
- }
- }
- }
- }
|