Example #1
0
 /// <inheritdoc/>
 public override String ToString()
 {
     System.Text.StringBuilder sb = new System.Text.StringBuilder();
     sb.Append('<').Append(_uri).Append('>')
     .Append(' ').Append(_attributes.Title);
     if (_attributes.Contains(LinkFormat.ResourceType))
     {
         sb.Append("\n\t").Append(LinkFormat.ResourceType)
         .Append(":\t").Append(_attributes.GetResourceTypes());
     }
     if (_attributes.Contains(LinkFormat.InterfaceDescription))
     {
         sb.Append("\n\t").Append(LinkFormat.InterfaceDescription)
         .Append(":\t").Append(_attributes.GetInterfaceDescriptions());
     }
     if (_attributes.Contains(LinkFormat.ContentType))
     {
         sb.Append("\n\t").Append(LinkFormat.ContentType)
         .Append(":\t").Append(_attributes.GetContentTypes());
     }
     if (_attributes.Contains(LinkFormat.MaxSizeEstimate))
     {
         sb.Append("\n\t").Append(LinkFormat.MaxSizeEstimate)
         .Append(":\t").Append(_attributes.MaximumSizeEstimate);
     }
     if (_attributes.Observable)
     {
         sb.Append("\n\t").Append(LinkFormat.Observable);
     }
     return(sb.ToString());
 }
Example #2
0
        private static bool Matches(IResource resource, List <string> query)
        {
            if (resource == null)
            {
                return(false);
            }
            if (query == null)
            {
                return(true);
            }

            using (IEnumerator <string> ie = query.GetEnumerator()) {
                if (!ie.MoveNext())
                {
                    return(true);
                }

                ResourceAttributes attributes = resource.Attributes;
                string             path       = resource.Path + resource.Name;

                do
                {
                    string s = ie.Current;

                    int delim = s.IndexOf('=');
                    if (delim == -1)
                    {
                        // flag attribute
                        if (attributes.Contains(s))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        string attrName = s.Substring(0, delim);
                        string expected = s.Substring(delim + 1);

                        if (attrName.Equals(LinkFormat.Link))
                        {
                            if (expected.EndsWith("*"))
                            {
                                return(path.StartsWith(expected.Substring(0, expected.Length - 1)));
                            }
                            else
                            {
                                return(path.Equals(expected));
                            }
                        }
                        else if (attributes.Contains(attrName))
                        {
                            // lookup attribute value
                            foreach (string value in attributes.GetValues(attrName))
                            {
                                string actual = value;
                                // get prefix length according to "*"
                                int prefixLength = expected.IndexOf('*');
                                if (prefixLength >= 0 && prefixLength < actual.Length)
                                {
                                    // reduce to prefixes
                                    expected = expected.Substring(0, prefixLength);
                                    actual   = actual.Substring(0, prefixLength);
                                }

                                // handle case like rt=[Type1 Type2]
                                if (actual.IndexOf(' ') > -1)
                                {
                                    foreach (string part in actual.Split(' '))
                                    {
                                        if (part.Equals(expected))
                                        {
                                            return(true);
                                        }
                                    }
                                }

                                if (expected.Equals(actual))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                } while (ie.MoveNext());
            }

            return(false);
        }