private void ArchiveStaleSessions() { while (true) { try { Trace.TraceInformation("Archive Stale Sessions started...", "Information"); List <LiveSession> sessions = new LiveSessionRepository().GetLiveSessionsAsync().Result; List <SessionHistory> sess = sessions.ConvertToHistory(); new SessionHistoryStorageAccess().ArchiveSessionDetailsAsync(sess).Wait(); new LiveSessionRepository().PurgeStaleSessionsAsync(sessions).Wait(); Trace.TraceInformation("Archive Stale Sessions completed. Going to sleep for " + purgeIntervalInMinutes.ToString() + " minutes", "Information"); Thread.Sleep(purgeIntervalInMinutes * 60 * 1000); // 1 hour } catch (ThreadAbortException ex) { Trace.TraceError("Worker Role for Archive Sessions failed(ThreadAborted)! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.ResetAbort(); Thread.Sleep(5 * 60 * 1000); } catch (Exception ex) { Trace.TraceError("Worker Role to Archive Sessions failed! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.Sleep(5 * 60 * 1000); } } }
public ReportService() { _LocationRepository = new LocationRepository(); _GroupRepository = new GroupRepository(); _MemberRepository = new MemberRepository(); _MemberService = new MemberService(); _GroupService = new GroupService(); _GeoService = new GeoUpdate(); _LiveSessionRepository = new LiveSessionRepository(); //Storage Classes _GroupStorageAccess = new GroupStorageAccess(); _MemberStorageAccess = new MemberStorageAccess(); _ReportRepository = new ReportRepository(); _SessionHistoryStorageAccess = new SessionHistoryStorageAccess(); }
private void BroadcastMessages() { //Processing Cycle time 30 secs //1. Process messages from LiveSession - Send Messages. Use intance id as identifier for the batch //Parallelly send messages for multiple profiles while (true) { try { Trace.TraceInformation("Broadcasting messages has started...", "Information"); Guid processKey = Guid.NewGuid(); List <LiveSession> sosSessions = new LiveSessionRepository().GetSessionsForNotifications(RoleInstanceId, processKey, Config.SendSms, Config.SMSPostGap, Config.EmailPostGap, Config.FacebookPostGap).Result; if (sosSessions != null && sosSessions.Count > 0) { var processedSessions = PostMessages.SendSOSNotifications(sosSessions).Result; var liteSessions = processedSessions.ConvertToLiveSessionLite(); string liteSessionsXML = Serialize <List <LiveSessionLite> >(liteSessions, true, true); new LiveSessionRepository().UpdateNotificationComplete(RoleInstanceId, processKey, liteSessionsXML).Wait(); } else { Trace.TraceInformation("Broadcasting messages has completed. Going to sleep for " + runInterval.ToString() + " seconds...", "Information"); Thread.Sleep(runInterval * 1000); } } catch (ThreadAbortException ex) { Trace.TraceError("Worker Role for Broadcasting messages failed(ThreadAborted)! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.ResetAbort(); Thread.Sleep(1 * 60 * 1000); } catch (Exception ex) { Trace.TraceError("Worker Role for Broadcasting messages failed! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.Sleep(1 * 60 * 1000); } } }
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); } }
private void DynamicAllocationToSubGroups() { var allocationInterval = Config.SubGroupAllocationIntervalInMinutes; var liveSessionRepository = new LiveSessionRepository(); var grouprepository = new GroupRepository(); GroupService grpService = new GroupService(); LocalResource myStorage = RoleEnvironment.GetLocalResource("LocalStorageWorkerRole"); while (true) { try { Trace.TraceInformation("Dynamic Allocation To Sub Groups started...", "Information"); //0. Cache Groups and SubGroups information along with Shape files - Clear cache 1hr or Tool to reset cache. //1. For every 5 minutes, check Active SOS in LiveSession. //2. Findout the groups and if any groups have SubGroups //3. If NotifySubGroups is enabled and Shape files are available, find out the nearest Subgroup for the latest lat/long of the user //4. Add record in GroupMembership table with SubGroupID and ProfileID of the user, if not already exist //5. If GroupNotifications are enabled, then notify the Sub Group //6. On SOS stop, Delete all dynamic SubGroup allocations var GrpWithSession = grpService.GetFilteredParentGroupLiveMemberSession().Result; //For debugging, please uncomment below //ParallelOptions opt = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount > 1 ? Environment.ProcessorCount - 1 : 1 }; //Parallel.ForEach(GrpWithSession, opt, s => Parallel.ForEach(GrpWithSession, s => { var DownloadedShapeFilePath = Utility.GrpIdGroupKeyAndShapePaths.FirstOrDefault(x => x.Item1.Equals(s.GrpId)); if (!DownloadedShapeFilePath.Equals(default(Tuple <int, string, string>))) { var dataRow = ShapeFileGISutility.FindIntersection(Convert.ToDouble(s.LiveSessionObj.Lat), Convert.ToDouble(s.LiveSessionObj.Long), DownloadedShapeFilePath.Item3); if (dataRow != null && !String.IsNullOrWhiteSpace(DownloadedShapeFilePath.Item2)) { var obj = dataRow[DownloadedShapeFilePath.Item2]; string wardName = obj != null ? obj.ToString() : String.Empty; Trace.WriteLine(String.Format("{0} found.", wardName)); if (!string.IsNullOrWhiteSpace(wardName)) { var SubGroupObj = GroupService.SubGroups.Where(x => x.SubGroupIdentificationKey.Equals(wardName, StringComparison.OrdinalIgnoreCase) && x.ParentGroupID == DownloadedShapeFilePath.Item1).FirstOrDefault(); if (SubGroupObj != null) { try { int result = grouprepository.AutoSubscribeLiveUserToSubGroup(SubGroupObj.GroupID, s.LiveSessionObj.ProfileID, s.LiveSessionObj.Name, s.LiveSessionObj.SessionID, DownloadedShapeFilePath.Item1).Result; } catch (Exception ex) { Trace.WriteLine(ex.Message); } } } } } }); Trace.TraceInformation("Dynamic Allocation To Sub Groups completed. Going to sleep for " + allocationInterval.ToString() + " minutes", "Information"); Thread.Sleep(allocationInterval * 60 * 1000); } catch (ThreadAbortException ex) { Trace.TraceError("Worker Role for DynamicAllocationToSubGroups failed(ThreadAborted)! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.ResetAbort(); Thread.Sleep(5 * 60 * 1000); } catch (Exception ex) { Trace.TraceError("Worker Role for DynamicAllocationToSubGroups failed! " + ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error"); Thread.Sleep(5 * 60 * 1000); } } }