Skip to content

Commit f826905

Browse files
committed
[InternalComponent] Implemented boolean run([enum context]) To Execute Action with specific context.
http://vssbe.r-eg.net/doc/Scripts/SBE-Scripts/Components/InternalComponent/#run ``` #[Core events.Pre.item("SpecBuild").run()] #[Core events.Pre.item(5).run(Build)] ``` Also: * Added messages about errors for actions in another thread when this failed. * C# Mode: Error/Warn messages also for result of this action by compiler settings - `Warnings & Errors` - `TreatWarningsAsErrors`
1 parent 327a5ab commit f826905

9 files changed

Lines changed: 190 additions & 45 deletions

File tree

vsSolutionBuildEvent/Actions/ActionCSharp.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013-2015 Denis Kuzmin (reg) <entry.reg@gmail.com>
2+
* Copyright (c) 2013-2016 Denis Kuzmin (reg) <entry.reg@gmail.com>
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Lesser General Public License as published by
@@ -39,7 +39,7 @@ public class ActionCSharp: Action, IAction
3939
/// <summary>
4040
/// Main class for user code.
4141
/// </summary>
42-
public const string MAIN_CLASS = "vsSolutionBuildEvent.CSharpMode";
42+
public const string MAIN_CLASS = Settings.APP_NAME + ".CSharpMode";
4343

4444
/// <summary>
4545
/// Entry point for user code.
@@ -49,7 +49,7 @@ public class ActionCSharp: Action, IAction
4949
/// <summary>
5050
/// Prefix to cached bytecode.
5151
/// </summary>
52-
protected const string PREFIX_CACHE = "cached_vssbe.";
52+
protected const string PREFIX_CACHE = "cached_" + Settings.APP_NAME_SHORT + ".";
5353

5454
/// <summary>
5555
/// Where to look cache.
@@ -108,13 +108,24 @@ public override bool process(ISolutionEvent evt)
108108
type = load(outputCacheFile(evt), assemblyName(evt));
109109
}
110110

111+
if(type == null) {
112+
Log.Error($"Compiled type is null. Something went wrong for C# Action '{evt.Name}'");
113+
}
114+
111115
int ret = run(type, cmd, evt);
112-
if(ret != 0)
113-
{
114-
Log.Warn("Return code '{0}'", ret);
115-
return false;
116+
if(ret == 0) {
117+
return true;
116118
}
117-
return true;
119+
120+
string retmsg = $"Return code '{ret}'";
121+
122+
if(((IModeCSharp)evt.Mode).TreatWarningsAsErrors) {
123+
Log.Error(retmsg);
124+
}
125+
else {
126+
Log.Warn(retmsg);
127+
}
128+
return false;
118129
}
119130

120131
/// <param name="cmd"></param>

vsSolutionBuildEvent/Actions/Command.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,23 @@ protected bool actionBy(ModeType type, ISolutionEvent evt)
180180
}
181181

182182
string marker = null;
183-
if(Thread.CurrentThread.Name == Events.LoggingEvent.IDENT_TH) {
184-
marker = Events.LoggingEvent.IDENT_TH;
183+
if(Thread.CurrentThread.Name == LoggingEvent.IDENT_TH) {
184+
marker = LoggingEvent.IDENT_TH;
185185
}
186186

187187
(new Task(() => {
188188

189189
if(Thread.CurrentThread.Name == null && marker != null) {
190190
Thread.CurrentThread.Name = marker;
191191
}
192-
Log.Trace("Task for another thread is started for '{0}' /{1}", evt.Name, type);
193-
actions[type].process(evt);
192+
193+
Log.Trace($"Task ({type}) for another thread is started for '{evt.Name}'");
194+
try {
195+
actions[type].process(evt);
196+
}
197+
catch(Exception ex) {
198+
Log.Error($"Task ({type}) for another thread is failed. '{evt.Name}' Error: `{ex.Message}`");
199+
}
194200

195201
})).Start();
196202

vsSolutionBuildEvent/IsolatedEnv.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public IsolatedEnv(string solutionFile, TProp properties)
374374
/// <param name="properties">Solution properties.</param>
375375
public IsolatedEnv(TProp properties)
376376
{
377-
377+
slnProperties = properties;
378378
}
379379

380380
/// <summary>

vsSolutionBuildEvent/SBEScripts/Bootloader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public virtual void register()
119119
register(new UserVariableComponent(this));
120120
register(new OWPComponent(Env));
121121
register(new DTEComponent(Env));
122-
register(new InternalComponent(Env));
122+
register(new InternalComponent(this));
123123
register(new MSBuildComponent(this));
124124
register(new BuildComponent(Env));
125125
register(new FunctionComponent(this));

vsSolutionBuildEvent/SBEScripts/Components/BoxComponent.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ protected string dataFree(IPM pm, string name)
378378
"stData",
379379
new string[] { "name", "forceEval" },
380380
new string[] { "The name of package.", "To force evaluate data of package before receiving." },
381-
CValueType.Void,
381+
CValueType.Mixed,
382382
CValueType.String, CValueType.Boolean)]
383383
protected string dataGet(ILevel level, IPM pm)
384384
{
@@ -408,15 +408,15 @@ protected string dataGet(IPM pm, string name, bool forceEval)
408408
"stData",
409409
new string[] { "name", "count" },
410410
new string[] { "The name of package.", "The number of clones." },
411-
CValueType.Void,
411+
CValueType.Mixed,
412412
CValueType.String, CValueType.Integer)]
413413
[Method("clone",
414414
"Multiple getting package data.",
415415
"data",
416416
"stData",
417417
new string[] { "name", "count", "forceEval" },
418418
new string[] { "The name of package.", "The number of clones.", "To force evaluate data of package before receiving." },
419-
CValueType.Void,
419+
CValueType.Mixed,
420420
CValueType.String, CValueType.Integer, CValueType.Boolean)]
421421
protected string dataClone(ILevel level, IPM pm)
422422
{

vsSolutionBuildEvent/SBEScripts/Components/InternalComponent.cs

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using System;
1919
using net.r_eg.vsSBE.Actions;
20+
using net.r_eg.vsSBE.Bridge;
2021
using net.r_eg.vsSBE.Events;
2122
using net.r_eg.vsSBE.Exceptions;
2223
using net.r_eg.vsSBE.SBEScripts.Dom;
@@ -47,6 +48,13 @@ public override bool CRegex
4748
get { return true; }
4849
}
4950

51+
/// <param name="loader">Initialization with loader</param>
52+
public InternalComponent(IBootloader loader)
53+
: base(loader)
54+
{
55+
56+
}
57+
5058
/// <param name="env">Used environment</param>
5159
public InternalComponent(IEnvironment env)
5260
: base(env)
@@ -166,28 +174,27 @@ protected string stEvents(IPM pm)
166174
}
167175

168176
/// <summary>
169-
/// Work with event-item node.
170-
/// `events.Type.item(string name | integer index)`
177+
/// `events.Type.item(string name | integer index)`
171178
/// </summary>
172179
/// <param name="type">Type of available events</param>
173180
/// <param name="pm"></param>
174-
/// <returns>evaluated data</returns>
181+
/// <returns></returns>
175182
[Method(
176-
"item",
177-
"Event item by name",
183+
"item",
184+
"Access to action by name",
178185
"", "stEvents",
179186
new string[] { "name" },
180-
new string[] { "Name of the event" },
187+
new string[] { "Name of the action" },
181188
CValueType.Void,
182189
CValueType.String
183190
)]
184191
[Method(
185-
"item",
186-
"Event item by index",
192+
"item",
193+
"Access to action by index",
187194
"",
188195
"stEvents",
189196
new string[] { "index" },
190-
new string[] { "Index of the event >= 1" },
197+
new string[] { "Index of the action >= 1" },
191198
CValueType.Void,
192199
CValueType.Integer
193200
)]
@@ -215,6 +222,9 @@ protected string stEventItem(SolutionEventType type, IPM pm)
215222
if(pm.Is(1, LevelType.Property, "Enabled")) {
216223
return pEnabled(evt, pm.pinTo(2));
217224
}
225+
if(pm.Is(1, LevelType.Method, "run")) {
226+
return mActionRun(type, evt, pm.pinTo(1));
227+
}
218228
if(pm.Is(1, LevelType.Property, "Status")) {
219229
return itemStatus(type, index, pm.pinTo(1));
220230
}
@@ -233,11 +243,11 @@ protected string stEventItem(SolutionEventType type, IPM pm)
233243
/// `item(...).Status.HasErrors`
234244
/// </summary>
235245
/// <param name="type">Selected event type.</param>
236-
/// <param name="index">Access by index.</param>
246+
/// <param name="index">Access to action by index.</param>
237247
/// <param name="pm"></param>
238248
/// <returns></returns>
239-
[Property("Status", "Available statuses for selected event-item.", "item", "stEventItem")]
240-
[Property("HasErrors", "Checking existence of errors after executed action for selected event-item.", "Status", "itemStatus", CValueType.Boolean)]
249+
[Property("Status", "Available states for selected event-action.", "item", "stEventItem")]
250+
[Property("HasErrors", "Checking existence of errors after executed action for selected event-action.", "Status", "itemStatus", CValueType.Boolean)]
241251
protected string itemStatus(SolutionEventType type, int index, IPM pm)
242252
{
243253
if(!pm.Is(LevelType.Property, "Status")) {
@@ -283,7 +293,7 @@ protected string pStderr(ISolutionEvent evt, IPM pm)
283293
/// <param name="evt">Selected event</param>
284294
/// <param name="pm"></param>
285295
/// <returns></returns>
286-
[Property("Enabled", "Gets or Sets Enabled status for selected event-item", "item", "stEventItem", CValueType.Boolean, CValueType.Boolean)]
296+
[Property("Enabled", "Gets or Sets Enabled status for selected event-action", "item", "stEventItem", CValueType.Boolean, CValueType.Boolean)]
287297
protected string pEnabled(ISolutionEvent evt, IPM pm)
288298
{
289299
if(pm.FinalEmptyIs(LevelType.RightOperandEmpty)) {
@@ -296,6 +306,51 @@ protected string pEnabled(ISolutionEvent evt, IPM pm)
296306
return Value.Empty;
297307
}
298308

309+
[Method(
310+
"run",
311+
"Execute Action with specific context. Returns true value if it was handled.",
312+
"item",
313+
"stEventItem",
314+
new string[] { "context" },
315+
new string[] { "Specific context." },
316+
CValueType.Boolean,
317+
CValueType.Enum
318+
)]
319+
[Method(
320+
"run",
321+
"Execute Action. Returns true value if it was handled.",
322+
"item",
323+
"stEventItem",
324+
new string[] { "" },
325+
new string[] { "" },
326+
CValueType.Boolean,
327+
CValueType.Void
328+
)]
329+
protected string mActionRun(SolutionEventType type, ISolutionEvent evt, IPM pm)
330+
{
331+
if(!pm.FinalEmptyIs(LevelType.Method, "run")) {
332+
throw new IncorrectNodeException(pm);
333+
}
334+
ILevel level = pm.FirstLevel;
335+
336+
BuildType buildType;
337+
if(level.Args == null || level.Args.Length < 1) {
338+
buildType = BuildType.Common;
339+
}
340+
else if(level.Is(ArgumentType.EnumOrConst)) {
341+
buildType = (BuildType)Enum.Parse(typeof(BuildType), (string)level.Args[0].data);
342+
}
343+
else {
344+
throw new ArgumentPMException(level, "run([enum context])");
345+
}
346+
347+
ICommand cmd = new Actions.Command(env, script, msbuild);
348+
Log.Info($"Execute action by user-script: '{evt.Name}'(context: {buildType}) /as '{type}' event");
349+
350+
cmd.Env.BuildType = buildType;
351+
return Value.from(cmd.exec(evt, type));
352+
}
353+
299354
protected virtual ISolutionEvent[] getEvent(SolutionEventType type)
300355
{
301356
try {

vsSolutionBuildEvent/UI/WForms/EventsFrm.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vsSolutionBuildEvent/UI/WForms/Logic/Events.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ public void execAction()
872872
SolutionEventType type = SBE.type;
873873
Log.Info("Action: execute action '{0}':'{1}' manually :: emulate '{2}' event", evt.Name, evt.Caption, type);
874874

875+
cmd.Env.BuildType = BuildType.Common; //TODO: IBuild.updateBuildType
875876
try {
876877
bool res = cmd.exec(evt, type);
877878
Log.Info("Action: '{0}':'{1}' completed as - '{2}'", evt.Name, evt.Caption, res.ToString());

0 commit comments

Comments
 (0)