Skip to content

Commit 6e6e462

Browse files
committed
Новый релиз
1 parent 1d185a3 commit 6e6e462

6 files changed

Lines changed: 163 additions & 50 deletions

File tree

OneScriptClientServer/OneScriptClientServer/OneScriptClientServer.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace oscs
1010
[ContextClass ("КлиентСерверДляОдноСкрипта", "OneScriptClientServer")]
1111
public class OneScriptClientServer : AutoContext<OneScriptClientServer>
1212
{
13+
private static CsClientMode cs_ClientMode = new CsClientMode();
1314
private static CsCommunicationStates cs_CommunicationStates = new CsCommunicationStates();
1415
public static CsServiceApplication CurrentServiceApplication = null;
1516
public static CsServiceClient CurrentServiceClient = null;
@@ -19,11 +20,12 @@ public class OneScriptClientServer : AutoContext<OneScriptClientServer>
1920
public static bool goOn = true;
2021
public static IValue ServerMessageReceived;
2122
public static IValue ServerMessageSent;
22-
public static bool thirdPartyClientMode = false;
23+
public static int thirdPartyClientMode;
2324

2425
[ScriptConstructor]
2526
public static IRuntimeContextInstance Constructor()
2627
{
28+
thirdPartyClientMode = cs_ClientMode.None;
2729
return new OneScriptClientServer();
2830
}
2931

@@ -49,12 +51,18 @@ public bool GoOn
4951
}
5052

5153
[ContextProperty("РежимСтороннегоКлиента", "ThirdPartyClientMode")]
52-
public bool ThirdPartyClientMode
54+
public int ThirdPartyClientMode
5355
{
5456
get { return thirdPartyClientMode; }
5557
set { thirdPartyClientMode = value; }
5658
}
5759

60+
[ContextProperty("РежимКлиента", "ClientMode")]
61+
public CsClientMode ClientMode
62+
{
63+
get { return cs_ClientMode; }
64+
}
65+
5866
[ContextProperty("СостояниеСоединения", "CommunicationStates")]
5967
public CsCommunicationStates CommunicationStates
6068
{
@@ -67,12 +75,6 @@ public CsTcpClient TcpClient(CsTcpEndPoint p1)
6775
return new CsTcpClient(p1);
6876
}
6977

70-
[ContextMethod("Действие", "Action")]
71-
public CsAction Action(IRuntimeContextInstance script, string methodName)
72-
{
73-
return new CsAction(script, methodName);
74-
}
75-
7678
[ContextMethod("TCPКонечнаяТочка", "TcpEndPoint")]
7779
public CsTcpEndPoint TcpEndPoint(string p1, int p2)
7880
{
@@ -85,6 +87,12 @@ public CsTcpServer TcpServer(int p1)
8587
return new CsTcpServer(p1);
8688
}
8789

90+
[ContextMethod("Действие", "Action")]
91+
public CsAction Action(IRuntimeContextInstance script, string methodName)
92+
{
93+
return new CsAction(script, methodName);
94+
}
95+
8896
[ContextMethod("ПолучитьСобытие", "DoEvents")]
8997
public DelegateAction DoEvents()
9098
{

OneScriptClientServer/OneScriptClientServer/OneScriptClientServer.csproj

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<WarningLevel>4</WarningLevel>
3131
</PropertyGroup>
3232
<ItemGroup>
33+
<Reference Include="Microsoft.CSharp" />
3334
<Reference Include="ScriptEngine, Version=1.7.0.214, Culture=neutral, processorArchitecture=MSIL">
3435
<SpecificVersion>False</SpecificVersion>
3536
<HintPath>bin\Debug\ScriptEngine.dll</HintPath>
@@ -39,20 +40,13 @@
3940
<HintPath>bin\Debug\ScriptEngine.HostedScript.dll</HintPath>
4041
</Reference>
4142
<Reference Include="System" />
42-
<Reference Include="System.Core" />
43-
<Reference Include="System.Windows.Forms" />
44-
<Reference Include="System.Xml.Linq" />
45-
<Reference Include="System.Data.DataSetExtensions" />
46-
<Reference Include="Microsoft.CSharp" />
47-
<Reference Include="System.Data" />
48-
<Reference Include="System.Net.Http" />
49-
<Reference Include="System.Xml" />
5043
</ItemGroup>
5144
<ItemGroup>
5245
<Compile Include="Action.cs" />
5346
<Compile Include="BoolMessage.cs" />
5447
<Compile Include="ByteMessage.cs" />
5548
<Compile Include="ClientInfo.cs" />
49+
<Compile Include="ClientMode.cs" />
5650
<Compile Include="Collection.cs" />
5751
<Compile Include="CommunicationStates.cs" />
5852
<Compile Include="DateTimeMessage.cs" />

OneScriptClientServer/OneScriptClientServer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// Можно задать все значения или принять номера сборки и редакции по умолчанию
3333
// используя "*", как показано ниже:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.1.0")]
36-
[assembly: AssemblyFileVersion("2.0.1.0")]
35+
[assembly: AssemblyVersion("3.0.0.0")]
36+
[assembly: AssemblyFileVersion("3.0.0.0")]

OneScriptClientServer/OneScriptClientServer/ScsSupport.cs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ protected override void SendMessageInternal(IScsMessage message)
912912
var totalSent = 0;
913913
lock (_syncLock)
914914
{
915-
if (oscs.OneScriptClientServer.thirdPartyClientMode)
915+
if (oscs.OneScriptClientServer.thirdPartyClientMode != 0)
916916
{
917917
byte[] sendBytes = new byte[0];
918918
if (message.GetType() == typeof(ScsRawDataMessage))
@@ -981,7 +981,7 @@ private void ReceiveCallback(IAsyncResult ar)
981981
return;
982982
}
983983

984-
if (oscs.OneScriptClientServer.thirdPartyClientMode)
984+
if (oscs.OneScriptClientServer.thirdPartyClientMode == 2) // Браузер
985985
{
986986
try
987987
{
@@ -1028,6 +1028,59 @@ private void ReceiveCallback(IAsyncResult ar)
10281028
{
10291029
throw new CommunicationException("Tcp socket is closed");
10301030
}
1031+
}
1032+
catch
1033+
{
1034+
Disconnect();
1035+
}
1036+
}
1037+
else if (oscs.OneScriptClientServer.thirdPartyClientMode == 1) // Нативный
1038+
{
1039+
try
1040+
{
1041+
System.Threading.Thread.Sleep(5); // без этого данные от разных отправок сторонних клиентов могут оказаться соединенными.
1042+
//Получить количество полученных байтов
1043+
var bytesRead = _clientSocket.EndReceive(ar);
1044+
1045+
if (_clientSocket.Available == 0)
1046+
{
1047+
out1 = true;
1048+
}
1049+
1050+
if (bytesRead > 0)
1051+
{
1052+
LastReceivedMessageTime = DateTime.Now;
1053+
1054+
// Скопируйте полученные байты в новый массив байтов
1055+
var receivedBytes = new byte[bytesRead];
1056+
Array.Copy(_buffer, 0, receivedBytes, 0, bytesRead);
1057+
1058+
rv = Combine(rv, receivedBytes); // Накопим данные из потока для одного клиента, если их больше 4096 байт.
1059+
1060+
if (out1)
1061+
{
1062+
string magicSign = Convert.ToString(rv[0], 16).ToUpper() + " " +
1063+
Convert.ToString(rv[1], 16).ToUpper() + " " +
1064+
Convert.ToString(rv[2], 16).ToUpper() + " " +
1065+
Convert.ToString(rv[3], 16).ToUpper();
1066+
1067+
if (magicSignature.Contains("," + magicSign + ","))
1068+
{
1069+
OnMessageReceived(new ScsRawDataMessage(rv));
1070+
}
1071+
else
1072+
{
1073+
OnMessageReceived(new ScsTextMessage(Encoding.UTF8.GetString(rv)));
1074+
}
1075+
1076+
rv = new byte[0];
1077+
out1 = false;
1078+
}
1079+
}
1080+
else
1081+
{
1082+
throw new CommunicationException("Tcp socket is closed");
1083+
}
10311084

10321085
// Прочитайте больше байтов, если все еще работаете
10331086
if (_running)

OneScriptClientServer/OneScriptClientServer/ServiceClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void M_ServiceClient_Connected(object sender, System.EventArgs e)
146146
catch
147147
{
148148
Disconnect();
149-
System.Windows.Forms.MessageBox.Show("Не удается войти на сервер. Пожалуйста, попробуйте еще раз позже.");
149+
Console.Write("Не удается войти на сервер. Пожалуйста, попробуйте еще раз позже.");
150150
}
151151

152152
if (dll_obj.Connected != null)

tests/ГенерацияSCSClientServer.os

Lines changed: 87 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Скрипт читает файлы справки в C:\444\OSClientServerRu\ и создает *.cs файлы в каталоге C:\444\ВыгруженныеОбъекты\
2-
// Из каталога C:\444\ВыгруженныеОбъекты\ файлы *.cs можно скопировать в каталог проекта.
1+
// Скрипт читает файлы справки в C:\444\OSClientServerRu\ и создает *.cs файлы в каталоге C:\444\ВыгрузкаКлиентСервера\
2+
// Из каталога C:\444\ВыгрузкаКлиентСервера\ файлы *.cs можно скопировать в каталог проекта.
33

44
Перем СтрДирективы, СтрШапка, СтрРазделОбъявленияПеременных, СтрКонструктор, СтрBase_obj, СтрСвойства, СтрМетоды, СтрПодвал, СтрВыгрузкиПеречислений;
55
Перем СтрРазделОбъявленияПеременныхДляПеречисления, СтрСвойстваДляПеречисления, СтрМетодовСистема, СписокСтрМетодовСистема;
@@ -333,7 +333,8 @@
333333
|
334334
|";
335335
Возврат Стр;
336-
ИначеЕсли ИмяКонтекстКлассаАнгл = "CommunicationStates" Тогда
336+
ИначеЕсли ИмяКонтекстКлассаАнгл = "CommunicationStates" или
337+
ИмяКонтекстКлассаАнгл = "ClientMode" Тогда
337338
Стр =
338339
"using ScriptEngine.Machine.Contexts;
339340
|
@@ -444,6 +445,7 @@
444445
Если ИмяКласса = "OneScriptClientServer" Тогда
445446
Стр =
446447
" public static IValue Event = null;
448+
| public static int thirdPartyClientMode;
447449
| public static IValue EventAction = null;
448450
| public static IValue ServerMessageReceived;
449451
| public static IValue ServerMessageSent;
@@ -471,6 +473,7 @@
471473
" [ScriptConstructor]
472474
| public static IRuntimeContextInstance Constructor()
473475
| {
476+
| thirdPartyClientMode = cs_ClientMode.None;
474477
| return new OneScriptClientServer();
475478
| }//end_constr
476479
|";
@@ -1047,6 +1050,16 @@
10471050
| }
10481051
|
10491052
|";
1053+
ИначеЕсли (СвойствоРус = "РежимСтороннегоКлиента") и (ИмяКонтекстКлассаАнгл = "OneScriptClientServer") Тогда
1054+
Стр = Стр +
1055+
" [ContextProperty(""РежимСтороннегоКлиента"", ""ThirdPartyClientMode"")]
1056+
| public int ThirdPartyClientMode
1057+
| {
1058+
| get { return thirdPartyClientMode; }
1059+
| set { thirdPartyClientMode = value; }
1060+
| }
1061+
|
1062+
|";
10501063
ИначеЕсли (СвойствоРус = "Сценарий") и (ИмяКонтекстКлассаАнгл = "Action") Тогда
10511064
Стр = Стр +
10521065
" [ContextProperty(""Сценарий"", ""Script"")]
@@ -1097,18 +1110,6 @@
10971110
| }
10981111
|
10991112
|";
1100-
ИначеЕсли (СвойствоРус = "РежимСтороннегоКлиента") и (ИмяКонтекстКлассаАнгл = "OneScriptClientServer") Тогда
1101-
СтрРазделОбъявленияПеременных = СтрРазделОбъявленияПеременных + Символы.ПС +
1102-
" public static bool thirdPartyClientMode = false;";
1103-
Стр = Стр +
1104-
" [ContextProperty(""РежимСтороннегоКлиента"", ""ThirdPartyClientMode"")]
1105-
| public bool ThirdPartyClientMode
1106-
| {
1107-
| get { return thirdPartyClientMode; }
1108-
| set { thirdPartyClientMode = value; }
1109-
| }
1110-
|
1111-
|";
11121113
ИначеЕсли (СвойствоРус = "Отправитель") и (ИмяКонтекстКлассаАнгл = "EventArgs") Тогда
11131114
Стр = Стр +
11141115
" [ContextProperty(""Отправитель"", ""Sender"")]
@@ -1658,15 +1659,20 @@
16581659
Знач3 = СписокПереч2.Получить(А).Значение;
16591660
Предст3 = СписокПереч2.Получить(А).Представление;
16601661
// Сообщить("Знач3 - " + Знач3 + " Предст3 - " + Предст3);
1661-
СтрРазделОбъявленияПеременных = СтрРазделОбъявленияПеременных + Символы.ПС +
1662-
" private static Cs" + Знач3 + " cs_" + Знач3 + " = new Cs" + Знач3 + "();";
16631662

1664-
Стр = Стр + Символы.ПС +
1665-
" [ContextProperty(""" + Предст3 + """, """ + Знач3 + """)]
1666-
| public Cs" + Знач3 + " " + Знач3 + "
1667-
| {
1668-
| get { return cs_" + Знач3 + "; }
1669-
| }" + Символы.ПС;
1663+
// Если Предст3 = "РежимСтороннегоКлиента" Тогда
1664+
// СтрРазделОбъявленияПеременных = СтрРазделОбъявленияПеременных + Символы.ПС +
1665+
// " public static int cs_ThirdPartyClientMode = 0;";
1666+
// Иначе
1667+
СтрРазделОбъявленияПеременных = СтрРазделОбъявленияПеременных + Символы.ПС +
1668+
" private static Cs" + Знач3 + " cs_" + Знач3 + " = new Cs" + Знач3 + "();";
1669+
Стр = Стр + Символы.ПС +
1670+
" [ContextProperty(""" + Предст3 + """, """ + Знач3 + """)]
1671+
| public Cs" + Знач3 + " " + Знач3 + "
1672+
| {
1673+
| get { return cs_" + Знач3 + "; }
1674+
| }" + Символы.ПС;
1675+
// КонецЕсли;
16701676
КонецЦикла;
16711677
Стр = Стр + Символы.ПС;
16721678
Возврат Стр;
@@ -2774,8 +2780,7 @@
27742780
Иначе
27752781
ИмяКонтекстКлассаАнгл1 = ИмяКонтекстКлассаАнгл;
27762782
КонецЕсли;
2777-
Если ИмяКонтекстКлассаАнгл = "Sounds" или // это перечисление собственное (не от микрософт)
2778-
ИмяКонтекстКлассаАнгл = "DataType" Тогда
2783+
Если ИмяКонтекстКлассаАнгл = "ClientMode" Тогда // это перечисление собственное (не от микрософт)
27792784
СтрРазделОбъявленияПеременныхДляПеречисления = СтрРазделОбъявленияПеременныхДляПеречисления + Символы.ПС +
27802785
" private int m_" + СоставнаяСтр + " = " + ЗначениеЧлена + "; // " + ЗначениеЧлена + " " + ОписаниеЧлена;
27812786

@@ -3522,7 +3527,7 @@
35223527
| catch
35233528
| {
35243529
| Disconnect();
3525-
| System.Windows.Forms.MessageBox.Show(""Не удается войти на сервер. Пожалуйста, попробуйте еще раз позже."");
3530+
| Console.Write(""Не удается войти на сервер. Пожалуйста, попробуйте еще раз позже."");
35263531
| }
35273532
|
35283533
| if (dll_obj.Connected != null)
@@ -5282,7 +5287,7 @@
52825287
| var totalSent = 0;
52835288
| lock (_syncLock)
52845289
| {
5285-
| if (oscs.OneScriptClientServer.thirdPartyClientMode)
5290+
| if (oscs.OneScriptClientServer.thirdPartyClientMode != 0)
52865291
| {
52875292
| byte[] sendBytes = new byte[0];
52885293
| if (message.GetType() == typeof(ScsRawDataMessage))
@@ -5351,7 +5356,7 @@
53515356
| return;
53525357
| }
53535358
|
5354-
| if (oscs.OneScriptClientServer.thirdPartyClientMode)
5359+
| if (oscs.OneScriptClientServer.thirdPartyClientMode == 2) // Браузер
53555360
| {
53565361
| try
53575362
| {
@@ -5398,6 +5403,59 @@
53985403
| {
53995404
| throw new CommunicationException(""Tcp socket is closed"");
54005405
| }
5406+
| }
5407+
| catch
5408+
| {
5409+
| Disconnect();
5410+
| }
5411+
| }
5412+
| else if (oscs.OneScriptClientServer.thirdPartyClientMode == 1) // Нативный
5413+
| {
5414+
| try
5415+
| {
5416+
| System.Threading.Thread.Sleep(5); // без этого данные от разных отправок сторонних клиентов могут оказаться соединенными.
5417+
| //Получить количество полученных байтов
5418+
| var bytesRead = _clientSocket.EndReceive(ar);
5419+
|
5420+
| if (_clientSocket.Available == 0)
5421+
| {
5422+
| out1 = true;
5423+
| }
5424+
|
5425+
| if (bytesRead > 0)
5426+
| {
5427+
| LastReceivedMessageTime = DateTime.Now;
5428+
|
5429+
| // Скопируйте полученные байты в новый массив байтов
5430+
| var receivedBytes = new byte[bytesRead];
5431+
| Array.Copy(_buffer, 0, receivedBytes, 0, bytesRead);
5432+
|
5433+
| rv = Combine(rv, receivedBytes); // Накопим данные из потока для одного клиента, если их больше 4096 байт.
5434+
|
5435+
| if (out1)
5436+
| {
5437+
| string magicSign = Convert.ToString(rv[0], 16).ToUpper() + "" "" +
5438+
| Convert.ToString(rv[1], 16).ToUpper() + "" "" +
5439+
| Convert.ToString(rv[2], 16).ToUpper() + "" "" +
5440+
| Convert.ToString(rv[3], 16).ToUpper();
5441+
|
5442+
| if (magicSignature.Contains("","" + magicSign + "",""))
5443+
| {
5444+
| OnMessageReceived(new ScsRawDataMessage(rv));
5445+
| }
5446+
| else
5447+
| {
5448+
| OnMessageReceived(new ScsTextMessage(Encoding.UTF8.GetString(rv)));
5449+
| }
5450+
|
5451+
| rv = new byte[0];
5452+
| out1 = false;
5453+
| }
5454+
| }
5455+
| else
5456+
| {
5457+
| throw new CommunicationException(""Tcp socket is closed"");
5458+
| }
54015459
|
54025460
| // Прочитайте больше байтов, если все еще работаете
54035461
| if (_running)
@@ -8703,7 +8761,7 @@
87038761
КонецФункции//СортировкаКласса2Уровня(СтрКласса)
87048762

87058763
КаталогСправки = "C:\444\OSClientServerRu";// без слэша в конце
8706-
КаталогВыгрузки = "C:\444\ВыгруженныеОбъекты";// без слэша в конце
8764+
КаталогВыгрузки = "C:\444\ВыгрузкаКлиентСервера";// без слэша в конце
87078765
// КаталогВыгрузки = "\\UBUNTU SHARE\allaccess";// без слэша в конце
87088766

87098767
ВыгрузкаДляCS();

0 commit comments

Comments
 (0)