Esempio n. 1
0
        private Uri BuildServiceUri(Resource resource, RestActions action, int? id,
            Dictionary<string, string> queryParameters)
        {
            string relativeUri;

              switch (action)
              {
            case RestActions.Index:
              relativeUri = resource.IndexUrl();
              break;
            case RestActions.Show:
              relativeUri = resource.ShowUrl(id);
              break;
            case RestActions.New:
              relativeUri = resource.NewUrl();
              break;
            case RestActions.Create:
              relativeUri = resource.CreateUrl();
              break;
            case RestActions.Edit:
              relativeUri = resource.EditUrl(id);
              break;
            case RestActions.Update:
              relativeUri = resource.UpdateUrl(id);
              break;
            case RestActions.Delete:
              relativeUri = resource.DeleteUrl(id);
              break;
            default:
              relativeUri = resource.IndexUrl();
              break;
              }

              var uriBuilder = new UriBuilder(uri.Scheme, uri.Host, uri.Port,
                                      AddQueryParametersTo(relativeUri + ".xml", queryParameters));
              if (UserName.Length != 0)
              {
            uriBuilder.UserName = UserName;
              }
              if (Password.Length != 0)
              {
            uriBuilder.Password = Password;
              }
              return uriBuilder.Uri;
        }