Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });
            services.AddDistributedMemoryCache();
            services.AddMemoryCache();
            services.AddDirectoryBrowser();
            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
            .AddViewLocalization();
            services.AddSignalR();
            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(options =>
            {
                options.LoginPath        = "/using";
                options.LogoutPath       = "/return";
                options.AccessDeniedPath = "/";
            });
            services.AddAuthorization(options =>
            {
                options.AddPolicy("Type", policy =>
                                  policy.Requirements.Add(new XTypeAuthorizationRequirement()));
                options.AddPolicy("object", policy =>
                                  policy.Requirements.Add(new XObjectAuthorizationRequirement()));
                options.AddPolicy("new", policy =>
                                  policy.Requirements.Add(new XConstructorInfoAuthorizationRequirement()));
                options.AddPolicy("Assembly", policy =>
                                  policy.Requirements.Add(new XAssemblyAuthorizationRequirement()));
            });
            services.AddSingleton <IAuthorizationHandler, XTypeAuthorizationHandler>();
            services.AddSingleton <IAuthorizationHandler, XObjectAuthorizationHandler>();
            services.AddSingleton <IAuthorizationHandler, XConstructorInfoAuthorizationHandler>();
            services.AddSingleton <IAuthorizationHandler, XAssemblyAuthorizationHandler>();
            X x = new XInternal();

            x.XAssembly = XAssemblyInternal.XNew;
            XTypeConverter typeConverter = new XObjectConverterInternal(x);

            services.AddSingleton(typeof(X), x);
            services.AddSingleton(typeof(XTypeConverter), typeConverter);
            services.AddSession(options =>
            {
                options.Cookie.IsEssential = true;
            });
        }
Beispiel #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            X           = new XInternal();
            X.XAssembly = XAssemblyInternal.XNew;

            List <string> argNames  = new List <string>();
            List <string> argValues = new List <string>();

            for (int i = 0; i < e.Args.Length; i++)
            {
                string arg = e.Args[i];
                if (arg.StartsWith("-"))
                {
                    int index = arg.IndexOf("=");
                    if (index > 0)
                    {
                        string name  = arg.Substring(1, index - 1);
                        string value = arg.Substring(index + 1);
                        argNames.Add(name);
                        argValues.Add(value);
                    }
                }
            }

            string assembly = FindResource("Assembly").ToString();
            string type     = string.Format("{0}.{0},{0}", assembly);

            XType          = X.XGetType(type);
            XTypeConverter = new XObjectConverterInternal(X);
            XConstructorInfo xconstructor = null;
            List <XObject>   xparams      = null;

            foreach (XConstructorInfo xctor in XType.XGetConstructors())
            {
                bool                         match      = true;
                List <XObject>               xvalues    = new List <XObject>();
                IEnumerator <string>         name       = argNames.GetEnumerator();
                IEnumerator <string>         value      = argValues.GetEnumerator();
                List <XParameterInfo>        xparmeters = new List <XParameterInfo>(xctor.XGetParameters());
                IEnumerator <XParameterInfo> xparam     = xparmeters.GetEnumerator();
                while (name.MoveNext() && value.MoveNext() && xparam.MoveNext())
                {
                    match = false;
                    if (name.Current == xparam.Current.XName)
                    {
                        XType xparamType = xparam.Current.XParameterType;
                        if (XTypeConverter.XCanConvertTo(xparamType))
                        {
                            XObject xvalue = XTypeConverter.XConvertTo(value, xparamType);
                            if (xvalue != null)
                            {
                                xvalues.Add(xvalue);
                                match = true;
                            }
                        }
                    }
                    if (match == false)
                    {
                        break;
                    }
                }
                if (match)
                {
                    xconstructor = xctor;
                    xparams      = xvalues;
                    break;
                }
            }
            XObject = null;
            if (xconstructor != null)
            {
                XObject = xconstructor.XInvoke(xparams.ToArray());
            }
        }