protected override void OnStart()
        {
            base.OnStart();
            ContentTypes.SetContentType(ScriptEngines.HandleExtension, "text/plain");
            ContentTypes.SetContentType(ScriptEngines.WindowExtension, "text/html");
            scriptEngines = new ScriptEngines(Site, Config);

            var assembly = Assembly.Load("netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51");

            scriptEngines.AddSysReferencedAssembly(assembly.Location);

            scriptEngines.AddSysReferencedAssembly(Assembly.GetExecutingAssembly().Location);
            scriptEngines.AddSysReferencedAssembly(typeof(Processor).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(ReflexHelper).Assembly.Location);

            scriptEngines.AddSysReferencedAssembly(typeof(object).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Uri).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Linq.Enumerable).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Data.SqlDbType).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Data.SqlClient.SqlConnection).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Data.SqlClient.SqlCommand).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.ServiceModel.ServiceHost).Assembly.Location);
            scriptEngines.AddSysReferencedAssembly(typeof(System.Runtime.Serialization.DataContractAttribute).Assembly.Location);
            foreach (var referencedAssemblyName in typeof(Framework.BaseDisposed).Assembly.GetReferencedAssemblies())
            {
                var referencedAssembly = Assembly.Load(referencedAssemblyName);
                scriptEngines.AddSysReferencedAssembly(referencedAssembly.Location);
            }

            scriptEngines.Start();

            var domain = scriptEngines.ApplicationDomain;
            var app    = domain.CreateApplication();

            app.Site    = Site;
            app.Setting = new ApplicationSetting(Site);

            Application.Current = app;
            Application.Current.Startup();
        }
Esempio n. 2
0
        internal void Initialize(ScriptEngines scriptEngines, IHttpContext httpContext, FileInfo fileInfo)
        {
            this.scriptEngines = scriptEngines;
            this.httpContext   = httpContext;

            FileName = fileInfo.FullName;

            httpRequest  = new HttpRequest(httpContext.Request);
            httpResponse = new HttpResponse(httpContext.Response);
            query        = new Dictionary <string, string>();
            form         = new Dictionary <string, string>();
            files        = new HttpFileCollection();
            var request  = this.httpContext.Request;
            var response = this.httpContext.Response;
            var encoding = httpRequest.ContentEncoding;

            if (response.ContentEncoding == null)
            {
                response.ContentEncoding = encoding;
                response.Headers.Set(HttpResponseHeader.ContentEncoding, encoding.BodyName);
            }

            var rawUrl = httpContext.RawUrl;
            var index  = rawUrl.IndexOf("?");

            if (index >= 0 && index < rawUrl.Length - 1)
            {
                var queryText = rawUrl.Substring(index + 1, rawUrl.Length - index - 1);
                Utility.HttpUtility.ResolveUrlEncoded(query, queryText);
            }
            if (request.HttpMethod == WebRequestMethods.Http.Post)
            {
                if (request.ContentLength64 > Application.Current.Setting.MaxPostLength)
                {
                    throw new InvalidOperationException("post size limited");
                }
                if (request.ContentType == null)
                {
                    throw new InvalidOperationException("content type error!");
                }

                var array       = request.ContentType.Split(';');
                var contentType = array[0].ToLower();
                switch (contentType)
                {
                case "application/x-www-form-urlencoded":
                {
                    var arraySegment = Utility.HttpUtility.ReadToEnd(request);
                    var postBodyText = encoding.GetString(arraySegment.Array, arraySegment.Offset, arraySegment.Count);
                    Utility.HttpUtility.ResolveUrlEncoded(form, postBodyText);
                }
                break;

                case "multipart/form-data":
                    files.Resolve(request);
                    break;

                default:
                    break;
                }
            }

            HttpBehaviour behaviour;
            Type          scriptType = GetType();

            foreach (var behaviourAttribute in scriptType.GetCustomAttributes <HttpBehaviourAttribute>(true))
            {
                behaviour = (HttpBehaviour)Activator.CreateInstance(behaviourAttribute.BehaviourType);
                behaviour.Handle(this);
            }
        }