示例#1
0
        public WebServiceClientRequest CreateRequest(RequestVerb verb, string relativeUri, IKeyValueStore <object> queryParameters = null)
        {
            var innerRequest = WebRequest.CreateHttp(CreateRequestUri(verb, relativeUri, queryParameters));

            innerRequest.Method      = verb.ToString().ToUpper();
            innerRequest.Accept      = CommunicationStrategy.ContentType;
            innerRequest.ContentType = $"{CommunicationStrategy.ContentType}; charset={(mConfiguration.Encoding ?? Encoding.UTF8).WebName}";

            var request = new WebServiceClientRequest(mConfiguration, CommunicationStrategy, innerRequest);

            return(request);
        }
示例#2
0
        public static AstoriaRequest BuildRandomRequest(Workspace workspace, RequestVerb verb, SerializationFormatKind format)
        {
            IEnumerable <ResourceContainer> safeContainers =
                workspace.ServiceContainer.ResourceContainers
                .Where(c => IsSafeOperation(verb, c));

            if (verb != RequestVerb.Get)
            {
                safeContainers = safeContainers.Where(c => c.ResourceTypes.Any(t => IsSafeOperation(verb, c, t)));
            }

            fxList <ResourceContainer> containers = new fxList <ResourceContainer>(safeContainers);

            if (!containers.Any())
            {
                return(null);
            }

            AstoriaRequest request = null;

            while (request == null && containers.Any())
            {
                ResourceContainer container = null;
                ResourceType      type      = null;
                KeyExpression     key       = null;

                while (container == null && containers.Any())
                {
                    container = containers.Choose();

                    if (verb == RequestVerb.Get)
                    {
                        key = workspace.GetRandomExistingKey(container);
                        if (key == null)
                        {
                            containers.Remove(container);
                            container = null;
                        }
                    }
                    else
                    {
                        fxList <ResourceType> types = new fxList <ResourceType>(container.ResourceTypes.Where(t => IsSafeOperation(verb, container, t)));

                        if (!types.Any())
                        {
                            containers.Remove(container);
                            container = null;
                        }

                        if (verb != RequestVerb.Delete)
                        {
                            type = types.Choose();
                        }
                        else
                        {
                            while (key == null && types.Any())
                            {
                                type = types.Choose();
                                key  = workspace.GetRandomExistingKey(container, type);
                                if (key == null)
                                {
                                    types.Remove(type);
                                }
                            }

                            if (key == null)
                            {
                                containers.Remove(container);
                                container = null;
                            }
                        }
                    }
                }

                // if we ran out of containers before finding one that would work
                //
                if (container == null)
                {
                    return(null);
                }

                // if the Build___ method returns null, we'll come back around with a different container/key
                //
                switch (verb)
                {
                case RequestVerb.Get:
                    request = BuildGet(workspace, key, HttpStatusCode.OK, format);
                    break;

                case RequestVerb.Post:
                    request = BuildInsert(workspace, container, type, HttpStatusCode.Created, format);
                    break;

                case RequestVerb.Put:
                case RequestVerb.Patch:
                    request = BuildUpdate(workspace, container, type, (verb == RequestVerb.Put), HttpStatusCode.NoContent, format);
                    break;

                case RequestVerb.Delete:
                    request = BuildDelete(workspace, key, HttpStatusCode.NoContent, format);
                    break;

                default:
                    throw new ArgumentException("Unsupported verb: " + verb.ToString());
                }
            }

            // might be null, but we did our best
            //
            return(request);
        }
示例#3
0
        public static AstoriaRequest BuildRandomRequest(Workspace workspace, RequestVerb verb, SerializationFormatKind format)
        {
            IEnumerable<ResourceContainer> safeContainers =
                workspace.ServiceContainer.ResourceContainers
                    .Where(c => IsSafeOperation(verb, c));

            if (verb != RequestVerb.Get)
                safeContainers = safeContainers.Where(c => c.ResourceTypes.Any(t => IsSafeOperation(verb, c, t)));

            fxList<ResourceContainer> containers = new fxList<ResourceContainer>(safeContainers);
            if (!containers.Any())
                return null;

            AstoriaRequest request = null;

            while (request == null && containers.Any())
            {
                ResourceContainer container = null;
                ResourceType type = null;
                KeyExpression key = null;

                while (container == null && containers.Any())
                {
                    container = containers.Choose();

                    if (verb == RequestVerb.Get)
                    {
                        key = workspace.GetRandomExistingKey(container);
                        if (key == null)
                        {
                            containers.Remove(container);
                            container = null;
                        }
                    }
                    else
                    {
                        fxList<ResourceType> types = new fxList<ResourceType>(container.ResourceTypes.Where(t => IsSafeOperation(verb, container, t)));

                        if (!types.Any())
                        {
                            containers.Remove(container);
                            container = null;
                        }

                        if (verb != RequestVerb.Delete)
                            type = types.Choose();
                        else
                        {
                            while (key == null && types.Any())
                            {
                                type = types.Choose();
                                key = workspace.GetRandomExistingKey(container, type);
                                if (key == null)
                                    types.Remove(type);
                            }

                            if (key == null)
                            {
                                containers.Remove(container);
                                container = null;
                            }
                        }
                    }
                }

                // if we ran out of containers before finding one that would work
                //
                if (container == null)
                    return null;

                // if the Build___ method returns null, we'll come back around with a different container/key
                //
                switch (verb)
                {
                    case RequestVerb.Get:
                        request = BuildGet(workspace, key, HttpStatusCode.OK, format);
                        break;

                    case RequestVerb.Post:
                        request = BuildInsert(workspace, container, type, HttpStatusCode.Created, format);
                        break;

                    case RequestVerb.Put:
                    case RequestVerb.Patch:
                        request = BuildUpdate(workspace, container, type, (verb == RequestVerb.Put), HttpStatusCode.NoContent, format);
                        break;

                    case RequestVerb.Delete:
                        request = BuildDelete(workspace, key, HttpStatusCode.NoContent, format);
                        break;

                    default:
                        throw new ArgumentException("Unsupported verb: " + verb.ToString());
                }
            }

            // might be null, but we did our best
            //
            return request;
        }
示例#4
0
 public static string ToHttpMethod(this RequestVerb verb)
 {
     return(verb.ToString().ToUpperInvariant());
 }
示例#5
0
 internal string GetVerb() => mVerb.ToString().ToUpperInvariant();