public DevelopmentManager(IEventManager eventManager, IPluginManager pluginManager) { // Create the logged in user's specific instance of the user manager proxy. // The actual implementation class could be changed in configuration // or using dependency injection (if we want to implement that)... _eventManager = eventManager; _pluginManager = pluginManager; _commonManagerProxy = new CommonManagerProxy(this); }
public int CreateNewReading(CommonManagerProxy proxy, WindSpeedDao speedDao) { try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { tx.PersistenceManager.UserRepository.Save<WindSpeedDao>(speedDao); tx.Commit(); } return speedDao.Id; } catch (DBConcurrencyException ex) { return 0; } catch (Exception ex) { LogError(proxy, ex); return 0; } }
public IList<WindSpeedDao> GetHistoricalData(CommonManagerProxy proxy, int days) { IList<WindSpeedDao> iwind = new List<WindSpeedDao>(); try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { string dateInString = DateTime.Now.ToString("yyyy-MM-dd"); DateTime startDate = DateTime.Parse(dateInString); DateTime expiryDate = startDate.AddDays(-days); iwind = tx.PersistenceManager.UserRepository.Query<WindSpeedDao>().Where(a => a.Date >= expiryDate).OrderBy(c => c.Date).Select(a => new WindSpeedDao { Id = a.Id, State = a.State, StationCode = a.StationCode, City = a.City, Variance = a.Variance, ActualSpeed = a.ActualSpeed, Date = a.Date, PredictedSpeed = a.PredictedSpeed, DesiredDate = a.Date != null ? a.Date.ToString("MMMM dd,yyyy") : "" }).ToList<WindSpeedDao>(); tx.Commit(); } return iwind; } catch (DBConcurrencyException ex) { return iwind; } catch (Exception ex) { LogError(proxy, ex); return iwind; } }
public string TestMethod(CommonManagerProxy proxy) { string response = ""; try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { //response = tx.PersistenceManager.UserRepository.ExecuteQuery("Query string")); tx.Commit(); } return response; } catch (DBConcurrencyException ex) { return response; } catch (Exception ex) { return response; } }
public bool SaveStations(CommonManagerProxy proxy) { try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { string jsonInput = File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "cities.json"); JavaScriptSerializer js = new JavaScriptSerializer(); List<WindStationsDao> stations = js.Deserialize<List<WindStationsDao>>(jsonInput).ToList<WindStationsDao>(); IList<WindStationsDao> iwind = new List<WindStationsDao>(); foreach (var wind in stations) { iwind.Add(new WindStationsDao { Id = 0, StationID = wind.StationID, StateName = wind.StateName, CityName = wind.CityName }); } tx.PersistenceManager.UserRepository.Save<WindStationsDao>(iwind); tx.Commit(); } return true; } catch (DBConcurrencyException ex) { return false; } catch (Exception ex) { LogError(proxy, ex); return false; } }
public bool SaveError(CommonManagerProxy proxy, ErrorDao _error) { try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { tx.PersistenceManager.UserRepository.Save<ErrorDao>(_error); tx.Commit(); } return true; } catch (DBConcurrencyException ex) { return false; } catch (Exception ex) { return false; } }
public bool LogError(CommonManagerProxy proxy, Exception ex) { try { ErrorDao errDao = new ErrorDao(); errDao.DateCreated = DateTime.Now; errDao.StackTrace = ex.StackTrace; errDao.Message = ex.Message.ToString(); SaveError(proxy, errDao); return true; } catch { return false; } }
public IList<WindStationsDao> GetStations(CommonManagerProxy proxy) { IList<WindStationsDao> iwind = new List<WindStationsDao>(); try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { iwind = tx.PersistenceManager.UserRepository.Query<WindStationsDao>().OrderBy(c => c.StateName.ToLower()).ToList<WindStationsDao>(); tx.Commit(); } return iwind; } catch (DBConcurrencyException ex) { return iwind; } catch (Exception ex) { LogError(proxy, ex); return iwind; } }
public int GetPredictedSpeed(CommonManagerProxy proxy, string stationCode) { int predictedSpeed = 0; try { using (ITransaction tx = proxy.DevelopmentManager.GetTransaction()) { predictedSpeed = Convert.ToInt32(tx.PersistenceManager.UserRepository.Query<WindStationsDao>().Where(a => a.StationID == stationCode).Select(a => a.PredictedSpeed).FirstOrDefault()); tx.Commit(); } } catch (DBConcurrencyException ex) { } catch (Exception ex) { LogError(proxy, ex); } return predictedSpeed; }