Skip to content

Commit 1338dc0

Browse files
committed
Релиз 1.1.0.0
1 parent 6433742 commit 1338dc0

14 files changed

Lines changed: 1933 additions & 491 deletions

DeclarativeForms/DeclarativeForms/DeclarativeForms.cs

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static IRuntimeContextInstance Constructor()
5959
DeclarativeForms inst = getInstance();
6060
inst.InjectGlobalProperty(shareStructure, "ОбщаяСтруктура", false);
6161
shareStructure.Insert("ДФ", inst);
62+
openInBrowser = false;
6263
return inst;
6364
}
6465

@@ -83,6 +84,23 @@ public static SystemGlobalContext GlobalContext()
8384
{
8485
return GlobalsManager.GetGlobalContext<SystemGlobalContext>();
8586
}
87+
88+
public static bool wsserverOn;
89+
[ContextProperty("ВебСерверРаботает", "WsserverOn")]
90+
public bool WsserverOn
91+
{
92+
get { return wsserverOn; }
93+
set { wsserverOn = value; }
94+
}
95+
96+
public static bool openInBrowser;
97+
[ContextProperty("ОткрытьВБраузере", "OpenInBrowser")]
98+
public bool OpenInBrowser
99+
{
100+
get { return openInBrowser; }
101+
set { openInBrowser = value; }
102+
}
103+
86104

87105
public static string CSSPath = "styles.css";
88106
private string _cssPath;
@@ -102,7 +120,7 @@ public DfBackground Background(IValue p1 = null, IValue p2 = null, IValue p3 = n
102120
{
103121
return new DfBackground(p1, p2, p3, p4, p5, p6, p7, p8);
104122
}
105-
123+
106124
[ContextMethod("Скрипт", "Script")]
107125
public DfScript Script()
108126
{
@@ -1652,7 +1670,53 @@ Процедура ЗапускКлиента(параметр1) Экспорт
16521670
|
16531671
|// Запустим цикл обработки событий
16541672
|Пока КСДФ.Продолжать Цикл
1655-
| КСДФ.ПолучитьСобытие().Выполнить();
1673+
| КСДФ.ПолучитьСобытие().Выполнить();
1674+
|КонецЦикла;
1675+
|"";
1676+
ЗагрузитьСценарийИзСтроки(Стр, Контекст);
1677+
КонецПроцедуры
1678+
1679+
Процедура ЗапускgetProps(параметр1) Экспорт
1680+
Контекст = Новый Структура(""ДФ"", параметр1);
1681+
Стр = ""
1682+
|Пока Истина Цикл
1683+
| Пока ДФ.КоличествоВОчереди() > 0 Цикл
1684+
| ДФ.Отправить();
1685+
| КонецЦикла;
1686+
| Приостановить(7);
1687+
|КонецЦикла;"";
1688+
ЗагрузитьСценарийИзСтроки(Стр, Контекст);
1689+
КонецПроцедуры
1690+
1691+
МассивПараметров = Новый Массив(1);
1692+
МассивПараметров[0] = ОбщаяСтруктура.ДФ;
1693+
Задание = ФоновыеЗадания.Выполнить(ЭтотОбъект, ""ЗапускКлиента"", МассивПараметров);
1694+
Задание = ФоновыеЗадания.Выполнить(ЭтотОбъект, ""ЗапускgetProps"", МассивПараметров);
1695+
";
1696+
1697+
string backgroundTasksBr = @"
1698+
Процедура ЗапускКлиента(параметр1) Экспорт
1699+
Контекст = Новый Структура(""ДФ"", параметр1);
1700+
Стр = ""
1701+
|Перем ВСДФ;
1702+
|
1703+
|Процедура ВСДФ_ПриПолученииСообщения() Экспорт
1704+
| // Сообщить(""""== ВСДФ_ПриПолученииСообщения ======================================="""");
1705+
| Сообщение = ВСДФ.АргументыСобытия.Сообщение;
1706+
| // Сообщить(""""Сообщение = """" + Сообщение);
1707+
| ДФ.ОбработатьСообщение(Сообщение);
1708+
|
1709+
|
1710+
|КонецПроцедуры
1711+
|
1712+
|ВСДФ = Новый ВебСерверДекларФорм();
1713+
|ВСДФ.ПриПолученииСообщения = ВСДФ.Действие(ЭтотОбъект, """"ВСДФ_ПриПолученииСообщения"""");
1714+
|ВСДФ.Начать(""""127.0.0.1"""", ДФ.Порт);
1715+
|
1716+
|
1717+
|// Запустим цикл обработки событий
1718+
|Пока ВСДФ.Продолжать Цикл
1719+
| ВСДФ.ПолучитьСобытие().Выполнить();
16561720
|КонецЦикла;
16571721
|"";
16581722
ЗагрузитьСценарийИзСтроки(Стр, Контекст);
@@ -1675,13 +1739,30 @@ Процедура ЗапускgetProps(параметр1) Экспорт
16751739
Задание = ФоновыеЗадания.Выполнить(ЭтотОбъект, ""ЗапускКлиента"", МассивПараметров);
16761740
Задание = ФоновыеЗадания.Выполнить(ЭтотОбъект, ""ЗапускgetProps"", МассивПараметров);
16771741
";
1678-
GlobalContext().LoadScriptFromString(backgroundTasks, extContext);
1742+
if (OpenInBrowser)
1743+
{
1744+
GlobalContext().LoadScriptFromString(backgroundTasksBr, extContext);
1745+
}
1746+
else
1747+
{
1748+
GlobalContext().LoadScriptFromString(backgroundTasks, extContext);
1749+
}
16791750

16801751
// Создаем в этом каталоге файл package.json с заданными в сценарии начальнымисвойствами формы.
1681-
File.WriteAllText(pathStartupScript + separator + "package.json", Packagejson.packagejson, System.Text.Encoding.UTF8);
1752+
if (!OpenInBrowser)
1753+
{
1754+
File.WriteAllText(pathStartupScript + separator + "package.json", Packagejson.packagejson, System.Text.Encoding.UTF8);
1755+
}
16821756

16831757
// Создаем в этом каталоге файл index.html.
1684-
File.WriteAllText(pathStartupScript + separator + "index.html", Indexhtml.indexhtml, System.Text.Encoding.UTF8);
1758+
if (OpenInBrowser)
1759+
{
1760+
File.WriteAllText(pathStartupScript + separator + "index.html", Indexhtml.IndexhtmlBr, System.Text.Encoding.UTF8);
1761+
}
1762+
else
1763+
{
1764+
File.WriteAllText(pathStartupScript + separator + "index.html", Indexhtml.indexhtml, System.Text.Encoding.UTF8);
1765+
}
16851766

16861767
// Создаем в этом каталоге файл стиля (имя_скрипта).css
16871768
// ...
@@ -1878,8 +1959,16 @@ public DfAction GettingProperty
18781959
[ContextMethod("ОбработатьСообщение", "ProcessMessage")]
18791960
public void ProcessMessage(string p1)
18801961
{
1881-
string[] zapros = p1.Split(new string[] { "\u000a", "\u000d" }, StringSplitOptions.RemoveEmptyEntries);
1882-
string strZapros = zapros[zapros.Length - 1];
1962+
string strZapros;
1963+
if (OpenInBrowser)
1964+
{
1965+
strZapros = p1;
1966+
}
1967+
else
1968+
{
1969+
string[] zapros = p1.Split(new string[] { "\u000a", "\u000d" }, StringSplitOptions.RemoveEmptyEntries);
1970+
strZapros = zapros[zapros.Length - 1];
1971+
}
18831972
string[] massiv = strZapros.Split(new string[] { paramDelimiter }, StringSplitOptions.RemoveEmptyEntries);
18841973
//GlobalContext().Echo("Сообщение.Текст = " + p1);
18851974
//GlobalContext().Echo("СтрЗапроса = " + strZapros);
@@ -2033,7 +2122,7 @@ public void ProcessMessage(string p1)
20332122
catch { }
20342123
if (resTest.Contains("!!!"))
20352124
{
2036-
GlobalContext().Echo("Ошибка: " + resTest);
2125+
GlobalContext().Echo("Ошибка1: " + resTest);
20372126
}
20382127
}
20392128
}
@@ -2128,7 +2217,7 @@ public DfEventArgs CreateEventArgs(string p1)
21282217
catch
21292218
{
21302219
((dynamic)Sender).SetPropValue(((dynamic)Sender).FindProperty(str2[0]), propValue);
2131-
}
2220+
}
21322221
}
21332222
catch { }
21342223
}
@@ -2160,7 +2249,7 @@ public IValue Execute(DfAction p1, DfEventArgs p2 = null)
21602249
}
21612250
catch (Exception ex)
21622251
{
2163-
GlobalContext().Echo("Ошибка: " + ex.Message);
2252+
GlobalContext().Echo("Ошибка2: " + ex.Message);
21642253
}
21652254
return res;
21662255
}
@@ -2313,7 +2402,7 @@ public void GetObjectProperty(IValue p1, string p2, DfAction p3 = null)
23132402
"}" +
23142403
"catch (err)" +
23152404
"{" +
2316-
" sendPost('!!! Ошибка:' + err.message);" +
2405+
" sendPost('!!! Ошибка3:' + err.message);" +
23172406
"}" +
23182407
"";
23192408
function1 = function1.Replace(" ", " ").Replace(" ", " ");

DeclarativeForms/DeclarativeForms/DeclarativeForms.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
<Compile Include="WeekSelection.cs" />
282282
<Compile Include="WhiteSpace.cs" />
283283
<Compile Include="WordWrap.cs" />
284+
<Compile Include="Wsserver.cs" />
284285
</ItemGroup>
285286
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
286287
</Project>

DeclarativeForms/DeclarativeForms/Form.cs

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using ScriptEngine.Machine.Contexts;
55
using ScriptEngine.Machine;
66
using ScriptEngine.HostedScript.Library;
7+
using System.Threading;
78

89
namespace osdf
910
{
@@ -259,45 +260,71 @@ public DfAction Resize
259260
[ContextMethod("Открыть", "Open")]
260261
public void Open()
261262
{
262-
// Сформируем package.json
263-
string resStr = " ";
264-
foreach (KeyValuePair<string, object> entry in props)
263+
if (DeclarativeForms.openInBrowser)
265264
{
266-
resStr = resStr + " " + entry.Value + Environment.NewLine;
265+
bool isWin = System.Environment.OSVersion.VersionString.Contains("Microsoft");
266+
string folderName = @".\";
267+
if (!isWin)
268+
{
269+
folderName = @"./";
270+
}
271+
DeclarativeForms.instance.LoadScripts(folderName);
272+
// Запустим index.html в браузере по умолчанию.
273+
string target = "index.html";
274+
System.Diagnostics.Process process = new System.Diagnostics.Process();
275+
DeclarativeForms.process = process;
276+
277+
process.StartInfo.FileName = target;
278+
process.Start();
279+
process.WaitForExit();
280+
while (DeclarativeForms.wsserverOn)
281+
{
282+
System.Threading.Thread.Sleep(9);
283+
}
284+
Environment.Exit(0);
267285
}
268-
269-
string str = osdf.Packagejson.packagejson;
270-
string strFind = osdf.DeclarativeForms.StrFindBetween(str, "window\u0022: {", "}", false).Get(0).AsString();
271-
resStr = resStr.Trim();
272-
if (resStr.Length > 0)
286+
else
273287
{
274-
resStr = resStr.Substring(0, resStr.Length - 1);
288+
// Сформируем package.json
289+
string resStr = " ";
290+
foreach (KeyValuePair<string, object> entry in props)
291+
{
292+
resStr = resStr + " " + entry.Value + Environment.NewLine;
293+
}
294+
295+
string str = Packagejson.packagejson;
296+
string strFind = DeclarativeForms.StrFindBetween(str, "window\u0022: {", "}", false).Get(0).AsString();
297+
resStr = resStr.Trim();
298+
if (resStr.Length > 0)
299+
{
300+
resStr = resStr.Substring(0, resStr.Length - 1);
301+
}
302+
string strReplace = "window\u0022: {" + Environment.NewLine + " " + resStr + Environment.NewLine + " }";
303+
str = str.Replace(strFind, strReplace);
304+
Packagejson.packagejson = str;
305+
306+
bool isWin = System.Environment.OSVersion.VersionString.Contains("Microsoft");
307+
string folderName = @".\";
308+
if (!isWin)
309+
{
310+
folderName = @"./";
311+
}
312+
313+
DeclarativeForms.instance.LoadScripts(folderName);
314+
string pathNW = DeclarativeForms._nw;
315+
316+
System.Diagnostics.Process process = new System.Diagnostics.Process();
317+
318+
DeclarativeForms.process = process;
319+
320+
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
321+
process.StartInfo.FileName = "\u0022" + pathNW + "\u0022";
322+
process.StartInfo.Arguments = "\u0022" + pathStartupScript + separator;
323+
process.Start();
324+
process.WaitForExit();
325+
326+
Environment.Exit(0);
275327
}
276-
string strReplace = "window\u0022: {" + Environment.NewLine + " " + resStr + Environment.NewLine + " }";
277-
str = str.Replace(strFind, strReplace);
278-
osdf.Packagejson.packagejson = str;
279-
280-
bool isWin = System.Environment.OSVersion.VersionString.Contains("Microsoft");
281-
string folderName = @".\";
282-
if (!isWin)
283-
{
284-
folderName = @"./";
285-
}
286-
287-
DeclarativeForms.instance.LoadScripts(folderName);
288-
string pathNW = DeclarativeForms._nw;
289-
290-
System.Diagnostics.Process process = new System.Diagnostics.Process();
291-
292-
DeclarativeForms.process = process;
293-
294-
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
295-
process.StartInfo.FileName = "\u0022" + pathNW + "\u0022";
296-
process.StartInfo.Arguments = "\u0022" + pathStartupScript + separator;
297-
process.Start();
298-
process.WaitForExit();
299-
300-
Environment.Exit(0);
301328
}
302329

303330
public DfMenu menu;

0 commit comments

Comments
 (0)