Exemple #1
0
        public void Invoke()
        {
            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);

            var remoteEndpoint = new EndpointId("other");
            var reg            = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var eventArgs      = new InteractionExtensionsTest.MySerializableEventArgs();
            var notifications  = new Mock <IRaiseProxyNotifications>();
            {
                notifications.Setup(c => c.RaiseNotification(It.IsAny <EndpointId>(), It.IsAny <NotificationId>(), It.IsAny <EventArgs>()))
                .Callback <EndpointId, NotificationId, EventArgs>(
                    (e, n, a) =>
                {
                    Assert.AreSame(remoteEndpoint, e);
                    Assert.AreSame(reg, n);
                    Assert.AreSame(eventArgs, a);
                })
                .Verifiable();
            }

            var action = new NotificationRaisedProcessAction(notifications.Object, systemDiagnostics);

            action.Invoke(
                new NotificationRaisedMessage(
                    remoteEndpoint,
                    new NotificationRaisedData(reg, eventArgs)));

            notifications.Verify(n => n.RaiseNotification(It.IsAny <EndpointId>(), It.IsAny <NotificationId>(), It.IsAny <EventArgs>()), Times.Once());
        }
                public override int GetHashCode()
                {
                    int hash = 1;

                    if (NotificationId.Length != 0)
                    {
                        hash ^= NotificationId.GetHashCode();
                    }
                    if (TitleKey.Length != 0)
                    {
                        hash ^= TitleKey.GetHashCode();
                    }
                    if (Category.Length != 0)
                    {
                        hash ^= Category.GetHashCode();
                    }
                    if (CreateTimestampMs != 0L)
                    {
                        hash ^= CreateTimestampMs.GetHashCode();
                    }
                    hash ^= variables_.GetHashCode();
                    hash ^= labels_.GetHashCode();
                    if (ExpireTimeMs != 0L)
                    {
                        hash ^= ExpireTimeMs.GetHashCode();
                    }
                    if (_unknownFields != null)
                    {
                        hash ^= _unknownFields.GetHashCode();
                    }
                    return(hash);
                }
    private void loadNewTemplate(ref NotificationView view, string templateId)
    {
        NotificationId tempId = view.Id;

        Destroy(view.gameObject);
        view = NotificationView.CreateNotificationView(templateId, tempId);
    }
        public void Invoke()
        {
            EndpointId     processedId  = null;
            NotificationId registration = null;
            var            sink         = new Mock <ISendNotifications>();
            {
                sink.Setup(s => s.RegisterForNotification(It.IsAny <EndpointId>(), It.IsAny <NotificationId>()))
                .Callback <EndpointId, NotificationId>((e, s) =>
                {
                    processedId  = e;
                    registration = s;
                });
            }

            var action = new RegisterForNotificationProcessAction(sink.Object);

            var id  = new EndpointId("id");
            var reg = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new RegisterForNotificationMessage(id, reg);

            action.Invoke(msg);

            Assert.AreEqual(id, processedId);
            Assert.AreEqual(reg, registration);
        }
Exemple #5
0
        public void ToMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Callback <Type>(t => Assert.IsTrue(typeof(int).Equals(t)))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new NotificationRaisedConverter(serializers.Object);

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var data = new NotificationRaisedData
            {
                Id                 = new MessageId(),
                InResponseTo       = new MessageId(),
                Sender             = new EndpointId("a"),
                NotificationId     = NotificationIdExtensions.Serialize(id),
                EventArgumentsType = new SerializedType
                {
                    FullName     = typeof(int).FullName,
                    AssemblyName = typeof(int).Assembly.GetName().Name,
                },
                EventArguments = new EventArgs(),
            };
            var msg = translator.ToMessage(data);

            Assert.IsInstanceOf(typeof(NotificationRaisedMessage), msg);
            Assert.AreSame(data.Id, msg.Id);
            Assert.AreSame(data.Sender, msg.Sender);
            Assert.AreEqual(id, ((NotificationRaisedMessage)msg).Notification.Notification);
            Assert.AreSame(data.EventArguments, ((NotificationRaisedMessage)msg).Notification.EventArgs);
        }
    public void PushNotification(NotificationData data, string notificationIdentifier = "")
    {
        if (data.TemplateId == "")
        {
            Debug.LogError("[ERROR] TemplateId Not Set");
            return;
        }
        if (!PrefabManager.IsContainPrefab(data.App, data.TemplateId))
        {
            Debug.LogError("[ERROR] TemplateId Not Found");
            return;
        }

        NotificationId   id = new NotificationId(data.App, notificationIdentifier);
        NotificationView notificationView;

        if (!tryGetNotificationView(id, out notificationView))
        {
            notificationView = NotificationView.CreateNotificationView(data.TemplateId, id);
        }
        loadNewTemplate(ref notificationView, data.TemplateId);
        notificationView.ResolveNotificationData(data);
        notificationView.transform.SetAsFirstSibling();
        StartCoroutine(notificationView.ShowTransition(m_lerpSpeed, m_lerpThreshold));
    }
Exemple #7
0
        /// <summary>
        /// Adds the proxy to the storage.
        /// </summary>
        /// <param name="endpoint">The endpoint from which the proxies came.</param>
        /// <param name="proxyType">The type of the proxy.</param>
        /// <param name="proxy">The proxy.</param>
        protected override void AddProxyFor(EndpointId endpoint, Type proxyType, NotificationSetProxy proxy)
        {
            if (m_RemoteNotifications.ContainsKey(endpoint))
            {
                var list = m_RemoteNotifications[endpoint];
                if (!list.ContainsKey(proxyType))
                {
                    list.Add(proxyType, proxy);
                }
            }
            else
            {
                var list = new SortedList <Type, NotificationSetProxy>(new TypeComparer())
                {
                    {
                        proxyType, proxy
                    }
                };
                m_RemoteNotifications.Add(endpoint, list);
            }

            if (!m_ProxiesByNotification.ContainsKey(endpoint))
            {
                m_ProxiesByNotification.Add(endpoint, new Dictionary <NotificationId, NotificationSetProxy>());
            }

            var collection = m_ProxiesByNotification[endpoint];
            var events     = proxyType.GetEvents();

            foreach (var eventInfo in events)
            {
                var id = NotificationId.Create(eventInfo);
                collection.Add(id, proxy);
            }
        }
Exemple #8
0
        public void FromMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new NotificationRaisedConverter(serializers.Object);

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new NotificationRaisedMessage(
                new EndpointId("a"),
                new Interaction.NotificationRaisedData(id, new EventArgs()));
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationRaisedData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationRaisedData)data).NotificationId);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().FullName,
                ((NotificationRaisedData)data).EventArgumentsType.FullName);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().Assembly.GetName().Name,
                ((NotificationRaisedData)data).EventArgumentsType.AssemblyName);
            Assert.AreSame(msg.Notification.EventArgs, ((NotificationRaisedData)data).EventArguments);
        }
        public override int GetHashCode()
        {
            int hashToId = ToId.GetHashCode();

            int hashNotificationId = NotificationId.GetHashCode();

            return(hashToId ^ hashNotificationId);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RegisterForNotificationMessage"/> class.
        /// </summary>
        /// <param name="origin">The ID of the endpoint that send the message.</param>
        /// <param name="id">The ID of the current message.</param>
        /// <param name="notificationToSubscribeTo">The notification to which the sender wants to subscribe.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="origin"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="notificationToSubscribeTo"/> is <see langword="null" />.
        /// </exception>
        public RegisterForNotificationMessage(EndpointId origin, MessageId id, NotificationId notificationToSubscribeTo)
            : base(origin, id)
        {
            {
                Lokad.Enforce.Argument(() => notificationToSubscribeTo);
            }

            Notification = notificationToSubscribeTo;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="UnregisterFromNotificationMessage"/> class.
        /// </summary>
        /// <param name="origin"> The ID of the endpoint that send the message. </param>
        /// <param name="id">The ID of the current message.</param>
        /// <param name="notificationToUnsubscribeFrom">The notification from which the sender wants to unsubscribe.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="origin"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="id"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="notificationToUnsubscribeFrom"/> is <see langword="null" />.
        /// </exception>
        public UnregisterFromNotificationMessage(EndpointId origin, MessageId id, NotificationId notificationToUnsubscribeFrom)
            : base(origin, id)
        {
            {
                Lokad.Enforce.Argument(() => notificationToUnsubscribeFrom);
            }

            Notification = notificationToUnsubscribeFrom;
        }
        /// <summary>
        /// Called when a method or property call is intercepted.
        /// </summary>
        /// <param name="invocation">Information about the call that was intercepted.</param>
        public void Intercept(IInvocation invocation)
        {
            {
                Debug.Assert(invocation.Method.Name.StartsWith(MethodPrefix, StringComparison.Ordinal), "Intercepted an incorrect method.");
                Debug.Assert(invocation.Arguments.Length == 1, "There should only be one argument.");
                Debug.Assert(invocation.Arguments[0] is Delegate, "The argument should be a delegate.");
            }

            m_Diagnostics.Log(
                LevelToLog.Trace,
                CommunicationConstants.DefaultLogTextPrefix,
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Invoking {0}",
                    MethodToText(invocation.Method)));

            var methodToInvoke = invocation.Method.Name;
            var eventName      = methodToInvoke.Substring(MethodPrefix.Length);
            var eventInfo      = m_InterfaceType.GetEvent(eventName);
            var eventId        = NotificationId.Create(eventInfo);

            var handler = invocation.Arguments[0] as Delegate;
            var proxy   = invocation.Proxy as NotificationSetProxy;

            proxy.RemoveFromEvent(eventId, handler);

            if (!proxy.HasSubscribers(eventId))
            {
                try
                {
                    m_TransmitDeregistration(eventId);
                }
                catch (EndpointNotContactableException e)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Error,
                        CommunicationConstants.DefaultLogTextPrefix,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Error while unregistering from a notification {0}. Error was: {1}",
                            MethodToText(invocation.Method),
                            e));
                }
                catch (FailedToSendMessageException e)
                {
                    m_Diagnostics.Log(
                        LevelToLog.Error,
                        CommunicationConstants.DefaultLogTextPrefix,
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "Error while unregistering from a notification {0}. Error was: {1}",
                            MethodToText(invocation.Method),
                            e));
                }
            }
        }
Exemple #13
0
 public NotificationCreated(NotificationId notificationId, int notificationType, string subject, string content,
                            string referenceId, DateTime dateSent)
 {
     NotificationId   = notificationId;
     NotificationType = notificationType;
     Subject          = subject;
     Content          = content;
     ReferenceId      = referenceId;
     DateSent         = dateSent;
 }
    public void HideNotification(Utility.App app, string notificationIdentifier)
    {
        NotificationId   id = new NotificationId(app, notificationIdentifier);
        NotificationView notificationView;

        if (tryGetNotificationView(id, out notificationView))
        {
            StartCoroutine(notificationView.HideTransition(m_lerpSpeed, m_lerpThreshold, destroyNotification, notificationView));
        }
    }
Exemple #15
0
        public void Create()
        {
            var id           = new EndpointId("sendingEndpoint");
            var notification = NotificationId.Create(
                typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new RegisterForNotificationMessage(id, notification);

            Assert.AreSame(id, msg.Sender);
            Assert.AreSame(notification, msg.Notification);
        }
        public List <string> ToNotificationDescription()
        {
            //BusinessObjects _businessObject = new BusinessObjects();
            //InventoryItem inventoryItem = _businessObject.get
            List <string> notificationDescription = new List <string>();

            notificationDescription.Add("Order ID: " + OrderId.ToString());
            notificationDescription.Add("Notification ID: " + NotificationId.ToString());
            notificationDescription.Add("Message: " + NotificationMessage.ToString());
            return(notificationDescription);
        }
        internal bool HasSubscribers(NotificationId eventId)
        {
            lock (m_Lock)
            {
                if (m_EventHandlers.ContainsKey(eventId))
                {
                    return(m_EventHandlers[eventId].Count > 0);
                }
            }

            return(false);
        }
Exemple #18
0
 /// <summary>
 /// Raises the notification with the given notification ID.
 /// </summary>
 /// <param name="endpoint">The ID of the endpoint that raised the notification.</param>
 /// <param name="id">The ID of the notification.</param>
 /// <param name="args">The event arguments for the notification.</param>
 public void RaiseNotification(EndpointId endpoint, NotificationId id, EventArgs args)
 {
     if (m_ProxiesByNotification.ContainsKey(endpoint))
     {
         var collection = m_ProxiesByNotification[endpoint];
         if (collection.ContainsKey(id))
         {
             var proxy = collection[id];
             proxy.RaiseEvent(id, args);
         }
     }
 }
Exemple #19
0
        /// <inheritdoc/>
        public Task <GetNotificationsResult> GetAsync(string userId, string?sinceUserNotificationId, int maxItems)
        {
            string?afterRowKey = null;

            if (!string.IsNullOrEmpty(sinceUserNotificationId))
            {
                var decodedId = NotificationId.FromString(sinceUserNotificationId, this.serializerSettingsProvider.Instance);

                afterRowKey = decodedId.RowKey;
            }

            return(this.GetInternalAsync(userId, null, afterRowKey, maxItems));
        }
        public void Create()
        {
            var id           = new EndpointId("sendingEndpoint");
            var notification = NotificationId.Create(
                typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var args = new MockEventArgs(1);
            var notificationRaised = new NotificationRaisedData(notification, args);
            var msg = new NotificationRaisedMessage(id, notificationRaised);

            Assert.AreSame(id, msg.Sender);
            Assert.AreSame(notification, msg.Notification.Notification);
            Assert.AreSame(args, msg.Notification.EventArgs);
        }
        public void ProxyDisconnectFromEventWithNormalEventHandler()
        {
            var local = new EndpointId("local");
            UnregisterFromNotificationMessage intermediateMsg = null;
            SendMessage messageSender = (e, m, r) =>
            {
                intermediateMsg = m as UnregisterFromNotificationMessage;
            };

            var systemDiagnostics = new SystemDiagnostics((p, s) => { }, null);
            var builder           = new NotificationProxyBuilder(local, messageSender, systemDiagnostics);

            var remoteEndpoint = new EndpointId("other");
            var proxy          = builder.ProxyConnectingTo <InteractionExtensionsTest.IMockNotificationSetWithEventHandler>(remoteEndpoint);

            object    sender       = null;
            EventArgs receivedArgs = null;

            EventHandler handler =
                (s, e) =>
            {
                sender       = s;
                receivedArgs = e;
            };

            proxy.OnMyEvent += handler;

            Assert.IsNull(intermediateMsg);

            var notificationObj = proxy as NotificationSetProxy;

            Assert.IsNotNull(notificationObj);

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithEventHandler).GetEvent("OnMyEvent"));
            var args = new EventArgs();

            notificationObj.RaiseEvent(id, args);

            Assert.AreSame(proxy, sender);
            Assert.AreSame(args, receivedArgs);

            sender           = null;
            receivedArgs     = null;
            proxy.OnMyEvent -= handler;

            Assert.AreEqual(id, intermediateMsg.Notification);

            notificationObj.RaiseEvent(id, new EventArgs());
            Assert.IsNull(sender);
            Assert.IsNull(receivedArgs);
        }
 public bool tryGetNotificationView(NotificationId id, out NotificationView view)
 {
     view = null;
     NotificationView[] viewList = NotificationContainer.GetComponentsInChildren <NotificationView>();
     for (int i = 0; i < viewList.Length; i++)
     {
         if (viewList[i].Id == id)
         {
             view = viewList[i];
             return(true);
         }
     }
     return(false);
 }
        public bool Equals(Notification other)
        {
            if (Object.ReferenceEquals(other, null))
            {
                return(false);
            }

            if (Object.ReferenceEquals(this, other))
            {
                return(true);
            }

            return(NotificationId.Equals(other.NotificationId) && ToId.Equals(other.ToId));
        }
Exemple #24
0
        public void FromMessage()
        {
            var translator = new NotificationUnregistrationConverter();

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new UnregisterFromNotificationMessage(new EndpointId("a"), id);

            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationUnregistrationData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationUnregistrationData)data).NotificationId);
        }
        private void SaveCommonProperties(Dictionary <string, string> properties)
        {
            properties[NotificationPropertyKeys.Common.NOTIFICATION_TYPE] = NotificationType;
            properties[NotificationPropertyKeys.Common.NOTIFICATION_ID]   = NotificationId.ToString();

            if (m_recipient != null)
            {
                properties[NotificationPropertyKeys.Common.RECIPIENT] = m_recipient;
            }

            if (m_deliveryCount != 0)
            {
                properties[NotificationPropertyKeys.Common.DELIVERY_COUNT] = m_deliveryCount.ToInvariantString();
            }
        }
        public INotification SendTo(INotificationListener listener)
        {
            Require.NotNull(listener, "listener");

            if (IsAddressed && IsAddressedTo(listener))
            {
                return(this);
            }

            return(CopyAndUpdate(properties =>
            {
                properties[NotificationPropertyKeys.Common.NOTIFICATION_ID] = NotificationId.Create().ToString();
                properties[NotificationPropertyKeys.Common.RECIPIENT] = listener.GetType().FullName;
            }));
        }
        /// <summary>
        /// Adds the given event handler to the collection of handlers for the given event.
        /// </summary>
        /// <param name="eventId">The ID of the event.</param>
        /// <param name="handler">The event handler.</param>
        internal void AddToEvent(NotificationId eventId, Delegate handler)
        {
            lock (m_Lock)
            {
                if (!m_EventHandlers.ContainsKey(eventId))
                {
                    m_EventHandlers.Add(eventId, new List <Delegate>());
                }

                var delegates = m_EventHandlers[eventId];
                if (!delegates.Contains(handler))
                {
                    delegates.Add(handler);
                }
            }
        }
 /// <summary>
 /// Removes the given event handler from the collection of handlers for the given event.
 /// </summary>
 /// <param name="eventId">The ID of the event.</param>
 /// <param name="handler">The event handler.</param>
 internal void RemoveFromEvent(NotificationId eventId, Delegate handler)
 {
     lock (m_Lock)
     {
         if (m_EventHandlers.ContainsKey(eventId))
         {
             var delegates = m_EventHandlers[eventId];
             if (delegates.Remove(handler))
             {
                 if (delegates.Count == 0)
                 {
                     m_EventHandlers.Remove(eventId);
                 }
             }
         }
     }
 }
        public override int GetHashCode()
        {
            int hash = 1;

            if (NotificationId != 0)
            {
                hash ^= NotificationId.GetHashCode();
            }
            if (Category.Length != 0)
            {
                hash ^= Category.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        /// <summary>
        /// Raises the event given by the <paramref name="eventId"/> parameter.
        /// </summary>
        /// <param name="eventId">The ID of the event that should be raised.</param>
        /// <param name="args">The event arguments with which the event should be raised.</param>
        internal void RaiseEvent(NotificationId eventId, EventArgs args)
        {
            var obj       = SelfReference();
            var delegates = new List <Delegate>();

            lock (m_Lock)
            {
                if (m_EventHandlers.ContainsKey(eventId))
                {
                    delegates.AddRange(m_EventHandlers[eventId]);
                }
            }

            foreach (var del in delegates)
            {
                del.DynamicInvoke(new[] { obj, args });
            }
        }
        /// <summary>
        /// Remove and delete a monitoring notification by ID.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="notificationId">The notification ID. This is obtained from <see cref="Notification.Id">Notification.Id</see>.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="notificationId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-notifications.html#service-notifications-delete">Delete Notification (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static void RemoveNotification(this IMonitoringService service, NotificationId notificationId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                service.RemoveNotificationAsync(notificationId, CancellationToken.None).Wait();
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Gets a collection of monitoring notifications.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-notifications.html#service-notifications-list">List Notifications (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<Notification, NotificationId> ListNotifications(this IMonitoringService service, NotificationId marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListNotificationsAsync(marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
        /// <summary>
        /// Test an existing notification by ID.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="notificationId">The notification ID. This is obtained from <see cref="Notification.Id">Notification.Id</see>.</param>
        /// <returns>A <see cref="NotificationData"/> object describing the test results.</returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">If <paramref name="notificationId"/> is <see langword="null"/>.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-notifications.html#service-notifications-test-existing">Test Existing Notification (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static NotificationData TestExistingNotification(this IMonitoringService service, NotificationId notificationId)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.TestExistingNotificationAsync(notificationId, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }