4 using Hammock.Extensions;
8 using Hammock.Silverlight.Compat;
16 public class RestRequest : RestBase
18 private object _entity;
19 private object _expectEntity;
21 protected internal virtual Web.WebHeaderCollection ExpectHeaders { get; set; }
22 public virtual HttpStatusCode? ExpectStatusCode { get; set; }
23 public virtual string ExpectStatusDescription { get; set; }
24 public virtual string ExpectContent { get; set; }
25 public virtual string ExpectContentType { get; set; }
32 private void Initialize()
34 ExpectHeaders = new Web.WebHeaderCollection();
37 public virtual object Entity
45 if (_entity != null && _entity.Equals(value))
51 OnPropertyChanged("Entity");
53 // [DC] Automatically posts an entity unless put is declared
54 RequestEntityType = _entity.GetType();
55 if (_entity != null && (Method != WebMethod.Post && Method != WebMethod.Put))
57 Method = WebMethod.Post;
62 public virtual object ExpectEntity
70 if (_expectEntity != null && _expectEntity.Equals(value))
75 _expectEntity = value;
76 OnPropertyChanged("ExpectEntity");
80 public virtual Type ResponseEntityType { get; set; }
81 public virtual Type RequestEntityType { get; set; }
83 public Uri BuildEndpoint(RestClient client)
85 var sb = new StringBuilder();
87 var path = Path.IsNullOrBlank()
88 ? client.Path.IsNullOrBlank() ? "" : client.Path
91 var versionPath = VersionPath.IsNullOrBlank()
92 ? client.VersionPath.IsNullOrBlank() ? "" : client.VersionPath
94 var skipAuthority = client.Authority.IsNullOrBlank();
96 sb.Append(skipAuthority ? "" : client.Authority);
97 sb.Append(skipAuthority ? "" : client.Authority.EndsWith("/") ? "" : "/");
98 sb.Append(skipAuthority ? "" : versionPath.IsNullOrBlank() ? "" : versionPath);
99 if (!skipAuthority && !versionPath.IsNullOrBlank())
101 sb.Append(versionPath.EndsWith("/") ? "" : "/");
103 sb.Append(path.IsNullOrBlank() ? "" : path.StartsWith("/") ? path.Substring(1) : path);
106 Uri.TryCreate(sb.ToString(), UriKind.RelativeOrAbsolute, out uri);
108 var queryStringHandling = QueryHandling ?? client.QueryHandling ?? Hammock.QueryHandling.None;
110 switch (queryStringHandling)
112 case Hammock.QueryHandling.AppendToParameters:
113 WebParameterCollection parameters;
114 uri = uri.UriMinusQuery(out parameters);
115 foreach (var parameter in parameters)
117 Parameters.Add(parameter);
127 public void ExpectHeader(string name, string value)
129 ExpectHeaders.Add(name, value);