Beispiel #1
0
        public void Parse3Test()
        {
            const string InputQuery = "uri:reddit.com";

            var r = new WorkspaceResult
            {
                Uri = InputQuery
            };

            var f = new UriFilter(InputQuery);

            Assert.IsTrue(f.IsMatch(r, "", null).Any());
        }
        private Object ReadData(HttpContext context)
        {
            //defining all the dictionaries
            Dictionary <String, Item> GeologicCollectionTitle = new Dictionary <String, Item>();
            Dictionary <String, Item> GeologicUnit            = new Dictionary <String, Item>();
            Dictionary <String, Item> TectonicUnit            = new Dictionary <String, Item>();
            Dictionary <String, Item> Proportion = new Dictionary <String, Item>();
            Dictionary <String, Item> TimeScale  = new Dictionary <String, Item>();
            //zusätzlich für TimeScale
            Dictionary <String, Item> Lithology        = new Dictionary <String, Item>();
            Dictionary <String, Item> EventProcess     = new Dictionary <String, Item>();
            Dictionary <String, Item> EventEnvironment = new Dictionary <String, Item>();
            //zusätzlich für GeologicUnit
            Dictionary <String, Item> DescriptionPurpose = new Dictionary <String, Item>();

            //String s;
            //s = getTopicsORCondition(context);
            //List<GE_GeologicFeature> myFeatures = new List<GE_GeologicFeature>();
            List <LidItem> L_ID             = null;// = new List<String>();
            String         topics           = context.Request["topics"];
            String         allTopics_string = context.Request["alltopics"];
            String         uri       = context.Request["uri"];
            String         language  = context.Request["language"];
            String         parameter = GetParameter(uri);
            String         value2    = context.Request["filters"];
            UriFilter      uriFilter = null;

            if (value2 != null)
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                //Object user = jss.DeserializeObject(value2);
                uriFilter = jss.Deserialize <UriFilter>(value2);
            }
            if (topics == null)
            {
                return(null);
            }
            List <string> notIncludedUriList = new List <string>();

            String[] filteredTopics = topics.Split(',');
            String[] allTopics      = allTopics_string.Split(',');
            if (filteredTopics != null && filteredTopics.Length > 0)
            {
                //FeatureDbo[] features = DoQuery(a);
                //IQueryable<FeatureDbo> features = DoQuery(filteredTopics, parameter, language);
                IQueryable <FeatureDbo> features = DoQuery(allTopics, parameter, language);
                if (features == null)
                {
                    return(null);
                }

                //also set the filters if ther are any:
                if (uriFilter != null)
                {
                    if (uriFilter.tectonicuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.tectonicuris.Contains(f.TectonicUnitUri));
                    }
                    if (uriFilter.geologicunituris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.geologicunituris.Contains(f.GeologicUnitNameUri));
                    }

                    if (uriFilter.proportionuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.proportionuris.Contains(f.ProportionUri));
                    }
                    if (uriFilter.timescaleuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.timescaleuris.Contains(f.AgeUri));
                    }
                    if (uriFilter.dataset != null)
                    {
                        features = features.Where(f => f.GeologicCollectionTitle == uriFilter.dataset);
                    }
                    //zusätzlich für TimeScale
                    if (uriFilter.lithologyuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.lithologyuris.Contains(f.LithologyUri));
                    }
                    if (uriFilter.eventprocessuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.eventprocessuris.Contains(f.EventProcessUri));
                    }
                    if (uriFilter.eventenvironmenturis.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.eventenvironmenturis.Contains(f.EventEnvironmentUri));
                    }
                    //zusätzlich für GeologicUnit
                    if (uriFilter.descriptionpurposeuris.Count() > 0)
                    {
                        features = features.Where(f => uriFilter.descriptionpurposeuris.Contains(f.DescriptionPurposeUri));
                    }
                }

                //var test = features.Select(f => f.L_ID).Distinct().ToList();
                //L_ID = features.Select(f => new LidItem() { l_id = f.L_ID, proportion = f.ProportionLbl }).DistinctBy(lid => lid.l_id).ToList();
                //L_ID = new List<LidItem>();

                //((ObjectQuery)features).MergeOption = MergeOption.NoTracking;
                IEnumerable <FeatureDbo> features2 = features.ToList();

                //make test which terms ar not included anymore
                foreach (string termUri in allTopics)
                {
                    bool matches = false;
                    if (parameter == "Lithology")
                    {
                        matches = features2.Any(p => p.LithologyUri == termUri);
                    }
                    else if (parameter == "GeologicUnit")
                    {
                        matches = features2.Any(p => p.GeologicUnitNameUri == termUri);
                    }
                    else if (parameter == "TectonicUnit")
                    {
                        matches = features2.Any(p => p.TectonicUnitUri == termUri);
                    }
                    else if (parameter == "GeologicTimeScale")
                    {
                        matches = features2.Any(p => p.AgeUri == termUri);
                    }
                    if (matches == false)
                    {
                        notIncludedUriList.Add(termUri);
                    }
                }

                //features nochmal einschränken
                if (allTopics.Length != filteredTopics.Length)
                {
                    if (parameter == "Lithology")
                    {
                        features2 = features2.Where(x => filteredTopics.Contains(x.LithologyUri));
                    }
                    else if (parameter == "GeologicUnit")
                    {
                        features2 = features2.Where(x => filteredTopics.Contains(x.GeologicUnitNameUri));
                    }
                    else if (parameter == "TectonicUnit")
                    {
                        features2 = features2.Where(x => filteredTopics.Contains(x.TectonicUnitUri));
                    }
                    else if (parameter == "GeologicTimeScale")
                    {
                        features2 = features2.Where(x => filteredTopics.Contains(x.AgeUri)).ToList();
                    }
                }
                L_ID = features2.Select(f => new LidItem()
                {
                    l_id = f.L_ID, proportion = f.ProportionLbl
                }).DistinctBy(lid => lid.l_id).ToList();


                //fill the dictionaries
                foreach (var feature in features2)
                {
                    this.Put(GeologicCollectionTitle, null, feature.GeologicCollectionTitle, feature.L_ID, null, feature.ProportionLbl);
                    this.Put(DescriptionPurpose, feature.DescriptionPurposeUri, feature.DescriptionPurposeLbl, feature.L_ID, null, feature.ProportionLbl);
                    this.Put(GeologicUnit, feature.GeologicUnitNameUri, feature.GeologicUnitNameLbl, feature.L_ID, feature.GeologicUnitNameDescription, feature.ProportionLbl);
                    this.Put(TectonicUnit, feature.TectonicUnitUri, feature.TectonicUnitLbl, feature.L_ID, feature.TectonicUnitDescription, feature.ProportionLbl);
                    this.Put(Proportion, feature.ProportionUri, feature.ProportionLbl, feature.L_ID, null, feature.ProportionLbl);
                    this.Put(TimeScale, feature.AgeUri, feature.AgeLbl, feature.L_ID, feature.AgeDescription, feature.ProportionLbl);
                    //zusätzlich für TimeScale
                    this.Put(Lithology, feature.LithologyUri, feature.LithologyLbl, feature.L_ID, feature.LithologyDescription, feature.ProportionLbl);
                    this.Put(Lithology, feature.LithologyUri, feature.LithologyLbl, feature.L_ID, feature.LithologyDescription, feature.ProportionLbl);
                    this.Put(EventProcess, feature.EventProcessUri, feature.EventProcessLbl, feature.L_ID, feature.EventProcessDescription, feature.ProportionLbl);
                    this.Put(EventEnvironment, feature.EventEnvironmentUri, feature.EventEnvironmentLbl, feature.L_ID, feature.EventEnvironmentDescription, feature.ProportionLbl);
                    //zusätzlich für GeologicUnit
                    this.Put(DescriptionPurpose, feature.DescriptionPurposeUri, feature.DescriptionPurposeLbl, feature.L_ID, null, feature.ProportionLbl);
                }
                //GeologicCollectionTitle.GroupBy(f => f.Value);
            }

            return(new
            {
                L_ID = L_ID,
                Filters = GetLocalizedFilters(filters, language),
                Dataset = GeologicCollectionTitle.Values.OrderBy(m => m.name).ToArray(),
                GeologicUnit = GeologicUnit.Values.OrderBy(m => m.name).ToArray(),
                TectonicUnit = TectonicUnit.Values.OrderBy(m => m.name).ToArray(),
                Proportion = Proportion.Values.OrderBy(m => m.name).ToArray(),
                TimeScale = TimeScale.Values.OrderBy(m => m.name).ToArray(),
                //zusätzlich für TimeScale
                Lithology = Lithology.Values.OrderBy(m => m.name).ToArray(),
                EventProcess = EventProcess.Values.OrderBy(m => m.name).ToArray(),
                EventEnvironment = EventEnvironment.Values.OrderBy(m => m.name).ToArray(),
                //zusätzlich für GeologicUnit
                DescriptionPurpose = DescriptionPurpose.Values.OrderBy(m => m.name).ToArray(),

                NotIncludedUris = notIncludedUriList
            });
        }
Beispiel #3
0
        public static bool IsLink(this string url,
            Uri baseUri, LinkKind kind, UriFilter filter = UriFilter.None)
        {
            Contract.Requires(baseUri.IsBaseUri());

            if (string.IsNullOrWhiteSpace(url))
                return false;

            url = url.Trim().ToLower();

            if (!Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute))
                return false;

            if (url.StartsWith("#"))
                return false;

            Uri uri;

            if (!Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
                return false;

            if (!uri.IsAbsoluteUri)
            {
                if (!Uri.TryCreate(baseUri, uri, out uri))
                    return false;
            }

            if (uri.Scheme != "http")
                return false;

            switch (filter)
            {
                case UriFilter.LocalPath:
                    if (!baseUri.IsBaseOf(uri))
                        return false;
                    break;
                case UriFilter.Authority:
                    if (uri.Authority != baseUri.Authority)
                        return false;
                    break;
            }

            if (kind == LinkKind.HTML)
                return true;

            if (!string.IsNullOrWhiteSpace(uri.Query))
                return false;

            string localPath;

            try
            {
                localPath = Path.GetFileName(uri.LocalPath);
            }
            catch
            {
                return false;
            }

            switch (Path.GetExtension(localPath))
            {
                case ".jpg":
                case ".jpeg":
                case ".png":
                case ".gif":
                case ".bmp":
                case ".tiff":
                    return true;
                default:
                    return false;
            }
        }