tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/13073-how-can-i-ensure-a-command-is-always-injected-with-a-payload-even-if-one-isnt-passedRobotlegs: Discussion 2015-08-05T09:27:28Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-03T04:55:47Z2015-08-04T11:39:24ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Hi kamcknig</p>
<p>Macrobot executes commands in an isolated environment using
a<br>
sub-injector, so anything you map at an higher level can be used in
the<br>
commands.</p>
<p>You could try to map a TimeoutVO instance in your context as the
default<br>
value, and then pass or not another one in the payloads. If you
don't<br>
pass a payload, the command should get th default value mapped in
the<br>
context. If you do pass a payload, it should replace the parent
mapping.</p>
<p>El 02/08/2015 a las 11:48, kamcknig escribió:</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-03T11:24:44Z2015-08-04T11:39:24ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Hi,</p>
<blockquote>
<p>My question is: how do I ensure that the command is always
injected with a timeout even if I don't/can't pass a payload. For
example, what If I did: add(SomeCommand)</p>
</blockquote>
<p>You can try to make the injection optional:</p>
<p>SomeCommand</p>
<pre>
<code>[Inject (optional=true)]
public var timeoutVo:TimeoutVO;</code>
</pre>
<p>same for the event, if need be:</p>
<pre>
<code>[Inject (optional=true)]
public var someEvent:SomeEvent;</code>
</pre>
<p>This way you are free to add a command to the sequence of
commands with or without a payload and also to run the command by
dispatching the event to which it was mapped in your config.</p>
<p>Does this solve your problem?</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-03T22:06:05Z2015-08-04T11:39:23ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Yep!</p>
<p>Unless you have a better way to do what I'm trying to accomplish
then that answers it!</p>
<p>Thanks so much</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T11:39:05Z2015-08-04T11:39:23ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>You're welcome!</p>
<p>There are a few ways to do that, but I don't know if they are
any better than your solution. As always, it depends on your
requirements what's best.</p>
<p><em>1</em> TimeoutVO is injected into every class that
dispatches SomeEvent that triggers SomeCommand.</p>
<p>timeoutVO.timeout is set to a new value before dispatching the
event (or before running the macro commands) and the command, which
is also injected with TimeoutVO, reads the vo's value. SomeEvent
has no payload, thus you don't need to inject it into the
command.</p>
<p><em>2</em> SomeEvent has a property timeout with a default value
= 30. SomeEvent is injected into SomeCommand and into the
BootstrapCommand or is created there. Before adding the command to
the sequence of commands, someEvent.timout is set to the desired
value.</p>
<pre>
<code>someEvent.timeout = 25;
add(SomeCommand).withPayloads(someEvent);</code>
</pre>
<p><em>3</em> SomeEvent has a property timeoutVO. You inject
SomeEvent into BootstrapCommand or create a new SomeEvent, then set
the value of SomeEvent's vo:</p>
<pre>
<code>var someEvent:SomeEvent = new SomeEvent("");
someEvent.timeoutVO = new TimeoutVO(25);
add(SomeCommand).withPayloads(someEvent);</code>
</pre>
<p>SomeCommand has only someEvent as a dependency. There you read
the value of someEvent.timeoutVO.timeout.</p>
<p>I'd use the 3rd solution, because I don't need to inject the VO
into the command as well and because I can send a strongly typed
payload with the event dispatched from elsewhere, if need be.</p>
<p>I can't think of other solutions right now.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T11:41:21Z2015-08-04T11:41:21ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>@greenLED I just saw your message and merged it with this
discussion. It was a private message (not visible to the public)
and also as a separate thread. I suspect, that happened because you
were answering through email. Either the tender forum has a bug, or
you set a private flag in your email when you answered. You should
try answering directly in the browser after logging in into the
forum.</p>
<p>Anyway, thanks for participating to the discussion.</p>
<blockquote>
<p>Macrobot executes commands in an isolated environment using a
sub-injector, so anything you map at an higher level can be used in
the<br>
commands.</p>
</blockquote>
<p>That's true with the exception of events that were mapped to a
command by the eventCommandMap. In order to get the event injected
automatically into a command that is run through the macrobot,
you'd either have to create a mapping for the event using
macrobot's injector, or to simply add the command
withPayloads(someEvent);</p>
<blockquote>
<p>You could try to map a TimeoutVO instance in your context as the
default value, and then pass or not another one in the payloads. If
you don't<br>
pass a payload, the command should get th default value mapped in
the<br>
context. If you do pass a payload, it should replace the parent
mapping.</p>
</blockquote>
<p>That's a good idea!! The mapping would look like this:</p>
<pre>
<code>var timeoutVO: TimeoutVO = new TimeoutVO (30);
injector.map(TimeoutVO).toValue(timeoutVO);</code>
</pre>
<p>However, I'd prefer a solution where you wouldn't need to inject
both, a VO and an Event with the VO as a payload.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T12:14:24Z2015-08-04T12:14:24ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Great!</p>
<p>Thanks so much for the answers.</p>
<p>@greenLED yeah I didn't even see your response until @Ondina
added it here.</p>
<p>All great solutions that I wouldn't have though of but all make
their own sense.</p>
<blockquote>
<p>However, I'd prefer a solution where you wouldn't need to inject
both, a VO and an > Event with the VO as a payload</p>
</blockquote>
<p>That' what I was hoping for, to not have to inject both and test
of the existence of one or the other!</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T13:20:55Z2015-08-04T13:20:55ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Just a variant of my 3rd solution from the previous post, where
only SomeEvent is injected into SomeCommand.</p>
<p>SomeEvent:</p>
<pre>
<code>private var _timeoutVO:TimeoutVO;
public function SomeEvent(type:String=null, vo:TimeoutVO=null, bubbles:Boolean=false, cancelable:Boolean=false)
{
_timeoutVO = vo || new TimeoutVO ();//default 30
//or
//_timeoutVO = vo || new TimeoutVO (90);
super(type, bubbles, cancelable);
}
public function get timeoutVO():TimeoutVO
{
return _timeoutVO;
}
override public function clone():Event
{
return new SomeEvent(type, timeoutVO, bubbles, cancelable);
}</code>
</pre>
<p>BootstrapCommand</p>
<pre>
<code>...
//this would trace the value set inside of the event, 90 or the default 30
//add(SomeCommand).withPayloads(new SomeEvent(""));
//or
var someEvent:SomeEvent = new SomeEvent("something", new TimeoutVO (120));
add(SomeCommand).withPayloads(someEvent);
...</code>
</pre>
<p>Some other class:</p>
<p>dispatch(new SomeEvent(SomeEvent.SOME_TYPE, new TimeoutVO
(5)));</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T13:38:31Z2015-08-04T13:38:31ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Perfect!</p>
<p>I'll mark this as closed.</p></div>kamcknigtag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-04T18:55:04Z2015-08-04T18:55:04ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>Hi @ondina and thanks for pointing out the private/public thing.
I never meant to make it private. I use to answer directly from
mail because sometimes this forum loads very slow from my
connection, but, lucky me, I tried again today and it is loading at
a normal speed again, so welcome web forms :) Sadly, also saw some
other mail answers marked as private, and aparently with no
connection with original questions. Looks like I have been doing
something very in the wrong way.</p>
<p>Anyway, how could I flag my email answers as public?</p></div>greenLEDtag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-05T08:38:45Z2015-08-05T08:58:33ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>@greenLED I've never replied per email to discussions on this
forum, hence I don't know much about Tender's email commands. There
is a list of commands on Tender Support that can be used by staff
members/supporters, but I'm not sure whether commands like #
private or # public can be used by regular users as well.<br>
<a href="https://help.tenderapp.com/kb/email-integration/updating-discussions-through-email-commands">
https://help.tenderapp.com/kb/email-integration/updating-discussion...</a><br>
When I receive an email from robotlegs forum, there is an
additional info text telling me which commands I can use to reply
per email, as a supporter.<br>
Something like this:</p>
<pre>
<code>You can use commands on a new line at the top of this email (more information):
#resolve #acknowledge #spam #delete #queue #notify #ignore #public #private #internal</code>
</pre>
<p>I don't know what you see as a regular user. Is there anything
about commands?</p>
<p>The next message will be a test sent by email.</p>
<p>@ kamcknig I'm glad to hear that you are back on track and sorry
for the following emails about emails:) Just ignore us for the time
being..</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-05T08:44:19Z2015-08-05T08:58:52ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>This message has been sent by email.<br>
I've edited the original message, which was just garbage.
Sorry.</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/375440422015-08-05T09:27:26Z2015-08-05T09:27:26ZHow can I ensure a command is always injected with a payload even if one isn't passed?<div><p>@greenLED I've created a new thread where we can test tender's
behaviour:</p>
<p><a href="http://knowledge.robotlegs.org/discussions/feedback/1014-testing-tenders-email-commands">
http://knowledge.robotlegs.org/discussions/feedback/1014-testing-te...</a></p>
<p>I'm going to close this discussion.</p></div>Ondina D.F.