patryk_szwed

Service1Part22

May 20th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.Serialization;
  5. using System.ServiceModel;
  6. using System.Text;
  7. using System.Threading;
  8.  
  9. namespace WcfServiceLibrary2
  10. {
  11. // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
  12. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
  13. public class myCallbackKalkulator : ICallbackKalkulator
  14. {
  15. private int result;
  16. private double coeff;
  17. private ICallbackHandler callback = null;
  18. public myCallbackKalkulator()
  19. {
  20. callback = OperationContext.Current.GetCallbackChannel<ICallbackHandler>();
  21. }
  22.  
  23. public void Function1(int n)
  24. {
  25. Console.WriteLine("...call of Function1({0})", n);
  26. long maxN = 1;
  27. for (int i = 1; i <= n; ++i)
  28. {
  29. bool isPrime = true;
  30. for (int j = 2; j < Math.Sqrt(i); ++j)
  31. {
  32. if (i % j == 0)
  33. {
  34. isPrime = false;
  35. break;
  36. }
  37. }
  38.  
  39. if (isPrime)
  40. {
  41. maxN = i;
  42. }
  43. }
  44. callback.Function1CB(maxN);
  45. }
  46.  
  47. public void Function2(int n, int k)
  48. {
  49. Console.WriteLine("...call of Function2({0}, {1})", n, k);
  50. coeff = (factorial(n) / (factorial(k) * factorial(n - k)));
  51. callback.Function2CB(coeff);
  52. }
  53.  
  54. private double factorial(int n)
  55. {
  56. result = 1;
  57. for (int i = 1; i <= n; i++)
  58. {
  59. result *= i;
  60. }
  61.  
  62. return result;
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment