/*********************************************************************/
/* */
/* AgentService Framework */
/* www.agentservice.it */
/* */
/* Copyright (C) 2007 l.i.d.o. - DIST, University of Genoa, Italy */
/* GNU Lesser General Public License */
/* */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation, */
/* version 2.1 of the License. */
/* */
/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
/* Boston, MA 02111-1307, USA. */
/* */
/*********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using AgentService.Platform;
using System.IO;
using AgentService.Platform.AMS;
namespace AgentService.Agent.Runtime
{
///
/// Events to send to remote platforms
///
[DataContract]
public class RemoteEvent
{
///
/// The AID of the recipient agent
///
private AID recipient;
[DataMember]
public AID Recipient
{
get
{
return this.recipient;
}
set
{
this.recipient = value;
}
}
///
/// type of the event
///
private PlatformEvent type;
[DataMember]
public PlatformEvent Type
{
get
{
return this.type;
}
set
{
this.type = value;
}
}
///
/// name of the event, in case of
/// custom events, the name distinguish
/// the type of the event
///
private string name;
[DataMember]
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
///
/// a string containing a binary serialization of the
/// event arguments
///
private string encodedArgs;
[DataMember]
public string EncodedArgs
{
get
{
return this.encodedArgs;
}
set
{
this.encodedArgs = value;
}
}
///
/// Constructs a PlatformEventArgsobject by specifying the
/// given PlatformEvent.
///
/// declares the type of the event
/// name of the event
public RemoteEvent(AID to, PlatformEvent type, string name, Object args)
{
this.recipient = to;
this.type = type;
switch (this.type)
{
case PlatformEvent.AgentCreated: this.name = "AgentCreated"; break;
case PlatformEvent.AgentPersisted: this.name = "AgentPersisted"; break;
case PlatformEvent.AgentStopped: this.name = "AgentStopped"; break;
case PlatformEvent.AgentResumed: this.name = "AgentResumed"; break;
case PlatformEvent.AgentWokenUp: this.name = "AgentWokenUp"; break;
case PlatformEvent.AssemblyRemoved: this.name = "AssemblyRemoved"; break;
case PlatformEvent.AssemblyUploaded: this.name = "AssemblyUploaded"; break;
case PlatformEvent.ConversationRequested: this.name = "ConversationRequested"; break;
case PlatformEvent.ConversationAccepted: this.name = "ConversationAccepted"; break;
case PlatformEvent.ConversationRefused: this.name = "ConversationRefused"; break;
case PlatformEvent.ConversationClosed: this.name = "ConversationClosed"; break;
case PlatformEvent.MessageSent: this.name = "MessageSent"; break;
case PlatformEvent.MessageReceived: this.name = "MessageReceived"; break;
case PlatformEvent.MessageBatch: this.name = "MessageBatch"; break;
default:
{
// custom events
this.name = name;
} break;
}
if (args != null)
{
MemoryStream mem = new MemoryStream();
CompactFormatter.CompactFormatterPlus cfp = new CompactFormatter.CompactFormatterPlus();
cfp.Serialize(mem, args);
byte[] b = mem.ToArray();
encodedArgs = Convert.ToBase64String(b);
}
}
}
}