Guest User

Untitled

a guest
Nov 13th, 2017
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. class Program
  2. {
  3.  
  4. static void Main()
  5. {
  6. var container = new UnityContainer();
  7.  
  8. //the instance to be injected
  9. var systemClient = new JobSystemClient
  10. {
  11. UserName = "admin",
  12. PassWord = "admin1234"
  13. };
  14.  
  15. container.RegisterInstance<ISystemClient>(systemClient);
  16.  
  17. //Registration of the Functions class
  18. container.RegisterType<Functions>();
  19.  
  20. var activator = new UnityJobActivator(container);
  21.  
  22. var config = new JobHostConfiguration();
  23. config.JobActivator = activator;
  24.  
  25. var host = new JobHost(config);
  26. // The following code will invoke a function called ManualTrigger and
  27. // pass in data (value in this case) to the function
  28. host.Call(typeof(Functions).GetMethod("ManualTrigger"), new { value = 20 });
  29.  
  30. host.RunAndBlock();
  31.  
  32. }
  33. }
  34.  
  35. public class Functions
  36. {
  37. private readonly ISystemClient _systemClient;
  38. public Functions(ISystemClient systemClient)
  39. {
  40. _systemClient = systemClient;
  41. }
  42.  
  43. //Not static anymore
  44. [NoAutomaticTrigger]
  45. public void ManualTrigger(TextWriter log, int value, [Queue("queue")] out string message)
  46. {
  47. log.WriteLine("Function is invoked with value={0}", value);
  48. message = value.ToString();
  49. log.WriteLine("username:{0} and password:{1}", _systemClient.UserName, _systemClient.PassWord);
  50. }
  51. }
  52.  
  53. Found the following functions:
  54. TestWebJob.Functions.ManualTrigger
  55. Executing 'Functions.ManualTrigger' (Reason='This function was programmatically called via the host APIs.', Id=bf9aedc0-89d1-4ba0-a33e-9b23e0d7b8a2)
  56. Function is invoked with value=20
  57. Following message will be written on the Queue=20
  58. username:admin and password:admin1234
  59. Executed 'Functions.ManualTrigger' (Succeeded, Id=bf9aedc0-89d1-4ba0-a33e-9b23e0d7b8a2)
  60. Job host started
Add Comment
Please, Sign In to add comment