示例#1
0
        private static void SerializeAttributesInCoral(ResourceAttributes attributes, CoralBody coral, Dictionary <string, CBORObject> dictionary, Uri uriRelative)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                if (!CoralsKeys.ContainsKey(name))
                {
                    continue;
                }

                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                if (uriRelative != null && name == "anchor")
                {
                    List <string> newValues = new List <string>();
                    foreach (string val in values)
                    {
                        newValues.Add(new Uri(uriRelative, val).ToString());
                    }

                    values = newValues;
                }

                SerializeAttributeInCoral(name, values, coral, null);
            }
        }
示例#2
0
        private static void SerializeAttributes(ResourceAttributes attributes, StringBuilder sb, Uri uriRelative)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                if (uriRelative != null && name == "anchor")
                {
                    List <string> newValues = new List <string>();
                    foreach (string val in values)
                    {
                        newValues.Add(new Uri(uriRelative, val).ToString());
                    }

                    values = newValues;
                }
                sb.Append(Separator);
                SerializeAttribute(name, values, sb);
            }
        }
示例#3
0
        private static void SerializeAttributes(ResourceAttributes attributes, CBORObject cbor, Dictionary <string, CBORObject> dictionary)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }

                SerializeAttribute(name, values, cbor, dictionary);
            }
        }
示例#4
0
        private static void SerializeAttributes(ResourceAttributes attributes, StringBuilder sb)
        {
            List <string> keys = new List <string>(attributes.Keys);

            keys.Sort();
            foreach (string name in keys)
            {
                List <string> values = new List <string>(attributes.GetValues(name));
                if (values.Count == 0)
                {
                    continue;
                }
                sb.Append(Separator);
                SerializeAttribute(name, values, sb);
            }
        }
示例#5
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);
        }