Beispiel #1
0
        public Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            //keep it simple fast and reliable.
            try
            {
                foreach (EventData message in messages)
                {
                    LiveLocation loc = this.DeserializeEventData(message);
                    if (loc != null)
                    {
                        Trace.WriteLine(string.Format("{0} > received message: {1} at partition {2}, offset: {3}",
                                                      DateTime.Now.ToString(), loc.ProfileID.ToString() + "-" + loc.SessionID + "-" + loc.ClientTimeStamp.ToString(),
                                                      context.Lease.PartitionId, message.Offset), "Information");

                        LocationProcessor.ProcessLocation(loc);
                    }
                    // increase the total events count.
                    Interlocked.Increment(ref this.totalMessages);
                }

                lock (this) { return(context.CheckpointAsync()); }
            }
            catch (Exception exp)
            {
                Trace.TraceError("Error in processing EventHub message: " + exp.Message);
            }

            return(Task.FromResult <object>(null));
        }
Beispiel #2
0
 public static async Task SendLocationEvent(LiveLocation liveLocation)
 {
     string serializedString = JsonConvert.SerializeObject(liveLocation);
     var    data             = new EventData(Encoding.UTF8.GetBytes(serializedString))
     {
         PartitionKey = liveLocation.ProfileID.ToString()
     };
     await client.SendAsync(data);
 }
 public async Task PostMyLocation(LiveLocation liveLocation)
 {
     if (IsEventHubEnabled)
     {
         await EventsSender.SendLocationEvent(liveLocation);
     }
     else
     {
         LocationProcessor.ProcessLocation(liveLocation);
     }
 }
        public void PostLiveLocationData()
        {
            LiveLocation loc = new LiveLocation()
            {
                ProfileID       = 1,
                SessionID       = "336173859039816",
                IsSOS           = true,
                ClientDateTime  = DateTime.UtcNow,
                ClientTimeStamp = DateTime.UtcNow.Ticks,
                Long            = "18.34",
                Lat             = "12.345"
            };
            LocationService locService = new LocationService();

            locService.PostMyLocation(loc).GetAwaiter().GetResult();
        }
Beispiel #5
0
        public void GetLocationDataByTokenUnitTest()
        {
            bool _isLocation = false;

            using (LocationRepository _locationRep = new LocationRepository())
            {
                //var x = _locationRep.GetMemberStatusFromLiveInfo(1, 1234567).Result;
                IEnumerable <LiveLocation> locations = _locationRep.GetLocationDataByToken(1, "ind", 6355987).Result;

                while (locations.GetEnumerator().MoveNext())
                {
                    LiveLocation location = locations.GetEnumerator().Current;
                    _isLocation = true;
                }
                Assert.AreEqual(_isLocation, true);
            }
        }
 public async Task PostMyLocationAsync(LiveLocation loc)
 {
     int result = await _guardianContext.Database
                  .ExecuteSqlCommandAsync("EXEC [dbo].[PostLiveLocation] @ProfileID,@SessionID,@ClientTimeStamp,@ClientDateTime,@Lat,@Long,@IsSOS,@Alt,@Speed,@MediaUri,@ExtendedCommand,@Accuracy",
                                          new SqlParameter("@ProfileID", loc.ProfileID),             //@ProfileID bigint
                                          new SqlParameter("@SessionID", loc.SessionID),             //@SessionID NVARCHAR(50)
                                          new SqlParameter("@ClientTimeStamp", loc.ClientTimeStamp), //@ClientTimeStamp BIGINT
                                          new SqlParameter("@ClientDateTime", loc.ClientDateTime),   //@ClientDateTime DATETIME
                                          new SqlParameter("@Lat", loc.Lat.OrDbNull()),              //@Lat NVARCHAR(20)
                                          new SqlParameter("@Long", loc.Long.OrDbNull()),            //@Long NVARCHAR(20)
                                          new SqlParameter("@IsSOS", loc.IsSOS),                     //@IsSOS BIT
                                          new SqlParameter("@Alt", loc.Alt.OrDbNull()),              //@Alt VARCHAR(10)
                                          new SqlParameter("@Speed", loc.Speed),                     //@Speed INT
                                          new SqlParameter("@MediaUri", loc.MediaUri.OrDbNull()),    //@MediaUri VARCHAR(250)
                                          new SqlParameter("@ExtendedCommand", DBNull.Value),        //@ExtendedCommand NVARCHAR(50)
                                          new SqlParameter("@Accuracy", loc.Accuracy.OrDbNull()));
 }
Beispiel #7
0
        public static bool ProcessLocation(LiveLocation loc)
        {
            try
            {
                List <Task> tasks = new List <Task>();
                //Process the location and push it to Data Stores
                //Task 1: Save in LiveSession & LiveLocation SQL tables
                Task liveSessionTask = new LiveSessionRepository().PostMyLocationAsync(loc);

                //Task 2: Save in LocationHistory Storage table
                Task historyTask = new LocationHistoryStorageAccess().SaveToLocationHistoryAsync(loc.ConvertToHistory());

                tasks.Add(liveSessionTask);
                tasks.Add(historyTask);
                Task.WhenAll(tasks.ToArray()).Wait();
                return(true);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Error processing Live Location. " + ex.Message);
                return(false);
            }
        }
Beispiel #8
0
        public async Task <bool> PostLocationWithMedia(GeoTag vGeoTag)
        {
            string liveUserID = WebOperationContext.Current.IncomingRequest.Headers["LiveUserID"];

            bool isAuthorizedForSelf = await _authService.SelfAccess(liveUserID, vGeoTag.ProfileID);

            if (isAuthorizedForSelf)
            {
                LiveLocation LiveLocation = vGeoTag.ConvertToLiveLocation();

                try
                {
                    if (vGeoTag.MediaContent != null && vGeoTag.MediaContent.Length > 0)
                    {
                        byte[] MediaContents = vGeoTag.MediaContent;
                        LiveLocation.MediaUri = new BlobAccess().UploadImage(MediaContents, Guid.NewGuid().ToString());
                    }
                    else
                    {
                        LiveLocation.MediaUri = null;
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(
                        string.Format("Error while saving the media contents for profile id: {0}; Error details: {1}",
                                      vGeoTag.ProfileID, ex.Message));
                }

                //new line added here
                await new LocationService().PostMyLocation(LiveLocation);

                return(true);
            }
            return(false);
        }
Beispiel #9
0
 public async Task PostMyLocation(LiveLocation loc)
 {
     _guardianContext.LiveLocations.Add(loc);
     await _guardianContext.SaveChangesAsync();
 }