AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 22.08.2012, 01:11   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
emeadaxsupport: AX for Retail: Custom command-line arguments for POS training mode
Источник: http://blogs.msdn.com/b/axsupport/ar...ning-mode.aspx
==============

We recently had a scenario where a customer wanted to be able to start the POS in training mode directly from an shortcut instead of having the user go in and select training mode from the menu.  They would then have two icons for POS:  one for “live” operation and one for training.  Usually this would entail using a command-line parameter to represent whether training mode would be set or not and then creating the shortcut with that parameter.

Unfortunately the POS does not have such a command-line argument.  But that doesn’t mean you can’t add one yourself.

Normally command-line arguments are read during application start up in the Main() method.  But .Net has a not-so-widely-used method in the Environment class that can be used to re-read them at any point:
Environment.GetCommandLineArgs()
This returns an array of strings just like the Main() method gets.  You can loop through this and see if your string is included:

 

1: foreach (string arg in Environment.GetCommandLineArgs()) 2: { 3: if (arg.StartsWith("-ATRAIN", StringComparison.OrdinalIgnoreCase)) 4: { 5: //do stuff 6: } 7: } 8:  

Note that this is a very simplistic way of checking command line arguments – there are plenty of parsing libraries out there if you want to add more flexibility.  Also note that I used “-ATRAIN” instead of “-TRAIN” because the POS app already has a monopoly on arguments that start with “-TR” (see the article AX for Retail: Modifying POS Labels and Strings for more about the usefulness of that flag).

So now that we know we can read our custom command-line argument, the question is finding a place to put it.  You have the option of simply calling GetCommandLineArgs() any time you need to check for it (since persisting it to an object may be difficult) or if you truly only need it at startup, you can put it in the ApplicationStart() method of the Application triggers.  In our example, we just want to start the POS in training mode which only needs to happen once during startup:

 

1: public void ApplicationStart() 2: { 3: LSRetailPosis.ApplicationLog.Log("IApplicationTriggers.ApplicationStart", "Application has started", LSRetailPosis.LogTraceLevel.Debug); 4: 5: foreach (string arg in Environment.GetCommandLineArgs()) 6: { 7: if (arg.StartsWith("-ATRAIN", StringComparison.OrdinalIgnoreCase)) 8: { 9: LSRetailPosis.ApplicationLog.Log("IApplicationTriggers.ApplicationStart", "Training Mode == true", LSRetailPosis.LogTraceLevel.Debug); 10: LSRetailPosis.Settings.ApplicationSettings.Terminal.TrainingMode = true; 11: } 12: } 13: } 

 

Deploying this custom ApplicationTriggers.dll to your POS folder will do two things:  write a quick message to the RetailLog table and flip the “TrainingMode” flag to true.  This will force the application to training mode before the logon screen even appears.

To utilize this this, option, create a desktop shortcut and add the argument after POS.exe:

 



 

Another advantage of this customization:  you can turn on “Hide Training Mode” so that the only way to get into training mode is by launching the shortcut.  This will allow you to prevent users from switching between training mode and live mode on the logon screen:

  



You can use custom command-line arguments for other purposes as well – it is a very simple way to “store” settings (as opposed to the POS.exe.config file, the registry, etc.).  If you think of any other creative uses, feel free to toss a note in the comments section below.

[Note:  this post was written with AX for Retail 2012 in mind.  The command-line argument trick should work in 2009 but I’m not sure if turning on training mode is as simple.]




Источник: http://blogs.msdn.com/b/axsupport/ar...ning-mode.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
emeadaxsupport: AX for Retail 2012: Working with Custom Fields Blog bot DAX Blogs 0 07.08.2012 07:12
emeadaxsupport: New Content for Microsoft Dynamics AX 2012 : October 2011 Blog bot DAX Blogs 0 27.10.2011 17:11
axinthefield: Dynamics AX Event IDs Blog bot DAX Blogs 0 01.03.2011 22:11
daxdilip: Whats New in Dynamics AX 2012 (A brief extract from the recently held Tech Conf.) Blog bot DAX Blogs 7 31.01.2011 12:35
axStart: Microsoft Dynamics AX 2009 Hot Topics Web Seminar Series Blog bot DAX Blogs 0 06.08.2008 12:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 20:44.