Example #1
0
        /// <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;
        }
Example #2
0
        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;
                }
            }
        }
Example #4
0
 /// <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();
     }
 }
Example #5
0
        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;
            }
        }
Example #6
0
        /// <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;
        }
Example #7
0
        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;
        }
Example #8
0
 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}\""));
        }
Example #10
0
 public Device QueryDevice(string acronym)
 {
     return(DataContext.Table <Device>().QueryRecordWhere("Acronym = {0}", acronym) ?? NewDevice());
 }
Example #11
0
 public void AddNewCustomActionAdapter(CustomActionAdapter customActionAdapter)
 {
     DataContext.Table <CustomActionAdapter>().AddNewRecord(customActionAdapter);
 }
Example #12
0
 public int QueryHistorianCount(string filterText)
 {
     return(DataContext.Table <Historian>().QueryRecordCount(filterText));
 }
Example #13
0
 public void AddNewOrUpdateDevice(Device device)
 {
     DataContext.Table <Device>().AddNewOrUpdateRecord(device);
 }
Example #14
0
 public void DeleteCustomActionAdapter(int id)
 {
     DataContext.Table <CustomActionAdapter>().DeleteRecord(id);
 }
Example #15
0
 public IEnumerable <Measurement> QueryDeviceMeasurements(int deviceID)
 {
     return(DataContext.Table <Measurement>().QueryRecordsWhere("DeviceID = {0}", deviceID));
 }
Example #16
0
 public void DeleteMeasurement(int id)
 {
     DataContext.Table <Measurement>().DeleteRecord(id);
 }
Example #17
0
 public Measurement QueryMeasurementByPointTag(string pointTag)
 {
     return(DataContext.Table <Measurement>().QueryRecordWhere("PointTag = {0}", pointTag) ?? NewMeasurement());
 }
Example #18
0
 public Measurement QueryMeasurementBySignalID(Guid signalID)
 {
     return(DataContext.Table <Measurement>().QueryRecordWhere("SignalID = {0}", signalID) ?? NewMeasurement());
 }
Example #19
0
 public Measurement QueryMeasurement(string signalReference)
 {
     return(DataContext.Table <Measurement>().QueryRecordWhere("SignalReference = {0}", signalReference) ?? NewMeasurement());
 }
Example #20
0
 public IEnumerable <Measurement> QueryMeasurements(string sortField, bool ascending, int page, int pageSize, string filterText)
 {
     return(DataContext.Table <Measurement>().QueryRecords(sortField, ascending, page, pageSize, filterText));
 }
Example #21
0
 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();
            }
        }
Example #23
0
 public Measurement NewMeasurement()
 {
     return(DataContext.Table <Measurement>().NewRecord());
 }
Example #24
0
        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;
        }
Example #25
0
 public void AddNewOrUpdateMeasurement(Measurement measurement)
 {
     DataContext.Table <Measurement>().AddNewOrUpdateRecord(measurement);
 }
Example #26
0
 public IEnumerable <CustomActionAdapter> QueryCustomActionAdapters(string sortField, bool ascending, int page, int pageSize, string filterText)
 {
     return(DataContext.Table <CustomActionAdapter>().QueryRecords(sortField, ascending, page, pageSize, filterText));
 }
Example #27
0
 public int QueryPhasorCount(string filterText)
 {
     return(DataContext.Table <Phasor>().QueryRecordCount(filterText));
 }
Example #28
0
 public CustomActionAdapter NewCustomActionAdapter()
 {
     return(DataContext.Table <CustomActionAdapter>().NewRecord());
 }
Example #29
0
 public void DeletePhasor(int id)
 {
     DataContext.Table <Phasor>().DeleteRecord(id);
 }
Example #30
0
 public void UpdateCustomActionAdapter(CustomActionAdapter customActionAdapter)
 {
     DataContext.Table <CustomActionAdapter>().UpdateRecord(customActionAdapter);
 }
Example #31
0
 public Phasor NewPhasor()
 {
     return(DataContext.Table <Phasor>().NewRecord());
 }
Example #32
0
 public IEnumerable <Historian> QueryHistorians(string sortField, bool ascending, int page, int pageSize, string filterText)
 {
     return(DataContext.Table <Historian>().QueryRecords(sortField, ascending, page, pageSize, filterText));
 }
Example #33
0
 public IEnumerable <Device> QueryChildDevices(int deviceID)
 {
     return(DataContext.Table <Device>().QueryRecordsWhere("ParentID = {0}", deviceID));
 }
Example #34
0
        /// <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;
        }
Example #35
0
 public Device QueryDeviceByID(int deviceID)
 {
     return(DataContext.Table <Device>().QueryRecordWhere("ID = {0}", deviceID) ?? NewDevice());
 }
Example #36
0
        /// <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;
        }
Example #37
0
 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;
 }
Example #39
0
 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();
            }
        }
Example #41
0
 public int QueryCustomActionAdapterCount(string filterText)
 {
     return(DataContext.Table <CustomActionAdapter>().QueryRecordCount(filterText));
 }
Example #42
0
 public void AddNewPhasor(Phasor phasor)
 {
     DataContext.Table <Phasor>().AddNewRecord(phasor);
 }
Example #43
0
 public Device NewDevice()
 {
     return(DataContext.Table <Device>().NewRecord());
 }
Example #44
0
        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;
        }
Example #45
0
 public void UpdatePhasor(Phasor phasor)
 {
     DataContext.Table <Phasor>().UpdateRecord(phasor);
 }