コード例 #1
0
ファイル: qmodule.cs プロジェクト: QetriX/QetriX-CS
 public Dict init(Dict args)
 {
     return(args);
 }
コード例 #2
0
ファイル: util.cs プロジェクト: QetriX/QetriX-CS
 public Dict set(Dict data)
 {
     this._data.Concat(data.toArray()).ToDictionary(d => d.Key, d => d.Value);
     return(this);
 }
コード例 #3
0
ファイル: qmodule.cs プロジェクト: QetriX/QetriX-CS
 public string main(Dict args)
 {
     return("It works! Now please add your custom implementation of method " + this.GetType().Name + ".main(Dict args):string.");
 }
コード例 #4
0
ファイル: util.cs プロジェクト: QetriX/QetriX-CS
        public static object convert(object data, string fromFormat, string toFormat, string toType, Dict args)
        {
            Type myType = QPage.getInstance().loadConverter(fromFormat, toFormat, toType);

            try {
                MethodInfo method = myType.GetMethod("convert");
                if (method == null)
                {
                    throw new Exception("Function convert not found in converter " + fromFormat);
                }
                var myInstance = Activator.CreateInstance(myType);
                return(method.Invoke(myInstance, new object[] { data, args }));
            } catch (Exception ex) {
                return("Exception: " + ex.InnerException.Message + " at " + ex.InnerException.Source + "\n" + String.Join("\n", ex.InnerException.StackTrace));
            }
        }
コード例 #5
0
 public Component action(string value, QModule mod, Dict args, string but)
 {
     this._action = value;
     return(this);
 }
コード例 #6
0
 public object convert(string fromFormat, string toFormat, string toType, Dict args)
 {
     return(Util.convert(this, fromFormat, toFormat, toType, args));
 }
コード例 #7
0
ファイル: qpage.cs プロジェクト: QetriX/QetriX-CS
        public string loadModule(string path, PathMode pathMode)
        {
            var page = this.parsePath(path);

            if (pathMode != PathMode.direct)
            {
                string mod = page.get("mod"), func = page.get("func");
                mod = mod.Length > 0 ? mod.Substring(0, 1).ToUpper() + mod.Substring(1) : appName();
                if (mod == "")
                {
                    mod = "qetrix";
                }

                // Handle keywords, add trailing underscore; '/list' in URL => function list_(Dict $args)
                var keywords = new string[] { "abstract", "and", "as", "bool", "break", "case", "catch", "class", "const", "continue", "declare", "default", "die", "do", "echo", "else", "elseif", "empty", "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "eval", "exit", "extends", "false", "final", "float", "for", "foreach", "function", "global", "goto", "if", "implements", "include", "include_once", "int", "instanceof", "insteadof", "interface", "isset", "list", "mixed", "namespace", "new", "null", "numeric", "or", "print", "private", "protected", "public", "require", "require_once", "resource", "return", "scalar", "static", "string", "switch", "throw", "trait", "true", "try", "unset", "use", "var", "while", "xor" };
                if (keywords.Contains(mod))
                {
                    mod = mod + "_";
                }
                keywords = keywords.Union(new string[] { "ds", "init", "page", "qmodule", "qpage", "stage" }).ToArray();
                if (keywords.Contains(func))
                {
                    func = func + "_";
                }

                var    myType     = loadAssembly(AssemblyType.module, mod);
                string methodName = "";

                var args = new Dict(this._args);
                if (page.has("id"))
                {
                    args.set("id", page.get("id"));
                }

                try {
                    var        modObject = Activator.CreateInstance(myType, this);
                    MethodInfo method;

                    method = myType.GetMethod("init");
                    method.Invoke(modObject, new object[] { args });

                    method = myType.GetMethod(func);
                    if (method == null)
                    {
                        method = myType.GetMethod("main");
                        args.set("0", func);                         // TODO: Will it be always "0"??
                        func = "main";
                    }
                    if (method == null)
                    {
                        throw new Exception(string.Format("Method {0} not found in module {1}", page.get("func"), mod));
                    }
                    methodName = method.Name;

                    var output = method.Invoke(modObject, new object[] { args });
                    this.sessionManager();                     // Write session data
                    return(output.ToString());
                } catch (TargetParameterCountException ex) {
                    return(string.Format("Err#xx: Method \"{0}\" must have following signature: public string {0}(Dict args);", methodName));;
                } catch (Exception ex) {
                    var exx = ex.InnerException == null ? ex : (ex.InnerException.InnerException == null ? ex.InnerException : ex.InnerException.InnerException);
                    return("Exception: " + exx.Message + " at " + exx.Source + "\n" + String.Join("\n", exx.StackTrace));
                }
            }

            _statusCode = 404;
            return("404 Not Found");
        }
コード例 #8
0
ファイル: qpage.cs プロジェクト: QetriX/QetriX-CS
        public Dict parsePath(string path)
        {
            var aPath = new List <string>(path.Trim(new char[] { '/' }).Split('/'));

            var page = new Dict();

            if (aPath.Count == 0)
            {
                return(page);
            }

            if (this._config["appName"] == "")
            {
                this._config["appName"] = aPath[0];
                aPath.RemoveAt(0);
            }

            page.set("app", this._config["appName"]);

            if (aPath.Count > 0)
            {
                page.set(int.TryParse(aPath[0], out int n) ? "id" : "mod", aPath[0]);
                aPath.RemoveAt(0);
            }
            else
            {
                page.set("mod", this._config["appName"]);
            }

            if (aPath.Count > 0)
            {
                page.set(int.TryParse(aPath[0], out int n) ? "id" : "func", aPath[0]);
                aPath.RemoveAt(0);
            }

            if (aPath.Count > 0)
            {
                if (!page.has("id") && int.TryParse(aPath[0], out int n))
                {
                    page.set("id", aPath[0]);
                    aPath.RemoveAt(0);
                }
                else if (!page.has("func"))
                {
                    page.set("func", aPath[0]);
                }
            }

            if (!page.has("func"))
            {
                page.set("func", "main");
            }

            // TODO: Process App Config
            // ...

            this.sessionManager();             // Read session data (Must be AFTER config!)

            if (aPath.Count > 0)
            {
                this._args = aPath.Select((s, i) => new { s, i }).ToDictionary(x => x.i.ToString(), x => x.s);
                this._args.ToList().ForEach(x => this._data.Add(x.Key, x.Value));
                //this._args = aPath.Distinct().ToDictionary(x => x);
            }

            return(page);
        }