예제 #1
0
 public static void Serializer(object untypedInput, Orleans.Serialization.BinaryTokenStreamWriter stream, System.Type expected)
 {
     GPSTracker.Common.DeviceMessage input = ((GPSTracker.Common.DeviceMessage)(untypedInput));
     Orleans.Serialization.SerializationManager.SerializeInner(input.DeviceId, stream, typeof(Guid));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Latitude, stream, typeof(Double));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Longitude, stream, typeof(Double));
     Orleans.Serialization.SerializationManager.SerializeInner(input.MessageId, stream, typeof(Int32));
     Orleans.Serialization.SerializationManager.SerializeInner(input.Timestamp, stream, typeof(DateTime));
 }
 public VelocityMessage(DeviceMessage deviceMessage, double velocity)
 {
     this.Latitude  = deviceMessage.Latitude;
     this.Longitude = deviceMessage.Longitude;
     this.MessageId = deviceMessage.MessageId;
     this.DeviceId  = deviceMessage.DeviceId;
     this.Timestamp = deviceMessage.Timestamp;
     this.Velocity  = velocity;
 }
예제 #3
0
 public VelocityMessage(DeviceMessage deviceMessage, double velocity)
 {
     this.Latitude = deviceMessage.Latitude;
     this.Longitude = deviceMessage.Longitude;
     this.MessageId = deviceMessage.MessageId;
     this.DeviceId = deviceMessage.DeviceId;
     this.Timestamp = deviceMessage.Timestamp;
     this.Velocity = velocity;
 }
예제 #4
0
 public VelocityMessage(DeviceMessage deviceMessage, double velocity)
 {
     Latitude  = deviceMessage.Latitude;
     Longitude = deviceMessage.Longitude;
     MessageId = deviceMessage.MessageId;
     DeviceId  = deviceMessage.DeviceId;
     Timestamp = deviceMessage.Timestamp;
     Velocity  = velocity;
 }
예제 #5
0
 public static object Deserializer(System.Type expected, Orleans.Serialization.BinaryTokenStreamReader stream)
 {
     GPSTracker.Common.DeviceMessage result = new GPSTracker.Common.DeviceMessage();
     result.DeviceId  = ((Guid)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Guid), stream)));
     result.Latitude  = ((Double)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Double), stream)));
     result.Longitude = ((Double)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Double), stream)));
     result.MessageId = ((Int32)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(Int32), stream)));
     result.Timestamp = ((DateTime)(Orleans.Serialization.SerializationManager.DeserializeInner(typeof(DateTime), stream)));
     return(result);
 }
예제 #6
0
 public static object DeepCopier(object original)
 {
     GPSTracker.Common.DeviceMessage input  = ((GPSTracker.Common.DeviceMessage)(original));
     GPSTracker.Common.DeviceMessage result = new GPSTracker.Common.DeviceMessage();
     Orleans.Serialization.SerializationContext.Current.RecordObject(original, result);
     result.DeviceId  = ((Guid)(Orleans.Serialization.SerializationManager.DeepCopyInner(input.DeviceId)));
     result.Latitude  = input.Latitude;
     result.Longitude = input.Longitude;
     result.MessageId = input.MessageId;
     result.Timestamp = input.Timestamp;
     return(result);
 }
예제 #7
0
        static double GetSpeed(DeviceMessage message1, DeviceMessage message2)
        {
            // calculate the speed of the device, using the interal state of the grain
            if (message1 == null) return 0;
            if (message2 == null) return 0;

            const double R = 6371 * 1000;
            var x = (message2.Longitude - message1.Longitude) * Math.Cos((message2.Latitude + message1.Latitude) / 2);
            var y = message2.Latitude - message1.Latitude;
            var distance = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2)) * R;
            var time = (message2.Timestamp - message1.Timestamp).TotalSeconds;
            if (time == 0) return 0;
            return distance / time;
        }
예제 #8
0
        public async Task ProcessMessage(DeviceMessage message)
        {
            if (null == this.LastMessage || this.LastMessage.Latitude != message.Latitude || this.LastMessage.Longitude != message.Longitude)
            {
                // only sent a notification if the position has changed
                var notifier = GrainFactory.GetGrain<IPushNotifierGrain>(0);
                var speed = GetSpeed(this.LastMessage, message);

                // record the last message
                this.LastMessage = message;

                // forward the message to the notifier grain
                var velocityMessage = new VelocityMessage(message, speed);
                await notifier.SendMessage(velocityMessage);
            }
            else
            {
                // the position has not changed, just record the last message
                this.LastMessage = message;
            }
        }
예제 #9
0
 public System.Threading.Tasks.Task ProcessMessage(GPSTracker.Common.DeviceMessage message)
 {
     return(base.InvokeMethodAsync <object>(842001816, new object[] { message }, TimeSpan.Zero));
 }