コード例 #1
0
        internal TU BaseRequest <TU>(HttpMethod method, object request, CallfireRestRoute <T> route)
        {
            var response = string.Empty;

            try
            {
                if (request != null && request.GetType() == typeof(CreateSound) && ((CreateSound)request).Item.GetType() == typeof(byte[]))
                {
                    CreateSound soundRequest = (CreateSound)request;
                    soundRequest.Name = string.IsNullOrEmpty(soundRequest.Name)
                        ? "unknown_name_" + DateTime.UtcNow.ToString("yyyy_MM_dd_HH_mm_ss")
                        : soundRequest.Name;
                    response = XmlClient.Send(route.ToString(), request,
                                              new MemoryStream((byte[])soundRequest.Item),
                                              string.Format("audio/{0}", _soundFormat.ToString().ToLower()));
                }
                else
                {
                    response = XmlClient.Send(route.ToString(), method, request);
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError &&
                    HttpStatusCode.InternalServerError == ((HttpWebResponse)ex.Response).StatusCode)
                {
                    var exceptionDeserializer = new XmlSerializer(typeof(ResourceException));
                    if (!string.IsNullOrEmpty(response))
                    {
                        TextReader exceptionReader = new StringReader(response);
                        ex.Data.Add("Exception", exceptionDeserializer.Deserialize(exceptionReader));
                    }
                }
                throw;
            }

            if (string.IsNullOrEmpty(response))
            {
                return(default(TU));
            }

            var        deserializer = new XmlSerializer(typeof(TU));
            TextReader reader       = new StringReader(response);

            return((TU)deserializer.Deserialize(reader));
        }
コード例 #2
0
 public void CallfireRestRoute_tostring_tests(CallfireRestRoute <Broadcast> route, string expected)
 {
     Assert.IsTrue(
         string.Equals(expected, route.ToString(), StringComparison.InvariantCultureIgnoreCase));
 }
コード例 #3
0
 internal TU BaseRequest <TU>(HttpMethod method, object request, CallfireRestRoute <T> route, CfSoundFormat cfSoundFormat)
 {
     _soundFormat = cfSoundFormat;
     return(BaseRequest <TU>(method, request, route));
 }
コード例 #4
0
 public void CallfireRestRoute_tostring_tests(CallfireRestRoute<Broadcast> route, string expected)
 {
     Assert.IsTrue(
         string.Equals(expected, route.ToString(), StringComparison.InvariantCultureIgnoreCase));
 }