Esempio n. 1
0
        /// <summary>
        /// Get Locations list that have warnings Only.
        /// </summary>
        /// <param name="pageNumber">Page Number.</param>
        /// <param name="pageSize">Items count per page.</param>
        /// <param name="loadParents">Enable or Disable loading the Parents objects.</param>
        /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param>
        /// <param name="viewID">The requested View to validate it's own locations for a warnings</param>
        /// <returns>List of Locations that have one warning or more.</returns>
        public APILocationResponseModels.GetLocationsList GetLocationsWithWarningsList(string searchFor, long?viewID, bool loadViews, bool loadThings, int pageNumber, int pageSize)
        {
            APILocationResponseModels.GetLocationsList result = new APILocationResponseModels.GetLocationsList();

            IPagedList <Location> locationsPL = uof_Repositories.repoLocations.GetLocationsWithWarningsPagedList(searchFor, viewID, pageNumber, pageSize);
            List <Location>       locations   = locationsPL.ToList();

            List <APILocation> listAPILocations = new List <APILocation>();

            foreach (Location location in locations)
            {
                APILocation apiLocation = TypesMapper.APILocationAdapter.fromLocation(location, loadViews, loadThings);
                listAPILocations.Add(apiLocation);
            }
            result.Locations = listAPILocations;


            PagingInfoResponseModel pagingInfo = new PagingInfoResponseModel();

            pagingInfo.CurrentPage  = locationsPL.PageNumber;
            pagingInfo.ItemsPerPage = locationsPL.PageSize;
            pagingInfo.ItemsCount   = locationsPL.TotalItemCount;
            pagingInfo.PagesCount   = locationsPL.PageCount;
            result.PagingInfo       = pagingInfo;
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Get Locations list that have warnings Only.
        /// </summary>
        /// <param name="pageNumber">Page Number.</param>
        /// <param name="pageSize">Items count per page.</param>
        /// <param name="loadParents">Enable or Disable loading the Parents objects.</param>
        /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param>
        /// <param name="viewID">The requested View to validate it's own locations for a warnings</param>
        /// <returns>List of Locations that have one warning or more.</returns>
        public List <APILocation> GetLocationsWithWarnings(int pageNumber, int pageSize, bool loadParents, bool loadChilds, long viewID)
        {
            List <APILocation> apiLocations = new List <APILocation>();
            List <Location>    locations    = db.Locations
                                              .Where(l =>
                                                     ((viewID == null || viewID == 0) || (l.LinkLocationsLocationViews.Any(a => a.LocationViewID == viewID))) &&
                                                     (
                                                         l.LinkThingsLocations.Any(
                                                             lt => lt.Thing.Endpoints.Any(
                                                                 e => e.IsNumericOnly == true &&
                                                                 (e.LastIONumericValue >= e.HighRange || e.LastIONumericValue <= e.LowRange)
                                                                 )
                                                             )
                                                     )
                                                     )
                                              .OrderBy(o => o.Title)
                                              .Skip((pageNumber - 1) * pageSize)
                                              .Take(pageSize).ToList();

            foreach (Location item in locations)
            {
                APILocation apiLocation = TypesMapper.APILocationAdapter.fromLocation(item, loadParents, loadChilds);
                apiLocations.Add(apiLocation);
            }
            return(apiLocations);
        }
Esempio n. 3
0
        public static APILocation fromLocation(Location sourceLocation, bool loadViews, bool loadThings)
        {
            APILocation result = new APILocation();

            result.GUID       = sourceLocation.GUID;
            result.IconID     = sourceLocation.IconID;
            result.ID         = sourceLocation.ID;
            result.isActive   = sourceLocation.isActive;
            result.LatitudeX  = sourceLocation.LatitudeX;
            result.LongitudeY = sourceLocation.LongitudeY;
            result.Status     = sourceLocation.Status;
            result.Title      = sourceLocation.Title;

            #region Parents
            #region LocationViews
            if (loadViews)
            {
                List <APILocationView> apiLocationViews = new List <APILocationView>();
                foreach (LocationView locationView in sourceLocation.locationViews)
                {
                    APILocationView apiLocationView = TypesMapper.APILocationViewAdapter.fromLocationView(locationView, false);
                    apiLocationViews.Add(apiLocationView);
                }
                result.LocationViews = apiLocationViews;
            }
            #endregion


            #endregion

            #region Childs
            if (loadThings)
            {
                #region Things
                List <APIThing> apiThings = new List <APIThing>();
                foreach (Thing thing in sourceLocation.Things)
                {
                    APIThing apiThing = TypesMapper.APIThingAdapter.fromThing(thing, false, false, false, false);
                    apiThings.Add(apiThing);
                }
                result.Things = apiThings;
                #endregion
            }
            result.ThingsCount = sourceLocation.Things.Count;



            #endregion

            return(result);
        }
Esempio n. 4
0
        public static APILocation fromLocation(Location sourceLocation)
        {
            APILocation result = new APILocation();

            result.GUID       = sourceLocation.GUID;
            result.IconID     = sourceLocation.IconID;
            result.ID         = sourceLocation.ID;
            result.isActive   = sourceLocation.isActive;
            result.LatitudeX  = sourceLocation.LatitudeX;
            result.LongitudeY = sourceLocation.LatitudeX;
            result.Status     = sourceLocation.Status;
            result.Title      = sourceLocation.Title;

            return(result);
        }
Esempio n. 5
0
        /// <summary>
        /// Get List of Locations.
        /// </summary>
        /// <param name="pageNumber">Page Number.</param>
        /// <param name="pageSize">Items count per page.</param>
        /// <param name="loadParents">Enable or Disable loading the Parents objects.</param>
        /// <param name="loadChilds">Enable or Disable loading the Childs objects.</param>
        /// <param name="searchFor">Search text as per the 'Title' field.</param>
        /// <param name="viewID">Filter by LocationView ID. You can keep it null or empty to ignore this filter.</param>
        /// <returns></returns>
        public List <APILocation> GetLocations(int pageNumber, int pageSize, bool loadParents, bool loadChilds, string searchFor, long viewID)
        {
            List <APILocation> apiLocations = new List <APILocation>();
            List <Location>    locations    = db.Locations
                                              .Where(v =>
                                                     ((searchFor == null || searchFor == "") || v.Title.Contains(searchFor)) &&
                                                     ((viewID == null || viewID == 0) || (v.LinkLocationsLocationViews.Any(a => a.LocationViewID == viewID)))
                                                     )
                                              .OrderBy(o => o.Title)
                                              .Skip((pageNumber - 1) * pageSize)
                                              .Take(pageSize).ToList();

            foreach (Location item in locations)
            {
                APILocation apiLocation = TypesMapper.APILocationAdapter.fromLocation(item, loadParents, loadChilds);
                apiLocations.Add(apiLocation);
            }
            return(apiLocations);
        }
Esempio n. 6
0
        public static APILocationView fromLocationView(LocationView sourceLocationView, bool loadChilds)
        {
            APILocationView result = new APILocationView();

            result.ID             = sourceLocationView.ID;
            result.IsActive       = sourceLocationView.IsActive;
            result.OwnerID        = sourceLocationView.OwnerID;
            result.Title          = sourceLocationView.Title;
            result.X              = sourceLocationView.X;
            result.Y              = sourceLocationView.Y;
            result.Z              = sourceLocationView.Z;
            result.LocationsCount = sourceLocationView.LinkLocationsLocationViews.Count;

            #region Load MasterTypes
            result.LocationViewType = TypesMapper.APILocationViewTypeAdapter.fromLocationViewType(sourceLocationView.LocationViewType);

            #endregion

            #region Load Parents

            #endregion

            #region Load Childs
            if (loadChilds)
            {
                #region Locations
                List <Location> locs = sourceLocationView.Locations;
                foreach (Location loc in locs)
                {
                    APILocation apiLocation = new APILocation();
                    apiLocation = TypesMapper.APILocationAdapter.fromLocation(loc, false, false);
                    result.Locations.Add(apiLocation);
                }

                #endregion
            }
            #endregion

            return(result);
        }
Esempio n. 7
0
        public static APIThing fromThing(Thing sourceThing, bool loadParents, bool loadChilds)
        {
            APIThing result = new APIThing();

            result.ID       = sourceThing.ID;
            result.Title    = sourceThing.Title;
            result.UTC_Diff = sourceThing.UTC_Diff;

            #region Load Master Types
            result.ThingsType = TypesMapper.APIThingsTypeAdapter.fromThingsType(sourceThing.ThingCategory);

            #endregion

            #region Parents
            if (loadParents)
            {
                #region Locations
                List <APILocation> apiLocations = new List <APILocation>();
                List <Location>    locations    = db.Locations.Where(l => l.LinkThingsLocations.Any(ll => ll.LocationID == l.ID)).ToList();
                foreach (Location location in locations)
                {
                    APILocation apiLocation = TypesMapper.APILocationAdapter.fromLocation(location, false, false);
                    apiLocations.Add(apiLocation);
                }
                result.Locations = apiLocations;
                #endregion
            }

            #endregion

            #region Load Childs
            if (loadChilds)
            {
                #region EndPoints
                List <APIEndPoint> apiEndPoints = new List <APIEndPoint>();
                foreach (Endpoint endpoint in sourceThing.Endpoints)
                {
                    APIEndPoint apiEndpoint = TypesMapper.APIEndPointAdapter.fromEndpoint(endpoint, false, false);
                    apiEndPoints.Add(apiEndpoint);
                }
                result.EndPoints = apiEndPoints;
                #endregion

                #region ThingEnds
                List <APIThingEnd> apiThingEnds = new List <APIThingEnd>();
                foreach (ThingEnd thingEnd in sourceThing.ThingEnds)
                {
                    APIThingEnd apiThingEnd = TypesMapper.APIThingEndAdapter.fromThingEnd(thingEnd, false, false);
                    apiThingEnds.Add(apiThingEnd);
                }
                result.ThingEnds = apiThingEnds;
                #endregion

                #region APIThingExtensionValues
                List <APIThingExtensionValue> apiThingExtensionValues = new List <APIThingExtensionValue>();
                foreach (ThingExtensionValue thingExtensionValue in sourceThing.ThingExtensionValues)
                {
                    APIThingExtensionValue apiThingExtensionValue = TypesMapper.APIThingExtensionValueAdapter.fromThingExtensionValue(thingExtensionValue, true, false);
                    apiThingExtensionValues.Add(apiThingExtensionValue);
                }
                result.APIThingExtensionValues = apiThingExtensionValues;
                #endregion
            }

            result.ThingEndsCount = sourceThing.ThingEnds.Count;
            #endregion


            List <APIEndPoint> apiEnds = new List <APIEndPoint>();
            //foreach(Endpoint end in sourceThing.Endpoints)
            //{
            //    APIEndPoint apiEnd = new APIEndPoint();
            //    apiEnd = TypesMapper.APIEndPointAdapter.fromEndpoint(end);
            //    apiEnds.Add(apiEnd);
            //}
            //result.EndPoints = apiEnds;

            return(result);
        }