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 new file mode 100644 index 000000000..031e12949 --- /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 Get(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..abb83c6e3 --- /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 BslUndefinedValue.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..61e4da39c --- /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..92ce4cebe 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,12 +304,12 @@ 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); + return result; else - return ValueFactory.Create(); + 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..b94cdda3a 100644 --- a/src/OneScript.Web.Server/HttpRequestWrapper.cs +++ b/src/OneScript.Web.Server/HttpRequestWrapper.cs @@ -20,6 +20,7 @@ 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 { @@ -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 @@ -48,7 +49,7 @@ public IValue ContentType get { if (_request.ContentType == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslStringValue.Create(_request.ContentType); } @@ -60,17 +61,17 @@ public IValue ContentLength get { if (_request.ContentLength == null) - return BslNullValue.Instance; + return BslUndefinedValue.Instance; else return BslNumericValue.Create((decimal)_request.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); @@ -83,7 +84,7 @@ public IValue QueryString if (_request.QueryString.HasValue) return BslStringValue.Create(_request.QueryString.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -95,7 +96,7 @@ public IValue Path if (_request.Path.HasValue) return BslStringValue.Create(_request.Path.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -107,7 +108,7 @@ public IValue PathBase if (_request.PathBase.HasValue) return BslStringValue.Create(_request.PathBase); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -119,7 +120,7 @@ public IValue Host if (_request.Host.HasValue) return BslStringValue.Create(_request.Host.Value); else - return BslNullValue.Instance; + return BslUndefinedValue.Instance; } } @@ -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 BslUndefinedValue.Instance; + } + } } } diff --git a/src/OneScript.Web.Server/HttpResponseWrapper.cs b/src/OneScript.Web.Server/HttpResponseWrapper.cs index 153d66f8f..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); } @@ -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..0557b7be6 --- /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..e257569bb 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,11 +29,11 @@ public IValue Protocol { get { - return _context.SubProtocol == null ? BslNullValue.Instance : (IValue)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(); }