Ejemplo n.º 1
0
        /// <summary>
        /// Signup the device to the subscription.
        /// </summary>
        /// <param name="deviceId">The device id of the device being added.</param>
        /// <param name="subscription">Name of the subscription being signed up.</param>
        /// <returns>Returns success if the signup is successful. Error otherwise.</returns>
        public PushMessageError AddSubscription(string deviceId, string subscription)
        {
            PushMessageError err = this.Validate(deviceId, subscription);

            if (err != PushMessageError.Success)
            {
                return(err);
            }

            SubscriptionDataModel sdm = this.sds.SelectByDeviceIdAndSubscription(deviceId, subscription);

            if (sdm == null)
            {
                sdm = new SubscriptionDataModel(subscription, deviceId);
                this.sds.Insert(sdm);
            }

            return(PushMessageError.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete the device signup.
        /// </summary>
        /// <param name="deviceId">Device id of the device to be deleted.</param>
        /// <param name="subscription">Subscription name.</param>
        /// <returns>Returns success if deletion is successful or error otherwise.</returns>
        public PushMessageError DeleteSubscription(string deviceId, string subscription)
        {
            PushMessageError err = this.Validate(deviceId, subscription);

            if (err != PushMessageError.Success)
            {
                return(err);
            }

            SubscriptionDataModel sdm = this.sds.SelectByDeviceIdAndSubscription(deviceId, subscription);

            if (sdm != null)
            {
                // Delete it from the d/b
                this.sds.Delete(sdm);
                return(PushMessageError.Success);
            }

            return(PushMessageError.ErrorDeviceNotRegisteredForSubscription);
        }
        /// <summary>
        /// Returns the error string for a given eror.
        /// </summary>
        /// <param name="err">For the PushMessageError err.</param>
        /// <returns>Returns a string representation of the error.</returns>
        public static string GetErrorString(PushMessageError err)
        {
            switch (err)
            {
            case PushMessageError.Success:
                return("success");

            case PushMessageError.ErrorDeviceAlreadyRegistered:
                return("Device already registered.");

            case PushMessageError.ErrorDeviceNotFound:
                return("Device not found.");

            case PushMessageError.ErrorIllegalDeviceId:
                return("Device ID syntax incorrect.");

            case PushMessageError.ErrorInternalError:
                return("Internal error.");

            case PushMessageError.ErrorSubscriptionNameAlreadyRegistered:
                return("Subscription name already registered.");

            case PushMessageError.ErrorSubscriptionNameNotFound:
                return("Subscription Name not found.");

            case PushMessageError.ErrorDeviceNotRegisteredForSubscription:
                return("Device not registed for service.");

            case PushMessageError.ErrorIllegalCount:
                return("Count value incorrect.");

            case PushMessageError.ErrorIllegalDeviceType:
                return("Device type not recognized.");

            case PushMessageError.ErrorIllegalUri:
                return("URI syntax incorrect.");
            }

            return("Success");
        }
        /// <summary>
        /// Returns the error string for a given eror. 
        /// </summary>
        /// <param name="err">For the PushMessageError err.</param>
        /// <returns>Returns a string representation of the error.</returns>
        public static string GetErrorString(PushMessageError err)
        {
            switch (err)
            {
                case PushMessageError.Success:
                    return "success";
                case PushMessageError.ErrorDeviceAlreadyRegistered:
                    return "Device already registered.";
                case PushMessageError.ErrorDeviceNotFound:
                    return "Device not found.";
                case PushMessageError.ErrorIllegalDeviceId:
                    return "Device ID syntax incorrect.";
                case PushMessageError.ErrorInternalError:
                    return "Internal error.";
                case PushMessageError.ErrorSubscriptionNameAlreadyRegistered:
                    return "Subscription name already registered.";
                case PushMessageError.ErrorSubscriptionNameNotFound:
                    return "Subscription Name not found.";
                case PushMessageError.ErrorDeviceNotRegisteredForSubscription:
                    return "Device not registed for service.";
                case PushMessageError.ErrorIllegalCount:
                    return "Count value incorrect.";
                case PushMessageError.ErrorIllegalDeviceType:
                    return "Device type not recognized.";
                case PushMessageError.ErrorIllegalUri:
                    return "URI syntax incorrect.";
            }

            return "Success";
        }