Beispiel #1
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, XObjectAuthorizationRequirement requirement)
        {
            bool success = false;

            if (context.User != null && context.Resource is AuthorizationFilterContext authContext && authContext.ModelState.IsValid)
            {
                XType xtype = _XTypeModel.XFromRoute(authContext.RouteData, x);
                if (xtype != null)
                {
                    _XThisCache xthis = _XThisModel.XAuthenticate(context.User, cache, authContext.HttpContext.Session);
                    if (xthis != null)
                    {
                        XObject xobject = _XThisModel.XFromRoute(authContext.RouteData, xthis, x);
                        if (xobject != null && xthis != null)
                        {
                            success = true;
                        }
                    }
                }
            }
            if (success)
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, XConstructorInfoAuthorizationRequirement requirement)
        {
            bool success = false;

            if (context.User != null && context.Resource is AuthorizationFilterContext authContext && authContext.ModelState.IsValid)
            {
                XType xtype = _XTypeModel.XFromRoute(authContext.RouteData, x);
                if (xtype != null)
                {
                    _XThisCache xthis = _XThisModel.XAuthenticate(context.User, cache, authContext.HttpContext.Session);
                    if (xthis != null)
                    {
                        success = _XThisModel.XAuthorize(xthis.XThis.XGetType(), xtype);
                        if (success == false)
                        {
                            List <XType>     xtypes       = _XTypeModel.XFromQuery(authContext.HttpContext.Request.Query, x);
                            XConstructorInfo xconstructor = xtype.XGetConstructor(xtypes.ToArray());
                            if (xconstructor != null)
                            {
                                success = _XThisModel.XAuthorize(xthis.XThis.XGetType(), xconstructor);
                            }
                        }
                    }
                }
            }
            if (success)
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
Beispiel #3
0
        public async Task <ActionResult <XObject> > XObject([FromQuery] string key)
        {
            _XThisCache xthis   = _XThisModel.XFromCache(cache, HttpContext.Session);
            XObject     xobject = _XObjectModel.XFromCache(xthis, key);

            return(Ok(xobject));
        }
Beispiel #4
0
        public async Task <ActionResult <bool> > XParams([FromForm] string key, [FromForm] string objectKey)
        {
            _XThisCache xthis = _XThisModel.XFromCache(cache, HttpContext.Session);
            bool        res   = _XParamsModel.XToCache(xthis, key, objectKey);

            return(Ok(res));
        }
Beispiel #5
0
        public async Task <ActionResult <XObject[]> > XParams([FromQuery] string key, [FromQuery] int?index, [FromQuery] int?count)
        {
            _XThisCache    xthis   = _XThisModel.XFromCache(cache, HttpContext.Session);
            List <XObject> xparams = null;

            _XParamsModel.XFromCache(xthis, key, out xparams, index, count);
            return(Ok(xparams.ToArray()));
        }
Beispiel #6
0
        public static XObject XFromCache(_XThisCache xthis, string key)
        {
            XObject xobject = null;

            if (xthis.XObjects.ContainsKey(key))
            {
                xthis.XObjects.TryGetValue(key, out xobject);
            }
            return(xobject);
        }
Beispiel #7
0
        public static XObject XFromCache(_XThisCache xthis, XType xtype, int hashCode)
        {
            XObject xobject = null;
            string  key     = xtype.XFullName + "@" + hashCode;

            if (xthis.XObjects.ContainsKey(key))
            {
                xthis.XObjects.TryGetValue(key, out xobject);
            }
            return(xobject);
        }
Beispiel #8
0
        public async Task <IViewComponentResult> InvokeAsync(XAssembly xassembly, _XThisCache xthis)
        {
            _XAssemblyModel xmodel = new _XAssemblyModel();
            XType           xtype  = xthis.XThis.XGetType();
            List <XType>    xtypes = _XThisModel.XAuthorize(xtype, xassembly.XExportedTypes);
            Dictionary <string, List <string> > childNSs;
            Dictionary <string, List <XType> >  childTypes;

            XToHiearchyTypes(xtypes, out childNSs, out childTypes);
            xmodel.XNamespaces  = childNSs;
            xmodel.XTypes       = childTypes;
            xmodel.XInformation = _XAssemblyModel.XToAbout(xassembly, xthis.XString);
            xmodel.XString      = xthis.XString;
            return(View(xmodel));
        }
Beispiel #9
0
        protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, XAssemblyAuthorizationRequirement requirement)
        {
            bool success = false;

            if (context.User != null && context.Resource is AuthorizationFilterContext authContext && authContext.ModelState.IsValid)
            {
                XAssembly xassembly = _XAssemblyModel.XFromRoute(authContext.RouteData, x);
                if (xassembly != null)
                {
                    _XThisCache xthis = _XThisModel.XAuthenticate(context.User, cache, authContext.HttpContext.Session);
                    if (xthis != null)
                    {
                        success = _XThisModel.XAuthorize(xthis.XThis.XGetType(), xassembly);
                    }
                }
            }
            if (success)
            {
                context.Succeed(requirement);
            }
            return(Task.CompletedTask);
        }
Beispiel #10
0
        public async Task <IViewComponentResult> InvokeAsync(_XThisCache xthis)
        {
            _XThisModel xmodel = new _XThisModel(xthis);

            xmodel.XObjects = new Dictionary <string, List <XObject> >();
            foreach (XObject xobject in xmodel.XObjects.Values)
            {
                string key = xobject.XGetType().XFullName;
                if (xmodel.XObjects.ContainsKey(key))
                {
                    List <XObject> list = xmodel.XObjects[key];
                    list.Add(xobject);
                }
                else
                {
                    List <XObject> list = xmodel.XObjects[key];
                    list.Add(xobject);
                    xmodel.XObjects.Add(key, list);
                }
            }
            return(View(xmodel));
        }
        public async Task <IViewComponentResult> InvokeAsync(XType xtype, _XThisCache xthis)
        {
            _XTypeModel xmodel = new _XTypeModel(xtype, xthis);

            xmodel.XConstructors = xtype.XGetConstructors();

            xmodel.XFields     = new Dictionary <string, List <XFieldInfo> >();
            xmodel.XFieldTypes = new List <XType>();
            foreach (XFieldInfo xfield in xtype.XGetFields())
            {
                if (xfield.XIsStatic)
                {
                    XType  xfieldType = xfield.XDeclaringType;
                    string fieldKey   = xfieldType.XFullName;
                    if (xmodel.XFields.ContainsKey(fieldKey))
                    {
                        xmodel.XFields[fieldKey].Add(xfield);
                    }
                    else
                    {
                        xmodel.XFieldTypes.Add(xfieldType);
                        List <XFieldInfo> xfields = new List <XFieldInfo>();
                        xfields.Add(xfield);
                        xmodel.XFields.Add(fieldKey, xfields);
                    }
                }
            }

            xmodel.XProperties    = new Dictionary <string, List <XPropertyInfo> >();
            xmodel.XPropertyTypes = new List <XType>();
            foreach (XPropertyInfo xprop in xtype.XGetProperties())
            {
                if (xprop.XIsStatic)
                {
                    XType  xpropType = xprop.XDeclaringType;
                    string propKey   = xpropType.XFullName;
                    if (xmodel.XProperties.ContainsKey(propKey))
                    {
                        xmodel.XProperties[propKey].Add(xprop);
                    }
                    else
                    {
                        xmodel.XPropertyTypes.Add(xpropType);
                        List <XPropertyInfo> xprops = new List <XPropertyInfo>();
                        xprops.Add(xprop);
                        xmodel.XProperties.Add(propKey, xprops);
                    }
                }
            }

            List <XMethodInfo> xmethods = new List <XMethodInfo>();

            foreach (XMethodInfo xmethod in xtype.XGetMethods())
            {
                if (xmethod.XIsStatic)
                {
                    xmethods.Add(xmethod);
                }
            }
            xmodel.XMethods = xmethods.ToArray();

            Dictionary <string, char> accessKeyMap = new Dictionary <string, char>();
            List <char> accessKeys = new List <char>();

            _XTypeModel.XToAccessKeyMap(xmodel.XFields, xmodel.XProperties, out accessKeyMap, out accessKeys);
            xmodel.XAccessKeys = accessKeyMap;

            return(View(xmodel));
        }
Beispiel #12
0
 protected void XBuild(_XInModel xmodel, out string view, _XThisCache xthis, bool ximplicit)
 {
     xmodel.DefaultValue   = "";
     xmodel.Disabled       = "";
     xmodel.Id             = "";
     xmodel.ReadOnly       = "";
     xmodel.Required       = "";
     xmodel.SpellCheck     = "";
     xmodel.AccessKeyIndex = xmodel.Text.IndexOf(xmodel.AccessKey, StringComparison.OrdinalIgnoreCase);
     xmodel.Type           = "";
     xmodel.Size           = (int)(XConst.XRATIO * xmodel.Text.Length);
     view = null;
     if (xmodel.XType.XIsEnum)
     {
         view = "Enum";
     }
     else if (xmodel.XType.XFullName == (typeof(string[])).FullName)
     {
         view = "StringArray";
     }
     else if (xmodel.XType.XIsArray)
     {
         view = "Array";
     }
     else
     {
         view = "Default";
         if (ximplicit)
         {
             xmodel.Type = "password";
         }
         else if (xmodel.XType.XFullName == (typeof(bool)).FullName)
         {
             xmodel.Type = "checkbox";
         }
         else if (xmodel.XType.XFullName == (typeof(Color)).FullName)
         {
             xmodel.Type = "color";
         }
         else if (xmodel.XType.XFullName == (typeof(DateTime)).FullName)
         {
             xmodel.Type = "datetime";
         }
         else if (xmodel.XType.XFullName == (typeof(File)).FullName)
         {
             xmodel.Type = "file";
         }
         else if (xmodel.XType.XFullName == (typeof(float)).FullName)
         {
             xmodel.Type = "number";
         }
         else if (xmodel.XType.XFullName == (typeof(int)).FullName)
         {
             xmodel.Type = "number";
         }
         else if (xmodel.XType.XFullName == (typeof(string)).FullName)
         {
             xmodel.SpellCheck = "spellcheck";
             xmodel.Type       = "text";
         }
         else if (xmodel.XType.XFullName == (typeof(Uri)).FullName)
         {
             xmodel.Type = "url";
         }
         else
         {
             view            = "Ref";
             xmodel.XObjects = new Dictionary <string, XObject>();
             foreach (var keyValue in xthis.XObjects)
             {
                 XType xtype2 = keyValue.Value.XGetType();
                 if (xmodel.XType.XIsAssignableFrom(xtype2))
                 {
                     xmodel.XObjects.Add(keyValue.Key, keyValue.Value);
                 }
             }
         }
     }
 }
Beispiel #13
0
        public async Task <IViewComponentResult> InvokeAsync(object model, char accessKey, int tabIndex, _XThisCache xthis)
        {
            if (xthis != null)
            {
                xstring = xthis.XString;
            }

            if (model is XParameterInfo xparam)
            {
                return(await xparameter(xparam, accessKey, tabIndex, xthis));
            }
            else if (model is XFieldInfo xfield)
            {
                return(await xfieldInfo(xfield, accessKey, tabIndex, xthis));
            }
            else if (model is XPropertyInfo xprop)
            {
                return(await xpropertyInfo(xprop, accessKey, tabIndex, xthis));
            }
            return(View());
        }
Beispiel #14
0
        protected async Task <IViewComponentResult> xpropertyInfo(XPropertyInfo xproperty, char accessKey, int tabIndex, _XThisCache xthis)
        {
            _XInModel xmodel = new _XInModel();

            xmodel.AccessKey = accessKey;
            xmodel.Class     = _XPropertyInfoModel.XToClass(xproperty);
            xmodel.Name      = xproperty.XName;
            xmodel.TabIndex  = tabIndex;
            xmodel.Text      = _XStringModel.XToString(xproperty, xstring);
            //xmodel.Title = _XStringModel.XToTitle(x, xproperty, xstring);
            xmodel.XString = xstring;
            xmodel.XType   = xproperty.XPropertyType;
            bool   ximplicit = _XPropertyInfoModel.XIsImplicit(xproperty, x);
            string view      = null;

            XBuild(xmodel, out view, xthis, ximplicit);
            if (view != null)
            {
                return(View(view, xmodel));
            }
            return(View(xmodel));
        }
Beispiel #15
0
        public static XObject[] XFromForm(X x, XParameterInfo[] xparams, XTypeConverter xtypeConverter, IFormCollection form, _XThisCache cache)
        {
            List <XObject> values = new List <XObject>();

            if (xtypeConverter.XCanConvertFrom(typeof(string)))
            {
                XType _this = x.XTypeOf(typeof(_XThis));
                foreach (XParameterInfo xparameter in xparams)
                {
                    StringValues value   = form[xparameter.XName];
                    XObject      xobject = null;
                    if (xtypeConverter.XCanConvertTo(xparameter.XParameterType))
                    {
                        xobject = xtypeConverter.XConvertTo(value.ToString(), xparameter.XParameterType);
                    }
                    else if (cache != null)
                    {
                        if (xparameter.XParameterType.XIsAssignableFrom(cache.XThis.XGetType()))
                        {
                            XObject[] xattrs = xparameter.XGetCustomAttributes(_this, true);
                            if (xattrs != null && xattrs.Length > 0)
                            {
                                xobject = cache.XThis;
                            }
                        }

                        if (xobject == null)
                        {
                            if (value.ToString() == "")
                            {
                                xobject = x.XNULL;
                            }
                            else
                            {
                                xobject = _XObjectModel.XFromCache(cache, value.ToString());
                            }
                        }
                    }
                    values.Add(xobject);
                }
            }
            return(values.ToArray());
        }
Beispiel #16
0
        public async Task <ActionResult> XString([FromQuery] string lang)
        {
            _XThisCache xthis = _XThisModel.XFromCache(cache, HttpContext.Session);

            return(Ok());
        }
Beispiel #17
0
        public static void XToCache(_XThisCache cache, XObject xobject)
        {
            string key = XToKey(xobject);

            cache.XObjects.Add(key, xobject);
        }
Beispiel #18
0
 public _XObjectModel(XObject xobj, _XThisCache xthis) : base(xthis)
 {
     XObject = xobj;
 }
Beispiel #19
0
        public async Task <ActionResult> XAwait([FromQuery] string type, int hashCode)
        {
            _XThisCache xthis = _XThisModel.XFromCache(cache, HttpContext.Session);

            return(Ok());
        }
Beispiel #20
0
 public _XTypeModel(XType type, _XThisCache xthis) : base(xthis)
 {
     XType = type;
 }