コード例 #1
0
        // Encode outgoing data.
        //
        // Warning: not all type are supported (see below).
        protected override bool OnBeforeOutgoing(IHubOutgoingInvokerContext context)
        {
            _log.Debug("");
            var args = context.Invocation.Args;

            for (int argI = 0; argI < args.Length; argI++)
            {
                if (typeof(IEncodable).IsAssignableFrom(args[argI].GetType()))
                {
                    IEncodable model = (IEncodable)args[argI];
                    model.Encode();
                }
                else if (args[argI].GetType() == typeof(string))
                {
                    args[argI] = HttpUtility.HtmlEncode(args[argI].ToString());
                }
                else if (args[argI].GetType() == typeof(List <string>))
                {
                    var items = (List <string>)args[argI];
                    for (int itemI = 0; itemI < items.Count; itemI++)
                    {
                        items[itemI] = HttpUtility.HtmlEncode(items[itemI]);
                    }
                    //} else {
                    //    Won't get encoded!
                }
            }
            return(base.OnBeforeOutgoing(context));
        }
コード例 #2
0
        public static void Encode(string fileName, IEncodable value)
        {
            FileStream stream = File.Open(fileName, FileMode.Create);

            EncoderUtil.Encode(stream, value);

            stream.Close();
        }
コード例 #3
0
        /// <summary>
        /// Gets the length of the URL that would be used for a simple redirect to carry
        /// this indirect message to its recipient.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns>The number of characters in the redirect URL.</returns>
        static int getSizeOfPayload(IEncodable message)
        {
            Debug.Assert(message != null);
            UriBuilder redirect = new UriBuilder(message.RedirectUrl);

            UriUtil.AppendQueryArgs(redirect, message.EncodedFields);
            return(redirect.Uri.AbsoluteUri.Length);
        }
コード例 #4
0
ファイル: TestSupport.cs プロジェクト: mdickson/opensim-libs
    /// <summary>
    /// Gets a URL that can be requested to send an indirect message.
    /// </summary>
    public static Uri ExtractUrl(this IResponse message)
    {
        DotNetOpenId.Response response  = (DotNetOpenId.Response)message;
        IEncodable            encodable = response.EncodableMessage;
        UriBuilder            builder   = new UriBuilder(encodable.RedirectUrl);

        UriUtil.AppendQueryArgs(builder, encodable.EncodedFields);
        return(builder.Uri);
    }
コード例 #5
0
 public GetRequest(ConsulClient client, string url, QueryOptions options, IEncodable filter) : base(client, url, HttpMethod.Get)
 {
     if (string.IsNullOrEmpty(url))
     {
         throw new ArgumentException(nameof(url));
     }
     Options = options ?? QueryOptions.Default;
     Filter  = filter;
 }
コード例 #6
0
        protected virtual Response Create301RedirectResponse(IEncodable message)
        {
            WebHeaderCollection headers = new WebHeaderCollection();
            UriBuilder          builder = new UriBuilder(message.RedirectUrl);

            UriUtil.AppendQueryArgs(builder, message.EncodedFields);
            headers.Add(HttpResponseHeader.Location, builder.Uri.AbsoluteUri);
            Logger.DebugFormat("Redirecting to {0}", builder.Uri.AbsoluteUri);
            return(new Response(HttpStatusCode.Redirect, headers, new byte[0], message));
        }
コード例 #7
0
        private T Execute <T>(IEncodable model, string apiUri)
        {
            var content         = model.AsFormUrlEncodedContent();
            var responseMessage = _client.PostAsync(apiUri, content).Result;

            responseMessage.EnsureSuccessStatusCode();
            var response = responseMessage.Content.ReadAsStringAsync().Result;

            return(JsonConvert.DeserializeObject <T>(response));
        }
コード例 #8
0
        public void Encode(IEncodable value)
        {
            bool hasValue = value != null;

            this.Encode(hasValue);

            if (hasValue)
            {
                value.Encode(this);
            }
        }
コード例 #9
0
        public ExtensionObject(IEncodable body, ExpandedNodeId typeId)
        {
            if (body == null)
            {
                this.BodyType = BodyType.None;
                return;
            }

            this.Body     = body;
            this.BodyType = BodyType.Encodable;
            this.TypeId   = typeId;
        }
コード例 #10
0
        public ExtensionObject(IEncodable body)
        {
            if (body == null)
            {
                this.BodyType = BodyType.None;
                return;
            }

            this.Body     = body;
            this.BodyType = BodyType.Encodable;
            this.TypeId   = body.GetType().GetTypeInfo().GetCustomAttribute <BinaryEncodingIdAttribute>(false)?.NodeId ?? throw new ServiceResultException(StatusCodes.BadDataEncodingUnsupported);
        }
コード例 #11
0
        static int getSizeOfPayload(IEncodable message)
        {
            Debug.Assert(message != null);
            int size = 0;

            foreach (var field in message.EncodedFields)
            {
                size += field.Key.Length;
                size += field.Value.Length;
            }
            return(size);
        }
コード例 #12
0
        public override Response Encode(IEncodable encodable)
        {
            var response = encodable as EncodableResponse;

            if (response != null)
            {
                if (response.NeedsSigning)
                {
                    signatory.Sign(response);
                }
            }
            return(base.Encode(encodable));
        }
コード例 #13
0
        /// <summary>
        /// Encodes messages into <see cref="Response"/> instances.
        /// </summary>
        public virtual Response Encode(IEncodable message)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            EncodingType encode_as = message.EncodingType;
            Response     wr;

            WebHeaderCollection headers = new WebHeaderCollection();

            switch (encode_as)
            {
            case EncodingType.DirectResponse:
                Logger.DebugFormat("Sending direct message response:{0}{1}",
                                   Environment.NewLine, Util.ToString(message.EncodedFields));
                HttpStatusCode code = (message is Exception) ?
                                      HttpStatusCode.BadRequest : HttpStatusCode.OK;
                // Key-Value Encoding is how response bodies are sent.
                // Setting the content-type to something other than text/html or text/plain
                // prevents free hosted sites like GoDaddy's from automatically appending
                // the <script/> at the end that adds a banner, and invalidating our response.
                headers.Add(HttpResponseHeader.ContentType, KeyValueFormContentType);
                wr = new Response(code, headers, ProtocolMessages.KeyValueForm.GetBytes(message.EncodedFields), message);
                break;

            case EncodingType.IndirectMessage:
                Logger.DebugFormat("Sending indirect message:{0}{1}",
                                   Environment.NewLine, Util.ToString(message.EncodedFields));
                // TODO: either redirect or do a form POST depending on payload size.
                Debug.Assert(message.RedirectUrl != null);
                if (getSizeOfPayload(message) <= GetToPostThreshold)
                {
                    wr = Create301RedirectResponse(message);
                }
                else
                {
                    wr = CreateFormPostResponse(message);
                }
                break;

            default:
                Logger.ErrorFormat("Cannot encode response: {0}", message);
                wr = new Response(HttpStatusCode.BadRequest, headers, new byte[0], message);
                break;
            }
            return(wr);
        }
コード例 #14
0
 /// <param name="code">The HTTP status code.</param>
 /// <param name="headers">The collection of any HTTP headers that should be included.  Cannot be null, but can be an empty collection.</param>
 /// <param name="body">The payload of the response, if any.  Cannot be null, but can be an empty array.</param>
 /// <param name="encodableMessage">
 /// Used to assist testing to decipher the field contents of a Response.
 /// </param>
 internal Response(HttpStatusCode code, WebHeaderCollection headers, byte[] body, IEncodable encodableMessage)
 {
     if (headers == null)
     {
         throw new ArgumentNullException("headers");
     }
     if (body == null)
     {
         throw new ArgumentNullException("body");
     }
     Debug.Assert(encodableMessage != null, "For testing, this is useful to have.");
     Code             = code;
     Headers          = headers ?? new WebHeaderCollection();
     Body             = body;
     EncodableMessage = encodableMessage;
 }
コード例 #15
0
        protected virtual Response CreateFormPostResponse(IEncodable message)
        {
            WebHeaderCollection headers      = new WebHeaderCollection();
            MemoryStream        body         = new MemoryStream();
            StreamWriter        bodyWriter   = new StreamWriter(body);
            StringBuilder       hiddenFields = new StringBuilder();

            foreach (var field in message.EncodedFields)
            {
                hiddenFields.AppendFormat("\t<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />\r\n",
                                          HttpUtility.HtmlEncode(field.Key), HttpUtility.HtmlEncode(field.Value));
            }
            bodyWriter.WriteLine(FormPostFormat,
                                 HttpUtility.HtmlEncode(message.RedirectUrl.AbsoluteUri), hiddenFields);
            bodyWriter.Flush();
            return(new Response(HttpStatusCode.OK, headers, body.ToArray(), message));
        }
コード例 #16
0
ファイル: EntityIO.cs プロジェクト: oxysoft/PokeSharp
        public MapEntity Read()
        {
            MapEntity   result = null;
            BinaryInput stream = _stream as BinaryInput;
            EntityType  type   = (EntityType)stream.ReadByte();

            if (type == EntityType.Building)
            {
                result = new BuildingEntity(factory, ScrollAffected);
            }

            IEncodable encodable = result as IEncodable;

            if (encodable != null)
            {
                encodable.Decode(stream);
            }

            return(result);
        }
コード例 #17
0
        public void Write(IAction t)
        {
            BinaryOutput stream = _stream as BinaryOutput;

            int i = 0;

            if (t is SetTileAction)
            {
                i = 1;
            }
            if (t is MultiAction)
            {
                i = 2;
            }
            if (t is FillAction)
            {
                i = 3;
            }
            if (t is RectangleAction)
            {
                i = 4;
            }
            if (t is AddEntityAction)
            {
                i = 5;
            }
            if (t is RemoveEntityAction)
            {
                i = 6;
            }

            stream.Write(i);

            IEncodable encodable = t as IEncodable;

            if (encodable != null)
            {
                encodable.Encode(stream);
            }
        }
コード例 #18
0
        public IAction Read()
        {
            IAction     result = null;
            BinaryInput stream = _stream as BinaryInput;
            int         i      = stream.ReadInt32();

            if (i == 1)
            {
                result = new SetTileAction();
            }
            if (i == 2)
            {
                result = new MultiAction();
            }
            if (i == 3)
            {
                result = new FillAction();
            }
            if (i == 4)
            {
                result = new RectangleAction();
            }
            if (i == 5)
            {
                result = new AddEntityAction();
            }
            if (i == 6)
            {
                result = new RemoveEntityAction();
            }

            IEncodable encodable = result as IEncodable;

            if (encodable != null)
            {
                encodable.Decode(stream);
            }
            return(result);
        }
コード例 #19
0
ファイル: NamedVariable.cs プロジェクト: oxysoft/PokeSharp
 public NamedEncodable(string name, IEncodable value) : base(name)
 {
     this.value = value;
 }
コード例 #20
0
 internal GetRequest <TOut> Get <TOut>(string path, QueryOptions opts = null, IEncodable filter = null)
 {
     return(new GetRequest <TOut>(this, path, opts, filter));
 }
コード例 #21
0
 public IEncodedValue(IEncodable value)
 {
 }
コード例 #22
0
 public ExtensionObject(IEncodable body)
 {
     this.Body     = body;
     this.BodyType = body != null ? BodyType.Encodable : BodyType.None;
 }
コード例 #23
0
 private static void CheckEncoded(string expected, IEncodable expression) =>
 Assert.Equal(expected, expression.Encode());
コード例 #24
0
 public void Write(IEncodable value)
 {
     value.Encode(this);
 }
コード例 #25
0
ファイル: NamedVariable.cs プロジェクト: oxysoft/PokeSharp
 public override IEncodable Decode(BinaryInput stream)
 {
     base.Decode(stream);
     value = stream.ReadObject <T>();
     return(this);
 }
コード例 #26
0
 public EncodeEventArgs(IEncodable encodable)
 {
     Message = encodable;
 }
コード例 #27
0
        public static void Encode(Stream stream, IEncodable value)
        {
            BinaryOutput output = new BinaryOutput(stream);

            value.Encode(output);
        }
コード例 #28
0
 public static void Encode(BinaryOutput output, IEncodable value)
 {
     value.Encode(output);
 }
コード例 #29
0
ファイル: Variant.cs プロジェクト: RoboPlusPlus/Csharp
 public Variant(IEncodable value)
 {
     this.Value           = new ExtensionObject(value);
     this.Type            = VariantType.ExtensionObject;
     this.ArrayDimensions = null;
 }
コード例 #30
0
 public async static Task SendSecretMessage(Stream s, byte[] key, IEncodable message, CancellationToken token = default)
 {
     await SendSecretMessage(s, key, message.Encode(), token);
 }
コード例 #31
-1
		public override Response Encode(IEncodable encodable) {
			var response = encodable as EncodableResponse;
			if (response != null) {
				if (response.NeedsSigning) {
					signatory.Sign(response);
				}
			}
			return base.Encode(encodable);
		}
コード例 #32
-1
ファイル: Response.cs プロジェクト: Belxjander/Asuna
		/// <param name="code">The HTTP status code.</param>
		/// <param name="headers">The collection of any HTTP headers that should be included.  Cannot be null, but can be an empty collection.</param>
		/// <param name="body">The payload of the response, if any.  Cannot be null, but can be an empty array.</param>
		/// <param name="encodableMessage">
		/// Used to assist testing to decipher the field contents of a Response.
		/// </param>
		internal Response(HttpStatusCode code, WebHeaderCollection headers, byte[] body, IEncodable encodableMessage) {
			if (headers == null) throw new ArgumentNullException("headers");
			if (body == null) throw new ArgumentNullException("body");
			Debug.Assert(encodableMessage != null, "For testing, this is useful to have.");
			Code = code;
			Headers = headers ?? new WebHeaderCollection();
			Body = body;
			EncodableMessage = encodableMessage;
		}
コード例 #33
-1
ファイル: MessageEncoder.cs プロジェクト: Belxjander/Asuna
		/// <summary>
		/// Encodes messages into <see cref="Response"/> instances.
		/// </summary>
		public virtual Response Encode(IEncodable message) {
			if (message == null) throw new ArgumentNullException("message");

			EncodingType encode_as = message.EncodingType;
			Response wr;

			WebHeaderCollection headers = new WebHeaderCollection();
			switch (encode_as) {
				case EncodingType.DirectResponse:
					Logger.DebugFormat("Sending direct message response:{0}{1}",
						Environment.NewLine, Util.ToString(message.EncodedFields));
					HttpStatusCode code = (message is Exception) ?
						HttpStatusCode.BadRequest : HttpStatusCode.OK;
					// Key-Value Encoding is how response bodies are sent.
					// Setting the content-type to something other than text/html or text/plain
					// prevents free hosted sites like GoDaddy's from automatically appending
					// the <script/> at the end that adds a banner, and invalidating our response.
					headers.Add(HttpResponseHeader.ContentType, KeyValueFormContentType);
					wr = new Response(code, headers, ProtocolMessages.KeyValueForm.GetBytes(message.EncodedFields), message);
					break;
				case EncodingType.IndirectMessage:
					Logger.DebugFormat("Sending indirect message:{0}{1}",
						Environment.NewLine, Util.ToString(message.EncodedFields));
					// TODO: either redirect or do a form POST depending on payload size.
					Debug.Assert(message.RedirectUrl != null);
					if (getSizeOfPayload(message) <= GetToPostThreshold)
						wr = Create301RedirectResponse(message);
					else
						wr = CreateFormPostResponse(message);
					break;
				default:
					Logger.ErrorFormat("Cannot encode response: {0}", message);
					wr = new Response(HttpStatusCode.BadRequest, headers, new byte[0], message);
					break;
			}
			return wr;
		}
コード例 #34
-1
ファイル: MessageEncoder.cs プロジェクト: Belxjander/Asuna
		protected virtual Response CreateFormPostResponse(IEncodable message) {
			WebHeaderCollection headers = new WebHeaderCollection();
			MemoryStream body = new MemoryStream();
			StreamWriter bodyWriter = new StreamWriter(body);
			StringBuilder hiddenFields = new StringBuilder();
			foreach (var field in message.EncodedFields) {
				hiddenFields.AppendFormat("\t<input type=\"hidden\" name=\"{0}\" value=\"{1}\" />\r\n",
					HttpUtility.HtmlEncode(field.Key), HttpUtility.HtmlEncode(field.Value));
			}
			bodyWriter.WriteLine(FormPostFormat,
				HttpUtility.HtmlEncode(message.RedirectUrl.AbsoluteUri), hiddenFields);
			bodyWriter.Flush();
			return new Response(HttpStatusCode.OK, headers, body.ToArray(), message);
		}
コード例 #35
-1
	public static void DecodeCopy(IEncodable encodable, IEncodable toCopy)
	{
		Decode(encodable, Encode(toCopy.Encode()));
	}
コード例 #36
-1
	public static string Encode(IEncodable encodable)
	{
		return Encode(encodable.Encode());
	}
コード例 #37
-1
 public ExtensionObject(IEncodable body)
 {
     this.Body = body;
     this.BodyType = body != null ? BodyType.Encodable : BodyType.None;
 }
コード例 #38
-1
ファイル: FaultyRequest.cs プロジェクト: tt/dotnetopenid
 internal FaultyRequest(OpenIdProvider provider, IEncodable response)
     : base(provider)
 {
     Response = response;
 }
コード例 #39
-1
	public static void Decode(IEncodable encodable, Encoding encodedElement)
	{
		encodable.Decode(encodedElement);
	}
コード例 #40
-1
ファイル: MessageEncoder.cs プロジェクト: Belxjander/Asuna
		protected virtual Response Create301RedirectResponse(IEncodable message) {
			WebHeaderCollection headers = new WebHeaderCollection();
			UriBuilder builder = new UriBuilder(message.RedirectUrl);
			UriUtil.AppendQueryArgs(builder, message.EncodedFields);
			headers.Add(HttpResponseHeader.Location, builder.Uri.AbsoluteUri);
			Logger.DebugFormat("Redirecting to {0}", builder.Uri.AbsoluteUri);
			return new Response(HttpStatusCode.Redirect, headers, new byte[0], message);
		}
コード例 #41
-1
ファイル: MessageEncoder.cs プロジェクト: Belxjander/Asuna
		static int getSizeOfPayload(IEncodable message) {
			Debug.Assert(message != null);
			int size = 0;
			foreach (var field in message.EncodedFields) {
				size += field.Key.Length;
				size += field.Value.Length;
			}
			return size;
		}
コード例 #42
-1
ファイル: MessageEncoder.cs プロジェクト: Belxjander/Asuna
		public EncodeEventArgs(IEncodable encodable) {
			Message = encodable;
		}
コード例 #43
-1
	public static void Decode(IEncodable encodable, string encodedString)
	{
//		Debug.Log ("Decoding string \""+encodedString+"\"");
		encodable.Decode(new Encoding(encodedString));
	}