private void OnDeserializedMethod(StreamingContext context)
        {
            // re-create each ValidationCallbackInfo from its string representation
            Type target = BuildManager.GetType(_targetTypeName, true /*throwOnFail*/, false /*ignoreCase*/);

            _callback = (HttpResponseSubstitutionCallback)Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), target, _methodName);
        }
예제 #2
0
        internal ResponseSubstBlockElement(SerializationInfo info, StreamingContext context)
        {
            // Simply retrieve the action if it is serializable
            if (info.GetBoolean("isSerializable"))
            {
                _callback = (HttpResponseSubstitutionCallback)info.GetValue("callback", typeof(HttpResponseSubstitutionCallback));
            }

            // Otherwise, recreate the action based on its serialized components
            else
            {
                // Retrieve the serialized method reference
                var method = (MethodInfo)info.GetValue("method", typeof(MethodInfo));

                // Create an instance of the anonymous delegate class
                object target = Activator.CreateInstance(method.DeclaringType, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);

                // Initialize the fields of the anonymous instance
                foreach (FieldInfo field in method.DeclaringType.GetFields())
                {
                    field.SetValue(target, info.GetValue(field.Name, field.FieldType));
                }

                // Recreate the action delegate
                _callback = (HttpResponseSubstitutionCallback)Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), target, method.Name);
            }
        }
        internal void RenderMarkup(HtmlTextWriter writer)
        {
            if (MethodName.Length == 0)
            {
                return;
            }

            TemplateControl target = TemplateControl;

            if (target == null)
            {
                return;
            }

            // get the delegate to the method
            HttpResponseSubstitutionCallback callback = null;

            try {
                callback = GetDelegate(target.GetType(), MethodName);
            }
            catch {
            }

            if (callback == null)
            {
                throw new HttpException(
                          SR.GetString(SR.Substitution_BadMethodName, MethodName));
            }

            // add the substitution to the response
            Page.Response.WriteSubstitution(callback);
        }
예제 #4
0
        static ConverterTest()
        {
            DefaultRawResponseHeaders = new NameValueCollection();
            DefaultRawResponseHeaders["Content-Encoding"] = "gzip";
            DefaultRawResponseHeaders["Content-Type"]     = "text/html";
            DefaultRawResponseHeaders["Server"]           = "Microsoft-IIS/8.0";

            DefaultHttpResponseSubstitutionCallback = new HttpResponseSubstitutionCallback(ctx => "test");

            HttpFileResponseElementType       = SystemWebAssembly.GetType("System.Web.HttpFileResponseElement");
            HttpSubstBlockResponseElementType = SystemWebAssembly.GetType("System.Web.HttpSubstBlockResponseElement");
            HttpResponseBufferElementType     = SystemWebAssembly.GetType("System.Web.HttpResponseBufferElement");
            IHttpResponseElementType          = SystemWebAssembly.GetType("System.Web.IHttpResponseElement");

            // Methods
            IHttpResponseElement_GetBytes = IHttpResponseElementType.GetMethod("GetBytes");
            IHttpResponseElement_GetSize  = IHttpResponseElementType.GetMethod("GetSize");

            // Fileds
            HttpFileResponseElement_FileName        = HttpFileResponseElementType.GetField("_filename", InternalCtorBindingFlags);
            HttpFileResponseElement_Offset          = HttpFileResponseElementType.GetField("_offset", InternalCtorBindingFlags);
            HttpFileResponseElement_IsImpersonating = HttpFileResponseElementType.GetField("_isImpersonating", InternalCtorBindingFlags);
            HttpFileResponseElement_UseTransmitFile = HttpFileResponseElementType.GetField("_useTransmitFile", InternalCtorBindingFlags);
            HttpSubstBlockResponseElement_Callback  = HttpSubstBlockResponseElementType.GetField("_callback", InternalCtorBindingFlags);
        }
        internal void RegisterPostCacheCallBack(HttpContext context,
                                                Page page,
                                                HtmlTextWriter writer) {
            // Assumption: called from AdRotator's Render phase

            HttpResponseSubstitutionCallback callback = new HttpResponseSubstitutionCallback(Render);
            context.Response.WriteSubstitution(callback);
        }
 public SubstitutionResponseElement(HttpResponseSubstitutionCallback callback)
 {
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     this._callback = callback;
 }
예제 #7
0
        public void SetData(HttpResponseSubstitutionCallback callback)
        {
            if (callback == null)
            {
                return;
            }

            Data.Add(new DataItem(callback));
        }
        internal void RegisterPostCacheCallBack(HttpContext context,
                                                Page page,
                                                HtmlTextWriter writer)
        {
            // Assumption: called from AdRotator's Render phase

            HttpResponseSubstitutionCallback callback = new HttpResponseSubstitutionCallback(Render);

            context.Response.WriteSubstitution(callback);
        }
예제 #9
0
		public SubstitutionResponseElement (HttpResponseSubstitutionCallback callback)
		{
			if (callback == null)
				throw new ArgumentNullException ("callback");

			this.Callback = callback;

			MethodInfo mi = callback.Method;
			this.typeName = mi.DeclaringType.AssemblyQualifiedName;
			this.methodName = mi.Name;
		}
		public void Constructor ()
		{
			SubstitutionResponseElement sre;

			AssertExtensions.Throws<ArgumentNullException> (() => {
				sre = new SubstitutionResponseElement (null);
			}, "#A1");

			var cb = new HttpResponseSubstitutionCallback (TestCallback);
			sre = new SubstitutionResponseElement (cb);
			Assert.AreEqual (cb, sre.Callback, "#B1");
		}
예제 #11
0
        public void Constructor()
        {
            SubstitutionResponseElement sre;

            Assert.Throws <ArgumentNullException> (() => {
                sre = new SubstitutionResponseElement(null);
            }, "#A1");

            var cb = new HttpResponseSubstitutionCallback(TestCallback);

            sre = new SubstitutionResponseElement(cb);
            Assert.AreEqual(cb, sre.Callback, "#B1");
        }
        public SubstitutionResponseElement(HttpResponseSubstitutionCallback callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            this.Callback = callback;

            MethodInfo mi = callback.Method;

            this.typeName   = mi.DeclaringType.AssemblyQualifiedName;
            this.methodName = mi.Name;
        }
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback, Encoding encoding, System.Text.Encoder encoder, IIS7WorkerRequest iis7WorkerRequest)
 {
     this._callback = callback;
     if (iis7WorkerRequest != null)
     {
         this._isIIS7WorkerRequest = true;
         string s = this._callback(HttpContext.Current);
         if (s == null)
         {
             throw new ArgumentNullException("substitutionString");
         }
         this.CreateFirstSubstData(s, iis7WorkerRequest, encoder);
     }
     else
     {
         this._firstSubstitution = this.Substitute(encoding);
     }
 }
예제 #14
0
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback, Encoding encoding, System.Text.Encoder encoder, IIS7WorkerRequest iis7WorkerRequest)
 {
     this._callback = callback;
     if (iis7WorkerRequest != null)
     {
         this._isIIS7WorkerRequest = true;
         string s = this._callback(HttpContext.Current);
         if (s == null)
         {
             throw new ArgumentNullException("substitutionString");
         }
         this.CreateFirstSubstData(s, iis7WorkerRequest, encoder);
     }
     else
     {
         this._firstSubstitution = this.Substitute(encoding);
     }
 }
예제 #15
0
        internal void WriteSubstBlock(HttpResponseSubstitutionCallback callback, IIS7WorkerRequest iis7WorkerRequest)
        {
            if (this._charBufferLength != this._charBufferFree)
            {
                this.FlushCharBuffer(true);
            }
            this._lastBuffer = null;
            IHttpResponseElement element = new HttpSubstBlockResponseElement(callback, this.Encoding, this.Encoder, iis7WorkerRequest);

            this._buffers.Add(element);
            if (iis7WorkerRequest != null)
            {
                this.SubstElements.Add(element);
            }
            if (!this._responseBufferingOn)
            {
                this._response.Flush();
            }
        }
예제 #16
0
 internal void RenderMarkup(HtmlTextWriter writer)
 {
     if (this.MethodName.Length != 0)
     {
         TemplateControl templateControl = base.TemplateControl;
         if (templateControl != null)
         {
             HttpResponseSubstitutionCallback callback = null;
             try
             {
                 callback = this.GetDelegate(templateControl.GetType(), this.MethodName);
             }
             catch
             {
             }
             if (callback == null)
             {
                 throw new HttpException(System.Web.SR.GetString("Substitution_BadMethodName", new object[] { this.MethodName }));
             }
             this.Page.Response.WriteSubstitution(callback);
         }
     }
 }
예제 #17
0
        public void WriteSubstitution(HttpResponseSubstitutionCallback callback)
        {
            // Emulation of .NET behavior
            if (callback == null)
            {
                throw new NullReferenceException();
            }

            object target = callback.Target;

            if (target != null && target.GetType() == typeof(Control))
            {
                throw new ArgumentException("callback");
            }

            string s = callback(context);

            if (!IsCached)
            {
                Write(s);
                return;
            }

            Cache.Cacheability = HttpCacheability.Server;
            Flush();
            if (WorkerRequest == null)
            {
                Write(s);                  // better this than nothing
            }
            else
            {
                byte[] bytes = WebEncoding.ResponseEncoding.GetBytes(s);
                WorkerRequest.SendResponseFromMemory(bytes, bytes.Length);
            }

            cached_response.SetData(callback);
        }
 private void OnDeserializedMethod(StreamingContext context) {
     // re-create each ValidationCallbackInfo from its string representation
     Type target = BuildManager.GetType(_targetTypeName, true /*throwOnFail*/, false /*ignoreCase*/);
     _callback = (HttpResponseSubstitutionCallback) Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), target, _methodName);
 }
        private SubstitutionResponseElement() { } // hide default constructor

        public SubstitutionResponseElement(HttpResponseSubstitutionCallback callback) {
            if (callback == null)
                throw new ArgumentNullException("callback");

            _callback = callback;
        }
 public void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     if ((callback.Target != null) && (callback.Target is Control))
     {
         throw new ArgumentException(System.Web.SR.GetString("Invalid_substitution_callback"), "callback");
     }
     if (this.UsingHttpWriter)
     {
         this._httpWriter.WriteSubstBlock(callback, this._wr as IIS7WorkerRequest);
     }
     else
     {
         this._writer.Write(callback(this._context));
     }
     if ((this._cachePolicy != null) && (this._cachePolicy.GetCacheability() == HttpCacheability.Public))
     {
         this._cachePolicy.SetCacheability(HttpCacheability.Server);
     }
 }
예제 #21
0
		void ObjectDeserialized (StreamingContext context)
		{
			Type type = Type.GetType (typeName, true);
			Callback = Delegate.CreateDelegate (typeof (HttpResponseSubstitutionCallback), type, methodName, false, true) as HttpResponseSubstitutionCallback;
		}
		public virtual void WriteSubstitution (HttpResponseSubstitutionCallback callback)
		{
			NotImplemented ();
		}
        void ObjectDeserialized(StreamingContext context)
        {
            Type type = Type.GetType(typeName, true);

            Callback = Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), type, methodName, false, true) as HttpResponseSubstitutionCallback;
        }
예제 #24
0
        internal void RegisterPostCacheCallBack(HttpContext context, Page page, HtmlTextWriter writer)
        {
            HttpResponseSubstitutionCallback callback = new HttpResponseSubstitutionCallback(this.Render);

            context.Response.WriteSubstitution(callback);
        }
 public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     proxiedResponse.WriteSubstitution(callback);
 }
예제 #26
0
		public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
		{
			//TODO Missing WriteSubstitution for HttpListenerResponse
		}
        //
        // Support for substitution blocks
        //

        internal void WriteSubstBlock(HttpResponseSubstitutionCallback callback, IIS7WorkerRequest iis7WorkerRequest) {
            if (_charBufferLength != _charBufferFree)
                FlushCharBuffer(true);
            _lastBuffer = null;

            // add new substitution block to the buffer list
            IHttpResponseElement element = new HttpSubstBlockResponseElement(callback, Encoding, Encoder, iis7WorkerRequest);
            _buffers.Add(element);

            if (iis7WorkerRequest != null) {
                SubstElements.Add(element);
            }

            if (!_responseBufferingOn)
                _response.Flush();
        }
 internal void RegisterPostCacheCallBack(HttpContext context, Page page, HtmlTextWriter writer)
 {
     HttpResponseSubstitutionCallback callback = new HttpResponseSubstitutionCallback(this.Render);
     context.Response.WriteSubstitution(callback);
 }
예제 #29
0
		public void SetData (HttpResponseSubstitutionCallback callback)
		{
			if (callback == null)
				return;

			Data.Add (new DataItem (callback));
		}
예제 #30
0
 public void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     Contract.Requires(callback != null);
 }
        private void OnDeserializedMethod(StreamingContext context)
        {
            Type target = BuildManager.GetType(this._targetTypeName, true, false);

            this._callback = (HttpResponseSubstitutionCallback)Delegate.CreateDelegate(typeof(HttpResponseSubstitutionCallback), target, this._methodName);
        }
 public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     throw new NotSupportedException(NotSupportedMessage);
 }
예제 #33
0
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback)
 {
     this._callback = callback;
 }
 public void WriteSubstitution (HttpResponseSubstitutionCallback callback)
 {
   Contract.Requires (callback != null);
 }
		void IHttpResponse.WriteSubstitution(HttpResponseSubstitutionCallback callback)
		{
			this._httpResponse.WriteSubstitution(callback);
		}
예제 #36
0
 public virtual void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     NotImplemented();
 }
        /// <devdoc>
        ///    <para>Writes a substition block to the response.</para>
        /// </devdoc>
        public void WriteSubstitution(HttpResponseSubstitutionCallback callback) {
            // cannot be instance method on a control
            if (callback.Target != null && callback.Target is Control) {
                throw new ArgumentException(SR.GetString(SR.Invalid_substitution_callback), "callback");
            }

            if (UsingHttpWriter) {
                // HttpWriter can take substitution blocks
                _httpWriter.WriteSubstBlock(callback, _wr as IIS7WorkerRequest);
            }
            else {
                // text writer -- write as string
                _writer.Write(callback(_context));
            }

            // set the cache policy: reduce cachability from public to server
            if (_cachePolicy != null && _cachePolicy.GetCacheability() == HttpCacheability.Public)
                _cachePolicy.SetCacheability(HttpCacheability.Server);
        }
예제 #38
0
			public DataItem (HttpResponseSubstitutionCallback callback) : this (null, 0)
			{
				Callback = callback;
			}
예제 #39
0
 public void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     _httpResponse.WriteSubstitution(callback);
 }
예제 #40
0
 public virtual void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     throw new NotImplementedException();
 }
예제 #41
0
 public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     base.WriteSubstitution(callback);
 }
 // special constructor used by OutputCache
 internal HttpSubstBlockResponseElement(HttpResponseSubstitutionCallback callback) {
     _callback = callback;
 }
 public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     this._httpResponse.WriteSubstitution(callback);
 }
 public void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
 }
 internal void WriteSubstBlock(HttpResponseSubstitutionCallback callback, IIS7WorkerRequest iis7WorkerRequest)
 {
     if (this._charBufferLength != this._charBufferFree)
     {
         this.FlushCharBuffer(true);
     }
     this._lastBuffer = null;
     IHttpResponseElement element = new HttpSubstBlockResponseElement(callback, this.Encoding, this.Encoder, iis7WorkerRequest);
     this._buffers.Add(element);
     if (iis7WorkerRequest != null)
     {
         this.SubstElements.Add(element);
     }
     if (!this._responseBufferingOn)
     {
         this._response.Flush();
     }
 }
 public virtual new void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
 }
예제 #47
0
 public ResponseSubstBlockElement(HttpResponseSubstitutionCallback callback, Encoding encoding)
 {
     _callback          = callback;
     _firstSubstitution = Substitute(encoding);
 }
예제 #48
0
 public DataItem(HttpResponseSubstitutionCallback callback) : this(null, 0)
 {
     Callback = callback;
 }
예제 #49
0
 public virtual void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     throw new NotImplementedException();
 }
예제 #50
0
		public void WriteSubstitution (HttpResponseSubstitutionCallback callback)
		{
			// Emulation of .NET behavior
			if (callback == null)
				throw new NullReferenceException ();

			object target = callback.Target;
			if (target != null && target.GetType () == typeof (Control))
				throw new ArgumentException ("callback");

			string s = callback (context);
			if (!IsCached) {
				Write (s);
				return;
			}

			Cache.Cacheability = HttpCacheability.Server;
			Flush ();
			if (WorkerRequest == null)
				Write (s); // better this than nothing
			else {
				byte[] bytes = WebEncoding.ResponseEncoding.GetBytes (s);
				WorkerRequest.SendResponseFromMemory (bytes, bytes.Length);
			}
			
			cached_response.SetData (callback);
		}
 public override void WriteSubstitution(HttpResponseSubstitutionCallback callback)
 {
     throw new NotSupportedException(NotSupportedMessage);
 }