Example #1
0
 protected void CreateWork <T1, T2>(string name, object state = null,
                                    UiAttribute ui            = null, AuthenticateAttribute authenticate = null, AuthorizeAttribute authorize = null, BeforeAttribute before = null, AfterAttribute after = null)
     where T1 : WebWork, new() where T2 : WebWork, new()
 {
     CreateWork <T1>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T2>(name, state, ui, authenticate, authorize, before, after);
 }
Example #2
0
 protected void CreateWork <T1, T2, T3, T4, T5, T6, T7>(string name, object state = null,
                                                        UiAttribute ui            = null, AuthenticateAttribute authenticate = null, AuthorizeAttribute authorize = null, BeforeAttribute before = null, AfterAttribute after = null)
     where T1 : WebWork, new() where T2 : WebWork, new() where T3 : WebWork, new() where T4 : WebWork, new() where T5 : WebWork, new() where T6 : WebWork, new() where T7 : WebWork, new()
 {
     CreateWork <T1>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T2>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T3>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T4>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T5>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T6>(name, state, ui, authenticate, authorize, before, after);
     CreateWork <T7>(name, state, ui, authenticate, authorize, before, after);
 }
Example #3
0
        /// <summary>
        /// Create and add a fixed-key subwork.
        /// </summary>
        /// <param name="name">the identifying name for the work</param>
        /// <param name="state"></param>
        /// <param name="ui">to override class-wise UI attribute</param>
        /// <param name="authenticate"></param>
        /// <param name="authorize">to override class-wise Authorize attribute</param>
        /// <param name="before"></param>
        /// <param name="after"></param>
        /// <typeparam name="T">the type of work to create</typeparam>
        /// <returns>The newly created and subwork instance.</returns>
        /// <exception cref="WebException">Thrown if error</exception>
        protected T CreateWork <T>(string name, object state = null,
                                   UiAttribute ui            = null, AuthenticateAttribute authenticate = null, AuthorizeAttribute authorize = null, BeforeAttribute before = null, AfterAttribute after = null) where T : WebWork, new()
        {
            if (works == null)
            {
                works = new Map <string, WebWork>();
            }

            var wrk = new T
            {
                Name      = name,
                Service   = Service,
                Parent    = this,
                Level     = Level + 1,
                IsVar     = false,
                Directory = (Parent == null) ? name : Path.Combine(Parent.Directory, name),
                Pathing   = Pathing + name + "/",
                State     = state
            };

            if (ui != null)
            {
                wrk.Ui = ui;
            }
            if (authenticate != null)
            {
                wrk.Authenticate = authenticate;
            }
            if (authorize != null)
            {
                wrk.Authorize = authorize;
            }
            if (before != null)
            {
                wrk.Before = before;
            }
            if (after != null)
            {
                wrk.After = after;
            }

            works.Add(wrk);

            wrk.OnCreate();
            return(wrk);
        }
Example #4
0
        /// <summary>
        /// Create and add a variable-key subwork.
        /// </summary>
        /// <param name="accessor">to resolve key from the principal object</param>
        /// <param name="state"> </param>
        /// <param name="ui">to override class-wise UI attribute</param>
        /// <param name="authenticate"></param>
        /// <param name="authorize">to override class-wise Authorize attribute</param>
        /// <param name="before"></param>
        /// <param name="after"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns>The newly created subwork instance.</returns>
        /// <exception cref="WebException">Thrown if error</exception>
        protected T CreateVarWork <T>(Func <IData, string, object> accessor = null, object state = null,
                                      UiAttribute ui = null, AuthenticateAttribute authenticate  = null, AuthorizeAttribute authorize = null, BeforeAttribute before = null, AfterAttribute after = null) where T : WebWork, new()
        {
            var wrk = new T
            {
                Service   = Service,
                Parent    = this,
                Level     = Level + 1,
                IsVar     = true,
                Directory = (Parent == null) ? VARDIR : Path.Combine(Parent.Directory, VARDIR),
                Pathing   = Pathing + (accessor == null ? VARPATHING : string.Empty) + "/",
                Accessor  = accessor,
                State     = state
            };

            if (ui != null)
            {
                wrk.Ui = ui;
            }
            if (authenticate != null)
            {
                wrk.Authenticate = authenticate;
            }
            if (authorize != null)
            {
                wrk.Authorize = authorize;
            }
            if (before != null)
            {
                wrk.Before = before;
            }
            if (after != null)
            {
                wrk.After = after;
            }

            varwork = wrk;

            wrk.OnCreate();
            return(wrk);
        }
Example #5
0
        internal WebAction(WebWork work, MethodInfo mi, bool async, string subscript)
        {
            this.work      = work;
            this.name      = mi.Name == "default" ? string.Empty : mi.Name;
            this.relative  = name == string.Empty ? "./" : name;
            this.async     = async;
            this.subscript = subscript;

            ui           = (UiAttribute)mi.GetCustomAttribute(typeof(UiAttribute), true);
            authenticate = (AuthenticateAttribute)mi.GetCustomAttribute(typeof(AuthenticateAttribute), true);
            authorize    = (AuthorizeAttribute)mi.GetCustomAttribute(typeof(AuthorizeAttribute), true);
            tool         = (ToolAttribute)mi.GetCustomAttribute(typeof(ToolAttribute), true);

            // create a doer delegate
            if (async)
            {
                if (subscript != null)
                {
                    do2Async = (Func <WebContext, int, Task>)mi.CreateDelegate(typeof(Func <WebContext, int, Task>), work);
                }
                else
                {
                    doAsync = (Func <WebContext, Task>)mi.CreateDelegate(typeof(Func <WebContext, Task>), work);
                }
            }
            else
            {
                if (subscript != null)
                {
                    do2 = (Action <WebContext, int>)mi.CreateDelegate(typeof(Action <WebContext, int>), work);
                }
                else
                {
                    @do = (Action <WebContext>)mi.CreateDelegate(typeof(Action <WebContext>), work);
                }
            }

            // comments
            var vlst = new ValueList <TagAttribute>(8);

            foreach (var m in mi.GetCustomAttributes())
            {
                if (m is TagAttribute c)
                {
                    vlst.Add(c);
                }
            }

            tags = vlst.ToArray();

            // resolve the action pathing
            var sb = new StringBuilder(work.Pathing);

            sb.Append(name);
            if (subscript != null)
            {
                sb.Append('-').Append('<').Append(subscript).Append('>');
            }

            pathing = sb.ToString();
        }