public void Initialize()
 {
     _actions        = new ActionCollection();
     _considerations = new ConsiderationCollection();
     _options        = new OptionCollection(_actions, _considerations);
     _behaviours     = new BehaviourCollection(_options);
 }
Exemple #2
0
 public void FillCollections(ref IActionCollection actionCollection, ref IConsiderationCollection considerationCollection)
 {
     foreach (var keyvalue in m_loaders)
     {
         var key         = keyvalue.Key;
         var loader      = keyvalue.Value;
         var dicoActions = loader.Actions;
         foreach (var keyvalueAction in dicoActions)
         {
             var keyAction = keyvalueAction.Key;
             var deleg     = keyvalueAction.Value;
             var id        = new InfoId()
             {
                 NamespaceId = key, NameId = keyAction
             };
             var newAction = new DynamicAction(id, deleg);
             //actionCollection.Add(newAction);
         }
         var dicoConsiderations = loader.Considerations;
         foreach (var keyvalueConsideration in dicoConsiderations)
         {
             var keyConsideration = keyvalueConsideration.Key;
             var deleg            = keyvalueConsideration.Value;
             var id = new InfoId()
             {
                 NamespaceId = key, NameId = keyConsideration
             };
             var newConsideration = new DynamicConsideration(id, deleg);
             //considerationCollection.Add(newConsideration);
         }
     }
 }
 public ActionManager(IKeywordService keywordService, IActionCollection actions, IActionContext context)
 {
     _context        = context;
     _actions        = actions;
     _logger         = _context.Log;
     _keywordService = keywordService;
 }
Exemple #4
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ActionBase"/> class.
 /// </summary>
 /// <param name="other">The other.</param>
 protected ActionBase(ActionBase other)
 {
     NameId      = other.NameId;
     _collection = other._collection;
     Cooldown    = other.Cooldown;
     Parameters  = other.Parameters?.Clone();
 }
Exemple #5
0
        /// <summary>
        /// Creates Actions
        /// </summary>
        /// <param name="taskDefinition">Task Definition to which triggers should be added</param>
        /// <param name="task">Task containing trigger information</param>
        private static void ConfigureActions(ITaskDefinition taskDefinition, ScheduledTask task)
        {
            IActionCollection actions = taskDefinition.Actions;

            if (task.Actions != null)
            {
                foreach (Entities.Action actionInfo in task.Actions)
                {
                    _TASK_ACTION_TYPE actionType = MapActionType(actionInfo.Type);
                    IAction           action     = actions.Create(actionType);

                    switch (actionType)
                    {
                    case _TASK_ACTION_TYPE.TASK_ACTION_EXEC:
                        ConfigureExecAction(action, actionInfo);
                        break;

                    case _TASK_ACTION_TYPE.TASK_ACTION_SEND_EMAIL:
                        ConfigureEmailAction(action, actionInfo);
                        break;

                    case _TASK_ACTION_TYPE.TASK_ACTION_SHOW_MESSAGE:
                        ConfigureShowMessageAction(action, actionInfo);
                        break;
                    }
                }
            }
        }
Exemple #6
0
        // Install the UAC bypass CosmosTask. This must be performed while the program is running under
        // administrator credentials with elevation.
        void InstallScheduledTask()
        {
            ITaskService xService = new TaskScheduler.TaskScheduler();

            xService.Connect();
            ITaskFolder     xFolder = xService.GetFolder(@"\");
            IRegisteredTask xTask   = TryGetInstallScheduledTask(xFolder);

            if (null != xTask)
            {
                // The first parameter MUST NOT be prefixed with the folder path.
                xFolder.DeleteTask(InstallScheduledTaskName, 0);
            }

            ITaskDefinition xTaskDef = xService.NewTask(0);

            xTaskDef.RegistrationInfo.Description        = "Cosmos DevKit UAC Bypass";
            xTaskDef.RegistrationInfo.Author             = "Cosmos Group";
            xTaskDef.Settings.Compatibility              = _TASK_COMPATIBILITY.TASK_COMPATIBILITY_V2_1;
            xTaskDef.Settings.DisallowStartIfOnBatteries = false;
            xTaskDef.Principal.RunLevel = _TASK_RUNLEVEL.TASK_RUNLEVEL_HIGHEST;

            IActionCollection xActions    = xTaskDef.Actions;
            IAction           xAction     = xActions.Create(_TASK_ACTION_TYPE.TASK_ACTION_EXEC);
            IExecAction       xExecAction = xAction as IExecAction;

            xExecAction.Path      = mSetupPath;
            xExecAction.Arguments = @"/SILENT";

            // 6 = task can be created or updated ["CreateOrUpdate" flag]
            // if Name id empty or null, System will create a task with name as GUID
            xTask = xFolder.RegisterTaskDefinition(InstallScheduledTaskName, xTaskDef, 6, null, null, _TASK_LOGON_TYPE.TASK_LOGON_NONE, null);
        }
 /// <summary>
 ///   Initializes a new instance of the <see cref="ActionBase{TContext}"/> class.
 /// </summary>
 /// <param name="other">The other.</param>
 protected ActionBase(ActionBase <TContext> other)
 {
     NameId         = other.NameId;
     _collection    = other._collection;
     Cooldown       = other.Cooldown;
     _cooldownTimer = new Stopwatch();
 }
 public bool ExecuteAction(ActionRequest request)
 {
     if (factories.ContainsKey(request.ActionType))
     {
         return(factories[request.ActionType]().Execute(request));
     }
     return(false);
 }
Exemple #9
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ActionBase"/> class.
 /// </summary>
 /// <param name="other">The other.</param>
 protected ActionBase(ActionBase other)
 {
     NameId         = other.NameId;
     _collection    = other._collection;
     Cooldown       = other.Cooldown;
     _cooldownTimer = new Stopwatch();
     Parameters     = other.Parameters?.Clone();
 }
Exemple #10
0
 public void Initialize()
 {
     _actions        = new ActionCollection();
     _considerations = new ConsiderationCollection();
     _options        = new OptionCollection(_actions, _considerations);
     _behaviours     = new BehaviourCollection(_options);
     _aIs            = new AiCollection(_behaviours);
     _ctor           = new MasterAiConstructor(_aIs);
 }
Exemple #11
0
        public void Initialize()
        {
            _ac  = new ActionCollection();
            _cc  = new ConsiderationCollection();
            _oc  = new OptionCollection(_ac, _cc);
            _bc  = new BehaviourCollection(_oc);
            _aic = new AiCollection(_bc);

            var b = new Behaviour("b1", _bc);
        }
Exemple #12
0
        public AiCollection(Info.AiInfoDatabase db)
        {
            m_ais            = new Dictionary <string, IUtilityAi>();
            m_actions        = new ActionCollection();
            m_considerations = new ConsiderationCollection();
            m_options        = new OptionCollection(Actions, Considerations);
            m_behaviours     = new BehaviourCollection(Options);

            Populate(db);
        }
Exemple #13
0
        public void Initialize()
        {
            _actions        = new ActionCollection();
            _considerations = new ConsiderationCollection();
            _options        = new OptionCollection(_actions, _considerations);
            _behaviours     = new BehaviourCollection(_options);
            _aIs            = new AiCollection(_behaviours);

            _utilityAi = new UtilityAi("ai0", _aIs);
        }
Exemple #14
0
        public void Inititalize()
        {
            _toon = new Toon();

            _ac  = new ActionCollection();
            _cc  = new ConsiderationCollection();
            _oc  = new OptionCollection(_ac, _cc);
            _bc  = new BehaviourCollection(_oc);
            _aic = new AiCollection(_bc);

            // The main AI
            _ai = new UtilityAi("ai", _aic);
            var coreBehaviour = new Behaviour("coreBehaviour", _bc);

            coreBehaviour.Selector = new MaxUtilitySelector();
            _ai.AddBehaviour(coreBehaviour.NameId);

            // Eat Option
            _eatOption         = new Option();
            _eatOption.Measure = new WeightedMetrics(1.4f);
            var eatAction           = new EatAction();
            var hungerConsideration = new HungerConsideration();

            (_eatOption as Option).SetAction(eatAction);
            _eatOption.AddConsideration(hungerConsideration);
            _eatOption.AddConsideration(new InverseBladderConsideration());
            coreBehaviour.AddConsideration(_eatOption);

            // Drink Option
            _drinkOption         = new Option();
            _drinkOption.Measure = new WeightedMetrics(3.0f);
            var drinkAction         = new DrinkAction();
            var thirstConsideration = new ThirstConsideration();

            (_drinkOption as Option).SetAction(drinkAction);
            _drinkOption.AddConsideration(thirstConsideration);
            _drinkOption.AddConsideration(new InverseBladderConsideration());

            // Toilet Option
            _toiletOption         = new Option();
            _toiletOption.Measure = new WeightedMetrics();
            var toiletAction         = new ToiletAction();
            var bladderConsideration = new BladderConsideration();

            (_toiletOption as Option).SetAction(toiletAction);
            _toiletOption.AddConsideration(bladderConsideration);

            coreBehaviour.AddConsideration(_eatOption);
            coreBehaviour.AddConsideration(_drinkOption);
            coreBehaviour.AddConsideration(_toiletOption);

            Console.WriteLine(coreBehaviour);

            _scheduler = new Scheduler();
        }
Exemple #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionCollection"/> class.
        /// </summary>
        /// <param name="actionCollection">The action collection.</param>
        /// <param name="considerationCollection">The consideration collection.</param>
        /// <exception cref="T:Crystal.OptionCollection.ActionCollectionNullException"></exception>
        /// <exception cref="T:Crystal.OptionCollection.ConsiderationCollectionNullException"></exception>
        public OptionCollection(IActionCollection actionCollection, IConsiderationCollection considerationCollection)
        {
            if (actionCollection == null)
            {
                throw new ActionCollectionNullException();
            }
            if (considerationCollection == null)
            {
                throw new ConsiderationCollectionNullException();
            }

            _optionsMap    = new Dictionary <string, IOption>();
            Actions        = actionCollection;
            Considerations = considerationCollection;
        }
Exemple #16
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="ActionBase"/> class.
        /// </summary>
        /// <param name="nameId">The name identifier.</param>
        /// <param name="collection">The collection.</param>
        /// <exception cref="Crystal.ActionBase.NameIdEmptyOrNullException"></exception>
        /// <exception cref="Crystal.ActionBase.ActionCollectionNullException"></exception>
        public ActionBase(string nameId, IActionCollection collection)
        {
            if (string.IsNullOrEmpty(nameId))
            {
                throw new NameIdEmptyOrNullException();
            }
            if (collection == null)
            {
                throw new ActionCollectionNullException();
            }

            NameId      = nameId;
            _collection = collection;
            AddSelfToCollection();
        }
Exemple #17
0
        internal virtual void Bind(ITaskDefinition iTaskDef)
        {
            IActionCollection iActions = iTaskDef.Actions;

            if (iActions.Count >= ActionCollection.MaxActions)
            {
                throw new ArgumentOutOfRangeException(nameof(iTaskDef), @"A maximum of 32 actions is allowed within a single task.");
            }
            CreateV2Action(iActions);
            Marshal.ReleaseComObject(iActions);
            foreach (string key in unboundValues.Keys)
            {
                try { ReflectionHelper.SetProperty(iAction, key, unboundValues[key]); }
                catch (TargetInvocationException tie) { throw tie.InnerException; }
                catch { }
            }
            unboundValues.Clear();
        }
        /// <summary>
        /// Returns the list of <see cref="AutorunObject"/> objects that have been added through TaskScheduler
        /// </summary>
        public List <AutorunObject> GetAutorunObjects()
        {
            List <AutorunObject> resultObjectsList = new List <AutorunObject>();

            TaskScheduler.TaskScheduler taskService = new TaskScheduler.TaskScheduler();
            taskService.Connect();

            ITaskFolder rootFolder = taskService.GetFolder(@"\");

            IRegisteredTaskCollection regTask = rootFolder.GetTasks(0);

            foreach (IRegisteredTask task in regTask)
            {
                ITaskDefinition    taskDefinition    = task.Definition;
                ITriggerCollection triggerCollection = taskDefinition.Triggers;

                foreach (ITrigger trigger in triggerCollection)
                {
                    if (trigger.Type == _TASK_TRIGGER_TYPE2.TASK_TRIGGER_BOOT ||
                        trigger.Type == _TASK_TRIGGER_TYPE2.TASK_TRIGGER_LOGON)
                    {
                        IActionCollection actionCollection = taskDefinition.Actions;

                        foreach (IExecAction action in actionCollection)
                        {
                            if (action.Type != _TASK_ACTION_TYPE.TASK_ACTION_EXEC)
                            {
                                continue;
                            }

                            var autorunObject = AutorunObjectHelper.GetAutorunObject(action.Path, action.Arguments, AutorunTypes.Scheduler);

                            if (autorunObject != null)
                            {
                                resultObjectsList.Add(autorunObject);
                            }
                        }
                    }
                }
            }

            return(resultObjectsList);
        }
Exemple #19
0
 internal ActionCollection([NotNull] ITaskDefinition iTaskDef)
 {
     v2Def  = iTaskDef;
     v2Coll = iTaskDef.Actions;
     System.Text.RegularExpressions.Match match;
     if (iTaskDef.Data != null && (match = System.Text.RegularExpressions.Regex.Match(iTaskDef.Data, psV2IdRegex)).Success)
     {
         var on = false;
         try { on = bool.Parse(match.Groups["v"].Value); } catch { try { on = int.Parse(match.Groups["v"].Value) == 1; } catch { } }
         if (on)
         {
             psConvert |= PowerShellActionPlatformOption.Version2;
         }
         else
         {
             psConvert &= ~PowerShellActionPlatformOption.Version2;
         }
     }
     UnconvertUnsupportedActions();
 }
Exemple #20
0
        public void FillCollections(ref IActionCollection actionCollection, ref IConsiderationCollection considerationCollection)
        {
            for (int i = 0, iLength = m_actionContextNames.Length; i < iLength; ++i)
            {
                var contextName = m_actionContextNames[i];
                for (int j = 0, jLength = m_actionNames[i].Length; j < jLength; ++j)
                {
                    var actionName = m_actionNames[i][j];

                    var action = m_loader.GetAction(contextName, actionName);

                    if (action == null)
                    {
                        throw new System.NullReferenceException();
                    }

                    actionCollection.Add(action, new IdInfoIndex(i, j));
                }
            }

            for (int i = 0, iLength = m_considerationContextNames.Length; i < iLength; ++i)
            {
                var contextName = m_considerationContextNames[i];
                for (int j = 0, jLength = m_considerationNames[i].Length; j < jLength; ++j)
                {
                    var considerationName = m_considerationNames[i][j];

                    var consideration = m_loader.GetConsideration(contextName, considerationName);

                    if (consideration == null)
                    {
                        throw new System.NullReferenceException();
                    }

                    considerationCollection.Add(consideration, new IdInfoIndex(i, j));
                }
            }
        }
Exemple #21
0
        private void CreateTaskScheduler()
        {
            string AutoCreateTaskScheduler = ConfigurationManager.AppSettings["RMS.AutoCreateTaskScheduler"] ?? "false";

            if (!Convert.ToBoolean(AutoCreateTaskScheduler))
            {
                return;
            }

            ITaskService       taskService         = null;
            ITaskDefinition    taskDefinition      = null;
            ITriggerCollection _iTriggerCollection = null;
            ITrigger           _trigger            = null;
            IActionCollection  actions             = null;
            IAction            action     = null;
            IExecAction        execAction = null;
            ITaskFolder        rootFolder = null;

            try
            {
                //create task service instance
                taskService = new TaskScheduler.TaskScheduler();
                taskService.Connect();

                taskDefinition = taskService.NewTask(0);
                taskDefinition.Settings.Enabled             = true;
                taskDefinition.Settings.Compatibility       = _TASK_COMPATIBILITY.TASK_COMPATIBILITY_V2_1;
                taskDefinition.RegistrationInfo.Description = "Testing the creation of a scheduled task via VB .NET";

                //create trigger for task creation.
                _iTriggerCollection    = taskDefinition.Triggers;
                _trigger               = _iTriggerCollection.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_DAILY);
                _trigger.StartBoundary = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
                //_trigger.EndBoundary = DateTime.Now.AddMinutes(1).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
                _trigger.Repetition.Interval = "PT5M";
                _trigger.Repetition.Duration = "P1D";
                _trigger.Enabled             = true;

                actions = taskDefinition.Actions;
                _TASK_ACTION_TYPE actionType = _TASK_ACTION_TYPE.TASK_ACTION_EXEC;

                //create new action
                action          = actions.Create(actionType);
                execAction      = action as IExecAction;
                execAction.Path = Assembly.GetExecutingAssembly().Location;
                rootFolder      = taskService.GetFolder(@"\");

                //register task.
                rootFolder.RegisterTaskDefinition(System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().Location), taskDefinition, (int)_TASK_CREATION.TASK_CREATE_OR_UPDATE, null, null,
                                                  _TASK_LOGON_TYPE.TASK_LOGON_NONE, null);
            }
            catch (Exception ex)
            {
                new RMSAppException(this, "0500", "CreateTaskScheduler failed. " + ex.Message, ex, true);
            }
            finally
            {
                if (rootFolder != null)
                {
                    Marshal.ReleaseComObject(rootFolder);
                }
                if (_iTriggerCollection != null)
                {
                    Marshal.ReleaseComObject(_iTriggerCollection);
                }
                if (_trigger != null)
                {
                    Marshal.ReleaseComObject(_trigger);
                }
                if (actions != null)
                {
                    Marshal.ReleaseComObject(actions);
                }
                if (action != null)
                {
                    Marshal.ReleaseComObject(action);
                }
                if (taskDefinition != null)
                {
                    Marshal.ReleaseComObject(taskDefinition);
                }
                if (taskService != null)
                {
                    Marshal.ReleaseComObject(taskService);
                }

                taskService         = null;
                taskDefinition      = null;
                _iTriggerCollection = null;
                _trigger            = null;
                actions             = null;
                action     = null;
                execAction = null;
                rootFolder = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
Exemple #22
0
 internal override void CreateV2Action(IActionCollection iActions)
 {
     iAction = iActions.Create(TaskActionType.SendEmail);
 }
Exemple #23
0
 internal override void CreateV2Action([NotNull] IActionCollection iActions)
 {
     iAction = iActions.Create(TaskActionType.ComHandler);
 }
Exemple #24
0
 internal abstract void CreateV2Action(IActionCollection iActions);
Exemple #25
0
 internal override void CreateV2Action(IActionCollection iActions)
 {
     iAction = iActions.Create(TaskActionType.Execute);
 }
Exemple #26
0
 public PhysicalExerciseAction(IActionCollection collection) : base(Name, collection)
 {
 }
Exemple #27
0
 /// <summary>
 ///   Initializes a new instance of the <see cref="ActionBase"/> class.
 /// </summary>
 /// <param name="other">The other.</param>
 protected ActionBase(ActionBase other)
 {
     NameId      = other.NameId;
     _collection = other._collection;
     Cooldown    = other.Cooldown;
 }
Exemple #28
0
 public EatAction(IActionCollection collection) : base(Name, collection)
 {
 }
Exemple #29
0
 public WorkAction(IActionCollection collection) : base(Name, collection)
 {
 }
Exemple #30
0
 internal override void CreateV2Action(IActionCollection iActions)
 {
     iAction = iActions.Create(TaskActionType.ShowMessage);
 }