Esempio n. 1
0
        /// <summary>
        /// Method top add a Group object into the container.
        /// </summary>
        /// <param name="group">
        /// A valid group object.
        /// </param>
        public void Add(Group group)
        {
            Debug.Assert(group != null, "Group object is null");

            this.items.Add(group);
        }
        /// <summary>
        /// Method reads groups from storage.
        /// </summary>
        /// <param name="key">Specifies a key to read.</param>
        /// <returns>A Groups object.</returns>
        private static Groups ReadGroups(string key)
        {
            Groups groups = new Groups();

            string value = RelayStorage.GetValue(key);
            if (string.IsNullOrEmpty(value))
            {
                return groups;
            }

            string[] groupsItems = value.Split(
                new string[] { RelayStorage.ObjectSeperator },
                System.StringSplitOptions.RemoveEmptyEntries);

            if (groupsItems == null || groupsItems.Length == 0)
            {
                return groups;
            }

            foreach (string item in groupsItems)
            {
                string[] groupItems = item.Split(
                    new string[] { RelayStorage.ValueSeperator },
                    System.StringSplitOptions.None);

                if (groupItems == null || groupItems.Length != 3)
                {
                    continue;
                }

                Group group = new Group()
                {
                    Name = groupItems[0],
                    RegistrationId = groupItems[1],
                    SecretKey = groupItems[2]
                };

                groups.Add(group);
            }

            return groups;
        }
        /// <summary>
        /// Helper method to initiate the call that deletes a group.
        /// </summary>
        /// <param name="clientId">The adm client Id.</param>
        /// <param name="clientSecret">The adm client secret.</param>
        /// <param name="group">Specifies a group to be deleted.</param>
        /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
        /// <param name="stateObject">Specifies a user-defined object.</param>
        public static void DeleteGroupAsync(
            string clientId,
            string clientSecret,
            Group group,
            ServiceAgent<GroupResult>.OnCompleteDelegate onComplete,
            object stateObject = null)
        {
            if (string.IsNullOrEmpty(clientId))
            {
                throw new ArgumentNullException("clientId");
            }

            if (string.IsNullOrEmpty(clientSecret))
            {
                throw new ArgumentNullException("clientSecret");
            }

            DeleteGroupAsync(
                new AdmAuthClientIdentity(clientId, clientSecret, RelayService.ServiceScope),
                group,
                onComplete,
                stateObject);
        }
        /// <summary>
        /// Helper method to initiate the call that deletes a group.
        /// </summary>
        /// <param name="clientIdentity">The hawaii client identity.</param>
        /// <param name="group">Specifies a group to be deleted.</param>
        /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
        /// <param name="stateObject">Specifies a user-defined object.</param>
        private static void DeleteGroupAsync(
            ClientIdentity clientIdentity,
            Group group,
            ServiceAgent<GroupResult>.OnCompleteDelegate onComplete,
            object stateObject = null)
        {
            DeleteGroupAgent agent = new DeleteGroupAgent(
                RelayService.HostName,
                clientIdentity,
                group,
                stateObject);

            agent.ProcessRequest(onComplete);
        }
        /// <summary>
        /// Helper method to initiate the call that deletes a group.
        /// </summary>
        /// <param name="hawaiiAppId">Specifies the Hawaii Application Id.</param>
        /// <param name="group">Specifies a group to be deleted.</param>
        /// <param name="onComplete">Specifies an "on complete" delegate callback.</param>
        /// <param name="stateObject">Specifies a user-defined object.</param>
        public static void DeleteGroupAsync(
            string hawaiiAppId,
            Group group,
            ServiceAgent<GroupResult>.OnCompleteDelegate onComplete,
            object stateObject = null)
        {
            if (string.IsNullOrEmpty(hawaiiAppId))
            {
                throw new ArgumentNullException("hawaiiAppId");
            }

            DeleteGroupAsync(
                new GuidAuthClientIdentity(hawaiiAppId), 
                group, 
                onComplete,
                stateObject);
        }