From ba904f5df968fadf203c8005fabcd6b5f032d905 Mon Sep 17 00:00:00 2001 From: akpaevj Date: Sat, 7 Dec 2024 02:29:21 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=92=20=D0=B2=D0=B5=D0=B1-=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B5=D1=80=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D1=81=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCollectionWrapper.cs | 80 ++++++++ .../FormFileCollectionWrapper.cs | 65 ++++++ src/OneScript.Web.Server/FormFileWrapper.cs | 47 +++++ .../HeaderDictionaryWrapper.cs | 194 +++++++++--------- .../HttpRequestWrapper.cs | 23 ++- .../HttpResponseWrapper.cs | 2 +- .../StringValuesWrapper.cs | 79 +++++++ .../WebSocketAcceptContextWrapper.cs | 4 +- 8 files changed, 389 insertions(+), 105 deletions(-) create mode 100644 src/OneScript.Web.Server/FormCollectionWrapper.cs create mode 100644 src/OneScript.Web.Server/FormFileCollectionWrapper.cs create mode 100644 src/OneScript.Web.Server/FormFileWrapper.cs create mode 100644 src/OneScript.Web.Server/StringValuesWrapper.cs diff --git a/src/OneScript.Web.Server/FormCollectionWrapper.cs b/src/OneScript.Web.Server/FormCollectionWrapper.cs new file mode 100644 index 000000000..b5c3e271b --- /dev/null +++ b/src/OneScript.Web.Server/FormCollectionWrapper.cs @@ -0,0 +1,80 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Http; +using OneScript.Contexts; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; +using OneScript.StandardLibrary.Collections; +using System.Collections.Generic; +using OneScript.StandardLibrary.Binary; +using Microsoft.Extensions.Primitives; + +namespace OneScript.Web.Server +{ + [ContextClass("Форма", "Form")] + public class FormCollectionWrapper : AutoCollectionContext + { + private readonly IFormCollection _items; + + internal FormCollectionWrapper(IFormCollection headers) + { + _items = headers; + } + + public override bool IsIndexed => true; + + public override StringValuesWrapper GetIndexedValue(IValue index) + { + if (_items.TryGetValue(index.AsString(), out var result)) + return result; + else + return StringValues.Empty; + } + + internal bool ContainsKey(IValue key) + { + return _items.ContainsKey(key.AsString()); + } + + public IEnumerable Keys() + { + foreach (var key in _items.Keys) + yield return ValueFactory.Create(key); + } + + #region ICollectionContext Members + + [ContextMethod("Получить", "Get")] + public StringValuesWrapper Retrieve(IValue key) + { + return GetIndexedValue(key); + } + + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _items.Count; + } + + #endregion + + #region IEnumerable Members + + public override IEnumerator GetEnumerator() + { + foreach (var item in _items) + { + yield return new KeyAndValueImpl(ValueFactory.Create(item.Key), (StringValuesWrapper)item.Value); + } + } + + #endregion + + [ContextProperty("Файлы", "Files", CanWrite = false)] + public FormFileCollectionWrapper Files => new(_items.Files); + } +} diff --git a/src/OneScript.Web.Server/FormFileCollectionWrapper.cs b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs new file mode 100644 index 000000000..faaa576a9 --- /dev/null +++ b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs @@ -0,0 +1,65 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Http; +using OneScript.Contexts; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; +using System.Collections.Generic; +using OneScript.Values; +using OneScript.StandardLibrary.Collections; + +namespace OneScript.Web.Server +{ + [ContextClass("ФайлыФормы", "FormFiles")] + public class FormFileCollectionWrapper : AutoCollectionContext + { + private readonly IFormFileCollection _items; + + internal FormFileCollectionWrapper(IFormFileCollection items) + { + _items = items; + } + + public override bool IsIndexed => true; + + public override IValue GetIndexedValue(IValue index) + { + var result = _items.GetFile(index.AsString()); + + if (result == null) + return BslNullValue.Instance; + else + return new FormFileWrapper(result); + } + + #region ICollectionContext Members + + [ContextMethod("Получить", "Get")] + public IValue Retrieve(IValue key) + { + return GetIndexedValue(key); + } + + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _items.Count; + } + + #endregion + + #region IEnumerable Members + + public override IEnumerator GetEnumerator() + { + foreach (var item in _items) + yield return new FormFileWrapper(item); + } + + #endregion + } +} diff --git a/src/OneScript.Web.Server/FormFileWrapper.cs b/src/OneScript.Web.Server/FormFileWrapper.cs new file mode 100644 index 000000000..79a291d21 --- /dev/null +++ b/src/OneScript.Web.Server/FormFileWrapper.cs @@ -0,0 +1,47 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using Microsoft.AspNetCore.Http; +using OneScript.Contexts; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; +using OneScript.Values; +using OneScript.StandardLibrary.Binary; + +namespace OneScript.Web.Server +{ + [ContextClass("ФайлФормы", "FormFile")] + public class FormFileWrapper : AutoContext + { + private readonly IFormFile _item; + + internal FormFileWrapper(IFormFile item) + { + _item = item; + } + + [ContextProperty("ТипКонтента", "ContentType", CanWrite = false)] + public IValue ContentType => BslStringValue.Create(_item.ContentType); + + [ContextProperty("РасположениеКонтента", "ContentDisposition", CanWrite = false)] + public IValue ContentDisposition => BslStringValue.Create(_item.ContentDisposition); + + [ContextProperty("Заголовки", "Headers", CanWrite = false)] + public HeaderDictionaryWrapper Headers => new(_item.Headers); + + [ContextProperty("Длина", "Length", CanWrite = false)] + public IValue Length => BslNumericValue.Create(_item.Length); + + [ContextProperty("Имя", "Name", CanWrite = false)] + public IValue Name => BslStringValue.Create(_item.Name); + + [ContextProperty("ИмяФайла", "FileName", CanWrite = false)] + public IValue FileName => BslStringValue.Create(_item.FileName); + + [ContextMethod("ОткрытьПотокЧтения", "OpenReadStream")] + public GenericStream OpenReadStream() => new(_item.OpenReadStream()); + } +} diff --git a/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs b/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs index 96c29a523..90e823b8b 100644 --- a/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs +++ b/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs @@ -14,6 +14,7 @@ This Source Code Form is subject to the terms of the using System.Linq; using OneScript.StandardLibrary.Collections; using OneScript.Types; +using Microsoft.Extensions.Primitives; namespace OneScript.Web.Server { @@ -22,274 +23,273 @@ public class HeaderDictionaryWrapper : AutoCollectionContext _items.Accept; + public StringValuesWrapper Accept => _items.Accept; [ContextProperty("AcceptCharset", CanWrite = false)] - public string AcceptCharset => _items.AcceptCharset; + public StringValuesWrapper AcceptCharset => _items.AcceptCharset; [ContextProperty("AcceptEncoding", CanWrite = false)] - public string AcceptEncoding => _items.AcceptEncoding; + public StringValuesWrapper AcceptEncoding => _items.AcceptEncoding; [ContextProperty("AcceptLanguage", CanWrite = false)] - public string AcceptLanguage => _items.AcceptLanguage; + public StringValuesWrapper AcceptLanguage => _items.AcceptLanguage; [ContextProperty("AcceptRanges", CanWrite = false)] - public string AcceptRanges => _items.AcceptRanges; + public StringValuesWrapper AcceptRanges => _items.AcceptRanges; [ContextProperty("AccessControlAllowCredentials", CanWrite = false)] - public string AccessControlAllowCredentials => _items.AccessControlAllowCredentials; + public StringValuesWrapper AccessControlAllowCredentials => _items.AccessControlAllowCredentials; [ContextProperty("AccessControlAllowHeaders", CanWrite = false)] - public string AccessControlAllowHeaders => _items.AccessControlAllowHeaders; + public StringValuesWrapper AccessControlAllowHeaders => _items.AccessControlAllowHeaders; [ContextProperty("AccessControlAllowMethods", CanWrite = false)] - public string AccessControlAllowMethods => _items.AccessControlAllowMethods; + public StringValuesWrapper AccessControlAllowMethods => _items.AccessControlAllowMethods; [ContextProperty("AccessControlAllowOrigin", CanWrite = false)] - public string AccessControlAllowOrigin => _items.AccessControlAllowOrigin; + public StringValuesWrapper AccessControlAllowOrigin => _items.AccessControlAllowOrigin; [ContextProperty("AccessControlExposeHeaders", CanWrite = false)] - public string AccessControlExposeHeaders => _items.AccessControlExposeHeaders; + public StringValuesWrapper AccessControlExposeHeaders => _items.AccessControlExposeHeaders; [ContextProperty("AccessControlMaxAge", CanWrite = false)] - public string AccessControlMaxAge => _items.AccessControlMaxAge; + public StringValuesWrapper AccessControlMaxAge => _items.AccessControlMaxAge; [ContextProperty("AccessControlRequestHeaders", CanWrite = false)] - public string AccessControlRequestHeaders => _items.AccessControlRequestHeaders; + public StringValuesWrapper AccessControlRequestHeaders => _items.AccessControlRequestHeaders; [ContextProperty("AccessControlRequestMethod", CanWrite = false)] - public string AccessControlRequestMethod => _items.AccessControlRequestMethod; + public StringValuesWrapper AccessControlRequestMethod => _items.AccessControlRequestMethod; [ContextProperty("Age", CanWrite = false)] - public string Age => _items.Age; + public StringValuesWrapper Age => _items.Age; [ContextProperty("Allow", CanWrite = false)] - public string Allow => _items.Allow; + public StringValuesWrapper Allow => _items.Allow; [ContextProperty("AltSvc", CanWrite = false)] - public string AltSvc => _items.AltSvc; + public StringValuesWrapper AltSvc => _items.AltSvc; [ContextProperty("Authorization", CanWrite = false)] - public string Authorization => _items.Authorization; + public StringValuesWrapper Authorization => _items.Authorization; [ContextProperty("Baggage", CanWrite = false)] - public string Baggage => _items.Baggage; + public StringValuesWrapper Baggage => _items.Baggage; [ContextProperty("CacheControl", CanWrite = false)] - public string CacheControl => _items.CacheControl; + public StringValuesWrapper CacheControl => _items.CacheControl; [ContextProperty("Connection", CanWrite = false)] - public string Connection => _items.Connection; + public StringValuesWrapper Connection => _items.Connection; [ContextProperty("ContentDisposition", CanWrite = false)] - public string ContentDisposition => _items.ContentDisposition; + public StringValuesWrapper ContentDisposition => _items.ContentDisposition; [ContextProperty("ContentEncoding", CanWrite = false)] - public string ContentEncoding => _items.ContentEncoding; + public StringValuesWrapper ContentEncoding => _items.ContentEncoding; [ContextProperty("ContentLanguage", CanWrite = false)] - public string ContentLanguage => _items.ContentLanguage; + public StringValuesWrapper ContentLanguage => _items.ContentLanguage; public long? ContentLength => _items.ContentLength; [ContextProperty("ContentLocation", CanWrite = false)] - public string ContentLocation => _items.ContentLocation; + public StringValuesWrapper ContentLocation => _items.ContentLocation; [ContextProperty("ContentMD5", CanWrite = false)] - public string ContentMD5 => _items.ContentMD5; + public StringValuesWrapper ContentMD5 => _items.ContentMD5; [ContextProperty("ContentRange", CanWrite = false)] - public string ContentRange => _items.ContentRange; + public StringValuesWrapper ContentRange => _items.ContentRange; [ContextProperty("ContentSecurityPolicy", CanWrite = false)] - public string ContentSecurityPolicy => _items.ContentSecurityPolicy; + public StringValuesWrapper ContentSecurityPolicy => _items.ContentSecurityPolicy; [ContextProperty("ContentSecurityPolicyReportOnly", CanWrite = false)] - public string ContentSecurityPolicyReportOnly => _items.ContentSecurityPolicyReportOnly; + public StringValuesWrapper ContentSecurityPolicyReportOnly => _items.ContentSecurityPolicyReportOnly; [ContextProperty("ContentType", CanWrite = false)] - public string ContentType => _items.ContentType; + public StringValuesWrapper ContentType => _items.ContentType; [ContextProperty("Cookie", CanWrite = false)] - public string Cookie => _items.Cookie; + public StringValuesWrapper Cookie => _items.Cookie; [ContextProperty("CorrelationContext", CanWrite = false)] - public string CorrelationContext => _items.CorrelationContext; + public StringValuesWrapper CorrelationContext => _items.CorrelationContext; [ContextProperty("Date", CanWrite = false)] - public string Date => _items.Date; + public StringValuesWrapper Date => _items.Date; [ContextProperty("ETag", CanWrite = false)] - public string ETag => _items.ETag; + public StringValuesWrapper ETag => _items.ETag; [ContextProperty("Expect", CanWrite = false)] - public string Expect => _items.Expect; + public StringValuesWrapper Expect => _items.Expect; [ContextProperty("Expires", CanWrite = false)] - public string Expires => _items.Expires; + public StringValuesWrapper Expires => _items.Expires; [ContextProperty("From", CanWrite = false)] - public string From => _items.From; + public StringValuesWrapper From => _items.From; [ContextProperty("GrpcAcceptEncoding", CanWrite = false)] - public string GrpcAcceptEncoding => _items.GrpcAcceptEncoding; + public StringValuesWrapper GrpcAcceptEncoding => _items.GrpcAcceptEncoding; [ContextProperty("GrpcEncoding", CanWrite = false)] - public string GrpcEncoding => _items.GrpcEncoding; + public StringValuesWrapper GrpcEncoding => _items.GrpcEncoding; [ContextProperty("GrpcMessage", CanWrite = false)] - public string GrpcMessage => _items.GrpcMessage; + public StringValuesWrapper GrpcMessage => _items.GrpcMessage; [ContextProperty("GrpcStatus", CanWrite = false)] - public string GrpcStatus => _items.GrpcStatus; + public StringValuesWrapper GrpcStatus => _items.GrpcStatus; [ContextProperty("GrpcTimeout", CanWrite = false)] - public string GrpcTimeout => _items.GrpcTimeout; + public StringValuesWrapper GrpcTimeout => _items.GrpcTimeout; [ContextProperty("Host", CanWrite = false)] - public string Host => _items.Host; + public StringValuesWrapper Host => _items.Host; [ContextProperty("IfMatch", CanWrite = false)] - public string IfMatch => _items.IfMatch; + public StringValuesWrapper IfMatch => _items.IfMatch; [ContextProperty("IfModifiedSince", CanWrite = false)] - public string IfModifiedSince => _items.IfModifiedSince; + public StringValuesWrapper IfModifiedSince => _items.IfModifiedSince; [ContextProperty("IfNoneMatch", CanWrite = false)] - public string IfNoneMatch => _items.IfNoneMatch; + public StringValuesWrapper IfNoneMatch => _items.IfNoneMatch; [ContextProperty("IfRange", CanWrite = false)] - public string IfRange => _items.IfRange; + public StringValuesWrapper IfRange => _items.IfRange; [ContextProperty("IfUnmodifiedSince", CanWrite = false)] - public string IfUnmodifiedSince => _items.IfUnmodifiedSince; + public StringValuesWrapper IfUnmodifiedSince => _items.IfUnmodifiedSince; [ContextProperty("KeepAlive", CanWrite = false)] - public string KeepAlive => _items.KeepAlive; + public StringValuesWrapper KeepAlive => _items.KeepAlive; [ContextProperty("LastModified", CanWrite = false)] - public string LastModified => _items.LastModified; + public StringValuesWrapper LastModified => _items.LastModified; [ContextProperty("Link", CanWrite = false)] - public string Link => _items.Link; + public StringValuesWrapper Link => _items.Link; [ContextProperty("Location", CanWrite = false)] - public string Location => _items.Location; + public StringValuesWrapper Location => _items.Location; [ContextProperty("MaxForwards", CanWrite = false)] - public string MaxForwards => _items.MaxForwards; + public StringValuesWrapper MaxForwards => _items.MaxForwards; [ContextProperty("Origin", CanWrite = false)] - public string Origin => _items.Origin; + public StringValuesWrapper Origin => _items.Origin; [ContextProperty("Pragma", CanWrite = false)] - public string Pragma => _items.Pragma; + public StringValuesWrapper Pragma => _items.Pragma; [ContextProperty("ProxyAuthenticate", CanWrite = false)] - public string ProxyAuthenticate => _items.ProxyAuthenticate; + public StringValuesWrapper ProxyAuthenticate => _items.ProxyAuthenticate; [ContextProperty("ProxyAuthorization", CanWrite = false)] - public string ProxyAuthorization => _items.ProxyAuthorization; + public StringValuesWrapper ProxyAuthorization => _items.ProxyAuthorization; [ContextProperty("ProxyConnection", CanWrite = false)] - public string ProxyConnection => _items.ProxyConnection; + public StringValuesWrapper ProxyConnection => _items.ProxyConnection; [ContextProperty("Range", CanWrite = false)] - public string Range => _items.Range; + public StringValuesWrapper Range => _items.Range; [ContextProperty("Referer", CanWrite = false)] - public string Referer => _items.Referer; + public StringValuesWrapper Referer => _items.Referer; [ContextProperty("RequestId", CanWrite = false)] - public string RequestId => _items.RequestId; + public StringValuesWrapper RequestId => _items.RequestId; [ContextProperty("RetryAfter", CanWrite = false)] - public string RetryAfter => _items.RetryAfter; + public StringValuesWrapper RetryAfter => _items.RetryAfter; [ContextProperty("SecWebSocketAccept", CanWrite = false)] - public string SecWebSocketAccept => _items.SecWebSocketAccept; + public StringValuesWrapper SecWebSocketAccept => _items.SecWebSocketAccept; [ContextProperty("SecWebSocketExtensions", CanWrite = false)] - public string SecWebSocketExtensions => _items.SecWebSocketExtensions; + public StringValuesWrapper SecWebSocketExtensions => _items.SecWebSocketExtensions; [ContextProperty("SecWebSocketKey", CanWrite = false)] - public string SecWebSocketKey => _items.SecWebSocketKey; + public StringValuesWrapper SecWebSocketKey => _items.SecWebSocketKey; [ContextProperty("SecWebSocketProtocol", CanWrite = false)] - public string SecWebSocketProtocol => _items.SecWebSocketProtocol; + public StringValuesWrapper SecWebSocketProtocol => _items.SecWebSocketProtocol; [ContextProperty("SecWebSocketVersion", CanWrite = false)] - public string SecWebSocketVersion => _items.SecWebSocketVersion; + public StringValuesWrapper SecWebSocketVersion => _items.SecWebSocketVersion; [ContextProperty("Server", CanWrite = false)] - public string Server => _items.Server; + public StringValuesWrapper Server => _items.Server; [ContextProperty("SetCookie", CanWrite = false)] - public string SetCookie => _items.SetCookie; + public StringValuesWrapper SetCookie => _items.SetCookie; [ContextProperty("StrictTransportSecurity", CanWrite = false)] - public string StrictTransportSecurity => _items.StrictTransportSecurity; + public StringValuesWrapper StrictTransportSecurity => _items.StrictTransportSecurity; [ContextProperty("TE", CanWrite = false)] - public string TE => _items.TE; + public StringValuesWrapper TE => _items.TE; [ContextProperty("TraceParent", CanWrite = false)] - public string TraceParent => _items.TraceParent; + public StringValuesWrapper TraceParent => _items.TraceParent; [ContextProperty("TraceState", CanWrite = false)] - public string TraceState => _items.TraceState; + public StringValuesWrapper TraceState => _items.TraceState; [ContextProperty("Trailer", CanWrite = false)] - public string Trailer => _items.Trailer; + public StringValuesWrapper Trailer => _items.Trailer; [ContextProperty("TransferEncoding", CanWrite = false)] - public string TransferEncoding => _items.TransferEncoding; + public StringValuesWrapper TransferEncoding => _items.TransferEncoding; [ContextProperty("Translate", CanWrite = false)] - public string Translate => _items.Translate; + public StringValuesWrapper Translate => _items.Translate; [ContextProperty("Upgrade", CanWrite = false)] - public string Upgrade => _items.Upgrade; + public StringValuesWrapper Upgrade => _items.Upgrade; [ContextProperty("UpgradeInsecureRequests", CanWrite = false)] - public string UpgradeInsecureRequests => _items.UpgradeInsecureRequests; + public StringValuesWrapper UpgradeInsecureRequests => _items.UpgradeInsecureRequests; [ContextProperty("UserAgent", CanWrite = false)] - public string UserAgent => _items.UserAgent; + public StringValuesWrapper UserAgent => _items.UserAgent; [ContextProperty("Vary", CanWrite = false)] - public string Vary => _items.Vary; + public StringValuesWrapper Vary => _items.Vary; [ContextProperty("Via", CanWrite = false)] - public string Via => _items.Via; + public StringValuesWrapper Via => _items.Via; [ContextProperty("Warning", CanWrite = false)] - public string Warning => _items.Warning; + public StringValuesWrapper Warning => _items.Warning; [ContextProperty("WebSocketSubProtocols", CanWrite = false)] - public string WebSocketSubProtocols => _items.WebSocketSubProtocols; + public StringValuesWrapper WebSocketSubProtocols => _items.WebSocketSubProtocols; [ContextProperty("WWWAuthenticate", CanWrite = false)] - public string WWWAuthenticate => _items.WWWAuthenticate; + public StringValuesWrapper WWWAuthenticate => _items.WWWAuthenticate; [ContextProperty("XContentTypeOptions", CanWrite = false)] - public string XContentTypeOptions => _items.XContentTypeOptions; + public StringValuesWrapper XContentTypeOptions => _items.XContentTypeOptions; [ContextProperty("XFrameOptions", CanWrite = false)] - public string XFrameOptions => _items.XFrameOptions; + public StringValuesWrapper XFrameOptions => _items.XFrameOptions; [ContextProperty("XPoweredBy", CanWrite = false)] - public string XPoweredBy => _items.XPoweredBy; + public StringValuesWrapper XPoweredBy => _items.XPoweredBy; [ContextProperty("XRequestedWith", CanWrite = false)] - public string XRequestedWith => _items.XRequestedWith; + public StringValuesWrapper XRequestedWith => _items.XRequestedWith; [ContextProperty("XUACompatible", CanWrite = false)] - public string XUACompatible => _items.XUACompatible; + public StringValuesWrapper XUACompatible => _items.XUACompatible; [ContextProperty("XXSSProtection", CanWrite = false)] - public string XXSSProtection => _items.XXSSProtection; + public StringValuesWrapper XXSSProtection => _items.XXSSProtection; public HeaderDictionaryWrapper(IHeaderDictionary headers) { @@ -304,13 +304,13 @@ public override bool IsIndexed } } - public override IValue GetIndexedValue(IValue index) + public override StringValuesWrapper GetIndexedValue(IValue index) { - if (_items.TryGetValue(index.AsString(), out var result)) - return ValueFactory.Create(result); - else - return ValueFactory.Create(); - } + if (_items.TryGetValue(index.AsString(), out var result)) + return result; + else + return StringValues.Empty; + } public override void SetIndexedValue(IValue index, IValue val) { @@ -362,7 +362,7 @@ public override IEnumerator GetEnumerator() { foreach (var item in _items) { - yield return new KeyAndValueImpl(ValueFactory.Create(item.Key), ValueFactory.Create(item.Value)); + yield return new KeyAndValueImpl(ValueFactory.Create(item.Key), (StringValuesWrapper)item.Value); } } diff --git a/src/OneScript.Web.Server/HttpRequestWrapper.cs b/src/OneScript.Web.Server/HttpRequestWrapper.cs index 7a1fd710e..effc1af81 100644 --- a/src/OneScript.Web.Server/HttpRequestWrapper.cs +++ b/src/OneScript.Web.Server/HttpRequestWrapper.cs @@ -20,10 +20,11 @@ This Source Code Form is subject to the terms of the using System.Text; using System.Threading.Tasks; using OneScript.StandardLibrary.Collections; +using OneScript.Types; namespace OneScript.Web.Server { - [ContextClass("HTTPСервисЗапрос", "HTTPServiceRequest")] + [ContextClass("HTTPСервисЗапрос", "HTTPServiceRequest")] public class HttpRequestWrapper : AutoContext { private readonly HttpRequest _request; @@ -40,7 +41,7 @@ public HttpRequestWrapper(HttpRequest request) public IValue HasFormContentType => BslBooleanValue.Create(_request.HasFormContentType); [ContextProperty("Тело", "Body", CanWrite = false)] - public GenericStream Body => new GenericStream(_request.Body); + public GenericStream Body => new(_request.Body); [ContextProperty("ТипКонтента", "ContentType", CanWrite = false)] public IValue ContentType @@ -67,10 +68,10 @@ public IValue ContentLength } [ContextProperty("Куки", "Cookie", CanWrite = false)] - public RequestCookieCollectionWrapper Cookies => new RequestCookieCollectionWrapper(_request.Cookies); + public RequestCookieCollectionWrapper Cookies => new(_request.Cookies); [ContextProperty("Заголовки", "Headers", CanWrite = false)] - public HeaderDictionaryWrapper Headers => new HeaderDictionaryWrapper(_request.Headers); + public HeaderDictionaryWrapper Headers => new(_request.Headers); [ContextProperty("Протокол", "Protocol", CanWrite = false)] public IValue Protocol => BslStringValue.Create(_request.Protocol); @@ -131,5 +132,17 @@ public IValue Host [ContextProperty("Метод", "Method", CanWrite = false)] public IValue Method => BslStringValue.Create(_request.Method); - } + + [ContextProperty("Форма", "Form", CanWrite = false)] + public IValue Form + { + get + { + if (_request.HasFormContentType) + return new FormCollectionWrapper(_request.Form); + else + return BslNullValue.Instance; + } + } + } } diff --git a/src/OneScript.Web.Server/HttpResponseWrapper.cs b/src/OneScript.Web.Server/HttpResponseWrapper.cs index 153d66f8f..f7afd802d 100644 --- a/src/OneScript.Web.Server/HttpResponseWrapper.cs +++ b/src/OneScript.Web.Server/HttpResponseWrapper.cs @@ -60,7 +60,7 @@ public IValue ContentLength } [ContextProperty("Тело", "Body", CanWrite = false)] - public GenericStream Body => new GenericStream(_response.Body); + public GenericStream Body => new(_response.Body); [ContextProperty("Заголовки", "Headers", CanWrite = false)] public HeaderDictionaryWrapper Headers => new HeaderDictionaryWrapper(_response.Headers); diff --git a/src/OneScript.Web.Server/StringValuesWrapper.cs b/src/OneScript.Web.Server/StringValuesWrapper.cs new file mode 100644 index 000000000..ae242bea6 --- /dev/null +++ b/src/OneScript.Web.Server/StringValuesWrapper.cs @@ -0,0 +1,79 @@ +/*---------------------------------------------------------- +This Source Code Form is subject to the terms of the +Mozilla Public License, v.2.0. If a copy of the MPL +was not distributed with this file, You can obtain one +at http://mozilla.org/MPL/2.0/. +----------------------------------------------------------*/ +using OneScript.Contexts; +using ScriptEngine.Machine; +using ScriptEngine.Machine.Contexts; +using System.Collections.Generic; +using OneScript.Values; +using Microsoft.Extensions.Primitives; + +namespace OneScript.Web.Server +{ + [ContextClass("СтроковыеЗначения", "StringValues")] + public class StringValuesWrapper : AutoCollectionContext + { + private readonly StringValues _value; + + public static implicit operator StringValues(StringValuesWrapper d) => d._value; + public static implicit operator StringValuesWrapper(StringValues b) => new(b); + + internal StringValuesWrapper(StringValues value) + { + _value = value; + } + + public override bool IsIndexed => true; + + public override IValue GetIndexedValue(IValue index) + { + var value = (int)index.AsNumber(); + + return ValueFactory.Create(_value[value]); + } + + #region ICollectionContext Members + + [ContextMethod("Получить", "Get")] + public IValue Retrieve(IValue key) + { + return GetIndexedValue(key); + } + + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _value.Count; + } + + #endregion + + #region IEnumerable Members + + public override IEnumerator GetEnumerator() + { + foreach (var item in _value) + yield return BslStringValue.Create(item); + } + + #endregion + + protected override string ConvertToString() + { + return _value.ToString(); + } + + public override string ToString() + { + return _value.ToString(); + } + + public override int GetHashCode() + { + return _value.GetHashCode(); + } + } +} diff --git a/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs b/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs index 0ccfd67f9..00ccef077 100644 --- a/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs +++ b/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs @@ -19,7 +19,7 @@ namespace OneScript.Web.Server.WebSockets [ContextClass("КонтекстПодключенияВебСокета", "WebSocketsAcceptContext")] public class WebSocketAcceptContextWrapper : AutoContext { - internal readonly WebSocketAcceptContext _context = new WebSocketAcceptContext(); + internal readonly WebSocketAcceptContext _context = new(); /// /// Согласовываемый субпротокол @@ -29,7 +29,7 @@ public IValue Protocol { get { - return _context.SubProtocol == null ? BslNullValue.Instance : (IValue)BslStringValue.Create(_context.SubProtocol); + return _context.SubProtocol == null ? BslNullValue.Instance : BslStringValue.Create(_context.SubProtocol); } set { From 62f1394118ff3b4dbb4e8ab198597b40c0121bd1 Mon Sep 17 00:00:00 2001 From: akpaevj Date: Tue, 10 Dec 2024 20:42:43 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D1=81=D1=82=D1=83=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormCollectionWrapper.cs | 96 +++++++++---------- .../FormFileCollectionWrapper.cs | 74 +++++++------- src/OneScript.Web.Server/FormFileWrapper.cs | 46 ++++----- .../HeaderDictionaryWrapper.cs | 10 +- .../HttpRequestWrapper.cs | 6 +- .../StringValuesWrapper.cs | 96 +++++++++---------- 6 files changed, 164 insertions(+), 164 deletions(-) diff --git a/src/OneScript.Web.Server/FormCollectionWrapper.cs b/src/OneScript.Web.Server/FormCollectionWrapper.cs index b5c3e271b..fee945790 100644 --- a/src/OneScript.Web.Server/FormCollectionWrapper.cs +++ b/src/OneScript.Web.Server/FormCollectionWrapper.cs @@ -15,66 +15,66 @@ This Source Code Form is subject to the terms of the namespace OneScript.Web.Server { - [ContextClass("Форма", "Form")] - public class FormCollectionWrapper : AutoCollectionContext - { - private readonly IFormCollection _items; + [ContextClass("Форма", "Form")] + public class FormCollectionWrapper : AutoCollectionContext + { + private readonly IFormCollection _items; - internal FormCollectionWrapper(IFormCollection headers) - { - _items = headers; - } + internal FormCollectionWrapper(IFormCollection headers) + { + _items = headers; + } public override bool IsIndexed => true; - public override StringValuesWrapper GetIndexedValue(IValue index) - { - if (_items.TryGetValue(index.AsString(), out var result)) - return result; - else - return StringValues.Empty; - } + public override StringValuesWrapper GetIndexedValue(IValue index) + { + if (_items.TryGetValue(index.AsString(), out var result)) + return result; + else + return StringValues.Empty; + } - internal bool ContainsKey(IValue key) - { - return _items.ContainsKey(key.AsString()); - } + internal bool ContainsKey(IValue key) + { + return _items.ContainsKey(key.AsString()); + } - public IEnumerable Keys() - { - foreach (var key in _items.Keys) - yield return ValueFactory.Create(key); - } + public IEnumerable Keys() + { + foreach (var key in _items.Keys) + yield return ValueFactory.Create(key); + } - #region ICollectionContext Members + #region ICollectionContext Members - [ContextMethod("Получить", "Get")] - public StringValuesWrapper Retrieve(IValue key) - { - return GetIndexedValue(key); - } + [ContextMethod("Получить", "Get")] + public StringValuesWrapper Retrieve(IValue key) + { + return GetIndexedValue(key); + } - [ContextMethod("Количество", "Count")] - public override int Count() - { - return _items.Count; - } + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _items.Count; + } - #endregion + #endregion - #region IEnumerable Members + #region IEnumerable Members - public override IEnumerator GetEnumerator() - { - foreach (var item in _items) - { - yield return new KeyAndValueImpl(ValueFactory.Create(item.Key), (StringValuesWrapper)item.Value); - } - } + public override IEnumerator GetEnumerator() + { + foreach (var item in _items) + { + yield return new KeyAndValueImpl(ValueFactory.Create(item.Key), (StringValuesWrapper)item.Value); + } + } - #endregion + #endregion - [ContextProperty("Файлы", "Files", CanWrite = false)] - public FormFileCollectionWrapper Files => new(_items.Files); - } + [ContextProperty("Файлы", "Files", CanWrite = false)] + public FormFileCollectionWrapper Files => new(_items.Files); + } } diff --git a/src/OneScript.Web.Server/FormFileCollectionWrapper.cs b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs index faaa576a9..eaef35f9f 100644 --- a/src/OneScript.Web.Server/FormFileCollectionWrapper.cs +++ b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs @@ -14,52 +14,52 @@ This Source Code Form is subject to the terms of the namespace OneScript.Web.Server { - [ContextClass("ФайлыФормы", "FormFiles")] - public class FormFileCollectionWrapper : AutoCollectionContext - { - private readonly IFormFileCollection _items; + [ContextClass("ФайлыФормы", "FormFiles")] + public class FormFileCollectionWrapper : AutoCollectionContext + { + private readonly IFormFileCollection _items; - internal FormFileCollectionWrapper(IFormFileCollection items) - { - _items = items; - } + internal FormFileCollectionWrapper(IFormFileCollection items) + { + _items = items; + } - public override bool IsIndexed => true; + public override bool IsIndexed => true; - public override IValue GetIndexedValue(IValue index) - { - var result = _items.GetFile(index.AsString()); + public override IValue GetIndexedValue(IValue index) + { + var result = _items.GetFile(index.AsString()); - if (result == null) - return BslNullValue.Instance; - else - return new FormFileWrapper(result); - } + if (result == null) + return BslNullValue.Instance; + else + return new FormFileWrapper(result); + } - #region ICollectionContext Members + #region ICollectionContext Members - [ContextMethod("Получить", "Get")] - public IValue Retrieve(IValue key) - { - return GetIndexedValue(key); - } + [ContextMethod("Получить", "Get")] + public IValue Retrieve(IValue key) + { + return GetIndexedValue(key); + } - [ContextMethod("Количество", "Count")] - public override int Count() - { - return _items.Count; - } + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _items.Count; + } - #endregion + #endregion - #region IEnumerable Members + #region IEnumerable Members - public override IEnumerator GetEnumerator() - { - foreach (var item in _items) - yield return new FormFileWrapper(item); - } + public override IEnumerator GetEnumerator() + { + foreach (var item in _items) + yield return new FormFileWrapper(item); + } - #endregion - } + #endregion + } } diff --git a/src/OneScript.Web.Server/FormFileWrapper.cs b/src/OneScript.Web.Server/FormFileWrapper.cs index 79a291d21..61e4da39c 100644 --- a/src/OneScript.Web.Server/FormFileWrapper.cs +++ b/src/OneScript.Web.Server/FormFileWrapper.cs @@ -13,35 +13,35 @@ This Source Code Form is subject to the terms of the namespace OneScript.Web.Server { - [ContextClass("ФайлФормы", "FormFile")] - public class FormFileWrapper : AutoContext - { - private readonly IFormFile _item; + [ContextClass("ФайлФормы", "FormFile")] + public class FormFileWrapper : AutoContext + { + private readonly IFormFile _item; - internal FormFileWrapper(IFormFile item) - { - _item = item; - } + internal FormFileWrapper(IFormFile item) + { + _item = item; + } - [ContextProperty("ТипКонтента", "ContentType", CanWrite = false)] - public IValue ContentType => BslStringValue.Create(_item.ContentType); + [ContextProperty("ТипКонтента", "ContentType", CanWrite = false)] + public IValue ContentType => BslStringValue.Create(_item.ContentType); - [ContextProperty("РасположениеКонтента", "ContentDisposition", CanWrite = false)] - public IValue ContentDisposition => BslStringValue.Create(_item.ContentDisposition); + [ContextProperty("РасположениеКонтента", "ContentDisposition", CanWrite = false)] + public IValue ContentDisposition => BslStringValue.Create(_item.ContentDisposition); - [ContextProperty("Заголовки", "Headers", CanWrite = false)] - public HeaderDictionaryWrapper Headers => new(_item.Headers); + [ContextProperty("Заголовки", "Headers", CanWrite = false)] + public HeaderDictionaryWrapper Headers => new(_item.Headers); - [ContextProperty("Длина", "Length", CanWrite = false)] - public IValue Length => BslNumericValue.Create(_item.Length); + [ContextProperty("Длина", "Length", CanWrite = false)] + public IValue Length => BslNumericValue.Create(_item.Length); - [ContextProperty("Имя", "Name", CanWrite = false)] - public IValue Name => BslStringValue.Create(_item.Name); + [ContextProperty("Имя", "Name", CanWrite = false)] + public IValue Name => BslStringValue.Create(_item.Name); - [ContextProperty("ИмяФайла", "FileName", CanWrite = false)] - public IValue FileName => BslStringValue.Create(_item.FileName); + [ContextProperty("ИмяФайла", "FileName", CanWrite = false)] + public IValue FileName => BslStringValue.Create(_item.FileName); - [ContextMethod("ОткрытьПотокЧтения", "OpenReadStream")] - public GenericStream OpenReadStream() => new(_item.OpenReadStream()); - } + [ContextMethod("ОткрытьПотокЧтения", "OpenReadStream")] + public GenericStream OpenReadStream() => new(_item.OpenReadStream()); + } } diff --git a/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs b/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs index 90e823b8b..92ce4cebe 100644 --- a/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs +++ b/src/OneScript.Web.Server/HeaderDictionaryWrapper.cs @@ -306,11 +306,11 @@ public override bool IsIndexed public override StringValuesWrapper GetIndexedValue(IValue index) { - if (_items.TryGetValue(index.AsString(), out var result)) - return result; - else - return StringValues.Empty; - } + if (_items.TryGetValue(index.AsString(), out var result)) + return result; + else + return StringValues.Empty; + } public override void SetIndexedValue(IValue index, IValue val) { diff --git a/src/OneScript.Web.Server/HttpRequestWrapper.cs b/src/OneScript.Web.Server/HttpRequestWrapper.cs index effc1af81..1805f6824 100644 --- a/src/OneScript.Web.Server/HttpRequestWrapper.cs +++ b/src/OneScript.Web.Server/HttpRequestWrapper.cs @@ -24,7 +24,7 @@ This Source Code Form is subject to the terms of the namespace OneScript.Web.Server { - [ContextClass("HTTPСервисЗапрос", "HTTPServiceRequest")] + [ContextClass("HTTPСервисЗапрос", "HTTPServiceRequest")] public class HttpRequestWrapper : AutoContext { private readonly HttpRequest _request; @@ -142,7 +142,7 @@ public IValue Form return new FormCollectionWrapper(_request.Form); else return BslNullValue.Instance; - } + } } - } + } } diff --git a/src/OneScript.Web.Server/StringValuesWrapper.cs b/src/OneScript.Web.Server/StringValuesWrapper.cs index ae242bea6..0557b7be6 100644 --- a/src/OneScript.Web.Server/StringValuesWrapper.cs +++ b/src/OneScript.Web.Server/StringValuesWrapper.cs @@ -13,67 +13,67 @@ This Source Code Form is subject to the terms of the namespace OneScript.Web.Server { - [ContextClass("СтроковыеЗначения", "StringValues")] - public class StringValuesWrapper : AutoCollectionContext - { - private readonly StringValues _value; + [ContextClass("СтроковыеЗначения", "StringValues")] + public class StringValuesWrapper : AutoCollectionContext + { + private readonly StringValues _value; - public static implicit operator StringValues(StringValuesWrapper d) => d._value; - public static implicit operator StringValuesWrapper(StringValues b) => new(b); + public static implicit operator StringValues(StringValuesWrapper d) => d._value; + public static implicit operator StringValuesWrapper(StringValues b) => new(b); - internal StringValuesWrapper(StringValues value) - { - _value = value; - } + internal StringValuesWrapper(StringValues value) + { + _value = value; + } - public override bool IsIndexed => true; + public override bool IsIndexed => true; - public override IValue GetIndexedValue(IValue index) - { - var value = (int)index.AsNumber(); + public override IValue GetIndexedValue(IValue index) + { + var value = (int)index.AsNumber(); - return ValueFactory.Create(_value[value]); - } + return ValueFactory.Create(_value[value]); + } - #region ICollectionContext Members + #region ICollectionContext Members - [ContextMethod("Получить", "Get")] - public IValue Retrieve(IValue key) - { - return GetIndexedValue(key); - } + [ContextMethod("Получить", "Get")] + public IValue Retrieve(IValue key) + { + return GetIndexedValue(key); + } - [ContextMethod("Количество", "Count")] - public override int Count() - { - return _value.Count; - } + [ContextMethod("Количество", "Count")] + public override int Count() + { + return _value.Count; + } - #endregion + #endregion - #region IEnumerable Members + #region IEnumerable Members - public override IEnumerator GetEnumerator() - { - foreach (var item in _value) - yield return BslStringValue.Create(item); - } + public override IEnumerator GetEnumerator() + { + foreach (var item in _value) + yield return BslStringValue.Create(item); + } - #endregion + #endregion - protected override string ConvertToString() - { - return _value.ToString(); - } + protected override string ConvertToString() + { + return _value.ToString(); + } - public override string ToString() - { - return _value.ToString(); - } + public override string ToString() + { + return _value.ToString(); + } - public override int GetHashCode() - { - return _value.GetHashCode(); - } - } + public override int GetHashCode() + { + return _value.GetHashCode(); + } + } } From 320db59320fda92925964e3a9e659776caad7253 Mon Sep 17 00:00:00 2001 From: akpaevj Date: Tue, 10 Dec 2024 20:54:22 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=A1=D0=BC=D0=B5=D0=BD=D0=B0=20null=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=9D=D0=B5=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=B2=20=D0=B2=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D0=B8=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=D1=85=20=D0=BC=D0=B5=D1=82=D0=BE?= =?UTF-8?q?=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OneScript.Web.Server/CookieOptionsWrapper.cs | 16 ++++++++-------- .../FormCollectionWrapper.cs | 2 +- .../FormFileCollectionWrapper.cs | 2 +- src/OneScript.Web.Server/HttpRequestWrapper.cs | 14 +++++++------- src/OneScript.Web.Server/HttpResponseWrapper.cs | 2 +- .../WebSockets/WebSocketAcceptContextWrapper.cs | 8 ++++---- .../WebSockets/WebSocketReceiveResultWrapper.cs | 2 +- .../WebSockets/WebSocketWrapper.cs | 8 ++++---- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/OneScript.Web.Server/CookieOptionsWrapper.cs b/src/OneScript.Web.Server/CookieOptionsWrapper.cs index 18384bed7..7417d7089 100644 --- a/src/OneScript.Web.Server/CookieOptionsWrapper.cs +++ b/src/OneScript.Web.Server/CookieOptionsWrapper.cs @@ -24,13 +24,13 @@ public IValue Domain get { if (_cookieOptions.Domain == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslStringValue.Create(_cookieOptions.Domain); } set { - if (value is BslNullValue) + if (value is BslUndefinedValue) _cookieOptions.Domain = null; else _cookieOptions.Domain = value.AsString(); @@ -40,10 +40,10 @@ public IValue Domain [ContextProperty("Путь", "Path")] public IValue Path { - get => _cookieOptions.Path == null ? BslNullValue.Instance : BslStringValue.Create(_cookieOptions.Path); + get => _cookieOptions.Path == null ? BslUndefinedValue.Instance : BslStringValue.Create(_cookieOptions.Path); set { - if (value is BslNullValue) + if (value is BslUndefinedValue) _cookieOptions.Path = null; else _cookieOptions.Path = value.AsString(); @@ -58,11 +58,11 @@ public IValue Expires if (_cookieOptions.Expires.HasValue) return BslDateValue.Create(_cookieOptions.Expires.Value.UtcDateTime); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } set { - if (value is BslNullValue) + if (value is BslUndefinedValue) _cookieOptions.Expires = null; else _cookieOptions.Expires = new DateTimeOffset(value.AsDate()); @@ -98,11 +98,11 @@ public IValue MaxAge if (_cookieOptions.MaxAge.HasValue) return BslNumericValue.Create((decimal)_cookieOptions.MaxAge.Value.TotalSeconds); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } set { - if (value is BslNullValue) + if (value is BslUndefinedValue) _cookieOptions.MaxAge = null; else _cookieOptions.MaxAge = TimeSpan.FromSeconds((double)value.AsNumber()); diff --git a/src/OneScript.Web.Server/FormCollectionWrapper.cs b/src/OneScript.Web.Server/FormCollectionWrapper.cs index fee945790..031e12949 100644 --- a/src/OneScript.Web.Server/FormCollectionWrapper.cs +++ b/src/OneScript.Web.Server/FormCollectionWrapper.cs @@ -49,7 +49,7 @@ public IEnumerable Keys() #region ICollectionContext Members [ContextMethod("Получить", "Get")] - public StringValuesWrapper Retrieve(IValue key) + public StringValuesWrapper Get(IValue key) { return GetIndexedValue(key); } diff --git a/src/OneScript.Web.Server/FormFileCollectionWrapper.cs b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs index eaef35f9f..abb83c6e3 100644 --- a/src/OneScript.Web.Server/FormFileCollectionWrapper.cs +++ b/src/OneScript.Web.Server/FormFileCollectionWrapper.cs @@ -31,7 +31,7 @@ public override IValue GetIndexedValue(IValue index) var result = _items.GetFile(index.AsString()); if (result == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return new FormFileWrapper(result); } diff --git a/src/OneScript.Web.Server/HttpRequestWrapper.cs b/src/OneScript.Web.Server/HttpRequestWrapper.cs index 1805f6824..b94cdda3a 100644 --- a/src/OneScript.Web.Server/HttpRequestWrapper.cs +++ b/src/OneScript.Web.Server/HttpRequestWrapper.cs @@ -49,7 +49,7 @@ public IValue ContentType get { if (_request.ContentType == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslStringValue.Create(_request.ContentType); } @@ -61,7 +61,7 @@ public IValue ContentLength get { if (_request.ContentLength == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslNumericValue.Create((decimal)_request.ContentLength); } @@ -84,7 +84,7 @@ public IValue QueryString if (_request.QueryString.HasValue) return BslStringValue.Create(_request.QueryString.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -96,7 +96,7 @@ public IValue Path if (_request.Path.HasValue) return BslStringValue.Create(_request.Path.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -108,7 +108,7 @@ public IValue PathBase if (_request.PathBase.HasValue) return BslStringValue.Create(_request.PathBase); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -120,7 +120,7 @@ public IValue Host if (_request.Host.HasValue) return BslStringValue.Create(_request.Host.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -141,7 +141,7 @@ public IValue Form if (_request.HasFormContentType) return new FormCollectionWrapper(_request.Form); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } } diff --git a/src/OneScript.Web.Server/HttpResponseWrapper.cs b/src/OneScript.Web.Server/HttpResponseWrapper.cs index f7afd802d..3f7575b0b 100644 --- a/src/OneScript.Web.Server/HttpResponseWrapper.cs +++ b/src/OneScript.Web.Server/HttpResponseWrapper.cs @@ -46,7 +46,7 @@ public IValue ContentLength get { if (_response.ContentLength == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslNumericValue.Create((decimal)_response.ContentLength); } diff --git a/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs b/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs index 00ccef077..e257569bb 100644 --- a/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs +++ b/src/OneScript.Web.Server/WebSockets/WebSocketAcceptContextWrapper.cs @@ -29,11 +29,11 @@ public IValue Protocol { get { - return _context.SubProtocol == null ? BslNullValue.Instance : BslStringValue.Create(_context.SubProtocol); + return _context.SubProtocol == null ? BslUndefinedValue.Instance : BslStringValue.Create(_context.SubProtocol); } set { - _context.SubProtocol = value is BslNullValue ? null : value.AsString(); + _context.SubProtocol = value is BslUndefinedValue ? null : value.AsString(); } } @@ -48,11 +48,11 @@ public IValue KeepAlive if (_context.KeepAliveInterval.HasValue) return BslNumericValue.Create((decimal)_context.KeepAliveInterval.Value.TotalSeconds); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } set { - if (value is BslNullValue) + if (value is BslUndefinedValue) _context.KeepAliveInterval = null; else _context.KeepAliveInterval = TimeSpan.FromSeconds((double)value.AsNumber()); diff --git a/src/OneScript.Web.Server/WebSockets/WebSocketReceiveResultWrapper.cs b/src/OneScript.Web.Server/WebSockets/WebSocketReceiveResultWrapper.cs index 540b8ba9c..b1ca85be4 100644 --- a/src/OneScript.Web.Server/WebSockets/WebSocketReceiveResultWrapper.cs +++ b/src/OneScript.Web.Server/WebSockets/WebSocketReceiveResultWrapper.cs @@ -40,7 +40,7 @@ public IValue CloseStatusDescription get { if (_result.CloseStatusDescription == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslStringValue.Create(_result.CloseStatusDescription); } diff --git a/src/OneScript.Web.Server/WebSockets/WebSocketWrapper.cs b/src/OneScript.Web.Server/WebSockets/WebSocketWrapper.cs index 1a04e09fc..4a2c90819 100644 --- a/src/OneScript.Web.Server/WebSockets/WebSocketWrapper.cs +++ b/src/OneScript.Web.Server/WebSockets/WebSocketWrapper.cs @@ -43,7 +43,7 @@ public IValue CloseStatusDescription get { if (_webSocket.CloseStatusDescription == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslStringValue.Create(_webSocket.CloseStatusDescription); } @@ -60,7 +60,7 @@ public IValue CloseStatusDescription /// [ContextProperty("Протокол", "Protocol", CanWrite = false)] public IValue Protocol - => _webSocket.SubProtocol == null ? BslNullValue.Instance : (IValue)BslStringValue.Create(_webSocket.SubProtocol); + => _webSocket.SubProtocol == null ? BslUndefinedValue.Instance : BslStringValue.Create(_webSocket.SubProtocol); /// /// Отменяет соединение WebSocket и отменяет все ожидающие операции ввода-вывода @@ -76,7 +76,7 @@ public IValue Protocol [ContextMethod("Закрыть", "Close")] public void Close(WebSocketCloseStatusWrapper status, IValue statusDescription) { - var desc = statusDescription is BslNullValue ? null : statusDescription.AsString(); + var desc = statusDescription is BslUndefinedValue ? null : statusDescription.AsString(); _webSocket.CloseAsync((WebSocketCloseStatus)status, desc, default).Wait(); } @@ -89,7 +89,7 @@ public void Close(WebSocketCloseStatusWrapper status, IValue statusDescription) [ContextMethod("ЗакрытьВыходнойПоток", "CloseOutput")] public void CloseOutput(WebSocketCloseStatusWrapper status, IValue statusDescription) { - var desc = statusDescription is BslNullValue ? null : statusDescription.AsString(); + var desc = statusDescription is BslUndefinedValue ? null : statusDescription.AsString(); _webSocket.CloseOutputAsync((WebSocketCloseStatus)status, desc, default).Wait(); }