Beispiel #1
0
        /// <summary>
        /// Gets all speakers
        /// </summary>
        /// <returns>All speakers</returns>
        public async Task <List <Speaker> > GetAllSpeakersAsync()
        {
            try {
                HttpResponseMessage response = await HttpMessageHelper.RequestApiAsync(client, HttpMethod.Get, "getall-speaker", new Dictionary <string, object>());

                List <Speaker> speakers = await HttpMessageHelper.DeserializeResponse <List <Speaker> >(response);

                return(speakers);
            } catch (MobileServiceInvalidOperationException ex) {
                throw new ServerAccessException(ex.Response.StatusCode);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new speaker
        /// </summary>
        /// <param name="name">The name of the speaker</param>
        /// <param name="enrollmentAudio">The audio used to identify the speaker</param>
        /// <returns>The created speaker</returns>
        public async Task <Speaker> CreateSpeakerAsync(string name, Stream enrollmentAudio)
        {
            try {
                HttpResponseMessage response = await HttpMessageHelper.RequestApiAsync(client, HttpMethod.Post, "create-speaker", new Dictionary <string, object>()
                {
                    { "name", name }
                }, new StreamContent(enrollmentAudio));

                Speaker speaker = await HttpMessageHelper.DeserializeResponse <Speaker>(response);

                return(speaker);
            } catch (MobileServiceInvalidOperationException ex) {
                throw new ServerAccessException(ex.Response.StatusCode);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new protocol
        /// </summary>
        /// <param name="audio">The audio of the protocol</param>
        /// <param name="protocol">The protocol information</param>
        /// <returns>The created protocol (without the sections, which are started to be created after the server responded with this protocol)</returns>
        public async Task <Protocol> CreateProtocolAsync(Stream audio, Protocol protocol)
        {
            try {
                HttpResponseMessage response = await HttpMessageHelper.RequestApiAsync(client, HttpMethod.Post, "create-protocol", new Dictionary <string, object>()
                {
                    { "protocol", protocol },
                    { "language", LANGUAGE }
                }, new StreamContent(audio));

                Protocol protocolResponse = await HttpMessageHelper.DeserializeResponse <Protocol>(response);

                return(protocolResponse);
            } catch (MobileServiceInvalidOperationException ex) {
                throw new ServerAccessException(ex.Response.StatusCode);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the protocol status of the protocol with the given id
        /// </summary>
        /// <param name="id">The id of the protocol</param>
        /// <returns>The protocol status</returns>
        public async Task <ProtocolStatus> GetProtocolStatusAsync(string id)
        {
            try {
                HttpResponseMessage response = await HttpMessageHelper.RequestApiAsync(client, HttpMethod.Get, "get-protocol-status", new Dictionary <string, object>()
                {
                    { "id", id }
                });

                ProtocolStatus protocolStatus = await HttpMessageHelper.DeserializeResponse <ProtocolStatus>(response);

                return(protocolStatus);
            } catch (MobileServiceInvalidOperationException ex) {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new ServerRessourceNotFoundException(nameof(GetProtocolStatusAsync), id);
                }
                else
                {
                    throw new ServerAccessException(ex.Response.StatusCode);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Updates the speaker
        /// </summary>
        /// <param name="speaker">The speaker to update</param>
        /// <param name="enrollmentAudio">The new audio used to identify the speaker (can be null indicating that the audio should not be updated)</param>
        /// <returns>The updated speaker</returns>
        public async Task <Speaker> UpdateSpeakerAsync(Speaker speaker, Stream enrollmentAudio = null)
        {
            try {
                HttpResponseMessage response = await HttpMessageHelper.RequestApiAsync(client, HttpMethod.Put, "update-speaker", new Dictionary <string, object>()
                {
                    { "speaker", speaker },
                    { "language", LANGUAGE }
                }, new StreamContent(enrollmentAudio));

                Speaker speakerResponse = await HttpMessageHelper.DeserializeResponse <Speaker>(response);

                return(speakerResponse);
            } catch (MobileServiceInvalidOperationException ex) {
                if (ex.Response.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new ServerRessourceNotFoundException(nameof(UpdateSpeakerAsync), speaker.Id);
                }
                else
                {
                    throw new ServerAccessException(ex.Response.StatusCode);
                }
            }
        }