/// <summary> /// Get the geofence the provided location falls within. /// </summary> /// <param name="latitude">Latitude geocoordinate</param> /// <param name="longitude">Longitude geocoordinate</param> /// <returns>Returns a <see cref="GeofenceItem"/> object the provided location falls within.</returns> public GeofenceItem GetGeofence(double latitude, double longitude) { return(GeofenceService.GetGeofence(Geofences .Select(x => x.Value) .ToList(), new Location(latitude, longitude) )); }
private AlarmList LoadAlarms(string alarmsFilePath) { _logger.Trace($"WebhookManager::LoadAlarms [AlarmsFilePath={alarmsFilePath}]"); if (!File.Exists(alarmsFilePath)) { _logger.Error($"Failed to load file alarms file '{alarmsFilePath}'..."); return(null); } var alarmData = File.ReadAllText(alarmsFilePath); if (string.IsNullOrEmpty(alarmData)) { _logger.Error($"Failed to load '{alarmsFilePath}', file is empty..."); return(null); } var alarms = JsonConvert.DeserializeObject <AlarmList>(alarmData); if (alarms == null) { _logger.Error($"Failed to deserialize the alarms file '{alarmsFilePath}', make sure you don't have any json syntax errors."); return(null); } _logger.Info($"Alarms file {alarmsFilePath} was loaded successfully."); alarms.Alarms.ForEach(x => { if (x.Geofences != null) { foreach (var geofenceName in x.Geofences) { var geofences = Geofences.Where(g => g.Name.Equals(geofenceName, StringComparison.OrdinalIgnoreCase) || g.Filename.Equals(geofenceName, StringComparison.OrdinalIgnoreCase)).ToList(); if (geofences.Any()) { x.GeofenceItems.AddRange(geofences); } else { _logger.Warn($"No geofences were found matching the name or filename \"{geofenceName}\" (for alarm \"{x.Name}\")"); } } } x.LoadAlerts(); x.LoadFilters(); }); return(alarms); }
private AlarmList LoadAlarms(string alarmsFilePath) { _logger.Trace($"WebhookManager::LoadAlarms [AlarmsFilePath={alarmsFilePath}]"); if (!File.Exists(alarmsFilePath)) { _logger.Error($"Failed to load file alarms file '{alarmsFilePath}'..."); return(null); } var alarmData = File.ReadAllText(alarmsFilePath); if (string.IsNullOrEmpty(alarmData)) { _logger.Error($"Failed to load '{alarmsFilePath}', file is empty..."); return(null); } var alarms = JsonConvert.DeserializeObject <AlarmList>(alarmData); if (alarms == null) { _logger.Error($"Failed to deserialize the alarms file '{alarmsFilePath}', make sure you don't have any json syntax errors."); return(null); } _logger.Info($"Alarms file {alarmsFilePath} was loaded successfully."); alarms.Alarms.ForEach(x => { var geofences = x.LoadGeofence(); for (var i = 0; i < geofences.Count; i++) { var geofence = geofences[i]; if (!Geofences.ContainsKey(geofence.Name)) { Geofences.Add(geofence.Name, geofence); _logger.Debug($"Geofence file loaded for {x.Name}..."); } } _logger.Info($"Loading alerts file {x.AlertsFile}..."); x.LoadAlerts(); _logger.Info($"Loading filters file {x.FiltersFile}..."); x.LoadFilters(); }); return(alarms); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { var obj = App.Current as App; if (obj.DBAutoUpdate) { Debug.WriteLine("AUTO UPDATES ENABLED"); var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); Battery bat = Battery.GetDefault(); // Update database only when battery percentage above 30% and Wi-Fi connection on. Update up; if (connectionProfile != null && connectionProfile.IsWlanConnectionProfile && bat.RemainingChargePercent >= 30) { up = new Update(); } } CopyAssets(); CultureInfo ci = new CultureInfo(Windows.System.UserProfile.GlobalizationPreferences.Languages[0]); ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings; if (localSettings.Values["Idioma"] == null) { localSettings.Values["Idioma"] = ci.TwoLetterISOLanguageName; } if (!localSettings.Values.ContainsKey("FIRST_RUN_FLAG")) { localSettings.Values.Add("FIRST_RUN_FLAG", "true"); } else { localSettings.Values.Remove("FIRST_RUN_FLAG"); localSettings.Values.Add("FIRST_RUN_FLAG", "false"); } #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); // TODO: change this value to a cache size that is appropriate for your application rootFrame.CacheSize = 1; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // Removes the turnstile navigation for startup. if (rootFrame.ContentTransitions != null) { this.transitions = new TransitionCollection(); foreach (var c in rootFrame.ContentTransitions) { this.transitions.Add(c); } } rootFrame.ContentTransitions = null; rootFrame.Navigated += this.RootFrame_FirstNavigated; // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter if (!rootFrame.Navigate(typeof(MainPage), e.Arguments)) { throw new Exception("Failed to create initial page"); } } Geofences.RegisterGeofences(); RegisterTask(); // Ensure the current window is active Window.Current.Activate(); }
public override string ToString() { return(string.Format("Requirement: {0},\n Geofences: {1},\n Amount: {2},\n Types: {3}", Requirement, Geofences.ToString(), Amount, Types)); }