protected void LoadWorkFlowsToSession() { var environment = new EnvironmentContext { Name = "prod", RootRouteKey = "admin", }; // Setup workflow with a job and a command var wf = new WorkFlow("Get Current Network Shares", environment) { Jobs = new List<Job> { new Job { Name = "List Shares", Commands = new List<Command>() { new Command("NET Command","listshares") { ExecuteFile = @"c:\windows\system32\net.exe", Arguments = "share", }, } } } }; Session["workflows"] = new List<WorkFlow> { wf }; }
public CommandProcessor(EnvironmentContext context,string routekey) { MessageConsumer = new MessageConsumer(); MessageProducer = new MessageProducer(); if (String.IsNullOrEmpty(routekey)) throw new Exception("Route key must not be null"); if (context == null) throw new Exception("CommandProcessor environment context must not be null"); _environment = context; RouteKey = routekey; MessageConsumer.OnMessageReceived += (msg) => { if (msg is CommandMessage) { try { if (msg.RoutingKey.Equals(_environment.GetRoute(RouteKey),StringComparison.CurrentCultureIgnoreCase)) { HandleMessage(msg); } } catch (Exception ex) { Log(msg.Ticket,ex.Message); } } }; }
public CommandQueueWatcher(EnvironmentContext environment, IList<string> queueNames) { _messageProducer = new MessageProducer(); _environment = environment; _tasks = new List<Task>(); foreach (var queueName in queueNames ?? new List<string>()) AddWatchedQueue(queueName); }
static void Main(string[] args) { var environment = new EnvironmentContext(); CommandQueueWatcher commandWatcher= new CommandQueueWatcher(environment, args); Task.WaitAll(commandWatcher.GetTasks()); }
public WorkFlow(string name, EnvironmentContext environment) { if (!String.IsNullOrWhiteSpace(name)) Name = name; else throw new Exception("Workflow must have a name."); if (environment != null) TargetEnvironment = environment; else throw new Exception("Workflow must have an environment."); }
static void Main(string[] args) { var environment = new EnvironmentContext(); // Setup workflow with a job and a command var wf = new WorkFlow("Get Current Network Shares and Windows Directory", environment) { Jobs = new List<Job> { new Job { Name = "List Shares and Directories", Commands = new List<Command>() { new Command("NET Command","listshares") { ExecuteFile = @"c:\windows\system32\net.exe", Arguments = "share", }, new Command("NET Command","listdir") { ExecuteFile = @"c:\windows\system32\cmd.exe", Arguments = @"/c dir", WorkingDirectory = @"c:\windows", }, } } } }; // Listen for results var workflowResultWatcher = new WorkFlowResultWatcher(wf); // Execute the workflow do { Console.WriteLine("Hit Enter To Execute Workflow"); if (Console.ReadLine()=="q") break; wf.Execute(); } while (true); foreach (var line in workflowResultWatcher.GetAllResults()) Console.WriteLine(line.CommandResult); }
public void AddCommandResultQueue(EnvironmentContext environment, string queueName) { var messageConsumer = new MessageConsumer(); messageConsumer.OnMessageReceived += (msg) => { lock (_locker) { var message = (CommandResultMessage) msg; if (!_results.ContainsKey(queueName)) { _results[queueName] = new List<CommandResultMessage>(); } _results[queueName].Add(message); } }; Tasks.Add(messageConsumer.ListenToQueueAsync( environment.GetResultRoute(queueName), environment.Credential)); }
public ConsoleCommandProcessor(EnvironmentContext context, string route) : base(context,route) { }
public void CommandWatcherReturnsListOfWatchedQueueTasks() { var env = new EnvironmentContext(); var watcher = new CommandQueueWatcher(env, new[] { "testqueue" }); Assert.AreNotEqual(0, watcher.GetTasks().Count()); }
public void CommandWatcherReturnsTaskWhenQueueIsAdded() { var env = new EnvironmentContext(); var watcher = new CommandQueueWatcher(env,null); var task = watcher.AddWatchedQueue("testqueue"); Assert.IsNotNull(task); }
public void JobExecutesCommandUsingAMessageProducer() { var env = new EnvironmentContext { Name = "atest", RootRouteKey = "admin", }; var wf = new WorkFlow("Test Workflow", env); var job = new Job { ParentWorkFlow = wf, Commands = new Command[] { new Command("Test Command","testqueue") }, }; job.MessageProducer = Substitute.For<IMessageProducer>(); job.Execute(); Assert.AreEqual("atest.admin.testqueue", job.Commands[0].RoutingKey); job.MessageProducer.Received().Publish(Arg.Any<Message>(),Arg.Any<NetworkCredential>()); }
public void EnvironmentHasUsername() { var e = new EnvironmentContext(); Assert.IsNotNull(e.Credential.UserName); }
public void EnvironmentHasRootRoute() { var e = new EnvironmentContext { RootRouteKey = "tomi" }; Assert.IsNotNull(e.RootRouteKey); }
public void EnvironmentHasPassword() { var e = new EnvironmentContext(); Assert.IsNotNull(e.Credential.Password); }
public void EnvironmentBuildsRouteKey() { var env = new EnvironmentContext(); Assert.AreEqual("dev.admin.somequeue",env.GetRoute("somequeue")); }