Пример #1
0
 public IHttpActionResult Post(RunTaskCommand command)
 {
     return(HandleCommand(command));
 }
Пример #2
0
        public void RunsTask()
        {
            _engine      = new AutomationEngineInstance(null);
            _runTask     = new RunTaskCommand();
            _textFile    = new TextFile.WriteCreateTextFileCommand();
            _setVariable = new Variable.SetVariableCommand();
            _taskScript  = new Script();

            List <ScriptVariable> variables = new List <ScriptVariable>();
            ScriptVariable        var1      = new ScriptVariable();

            var1.VariableName  = "output";
            var1.VariableValue = "outputValue";
            var1.VariableType  = typeof(string);
            variables.Add(var1);

            _taskScript.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            // set script variables
            _taskScript.Variables = variables;

            List <ScriptArgument> arguments = new List <ScriptArgument>();
            ScriptArgument        arg1      = new ScriptArgument();

            arg1.ArgumentName  = "inputArg";
            arg1.Direction     = ScriptArgumentDirection.In;
            arg1.ArgumentValue = "default";
            arg1.ArgumentType  = typeof(string);
            arguments.Add(arg1);
            ScriptArgument arg2 = new ScriptArgument();

            arg2.ArgumentName     = "outputArg";
            arg2.Direction        = ScriptArgumentDirection.Out;
            arg2.ArgumentValue    = "default";
            arg2.AssignedVariable = "{outputVar}";
            arg2.ArgumentType     = typeof(string);
            arguments.Add(arg2);

            // set script arguments
            _taskScript.Arguments = arguments;

            string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName;
            string filePath         = Path.Combine(projectDirectory, @"Resources");

            _textFile.v_FilePath    = Path.Combine(filePath, @"test.txt");
            _textFile.v_TextToWrite = "{inputArg}";
            _textFile.v_Overwrite   = "Overwrite";
            _engine.AutomationEngineContext.FilePath = Path.Combine(filePath, "task.obscript");
            _engine.AutomationEngineContext.IsTest   = true;
            List <ScriptAction> commands = new List <ScriptAction>();
            ScriptAction        com1     = new ScriptAction();

            com1.ScriptCommand = _textFile;
            commands.Add(com1);

            _setVariable.v_Input = "outputValue";
            _setVariable.v_OutputUserVariableName = "{outputArg}";
            ScriptAction com2 = new ScriptAction();

            com2.ScriptCommand = _setVariable;
            commands.Add(com2);

            _taskScript.Commands = commands;

            //write to file
            var serializerSettings = new JsonSerializerSettings()
            {
                TypeNameHandling = TypeNameHandling.Objects,
            };
            JsonSerializer serializer = JsonSerializer.Create(serializerSettings);

            using (StreamWriter sw = new StreamWriter(_engine.AutomationEngineContext.FilePath))
                using (JsonWriter writer = new JsonTextWriter(sw)
                {
                    Formatting = Formatting.Indented
                })
                {
                    serializer.Serialize(writer, _taskScript, typeof(Script));
                }

            DataTable argumentTable = new DataTable();

            argumentTable.Columns.Add("ArgumentName");
            argumentTable.Columns.Add("ArgumentType");
            argumentTable.Columns.Add("ArgumentValue");
            argumentTable.Columns.Add("ArgumentDirection");
            argumentTable.Columns[1].DataType = typeof(Type);
            DataRow arg1row = argumentTable.NewRow();

            arg1row["ArgumentName"]      = "inputArg";
            arg1row["ArgumentType"]      = typeof(string);
            arg1row["ArgumentValue"]     = "{taskInput}";
            arg1row["ArgumentDirection"] = "In";
            DataRow arg2row = argumentTable.NewRow();

            arg2row["ArgumentName"]      = "outputArg";
            arg2row["ArgumentType"]      = typeof(string);
            arg2row["ArgumentValue"]     = "{outputVar}";
            arg2row["ArgumentDirection"] = "Out";
            argumentTable.Rows.Add(arg1row);
            argumentTable.Rows.Add(arg2row);

            _runTask.v_TaskPath            = _engine.AutomationEngineContext.FilePath;
            _runTask.v_AssignArguments     = true;
            _runTask.v_ArgumentAssignments = argumentTable;

            List <ScriptAction> mainCommands  = new List <ScriptAction>();
            ScriptAction        runTaskAction = new ScriptAction();

            runTaskAction.ScriptCommand = _runTask;

            VariableMethods.CreateTestVariable("inputValue", _engine, "taskInput", typeof(string));
            VariableMethods.CreateTestVariable("default", _engine, "taskOutput", typeof(string));
            VariableMethods.CreateTestVariable(null, _engine, "outputVar", typeof(string));

            _engine.ExecuteCommand(runTaskAction);

            Assert.Equal("outputValue", "{outputVar}".ConvertUserVariableToString(_engine));
            Assert.True(OBIO.File.Exists(Path.Combine(filePath, @"test.txt")));
            Assert.Equal("inputValue", OBIO.File.ReadAllText(Path.Combine(filePath, @"test.txt")));

            OBIO.File.Delete(Path.Combine(filePath, @"test.txt"));
            OBIO.File.Delete(Path.Combine(filePath, @"task.obscript"));
        }
Пример #3
0
        public MainWindowViewModel(List <Task> tasks, UserGroup group)
        {
            GridWidth = false;

            // Set the current user
            CurrentUser = RunTimeContext.Context.CurrentUser;

            #region Lists

            // The list of scheduled tasks (bind to the Schedule list in UI)
            ScheduledList = new ObservableCollection <Schedule>(ScheduleManager.GetScheduledTask(RunTimeContext.Context.CurrentUser,
                                                                                                 RunTimeContext.Context.DatabaseContext));

            // Result list (bind to the result panel in UI)
            ResultList = new ObservableCollection <ResultTask>();

            // Property list, to use with FileLib, /!\ not implemented now :(
            Props = new ObservableCollection <Dictionary <string, string> >();

            // Task list, with all the task, given by the loading screen as constructor parameter
            TaskList = tasks == null ? new ObservableCollection <Task>() : new ObservableCollection <Task>(tasks);

            // The list of queued tasks (bind to the queue panel in UI)
            QueueList = new ObservableCollection <Task>();

            // The list of markets (Bind to the combobox with the list of markets in UI)
            MarketList = new ObservableCollection <Market>(MarketManager.GetAllMarkets(RunTimeContext.Context.DatabaseContext));

            #endregion

            #region Selected

            // Set the market to the main market of the user
            SelectedMarket = CurrentUser.MainMarket;

            // Set the selected task to the first one of the list
            SelectedTask = FilteredTasks.FirstOrDefault();

            #endregion

            #region User right

            // Those three properties are used to be bind with some UI elements like menu
            // If you bind the IsVisibility property of a control with one of those, only the group of person with the appropriate
            // rights will be able to see it
            // eg : Visibility="{Binding IsAdmin}" <-- only Admin level people will see

            // Do the user have Admin Access ?
            IsAdmin = (@group == UserGroup.Dev || @group == UserGroup.Admin) ? Visibility.Visible : Visibility.Collapsed;

            // Manager ?
            IsManager = @group == UserGroup.Manager ? Visibility.Visible : Visibility.Collapsed;

            // Or maybe a Developer ?
            IsDev = @group == UserGroup.Dev ? Visibility.Visible : Visibility.Collapsed;

            #endregion

            #region Commands

            OpenConfigCommand   = new OpenConfigCommand(this);
            OpenScheduleCommand = new OpenScheduleCommand(this);

            OpenFileCommand   = new OpenFileCommand(this);
            OpenFolderCommand = new OpenFolderCommand(this);

            OpenLogCommand = new OpenLogCommand(this);

            RunCommand      = new RunTaskCommand(this);
            QueueCommand    = new QueueTaskCommand(this);
            RemoveCommand   = new RemoveTaskCommand(this);
            CloseCommand    = new CloseWindowCommand();
            MinimizeCommand = new MinimizeWindowCommand();
            MaximizeCommand = new MaximizeWindowCommand();
            LogoutCommand   = new LogoutCommand();

            ClearQueueCommand    = new ClearQueueCommand(this);
            MoveDownQueueCommand = new MoveDownQueueCommand(this);
            MoveUpQueueCommand   = new MoveUpQueueCommand(this);

            StartQueueCommand     = new StartQueueCommand(this);
            AddScheduleCommand    = new AddScheduleCommand(this);
            RemoveScheduleCommand = new RemoveScheduleCommand(this);
            ChangeScheduleCommand = new ChangeScheduleCommand(this);
            ShowAllTaskCommand    = new ShowAllTaskCommand(this);
            ShowMarketTaskCommand = new ShowMarketTaskCommand(this);

            ShowInfoCommand  = new ShowInfoCommand(this);
            ShowQueueCommand = new ShowQueueCommand(this);

            FilterResultCommand = new FilterResultCommand(this);

            ReportDevCommand = new ReportDevCommand(this);

            #endregion

            // Number of time in a row a task failed
            // if 3 the error window will appear automatically
            FailedInARow = 0;

            #region Hide other regions

            GridWidth = true;
            //CollapseQueue();
            //CollapseGrid();

            #endregion

            // A simple bool to see if a task is running at the moment or not
            TaskRunning = false;

            // The result filter, chaging it will change automatically the task list
            ResultFilter = "";

            // The log List
            Log = new ObservableCollection <Log>();

            // The list of currently scheduled tasks, use for rerun if failed and keep track of current running status
            CurrentlyScheduledTasks = new Dictionary <int, ScheduledTaskInfo>();

            #region Timer

            // Create new DispatcherTimer and attach event handler to it
            var launchScheduleTimer = new DispatcherTimer();
            launchScheduleTimer.Tick    += LaunchScheduleTimer_Tick;
            launchScheduleTimer.Interval = new TimeSpan(0, 1, 0);
            launchScheduleTimer.Start();

            #endregion
        }