-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
В веб-сервер добавлена возможность работы с данными форм.
- Loading branch information
Showing
8 changed files
with
389 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FormCollectionWrapper, KeyAndValueImpl> | ||
{ | ||
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<IValue> 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<IValue> Members | ||
|
||
public override IEnumerator<KeyAndValueImpl> 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FormFileCollectionWrapper, FormFileWrapper> | ||
{ | ||
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<IValue> Members | ||
|
||
public override IEnumerator<FormFileWrapper> GetEnumerator() | ||
{ | ||
foreach (var item in _items) | ||
yield return new FormFileWrapper(item); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<FormFileWrapper> | ||
{ | ||
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()); | ||
} | ||
} |
Oops, something went wrong.