Ejemplo n.º 1
0
        private void CleanUpMemory(int cleanRange)
        {
            int currentIndex      = PreviewItems.IndexOf(SelectedPreview);
            int previewItemsCount = PreviewItems.Count - 1;

            switch (GalleryDirection)
            {
            case GalleryDirection.Next:
                if ((currentIndex - cleanRange) >= 0)
                {
                    int cleanIndex = currentIndex - cleanRange;
                    if (PreviewItems[cleanIndex].IsBusy)
                    {
                        PreviewItems[cleanIndex].CancelPreviewRequest();
                    }
                    PreviewItems[cleanIndex].InViewingRange  = false;
                    PreviewItems[cleanIndex].PreviewImageUri = null;
                }
                break;

            case GalleryDirection.Previous:
                if ((currentIndex + cleanRange) <= previewItemsCount)
                {
                    int cleanIndex = currentIndex + cleanRange;
                    if (PreviewItems[cleanIndex].IsBusy)
                    {
                        PreviewItems[cleanIndex].CancelPreviewRequest();
                    }
                    PreviewItems[cleanIndex].InViewingRange  = false;
                    PreviewItems[cleanIndex].PreviewImageUri = null;
                }
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set the range of previews to load before and after the current preview.
        /// </summary>
        /// <param name="viewRange">Range from the current item to load the previews.</param>
        /// <param name="initialize">Indicates if is an initialization.</param>
        /// <exception cref="ArgumentOutOfRangeException"/>
        private void SetViewingRange(int viewRange, bool initialize)
        {
            if (SelectedPreview == null)
            {
                return;
            }

            int currentIndex = PreviewItems.IndexOf(SelectedPreview);
            int lowIndex     = currentIndex - viewRange;

            if (lowIndex < 0)
            {
                lowIndex = 0;
            }
            int highIndex = currentIndex + viewRange;

            if (highIndex > PreviewItems.Count - 1)
            {
                highIndex = PreviewItems.Count - 1;
            }

            if (initialize)
            {
                for (int i = currentIndex; i >= lowIndex; i--)
                {
                    PreviewItems[i].InViewingRange = true;
                }
                for (int i = currentIndex; i <= highIndex; i++)
                {
                    PreviewItems[i].InViewingRange = true;
                }
            }
            else
            {
                switch (GalleryDirection)
                {
                case GalleryDirection.Next:
                default:
                    PreviewItems[highIndex].InViewingRange = true;
                    break;

                case GalleryDirection.Previous:
                    PreviewItems[lowIndex].InViewingRange = true;
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        private void UpdatePreviewItems()
        {
            if (FilterScheme is null || RawCollection is null)
            {
                return;
            }

            if (!AllowLivePreview)
            {
                return;
            }

            if (!EnableLivePreview)
            {
                PreviewItems.Clear();
                return;
            }

            FilterScheme.Apply(RawCollection, PreviewItems);
        }
Ejemplo n.º 4
0
        //GET TRACKS
        public JsonResult GetFeatures(double neLat, double neLng, double swLat, double swLng, string fullurl, int pagesize, int page, string trackType, string difficulty, string duration, string amenities, string activities, string access, string query)
        {
            try
            {
                var          cd = SetGetMemoryCache();
                PreviewItems p  = new PreviewItems();

                //Filter items
                bool filtered         = false;
                bool thisfilteredok   = false;
                bool trackTypeFilter  = false;
                bool difficultyFilter = false;
                bool durationFilter   = false;
                bool amenitiesFilter  = false;
                bool activitiesFilter = false;
                bool accessFilter     = false;


                if (trackType != "" && trackType != "all")
                {
                    filtered        = true;
                    trackTypeFilter = true;
                }
                if (difficulty != "" && difficulty != "all")
                {
                    filtered         = true;
                    difficultyFilter = true;
                }
                if (duration != "" && duration != "all")
                {
                    filtered       = true;
                    durationFilter = true;
                }
                if (amenities != "" && amenities != "all")
                {
                    filtered        = true;
                    amenitiesFilter = true;
                }
                if (activities != "" && activities != "all")
                {
                    filtered         = true;
                    activitiesFilter = true;
                }
                if (access != "" && access != "all")
                {
                    filtered     = true;
                    accessFilter = true;
                }

                foreach (CachedDataClass.Track.Feature f in cd.track.features)
                {
                    bool found = false;

                    if (query.Length > 0)
                    {
                        if (ncstr(f.properties.NAME).ToLower().Contains(query.ToLower()))
                        {
                            found = true;
                        }
                    }
                    else
                    {
                        if (f.geometry.type == "MultiLineString")
                        {
                            foreach (List <object> g in f.geometry.coordinates)
                            {
                                foreach (object o in g)
                                {
                                    Newtonsoft.Json.Linq.JArray h = (Newtonsoft.Json.Linq.JArray)o;
                                    double x = (double)h[0];
                                    double y = (double)h[1];
                                    if (((x >= neLng && x <= swLng) || (x <= neLng && x >= swLng)) && ((y >= neLat && y <= swLat) || (y <= neLat && y >= swLat)))
                                    {
                                        found = true;
                                        break;
                                    }
                                    if (found)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (f.geometry.type == "LineString")
                        {
                            foreach (List <object> h in f.geometry.coordinates)
                            {
                                double x = (double)h[0];
                                double y = (double)h[1];
                                if (((x >= neLng && x <= swLng) || (x <= neLng && x >= swLng)) && ((y >= neLat && y <= swLat) || (y <= neLat && y >= swLat)))
                                {
                                    found = true;
                                    break;
                                }
                                if (found)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    if (found)
                    {
                        PreviewItems.Result result = new PreviewItems.Result();
                        result.links = new PreviewItems.Links();
                        string serialno = "0000";
                        if (f.properties.SERIAL_NO != null)
                        {
                            serialno = f.properties.SERIAL_NO;
                        }
                        result.id          = serialno;
                        result.name        = f.properties.NAME;
                        result.description = f.properties.COMMENTS;
                        if (f.properties.COMMENTS == null && f.properties.W_COMMENT != null)
                        {
                            result.description = f.properties.W_COMMENT.ToString();
                        }
                        if (f.properties.COMMENTS != null && f.properties.W_COMMENT != null)
                        {
                            result.description = f.properties.COMMENTS + ' ' + f.properties.W_COMMENT.ToString();
                        }
                        result.featureType = "track";
                        result.closed      = false;
                        if (f.properties.CLOS_STAT != null)
                        {
                            result.closed = true;
                        }
                        result.features      = new List <string>();
                        result.links.details = _appsettings.BaseURL + "/tracks/" + serialno;


                        if (f.photos.Count > 0)
                        {
                            result.image = getImageString(f.photos[0]);
                        }


                        //Get Features
                        foreach (string s in f.trackFeatures)
                        {
                            if (!result.features.Contains(s))
                            {
                                result.features.Add(s);
                            }
                        }


                        if (trackTypeFilter || difficultyFilter || durationFilter || activitiesFilter || amenitiesFilter || accessFilter)
                        {
                            thisfilteredok = true;
                            bool filter1ok = true;
                            bool filter2ok = true;
                            bool filter3ok = true;
                            bool filter4ok = true;
                            bool filter5ok = true;
                            bool filter6ok = true;
                            bool debugtest = false;

                            if (trackTypeFilter)
                            {
                                if (f.properties.SERIAL_NO == "1764")
                                {
                                    debugtest = false;
                                }
                                if (!filterCompare(f.filters.trackType, trackType))
                                {
                                    filter1ok = false;
                                }
                            }

                            if (difficultyFilter && !filterCompare(f.filters.difficulty, difficulty))
                            {
                                filter2ok = false;
                            }


                            if (durationFilter)
                            {
                                if (!filterCompare(f.filters.duration, duration))
                                {
                                    filter3ok = false;
                                }
                                else
                                {
                                    debugtest = true;
                                }
                            }

                            /*
                             * if (activitiesFilter)
                             * {
                             *  if (!filterCompare(f.filters.activities, activities))
                             *  {
                             *      filter4ok = false;
                             *  }
                             *  else
                             *  {
                             *      debugtest = true;
                             *  }
                             * }
                             *
                             * if (amenitiesFilter)
                             * {
                             *  if (!filterCompare(f.filters.amenities, amenities))
                             *  {
                             *      filter5ok = false;
                             *  }
                             *  else
                             *  {
                             *      debugtest = true;
                             *  }
                             * }
                             *
                             * if (accessFilter && !filterCompare(f.filters.access, access))
                             * {
                             *  filter6ok = false;
                             * }
                             */

                            //if (filter1ok) thisfilteredok = true;
                            if (!filter1ok || !filter2ok || !filter2ok || !filter3ok || !filter4ok || !filter5ok || !filter6ok)
                            {
                                thisfilteredok = false;
                            }
                        }


                        if (filtered)
                        {
                            if (thisfilteredok)
                            {
                                p.results.Add(result);
                            }
                        }
                        else
                        {
                            p.results.Add(result);
                        }
                    }
                }



                //GET SITES
                if (/*!trackTypeFilter  && !difficultyFilter && !durationFilter ||*/ true)
                {
                    foreach (CachedDataClass.Site.Feature f in cd.site.features)
                    {
                        bool   found       = false;
                        bool   filterFound = false;
                        double x           = f.geometry.coordinates[0];
                        double y           = f.geometry.coordinates[1];


                        if (query.Length > 0)
                        {
                            if (f.properties.NAME.ToLower().Contains(query.ToLower()))
                            {
                                found = true;
                            }
                        }
                        else
                        {
                            if (((x >= neLng && x <= swLng) || (x <= neLng && x >= swLng)) && ((y >= neLat && y <= swLat) || (y <= neLat && y >= swLat)))
                            {
                                found = true;
                            }
                        }

                        if (found)
                        {
                            if (f.properties.SERIAL_NO == "2118" || f.properties.SERIAL_NO == "10342" || f.properties.SERIAL_NO == "8540")
                            {
                                string debug = "test";
                            }
                            PreviewItems.Result result = new PreviewItems.Result();
                            result.links       = new PreviewItems.Links();
                            result.id          = f.properties.SERIAL_NO;
                            result.name        = f.properties.NAME;
                            result.description = f.siteDescriptrionFromFirstActivity;

                            result.featureType = "site";
                            result.closed      = false;
                            if (f.properties.CLOS_STAT != null)
                            {
                                result.closed = true;
                            }

                            if (f.properties.PHOTO_ID_1 != null)
                            {
                                int pid = 0;
                                int.TryParse(f.properties.PHOTO_ID_1, out pid);
                                if (pid > 0)
                                {
                                    result.image = getImageString(pid);
                                }
                            }

                            result.features      = new List <string>();
                            result.links.details = _appsettings.BaseURL + "/sites/" + f.properties.SERIAL_NO;

                            //Get Features and filters
                            filterFound = false;
                            foreach (string s in f.siteFeatures)
                            {
                                if (!result.features.Contains(s))
                                {
                                    result.features.Add(s);
                                }
                                filterFound = ff(s, trackType, filterFound);
                            }


                            if (/*trackTypeFilter || difficultyFilter || durationFilter ||*/ activitiesFilter || amenitiesFilter || accessFilter)
                            {
                                thisfilteredok = true;
                                bool filter4ok = true;
                                bool filter5ok = true;
                                bool filter6ok = true;
                                bool debugtest = false;

                                if (activitiesFilter && !filterCompare(f.filters.activities, activities))
                                {
                                    filter4ok = false;
                                }

                                if (amenitiesFilter)
                                {
                                    if (!filterCompare(f.filters.amenities, amenities))
                                    {
                                        filter5ok = false;
                                    }
                                    else
                                    {
                                        debugtest = true;
                                    }
                                }

                                if (accessFilter && !filterCompare(f.filters.access, access))
                                {
                                    filter6ok = false;
                                }

                                if (!filter4ok || !filter5ok || !filter6ok)
                                {
                                    thisfilteredok = false;
                                }

                                if (thisfilteredok)
                                {
                                    p.results.Add(result);
                                }
                            }
                            else
                            {
                                p.results.Add(result);
                            }
                        }
                    }
                }


                //GET RELICS
                if (!filtered)
                {
                    foreach (CachedDataClass.Relic.Feature f in cd.relic.features)
                    {
                        bool   found = false;
                        double x     = f.geometry.coordinates[0];
                        double y     = f.geometry.coordinates[1];


                        if (query.Length > 0)
                        {
                            if (f.properties.NAME.ToLower().Contains(query.ToLower()))
                            {
                                found = true;
                            }
                        }
                        else
                        {
                            if (((x >= neLng && x <= swLng) || (x <= neLng && x >= swLng)) && ((y >= neLat && y <= swLat) || (y <= neLat && y >= swLat)))
                            {
                                found = true;
                            }
                        }

                        if (found)
                        {
                            PreviewItems.Result result = new PreviewItems.Result();
                            result.links       = new PreviewItems.Links();
                            result.id          = f.properties.SERIAL_NO;
                            result.name        = f.properties.NAME;
                            result.description = f.properties.COMMENTS;
                            result.featureType = "relic";
                            result.closed      = false;
                            if (f.properties.PHOTO_ID_1 != null)
                            {
                                int pid = 0;
                                int.TryParse(f.properties.PHOTO_ID_1, out pid);
                                if (pid > 0)
                                {
                                    result.image = getImageString(pid);
                                }
                            }
                            result.features = new List <string>();
                            result.features.Add("historicRelic");

                            foreach (string rf in f.relicFeatures)
                            {
                                result.features.Add(rf);
                            }

                            result.links.details = _appsettings.BaseURL + "/relics/" + f.properties.SERIAL_NO;
                            p.results.Add(result);
                        }
                    }
                }

                int totalcount = p.results.Count();

                if (pagesize > 0 && p.results.Count() > pagesize)
                {
                    PreviewItems ppaged = new PreviewItems();

                    int i = 0;
                    foreach (PreviewItems.Result r in p.results)
                    {
                        int mini = pagesize * (page - 1);
                        int maxi = (pagesize * page) - 1;

                        if (i >= mini && i <= maxi)
                        {
                            ppaged.results.Add(r);
                        }

                        if (maxi >= totalcount - 1)
                        {
                            ppaged.meta.links.next = null;
                        }
                        else
                        {
                            string s = fullurl.ToLower().Replace("page=" + page.ToString(), "");
                            s += "&page=" + (page + 1).ToString();
                            s  = s.Replace("&&", "&");
                            ppaged.meta.links.next = s;
                        }
                        i++;
                    }


                    ppaged.meta.totalResults = totalcount;
                    ppaged.meta.links.self   = fullurl.ToLower();

                    JsonResult jsonresult = new JsonResult(ppaged);
                    return(jsonresult);
                }
                else
                {
                    p.meta.totalResults = totalcount;
                    p.meta.links.self   = fullurl.ToLower();

                    JsonResult jsonresult = new JsonResult(p);
                    return(jsonresult);
                }
            }
            catch (Exception ex)
            {
                JsonResult jsonresult = new JsonResult("Error: " + ex.ToString());
                return(jsonresult);
            }
        }