コード例 #1
0
        /// <summary>
        /// Adds a capability resource. The resource returned can be used to define the actions allowed for it by chaining the Allow methods
        /// Possible options are: AllowAll, AllowPublish, AllowPresence and AllowSubscribe
        /// A Resource can be a channel "channel" or a namespace "namespace:*". Please consult the rest documentation
        /// </summary>
        /// <code>
        /// var capability = new Capability();
        ///
        /// capability.AddResource("name").AllowPublish();
        /// </code>
        /// <param name="name">name of the resource</param>
        /// <returns>CapabilityResource</returns>
        public CapabilityResource AddResource(string name)
        {
            var resource = new CapabilityResource(name);
            Resources.Add(resource);

            return resource;
        }
コード例 #2
0
 private static JArray GetResourceValue(CapabilityResource resource)
 {
     if (resource.AllowsAll)
         return new JArray(CapabilityResource.AllowedOps.All);
     if (resource.AllowedOperations.Count == 1)
         return new JArray(resource.AllowedOperations.First());
     return new JArray(resource.AllowedOperations.ToArray());
 }
コード例 #3
0
 private static CapabilityResource GetResource(JProperty child)
 {
     var resource = new CapabilityResource(child.Name);
     var allowedOperations = child.Value as JArray;
     if (allowedOperations != null)
         foreach (JToken token in allowedOperations)
             resource.AllowedOperations.Add((string)token);
     return resource;
 }
コード例 #4
0
ファイル: Capability.cs プロジェクト: ably/ably-dotnet
        private static JArray GetResourceValue(CapabilityResource resource)
        {
            if (resource.AllowsAll)
            {
                return(new JArray(CapabilityResource.AllowedOps.All));
            }

            if (resource.AllowedOperations.Count == 1)
            {
                return(new JArray(resource.AllowedOperations.First()));
            }

            // Up-casting here: but in this case it's OK since we're reading, rather than writing.
            return(new JArray(resource.AllowedOperations.Cast <object>().ToArray()));
        }