예제 #1
0
        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);
 }
예제 #4
0
        static void Main(string[] args)
        {
            var environment = new EnvironmentContext();

            CommandQueueWatcher commandWatcher= new CommandQueueWatcher(environment, args);

            Task.WaitAll(commandWatcher.GetTasks());
        }
예제 #5
0
        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.");
        }
예제 #6
0
        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)
 {
 }
예제 #9
0
 public void CommandWatcherReturnsListOfWatchedQueueTasks()
 {
     var env = new EnvironmentContext();
     var watcher = new CommandQueueWatcher(env, new[] { "testqueue" });
     Assert.AreNotEqual(0, watcher.GetTasks().Count());
 }
예제 #10
0
 public void CommandWatcherReturnsTaskWhenQueueIsAdded()
 {
     var env = new EnvironmentContext();
     var watcher = new CommandQueueWatcher(env,null);
     var task = watcher.AddWatchedQueue("testqueue");
     Assert.IsNotNull(task);
 }
예제 #11
0
        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>());
        }
예제 #12
0
 public void EnvironmentHasUsername()
 {
     var e = new EnvironmentContext();
     Assert.IsNotNull(e.Credential.UserName);
 }
예제 #13
0
 public void EnvironmentHasRootRoute()
 {
     var e = new EnvironmentContext { RootRouteKey = "tomi" };
     Assert.IsNotNull(e.RootRouteKey);
 }
예제 #14
0
 public void EnvironmentHasPassword()
 {
     var e = new EnvironmentContext();
     Assert.IsNotNull(e.Credential.Password);
 }
예제 #15
0
 public void EnvironmentBuildsRouteKey()
 {
     var env = new EnvironmentContext();
     Assert.AreEqual("dev.admin.somequeue",env.GetRoute("somequeue"));
 }