Guest User

Untitled

a guest
Apr 23rd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. private static List<Alert> _alerts = new List<Alert>(); // List of the Alerts
  2. private TcpChannel _tcpChannel;
  3.  
  4. protected override void OnStart(string[] args)
  5. {
  6. loadAlerts(); // This sets up the List (code not req'd)
  7. // Set up the remotelister so that other processes can access _alerts
  8. // Create the TcpChannel
  9. _tcpChannel = new TcpChannel(65000);
  10. ChannelServices.RegisterChannel(_tcpChannel, false);
  11.  
  12. // Register the Proxy class for remoting.
  13. RemotingConfiguration.RegisterWellKnownServiceType(
  14. typeof(RemoteLister),
  15. "AlertList.soap",
  16. WellKnownObjectMode.Singleton);
  17. }
  18.  
  19. [Serializable]
  20. public class RemoteLister : MarshalByRefObject
  21. {
  22. public List<Alert> TheList
  23. {
  24. get { return _alerts; }
  25. set { _alerts = value; }
  26. }
  27.  
  28. public bool save()
  29. {
  30. EventLog.WriteEntry("AlertService", "Calling saveAlerts...");
  31. return saveAlerts();
  32. }
  33. }
  34.  
  35. private string _alertName; // Name of alert
  36.  
  37. public string AlertName
  38. {
  39. get { return _alertName; }
  40. set { _alertName = value; }
  41. }
  42.  
  43. AlertService.RemoteLister remoteAlertList;
  44.  
  45. protected void Page_Load(object sender, EventArgs e)
  46. {
  47. // This is where we create a local object that accesses the remote object in the service
  48. Type requiredType = typeof(AlertService.RemoteLister);
  49. // remoteAlertList is our reference to the List<Alert> in the always running service
  50. remoteAlertList = (AlertService.RemoteLister)Activator.GetObject(requiredType,
  51. "tcp://localhost:65000/AlertList.soap");
  52. }
  53.  
  54. private void fillFields()
  55. {
  56. AlertNameTextBox.Text = remoteAlertList.TheList[AlertDropDownList.SelectedIndex].AlertName;
  57. }
  58.  
  59. protected void AlertSaveButton_Click(object sender, EventArgs e)
  60. {
  61. remoteAlertList.TheList[AlertDropDownList.SelectedIndex].AlertName = AlertNameTextBox.Text;
  62. }
  63.  
  64. public class RemoteLister : MarshalByRefObject
  65. {
  66. public Alert this[int index] {get {...} set {...}}
  67. }
  68.  
  69. obj[index].Name = "abc";
  70.  
  71. var tmp = obj[index]; // tmp points to the deserialized disconnected Alert
  72. tmp.Name = "abc"; // we update the local disconnected Alert
  73.  
  74. obj[index] = tmp;
  75.  
  76. public void setAlertName(int index, string name)
  77. {
  78. _alerts[index].AlertName = name;
  79. }
  80.  
  81. protected void AlertSaveButton_Click(object sender, EventArgs e)
  82. {
  83. remoteAlertList.setAlertName(AlertDropDownList.SelectedIndex, AlertNameTextBox.Text);
  84. }
Add Comment
Please, Sign In to add comment