Exemplo n.º 1
0
        public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
        {
            _config             = new WindowsFeatureTaskConfig();
            _config.Description = config.Description;

            if (properties.ContainsKey("includeAllSubFeatures"))
            {
                _config.IncludeAllSubFeatures = bool.Parse(properties["includeAllSubFeatures"].ToString());
            }

            if (properties.ContainsKey("windows10"))
            {
                _config.IsWindows10 = bool.Parse(properties["windows10"].ToString());
            }

            if (properties.ContainsKey("remove"))
            {
                _config.ShouldRemove = bool.Parse(properties["remove"].ToString());
            }

            _config.Features = new List <string>();

            if (properties.ContainsKey("features") && properties["features"] != null)
            {
                var features = properties["features"] as List <object>;

                if (features != null)
                {
                    foreach (object feature in features)
                    {
                        _config.Features.Add(feature.ToString());
                    }
                }
            }
        }
Exemplo n.º 2
0
        protected bool SetConfig()
        {
            if (mConfig == null && mManager != null)
            {
                mConfig = mManager.CreateConfigInstance();
            }

            if (mConfig != null)
            {
                (mConfig as CConfig).Name = textBox_name.Text;
                mConfig.SetValue("Name", textBox_name.Text);

                mConfig.Desc      = textBox_desc.Text;
                mConfig.Type      = CtrlUtil.GetComboBoxText(comboBox_type);
                mConfig.Scheduler = CtrlUtil.GetComboBoxText(comboBox_scheduler);
                mConfig.AutoRun   = checkBox_autorun.Checked;
                mConfig.Enabled   = checkBox_enabled.Checked;

                mConfig.ClearActions();
                foreach (IActionParam config in checkedListBox_action.Items)
                {
                    mConfig.AppendAction(config);
                }

                return(true);
            }
            return(false);
        }
Exemplo n.º 3
0
        private static object GetConfigurationFromTaskConfig(ITaskConfig taskConfig)
        {
            Type       configurationType = GetConfigType(taskConfig.TaskType);
            MethodInfo method            = taskConfig.GetType().GetMethod("GetTaskConfig").MakeGenericMethod(new[] { configurationType });

            return(method.Invoke(taskConfig, null));
        }
Exemplo n.º 4
0
 public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
 {
     _config                = new MockTaskConfig();
     _config.Description    = config.Description;
     _config.CustomProperty = properties["customProperty"].ToString();
     _config.Config         = config.Config;
 }
Exemplo n.º 5
0
        public ITask CreateTask(ITaskConfig taskConfig)
        {
            var config = taskConfigReader.GetTaskConfig(taskConfig);

            return(container.Resolve(
                       taskConfig.TaskType,
                       new TypedParameter(typeof(string), taskConfig.TaskId),
                       new TypedParameter(config.GetType(), config)) as ITask);
        }
Exemplo n.º 6
0
        public ITask CreateTask(ITaskConfig config, ITaskType type)
        {
            if (config == null || !config.Enabled)
            {
                return(null);
            }

            lock (mTasks.SyncRoot)
            {
                CTask task = mTasks[config.Name] as CTask;
                if (task == null)
                {
                    if (type == null)
                    {
                        type = mSystemContext.TaskTypeManager.GetConfig(config.Type);
                    }

                    if (type != null && type.Enabled && !type.TaskClass.Equals(""))
                    {
                        if (!type.FileName.Equals(""))
                        {
                            task = CommonUtil.CreateInstance(SystemContext, type.FileName, type.TaskClass) as CTask;
                        }
                        else
                        {
                            task = CommonUtil.CreateInstance(type.TaskClass) as CTask;
                        }
                    }

                    if (task != null)
                    {
                        if (task.Init(this, config, type))
                        {
                            task.OnTaskStateChanged += new TaskStateChanged(DoTaskStateChanged);
                            //task.OnBeforeTask += new TaskEvent(DoBeforeTask);
                            //task.OnAfterTask += new TaskEvent(DoAfterTask);

                            mTasks.Add(task.Name, task);

                            task.RefreshState();
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
                else
                {
                    task.Config = config;
                }
                return(task);
            }
        }
Exemplo n.º 7
0
        public bool ConfigTask(string name, ITaskConfig config)
        {
            ITask task = GetTask(name);

            if (task != null)
            {
                task.Config = config;
                return(true);
            }
            return(false);
        }
Exemplo n.º 8
0
 public ITask CreateTask(ITaskConfig config)
 {
     if (config != null)
     {
         ITaskType type = mSystemContext.TaskTypeManager.GetConfig(config.Type);
         return(CreateTask(config, type));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 9
0
        public static string GetTaskInfo(this ITaskConfig taskConfig)
        {
            var taskInfo = taskConfig.TaskId ?? string.Empty;

            if (!string.IsNullOrEmpty(taskConfig.Description))
            {
                taskInfo += ": " + taskConfig.Description;
            }

            taskInfo += " [" + taskConfig.TaskType + "]";
            return(taskInfo.TrimStart());
        }
Exemplo n.º 10
0
        public ITask CreateTask(string name)
        {
            ITaskConfig config = mSystemContext.TaskConfigManager.GetConfig(name) as ITaskConfig;

            if (config != null)
            {
                return(CreateTask(config));
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 11
0
 public void ShowAddDialog(ITaskType type)
 {
     Text     = "新增任务模块";
     mIsOk    = false;
     mManager = type.SystemContext.TaskConfigManager;
     mType    = type;
     mConfig  = null;
     InitTypeList(mManager.SystemContext);
     InitSchedulerList(mManager.SystemContext);
     InitActionList(mManager.SystemContext);
     if (InitDialog())
     {
         ShowDialog();
     }
 }
Exemplo n.º 12
0
        public TaskResult RunTask(string taskId)
        {
            try
            {
                logger.InfoFormat("Running task: '{0}'", taskId);

                ITaskConfig taskConfig = predefinedTasksConfig.GetTaskConfig(taskId);
                return(taskFactory.CreateTask(taskConfig).Run());
            }
            catch (Exception ex)
            {
                var message = string.Format("Running task '{0}' failed.", taskId);
                logger.Info(message, ex);
                return(TaskResult.Failed(message));
            }
        }
Exemplo n.º 13
0
        public override void ShowEditDialog(IConfig config)
        {
            Text     = "编辑任务模块 - [" + config.Name + "]";
            mIsOk    = false;
            mManager = null;
            mType    = null;
            mConfig  = config as ITaskConfig;

            if (config.Verify(ACOpts.Manager_Modify, false))
            {
                InitTypeList(config.SystemContext);
                InitSchedulerList(config.SystemContext);
                InitActionList(config.SystemContext);
                if (InitDialog())
                {
                    ShowDialog();
                }
            }
        }
Exemplo n.º 14
0
        public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
        {
            _config             = new PowershellTaskConfig();
            _config.Description = config.Description;

            _config.Commands = new List <string>();

            if (properties.ContainsKey("commands") && properties["commands"] != null)
            {
                var commands = properties["commands"] as List <object>;

                if (commands != null)
                {
                    foreach (object command in commands)
                    {
                        _config.Commands.Add(command.ToString());
                    }
                }
            }
        }
Exemplo n.º 15
0
 public CTask(ITaskManager manager, ITaskConfig config, ITaskType type)
 {
     Init(manager, config, type);
 }
Exemplo n.º 16
0
        public bool Init(ITaskManager manager, ITaskConfig config, ITaskType type)
        {
            mConfig  = config;
            mManager = manager;
            mType    = type;

            if (!IsInit && Verify(ACOpts.Exec_Init))
            {
                if (mManager.SystemContext.MonitorSystem.IsLocal)
                {
                    if (InitTask())
                    {
                        State = TaskState.Init;

                        Config = mConfig;

                        if (!IsActive && mConfig.AutoRun)
                        {
                            this.Start();
                        }

                        return(true);
                    }
                }
                else if (mManager.SystemContext.RemoteManageClient != null)
                {
                    SystemContext.RemoteManageClient.OnConnected    -= new ClientConnectEvent(DoConnected);
                    SystemContext.RemoteManageClient.OnDisconnected -= new ClientConnectEvent(DoDisconnected);
                    SystemContext.RemoteManageClient.OnReceiveData  -= new ClientReceiveEvent(DoReceiveData);

                    SystemContext.RemoteManageClient.OnConnected    += new ClientConnectEvent(DoConnected);
                    SystemContext.RemoteManageClient.OnDisconnected += new ClientConnectEvent(DoDisconnected);
                    SystemContext.RemoteManageClient.OnReceiveData  += new ClientReceiveEvent(DoReceiveData);

                    IRemoteSystem rs = mManager.SystemContext.MonitorSystem as IRemoteSystem;
                    if (rs != null)
                    {
                        StringBuilder sb = new StringBuilder(mManager.SystemContext.RequestHeadInfo);

                        ISchedulerConfig sc = mManager.SystemContext.SchedulerConfigManager.GetConfig(mConfig.Scheduler);
                        if (sc != null)
                        {
                            ISchedulerType st = mManager.SystemContext.SchedulerTypeManager.GetConfig(sc.Type);
                            if (st != null)
                            {
                                sb.Append(sc.Name + "<Scheduler>");
                                sb.Append("InitConfig<Command>");
                                sb.Append(st.ToXml() + "<Type>");
                                sb.Append(sc.ToXml() + "<Config><CommandSegment>");
                            }
                        }

                        IActionConfig  ac;
                        IActionParam[] apList = mConfig.GetActionList();
                        if (apList != null)
                        {
                            foreach (IActionParam pc in apList)
                            {
                                ac = mManager.SystemContext.ActionConfigManager.GetConfig(pc.Name);
                                if (ac != null)
                                {
                                    IActionType at = mManager.SystemContext.ActionTypeManager.GetConfig(ac.Type);

                                    if (at != null)
                                    {
                                        sb.Append(ac.Name + "<Action>");
                                        sb.Append("Init;Start<Command>");
                                        sb.Append(at.ToXml() + "<Type>");
                                        sb.Append(ac.ToXml() + "<Config><CommandSegment>");
                                    }
                                }
                            }
                        }

                        sb.Append(Name + "<Task>");
                        sb.Append("Init<Command>");
                        sb.Append(mType.ToXml() + "<Type>");
                        sb.Append(mConfig.ToXml() + "<Config>");

                        return(mManager.SystemContext.RemoteManageClient.WaitReliableSend(rs.Config.IP, rs.Config.Port, sb.ToString()));
                    }
                }
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 17
0
 public object GetTaskConfig(ITaskConfig taskConfig)
 {
     return(GetConfigurationFromTaskConfig(taskConfig));
 }
Exemplo n.º 18
0
        protected override TaskResult DoTask()
        {
            ITaskConfig taskConfig = tasksConfig.GetTaskConfig(config.TaskId);

            return(taskFactory.CreateTask(taskConfig).Run());
        }
Exemplo n.º 19
0
 public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
 {
     _config             = new PowershellFileTaskConfig();
     _config.Description = config.Description;
     _config.Uri         = properties["uri"].ToString();
 }
Exemplo n.º 20
0
        public static void AddRemoteConfig(IMonitorSystemContext context, string name, string data, bool saveConfig)
        {
            IConfig config = null;

            if (data.StartsWith("<Monitor>"))
            {
                config = context.MonitorConfigManager.GetConfig(name);
                if (config == null)
                {
                    IMonitorConfig monitorConfig = context.MonitorConfigManager.BuildConfigFromXml(data) as IMonitorConfig;
                    if (monitorConfig != null)
                    {
                        context.MonitorConfigManager.Append(monitorConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<MonitorType>"))
            {
                config = context.MonitorTypeManager.GetConfig(name);
                if (config == null)
                {
                    IMonitorType monitorType = context.MonitorTypeManager.BuildConfigFromXml(data) as IMonitorType;
                    if (monitorType != null)
                    {
                        context.MonitorTypeManager.Append(monitorType, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<VideoSource>"))
            {
                config = context.VideoSourceConfigManager.GetConfig(name);
                if (config == null)
                {
                    IVideoSourceConfig vsConfig = context.VideoSourceConfigManager.BuildConfigFromXml(data) as IVideoSourceConfig;
                    if (vsConfig != null)
                    {
                        context.VideoSourceConfigManager.Append(vsConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<VideoSourceType>"))
            {
                config = context.VideoSourceTypeManager.GetConfig(name);
                if (config == null)
                {
                    IVideoSourceType vsType = context.VideoSourceTypeManager.BuildConfigFromXml(data) as IVideoSourceType;
                    if (vsType != null)
                    {
                        context.VideoSourceTypeManager.Append(vsType, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<Action>"))
            {
                config = context.ActionConfigManager.GetConfig(name);
                if (config == null)
                {
                    IActionConfig actionConfig = context.ActionConfigManager.BuildConfigFromXml(data) as IActionConfig;
                    if (actionConfig != null)
                    {
                        context.ActionConfigManager.Append(actionConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<ActionType>"))
            {
                config = context.ActionTypeManager.GetConfig(name);
                if (config == null)
                {
                    IActionType actionType = context.ActionTypeManager.BuildConfigFromXml(data) as IActionType;
                    if (actionType != null)
                    {
                        context.ActionTypeManager.Append(actionType, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<Scheduler>"))
            {
                config = context.SchedulerConfigManager.GetConfig(name);
                if (config == null)
                {
                    ISchedulerConfig schedulerConfig = context.SchedulerConfigManager.BuildConfigFromXml(data) as ISchedulerConfig;
                    if (schedulerConfig != null)
                    {
                        context.SchedulerConfigManager.Append(schedulerConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<SchedulerType>"))
            {
                config = context.SchedulerTypeManager.GetConfig(name);
                if (config == null)
                {
                    ISchedulerType schedulerType = context.SchedulerTypeManager.BuildConfigFromXml(data) as ISchedulerType;
                    if (schedulerType != null)
                    {
                        context.SchedulerTypeManager.Append(schedulerType, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<Task>"))
            {
                config = context.TaskConfigManager.GetConfig(name);
                if (config == null)
                {
                    ITaskConfig taskConfig = context.TaskConfigManager.BuildConfigFromXml(data) as ITaskConfig;
                    if (taskConfig != null)
                    {
                        context.TaskConfigManager.Append(taskConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<TaskType>"))
            {
                config = context.TaskTypeManager.GetConfig(name);
                if (config == null)
                {
                    ITaskType taskType = context.TaskTypeManager.BuildConfigFromXml(data) as ITaskType;
                    if (taskType != null)
                    {
                        context.TaskTypeManager.Append(taskType, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<RemoteSystem>"))
            {
                config = context.RemoteSystemConfigManager.GetConfig(name);
                if (config == null)
                {
                    IRemoteSystemConfig rsConfig = context.RemoteSystemConfigManager.BuildConfigFromXml(data) as IRemoteSystemConfig;
                    if (rsConfig != null)
                    {
                        context.RemoteSystemConfigManager.Append(rsConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<Role>"))
            {
                config = context.RoleConfigManager.GetConfig(name);
                if (config == null)
                {
                    IRoleConfig roleConfig = context.RoleConfigManager.BuildConfigFromXml(data) as IRoleConfig;
                    if (roleConfig != null)
                    {
                        context.RoleConfigManager.Append(roleConfig, saveConfig);
                    }
                }
            }
            else if (data.StartsWith("<User>"))
            {
                config = context.UserConfigManager.GetConfig(name);
                if (config == null)
                {
                    IUserConfig userConfig = context.UserConfigManager.BuildConfigFromXml(data) as IUserConfig;
                    if (userConfig != null)
                    {
                        context.UserConfigManager.Append(userConfig, saveConfig);
                    }
                }
            }
        }
Exemplo n.º 21
0
        public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
        {
            _config             = new OctopusTentacleTaskConfig();
            _config.Description = config.Description;

            // Guards: role, environment, apikey, server, thumbprint, tentacleName are all required
            Guard(properties, "role");
            Guard(properties, "environment");
            Guard(properties, "apikey");
            Guard(properties, "octopusServer");
            Guard(properties, "thumbprint");
            Guard(properties, "tentacleName");

            if (properties.ContainsKey("apikey"))
            {
                _config.ApiKey = properties["apikey"].ToString();
            }

            if (properties.ContainsKey("environment"))
            {
                _config.Environment = properties["environment"].ToString();
            }

            if (properties.ContainsKey("installDirectory"))
            {
                _config.TentacleExePath = properties["installDirectory"].ToString();
            }

            if (properties.ContainsKey("octopusServer"))
            {
                _config.OctopusServer = properties["octopusServer"].ToString();
            }

            if (properties.ContainsKey("role"))
            {
                _config.Role = properties["role"].ToString();
            }

            if (properties.ContainsKey("thumbprint"))
            {
                _config.Thumbprint = properties["thumbprint"].ToString();
            }

            if (properties.ContainsKey("certText"))
            {
                _config.CertText = properties["certText"].ToString();
            }

            if (properties.ContainsKey("port"))
            {
                _config.Port = properties["port"].ToString();
            }

            if (properties.ContainsKey("homeDir"))
            {
                _config.HomeDirectory = properties["homeDir"].ToString();
            }

            if (properties.ContainsKey("appDir"))
            {
                _config.AppDirectory = properties["appDir"].ToString();
            }

            if (properties.ContainsKey("tentacleName"))
            {
                _config.TentacleName = properties["tentacleName"].ToString();
            }

            if (properties.ContainsKey("exePath"))
            {
                _config.TentacleName = properties["exePath"].ToString();
            }
        }
Exemplo n.º 22
0
 public void SetConfiguration(ITaskConfig config, Dictionary <object, object> properties)
 {
     Config = config;
 }