Skip to content

Commit

Permalink
[InternalComponent] Implemented boolean run([enum context]) To Exec…
Browse files Browse the repository at this point in the history
…ute 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`
  • Loading branch information
3F committed Nov 11, 2016
1 parent 327a5ab commit f826905
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 45 deletions.
27 changes: 19 additions & 8 deletions vsSolutionBuildEvent/Actions/ActionCSharp.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2015 Denis Kuzmin (reg) <[email protected]>
* Copyright (c) 2013-2016 Denis Kuzmin (reg) <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand Down Expand Up @@ -39,7 +39,7 @@ public class ActionCSharp: Action, IAction
/// <summary>
/// Main class for user code.
/// </summary>
public const string MAIN_CLASS = "vsSolutionBuildEvent.CSharpMode";
public const string MAIN_CLASS = Settings.APP_NAME + ".CSharpMode";

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

/// <summary>
/// Where to look cache.
Expand Down Expand Up @@ -108,13 +108,24 @@ public override bool process(ISolutionEvent evt)
type = load(outputCacheFile(evt), assemblyName(evt));
}

if(type == null) {
Log.Error($"Compiled type is null. Something went wrong for C# Action '{evt.Name}'");
}

int ret = run(type, cmd, evt);
if(ret != 0)
{
Log.Warn("Return code '{0}'", ret);
return false;
if(ret == 0) {
return true;
}
return true;

string retmsg = $"Return code '{ret}'";

if(((IModeCSharp)evt.Mode).TreatWarningsAsErrors) {
Log.Error(retmsg);
}
else {
Log.Warn(retmsg);
}
return false;
}

/// <param name="cmd"></param>
Expand Down
14 changes: 10 additions & 4 deletions vsSolutionBuildEvent/Actions/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,23 @@ protected bool actionBy(ModeType type, ISolutionEvent evt)
}

string marker = null;
if(Thread.CurrentThread.Name == Events.LoggingEvent.IDENT_TH) {
marker = Events.LoggingEvent.IDENT_TH;
if(Thread.CurrentThread.Name == LoggingEvent.IDENT_TH) {
marker = LoggingEvent.IDENT_TH;
}

(new Task(() => {

if(Thread.CurrentThread.Name == null && marker != null) {
Thread.CurrentThread.Name = marker;
}
Log.Trace("Task for another thread is started for '{0}' /{1}", evt.Name, type);
actions[type].process(evt);

Log.Trace($"Task ({type}) for another thread is started for '{evt.Name}'");
try {
actions[type].process(evt);
}
catch(Exception ex) {
Log.Error($"Task ({type}) for another thread is failed. '{evt.Name}' Error: `{ex.Message}`");
}

})).Start();

Expand Down
2 changes: 1 addition & 1 deletion vsSolutionBuildEvent/IsolatedEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public IsolatedEnv(string solutionFile, TProp properties)
/// <param name="properties">Solution properties.</param>
public IsolatedEnv(TProp properties)
{

slnProperties = properties;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion vsSolutionBuildEvent/SBEScripts/Bootloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public virtual void register()
register(new UserVariableComponent(this));
register(new OWPComponent(Env));
register(new DTEComponent(Env));
register(new InternalComponent(Env));
register(new InternalComponent(this));
register(new MSBuildComponent(this));
register(new BuildComponent(Env));
register(new FunctionComponent(this));
Expand Down
6 changes: 3 additions & 3 deletions vsSolutionBuildEvent/SBEScripts/Components/BoxComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ protected string dataFree(IPM pm, string name)
"stData",
new string[] { "name", "forceEval" },
new string[] { "The name of package.", "To force evaluate data of package before receiving." },
CValueType.Void,
CValueType.Mixed,
CValueType.String, CValueType.Boolean)]
protected string dataGet(ILevel level, IPM pm)
{
Expand Down Expand Up @@ -408,15 +408,15 @@ protected string dataGet(IPM pm, string name, bool forceEval)
"stData",
new string[] { "name", "count" },
new string[] { "The name of package.", "The number of clones." },
CValueType.Void,
CValueType.Mixed,
CValueType.String, CValueType.Integer)]
[Method("clone",
"Multiple getting package data.",
"data",
"stData",
new string[] { "name", "count", "forceEval" },
new string[] { "The name of package.", "The number of clones.", "To force evaluate data of package before receiving." },
CValueType.Void,
CValueType.Mixed,
CValueType.String, CValueType.Integer, CValueType.Boolean)]
protected string dataClone(ILevel level, IPM pm)
{
Expand Down
81 changes: 68 additions & 13 deletions vsSolutionBuildEvent/SBEScripts/Components/InternalComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using net.r_eg.vsSBE.Actions;
using net.r_eg.vsSBE.Bridge;
using net.r_eg.vsSBE.Events;
using net.r_eg.vsSBE.Exceptions;
using net.r_eg.vsSBE.SBEScripts.Dom;
Expand Down Expand Up @@ -47,6 +48,13 @@ public override bool CRegex
get { return true; }
}

/// <param name="loader">Initialization with loader</param>
public InternalComponent(IBootloader loader)
: base(loader)
{

}

/// <param name="env">Used environment</param>
public InternalComponent(IEnvironment env)
: base(env)
Expand Down Expand Up @@ -166,28 +174,27 @@ protected string stEvents(IPM pm)
}

/// <summary>
/// Work with event-item node.
/// `events.Type.item(string name | integer index)`
/// `events.Type.item(string name | integer index)`
/// </summary>
/// <param name="type">Type of available events</param>
/// <param name="pm"></param>
/// <returns>evaluated data</returns>
/// <returns></returns>
[Method(
"item",
"Event item by name",
"item",
"Access to action by name",
"", "stEvents",
new string[] { "name" },
new string[] { "Name of the event" },
new string[] { "Name of the action" },
CValueType.Void,
CValueType.String
)]
[Method(
"item",
"Event item by index",
"item",
"Access to action by index",
"",
"stEvents",
new string[] { "index" },
new string[] { "Index of the event >= 1" },
new string[] { "Index of the action >= 1" },
CValueType.Void,
CValueType.Integer
)]
Expand Down Expand Up @@ -215,6 +222,9 @@ protected string stEventItem(SolutionEventType type, IPM pm)
if(pm.Is(1, LevelType.Property, "Enabled")) {
return pEnabled(evt, pm.pinTo(2));
}
if(pm.Is(1, LevelType.Method, "run")) {
return mActionRun(type, evt, pm.pinTo(1));
}
if(pm.Is(1, LevelType.Property, "Status")) {
return itemStatus(type, index, pm.pinTo(1));
}
Expand All @@ -233,11 +243,11 @@ protected string stEventItem(SolutionEventType type, IPM pm)
/// `item(...).Status.HasErrors`
/// </summary>
/// <param name="type">Selected event type.</param>
/// <param name="index">Access by index.</param>
/// <param name="index">Access to action by index.</param>
/// <param name="pm"></param>
/// <returns></returns>
[Property("Status", "Available statuses for selected event-item.", "item", "stEventItem")]
[Property("HasErrors", "Checking existence of errors after executed action for selected event-item.", "Status", "itemStatus", CValueType.Boolean)]
[Property("Status", "Available states for selected event-action.", "item", "stEventItem")]
[Property("HasErrors", "Checking existence of errors after executed action for selected event-action.", "Status", "itemStatus", CValueType.Boolean)]
protected string itemStatus(SolutionEventType type, int index, IPM pm)
{
if(!pm.Is(LevelType.Property, "Status")) {
Expand Down Expand Up @@ -283,7 +293,7 @@ protected string pStderr(ISolutionEvent evt, IPM pm)
/// <param name="evt">Selected event</param>
/// <param name="pm"></param>
/// <returns></returns>
[Property("Enabled", "Gets or Sets Enabled status for selected event-item", "item", "stEventItem", CValueType.Boolean, CValueType.Boolean)]
[Property("Enabled", "Gets or Sets Enabled status for selected event-action", "item", "stEventItem", CValueType.Boolean, CValueType.Boolean)]
protected string pEnabled(ISolutionEvent evt, IPM pm)
{
if(pm.FinalEmptyIs(LevelType.RightOperandEmpty)) {
Expand All @@ -296,6 +306,51 @@ protected string pEnabled(ISolutionEvent evt, IPM pm)
return Value.Empty;
}

[Method(
"run",
"Execute Action with specific context. Returns true value if it was handled.",
"item",
"stEventItem",
new string[] { "context" },
new string[] { "Specific context." },
CValueType.Boolean,
CValueType.Enum
)]
[Method(
"run",
"Execute Action. Returns true value if it was handled.",
"item",
"stEventItem",
new string[] { "" },
new string[] { "" },
CValueType.Boolean,
CValueType.Void
)]
protected string mActionRun(SolutionEventType type, ISolutionEvent evt, IPM pm)
{
if(!pm.FinalEmptyIs(LevelType.Method, "run")) {
throw new IncorrectNodeException(pm);
}
ILevel level = pm.FirstLevel;

BuildType buildType;
if(level.Args == null || level.Args.Length < 1) {
buildType = BuildType.Common;
}
else if(level.Is(ArgumentType.EnumOrConst)) {
buildType = (BuildType)Enum.Parse(typeof(BuildType), (string)level.Args[0].data);
}
else {
throw new ArgumentPMException(level, "run([enum context])");
}

ICommand cmd = new Actions.Command(env, script, msbuild);
Log.Info($"Execute action by user-script: '{evt.Name}'(context: {buildType}) /as '{type}' event");

cmd.Env.BuildType = buildType;
return Value.from(cmd.exec(evt, type));
}

protected virtual ISolutionEvent[] getEvent(SolutionEventType type)
{
try {
Expand Down
2 changes: 1 addition & 1 deletion vsSolutionBuildEvent/UI/WForms/EventsFrm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vsSolutionBuildEvent/UI/WForms/Logic/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ public void execAction()
SolutionEventType type = SBE.type;
Log.Info("Action: execute action '{0}':'{1}' manually :: emulate '{2}' event", evt.Name, evt.Caption, type);

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

0 comments on commit f826905

Please sign in to comment.