Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static List<Alert> _alerts = new List<Alert>(); // List of the Alerts
- private TcpChannel _tcpChannel;
- protected override void OnStart(string[] args)
- {
- loadAlerts(); // This sets up the List (code not req'd)
- // Set up the remotelister so that other processes can access _alerts
- // Create the TcpChannel
- _tcpChannel = new TcpChannel(65000);
- ChannelServices.RegisterChannel(_tcpChannel, false);
- // Register the Proxy class for remoting.
- RemotingConfiguration.RegisterWellKnownServiceType(
- typeof(RemoteLister),
- "AlertList.soap",
- WellKnownObjectMode.Singleton);
- }
- [Serializable]
- public class RemoteLister : MarshalByRefObject
- {
- public List<Alert> TheList
- {
- get { return _alerts; }
- set { _alerts = value; }
- }
- public bool save()
- {
- EventLog.WriteEntry("AlertService", "Calling saveAlerts...");
- return saveAlerts();
- }
- }
- private string _alertName; // Name of alert
- public string AlertName
- {
- get { return _alertName; }
- set { _alertName = value; }
- }
- AlertService.RemoteLister remoteAlertList;
- protected void Page_Load(object sender, EventArgs e)
- {
- // This is where we create a local object that accesses the remote object in the service
- Type requiredType = typeof(AlertService.RemoteLister);
- // remoteAlertList is our reference to the List<Alert> in the always running service
- remoteAlertList = (AlertService.RemoteLister)Activator.GetObject(requiredType,
- "tcp://localhost:65000/AlertList.soap");
- }
- private void fillFields()
- {
- AlertNameTextBox.Text = remoteAlertList.TheList[AlertDropDownList.SelectedIndex].AlertName;
- }
- protected void AlertSaveButton_Click(object sender, EventArgs e)
- {
- remoteAlertList.TheList[AlertDropDownList.SelectedIndex].AlertName = AlertNameTextBox.Text;
- }
- public class RemoteLister : MarshalByRefObject
- {
- public Alert this[int index] {get {...} set {...}}
- }
- obj[index].Name = "abc";
- var tmp = obj[index]; // tmp points to the deserialized disconnected Alert
- tmp.Name = "abc"; // we update the local disconnected Alert
- obj[index] = tmp;
- public void setAlertName(int index, string name)
- {
- _alerts[index].AlertName = name;
- }
- protected void AlertSaveButton_Click(object sender, EventArgs e)
- {
- remoteAlertList.setAlertName(AlertDropDownList.SelectedIndex, AlertNameTextBox.Text);
- }
Add Comment
Please, Sign In to add comment