From 5991cec92d07516db5bbf01543df538f7137fcd3 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Wed, 13 May 2020 03:31:42 +0300 Subject: [PATCH] Enum --- Esyur/Data/Codec.cs | 41 ++++++++++++++++++++----- Esyur/Net/HTTP/HTTPConnection.cs | 4 ++- Esyur/Net/Packets/HTTPResponsePacket.cs | 4 +-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Esyur/Data/Codec.cs b/Esyur/Data/Codec.cs index f7d090a..73f98f6 100644 --- a/Esyur/Data/Codec.cs +++ b/Esyur/Data/Codec.cs @@ -1172,20 +1172,30 @@ namespace Esyur.Data if (value is IUserType) value = (value as IUserType).Get(); - + // value = (List<>)value.ToArray(); if (value is Func) //if (connection != null) - value = (value as Func)(connection); - //else - // return (DataType.Void, null); + value = (value as Func)(connection); + //else + // return (DataType.Void, null); else if (value is DistributedPropertyContext) - //if (connection != null) + { + try + { + //if (connection != null) value = (value as DistributedPropertyContext).Method(connection); - //else + //else + } + catch(Exception ex) + { + Global.Log(ex); + return (DataType.Void, null); + } // return (DataType.Void, null); - + } + if (value == null) return (DataType.Void, null); @@ -1208,10 +1218,27 @@ namespace Esyur.Data var isArray = t.IsArray; if (isArray) + { t = t.GetElementType(); + if (t.IsEnum) + { + var src = value as Array; + t = t.GetEnumUnderlyingType(); + var dst = Array.CreateInstance(t, src.Length); + src.CopyTo(dst, 0); + value = dst; + } + } + else if (t.IsEnum) + { + t = t.GetEnumUnderlyingType(); + value = Convert.ChangeType(value, t); + } DataType type; + + if (t == typeof(bool)) type = DataType.Bool; else if (t == typeof(char)) diff --git a/Esyur/Net/HTTP/HTTPConnection.cs b/Esyur/Net/HTTP/HTTPConnection.cs index d5e3b26..c2acabc 100644 --- a/Esyur/Net/HTTP/HTTPConnection.cs +++ b/Esyur/Net/HTTP/HTTPConnection.cs @@ -268,8 +268,10 @@ namespace Esyur.Net.HTTP if ((fileEditTime - ims).TotalSeconds < 2) { Response.Number = HTTPResponsePacket.ResponseCode.NotModified; + Response.Headers.Clear(); //Response.Text = "Not Modified"; - Send((byte[])null); + Send(HTTPResponsePacket.ComposeOptions.SpecifiedHeadersOnly); + return true; } } catch diff --git a/Esyur/Net/Packets/HTTPResponsePacket.cs b/Esyur/Net/Packets/HTTPResponsePacket.cs index 2f4f085..01b22fa 100644 --- a/Esyur/Net/Packets/HTTPResponsePacket.cs +++ b/Esyur/Net/Packets/HTTPResponsePacket.cs @@ -139,8 +139,8 @@ namespace Esyur.Net.Packets { string header = $"{Version} {(int)Number} {Text}\r\nServer: Esyur {Global.Version}\r\nDate: {DateTime.Now.ToUniversalTime().ToString("r")}\r\n"; - if (options == ComposeOptions.AllCalculateLength && Message != null) - Headers["Content-Length"] = Message.Length.ToString(); + if (options == ComposeOptions.AllCalculateLength) + Headers["Content-Length"] = Message?.Length.ToString() ?? "0"; foreach (var kv in Headers) header += kv.Key + ": " + kv.Value + "\r\n";