/// <summary> /// Metoda zapisująca informacje o użytkowniku /// </summary> /// <param name="email"></param> /// <param name="result"></param> /// <returns></returns> public bool SaveUser(string email, Users result) { try { using (var context = new DataContext()) { var user = context.Table<Users>().NewQuery().FirstOrDefault(x => x.Email == email); if (user != null) { user.Name = result.Name; user.Surname = result.Surname; if (!string.IsNullOrEmpty(result.Password)) { user.Password = result.Password; } context.Table<Users>().Update(user); context.SaveChanges(); return true; } } } catch (Exception ex) { // ojojojoj } return false; }
public bool AddCity(string email, string city, int quantity) { var userId = this.GetUserId(email); try { using (var context = new DataContext()) { var weatherElement = context.Table<Mashup.Data.Model.Weather>().NewRow(); weatherElement.ID_user = userId; weatherElement.City = city; weatherElement.Quantity = quantity; context.Table<Mashup.Data.Model.Weather>().Insert(weatherElement); context.SaveChanges(); return true; } } catch (Exception) { //ojojojo } return false; }
public IEnumerable<BreakerOperation> GetBreakerOperations(EventJSON json) { using (DataContext dataContext = new DataContext("systemSettings")) { DateTime startTime = (json != null ? (json.StartDate ?? DateTime.Parse("01/01/01")) : DateTime.Parse("01/01/01")); DateTime endTime = (json != null ? (json.EndDate ?? DateTime.Now) : DateTime.Now); IEnumerable<DataRow> table = Enumerable.Empty<DataRow>(); try { if (json == null || (json.EventIDList == null && json.MeterAssetKeyList == null && json.LineIDList == null && json.LineAssetKeyList == null && json.MeterIDList == null)) { table = dataContext.Connection.RetrieveData("Select * FROM BreakerOperation WHERE TripCoilEnergized >= {0} AND TripCoilEnergized <= {1}", startTime, endTime).Select(); return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).ToList(); } if (json.MeterIDList != null) { object[] ids = json.MeterIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN ({param}))", ids).Select().Concat(table); } if (json.MeterAssetKeyList != null) { object[] ids = json.MeterAssetKeyList.Split(',').Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN (SELECT ID FROM Meter WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.LineIDList != null) { object[] ids = json.LineIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN ({param}))", ids).Select().Concat(table); } if (json.LineAssetKeyList != null) { object[] ids = json.LineAssetKeyList.Split(',').Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN (SELECT ID FROM Line WHERE AssetKey IN ({param})))", ids).Select().Concat(table); } if (json.EventIDList != null) { object[] ids = json.EventIDList.Split(',').Select(int.Parse).Cast<object>().ToArray(); string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}")); table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN ({param})", ids).Select().Concat(table); } return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).DistinctBy(evt => evt.ID).ToList(); } catch (Exception) { return null; } } }
/// <summary> /// Metoda pobierająca id użytkownika na podstawie jego maila /// </summary> /// <param name="email"></param> /// <returns></returns> public int GetUserId(string email) { using (var context = new DataContext()) { return context.Table<Users>().NewQuery().Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault(); } }
public List<LocalWeather> LocalWeather(string userMail) { try { using (var context = new DataContext()) { var user = context.Table<Users>().NewQuery().SingleOrDefault(x => x.Email == userMail); if (user == null) { return new List<LocalWeather>(); } var weathers = context.Table<Data.Model.Weather>().NewQuery().Where(x => x.ID_user == user.ID).ToList(); return weathers.Select(x => provider.LocalWeather(x.City, x.Quantity)).ToList(); } } catch (Exception) { //ojojojo return null; } }
/// <summary> /// Metoda dodająca nowy feed /// </summary> /// <param name="email"></param> /// <param name="feedUrl"></param> /// <returns></returns> public bool AddFeed(string email, string feedUrl) { var userId = this.GetUserId(email); try { using (var context = new DataContext()) { var feedElement = context.Table<RSS>().NewRow(); feedElement.ID_user = userId; feedElement.RSS_URL = feedUrl; context.Table<RSS>().Insert(feedElement); context.SaveChanges(); return true; } } catch (Exception) { //ojojojo } return false; }
public Users GetUserInfo(string email) { try { using (var context = new DataContext()) { var user = context.Table<Users>().NewQuery().Include(x => x.Weather).Include(x => x.RSS).FirstOrDefault(x => x.Email == email); return user; } } catch (Exception ex) { // ojojojoj } return null; }
public ActiveMeasurement NewActiveMeasurement() { return(DataContext.Table <ActiveMeasurement>().NewRecord()); }
private string GetHeaders(DataContext dataContext, IEnumerable<int> pointIDs) { object[] parameters = pointIDs.Cast<object>().ToArray(); string parameterizedQueryString = $"PointID IN ({string.Join(",", parameters.Select((parameter, index) => $"{{{index}}}"))})"; RecordRestriction pointIDRestriction = new RecordRestriction(parameterizedQueryString, parameters); return "\"Timestamp\"," + string.Join(",", dataContext.Table<Measurement>(). QueryRecords(restriction: pointIDRestriction). Select(measurement => $"\"[{measurement.PointID}] {measurement.PointTag}\"")); }
public Device QueryDevice(string acronym) { return(DataContext.Table <Device>().QueryRecordWhere("Acronym = {0}", acronym) ?? NewDevice()); }
public void AddNewCustomActionAdapter(CustomActionAdapter customActionAdapter) { DataContext.Table <CustomActionAdapter>().AddNewRecord(customActionAdapter); }
public int QueryHistorianCount(string filterText) { return(DataContext.Table <Historian>().QueryRecordCount(filterText)); }
public void AddNewOrUpdateDevice(Device device) { DataContext.Table <Device>().AddNewOrUpdateRecord(device); }
public void DeleteCustomActionAdapter(int id) { DataContext.Table <CustomActionAdapter>().DeleteRecord(id); }
public IEnumerable <Measurement> QueryDeviceMeasurements(int deviceID) { return(DataContext.Table <Measurement>().QueryRecordsWhere("DeviceID = {0}", deviceID)); }
public void DeleteMeasurement(int id) { DataContext.Table <Measurement>().DeleteRecord(id); }
public Measurement QueryMeasurementByPointTag(string pointTag) { return(DataContext.Table <Measurement>().QueryRecordWhere("PointTag = {0}", pointTag) ?? NewMeasurement()); }
public Measurement QueryMeasurementBySignalID(Guid signalID) { return(DataContext.Table <Measurement>().QueryRecordWhere("SignalID = {0}", signalID) ?? NewMeasurement()); }
public Measurement QueryMeasurement(string signalReference) { return(DataContext.Table <Measurement>().QueryRecordWhere("SignalReference = {0}", signalReference) ?? NewMeasurement()); }
public IEnumerable <Measurement> QueryMeasurements(string sortField, bool ascending, int page, int pageSize, string filterText) { return(DataContext.Table <Measurement>().QueryRecords(sortField, ascending, page, pageSize, filterText)); }
public int QueryMeasurementCount(string filterText) { return(DataContext.Table <Measurement>().QueryRecordCount(filterText)); }
public IEnumerable<Line> GetLines(ConfigJSON json) { using (DataContext dataContext = new DataContext("systemSettings")) { string assetKey = (json != null ? (json.AssetKey ?? "%") : "%"); int id = (json != null ? (json.ID == null ? -1 : int.Parse(json.ID)) : -1); DataTable table = dataContext.Connection.RetrieveData("Select * FROM Line WHERE AssetKey LIKE {0} " + (id != -1 ? "AND ID LIKE {1}" : "") , assetKey, id); return table.Select().Select(row => dataContext.Table<Line>().LoadRecord(row)).ToList(); } }
public Measurement NewMeasurement() { return(DataContext.Table <Measurement>().NewRecord()); }
public bool RemoveCity(string email, int cityId) { var userId = this.GetUserId(email); try { using (var context = new DataContext()) { var weatherElement = context.Table<Data.Model.Weather>().NewQuery().FirstOrDefault(x => x.ID_user == userId && x.ID == cityId); if (weatherElement != null) { context.Table<Data.Model.Weather>().Delete(weatherElement); context.SaveChanges(); return true; } } } catch (Exception) { //ojojojo } return false; }
public void AddNewOrUpdateMeasurement(Measurement measurement) { DataContext.Table <Measurement>().AddNewOrUpdateRecord(measurement); }
public IEnumerable <CustomActionAdapter> QueryCustomActionAdapters(string sortField, bool ascending, int page, int pageSize, string filterText) { return(DataContext.Table <CustomActionAdapter>().QueryRecords(sortField, ascending, page, pageSize, filterText)); }
public int QueryPhasorCount(string filterText) { return(DataContext.Table <Phasor>().QueryRecordCount(filterText)); }
public CustomActionAdapter NewCustomActionAdapter() { return(DataContext.Table <CustomActionAdapter>().NewRecord()); }
public void DeletePhasor(int id) { DataContext.Table <Phasor>().DeleteRecord(id); }
public void UpdateCustomActionAdapter(CustomActionAdapter customActionAdapter) { DataContext.Table <CustomActionAdapter>().UpdateRecord(customActionAdapter); }
public Phasor NewPhasor() { return(DataContext.Table <Phasor>().NewRecord()); }
public IEnumerable <Historian> QueryHistorians(string sortField, bool ascending, int page, int pageSize, string filterText) { return(DataContext.Table <Historian>().QueryRecords(sortField, ascending, page, pageSize, filterText)); }
public IEnumerable <Device> QueryChildDevices(int deviceID) { return(DataContext.Table <Device>().QueryRecordsWhere("ParentID = {0}", deviceID)); }
/// <summary> /// Metoda usuwająca feed /// </summary> /// <param name="name"></param> /// <param name="feedId"></param> /// <returns></returns> public bool RemoveFeed(string name, int feedId) { var userId = this.GetUserId(name); try { using (var context = new DataContext()) { var feedElement = context.Table<RSS>().NewQuery().FirstOrDefault(x => x.ID_user == userId && x.ID == feedId); if (feedElement != null) { context.Table<RSS>().Delete(feedElement); context.SaveChanges(); return true; } } } catch (Exception) { //ojojojo } return false; }
public Device QueryDeviceByID(int deviceID) { return(DataContext.Table <Device>().QueryRecordWhere("ID = {0}", deviceID) ?? NewDevice()); }
/// <summary> /// Metoda pobierająca wszystkie feedy /// </summary> /// <param name="userName">Nazwa zalogowanego uzytkownika</param> /// <param name="numberPerFeed">ilość per feed</param> /// <returns></returns> public List<RSSModel> GetAllRssFeeds(string userName, int? numberPerFeed = null) { var userId = this.GetUserId(userName); var result = new List<RSSModel>(); try { using (var context = new DataContext()) { var feedUrls = context.Table<RSS>().NewQuery().Where(x => x.ID_user == userId).Select(x => x.RSS_URL).ToList(); foreach (var url in feedUrls) { var subResult = new RSSModel(); XmlReader rssXml; try { rssXml = XmlReader.Create(url); } catch (Exception) { break; } var rss = SyndicationFeed.Load(rssXml); if (rss != null) { subResult.RSSName = rss.Title.Text; subResult.RSSDescription = rss.Description.Text; if (numberPerFeed != null) { rss.Items = rss.Items.OrderBy(x => x.PublishDate.DateTime).Take((int)numberPerFeed).ToList(); } foreach (var item in rss.Items) { var rssItemSubResult = new RSSItemModel { Title = item.Title.Text, PublishDate = item.PublishDate.DateTime, Content = item.Summary.Text }; var uri = item.Links.Select(x => x.Uri).FirstOrDefault(); if (uri != null) { rssItemSubResult.Url = uri.AbsoluteUri; } subResult.RssItems.Add(rssItemSubResult); } } result.Add(subResult); } return result; } } catch (Exception) { // ojojojoj } return null; }
public Phasor QueryPhasorForDevice(int deviceID, int sourceIndex) { return(DataContext.Table <Phasor>().QueryRecordWhere("DeviceID = {0} AND SourceIndex = {1}", deviceID, sourceIndex) ?? NewPhasor()); }
public IEnumerable<EventData> GetEventWaveformData(EventDataJSON json) { if(json != null && json.EventID != null) { try { int eventID = int.Parse(json.EventID); using (DataContext dataContext = new DataContext("systemSettings")) { DataTable table = dataContext.Connection.RetrieveData("Select * FROM GetEventData({0}) as GottenEventData JOIN Series ON GottenEventData.SeriesID = Series.ID JOIN Channel ON Series.ChannelID = Channel.ID WHERE Characteristic = 'Instantaneous'", eventID); return table.Select().Select(row => dataContext.Table<EventData>().LoadRecord(row)).ToList(); } } catch(Exception ex) { return null; } } else return null; }
public IEnumerable <Phasor> QueryPhasorsForDevice(int deviceID) { return(DataContext.Table <Phasor>().QueryRecordsWhere("DeviceID = {0}", deviceID).OrderBy(phasor => phasor.SourceIndex)); }
public IEnumerable<Channel> GetChannelsByMeter(ConfigJSON json) { using (DataContext dataContext = new DataContext("systemSettings")) { string assetKey = (json != null ? (json.AssetKey ?? "%") : "%"); int id = (json != null ? (json.ID == null ? -1 : int.Parse(json.ID)) : -1); string name = (json != null ? (json.Name ?? "%") : "%"); DataTable table = dataContext.Connection.RetrieveData("Select * FROM Channel WHERE MeterID IN (Select ID FROM Meter WHERE AssetKey LIKE {0} AND " + (id != -1 ? "ID LIKE {1} AND " : "") + "NAME LIKE {2})", assetKey, id, name); return table.Select().Select(row => dataContext.Table<Channel>().LoadRecord(row)).ToList(); } }
public int QueryCustomActionAdapterCount(string filterText) { return(DataContext.Table <CustomActionAdapter>().QueryRecordCount(filterText)); }
public void AddNewPhasor(Phasor phasor) { DataContext.Table <Phasor>().AddNewRecord(phasor); }
public Device NewDevice() { return(DataContext.Table <Device>().NewRecord()); }
public bool ValidateUser(string email, string password) { try { using (var context = new DataContext()) { return context.Table<Users>().NewQuery().Any(x => x.Email == email && x.Password == password); } } catch (Exception ex) { // ojojojoj } return false; }
public void UpdatePhasor(Phasor phasor) { DataContext.Table <Phasor>().UpdateRecord(phasor); }