public void AddResource(Response response, ResourceBody resourceBody) { foreach (IResponseModifier modifier in _modifiers) { modifier.AddResource(response, resourceBody); } }
public void AddResource(Response response, ResourceBody resourceBody) { if (resourceBody is IPagedResourceBody pagedResource) { response.ExtraBody["Page"] = pagedResource.PageLinks; } }
public void AddResource(Response response, ResourceBody resourceBody) { if (WrapResourceObject) { response.ExtraBody[StatusKey] = "ok"; } }
public IHttpActionResult SendResources([FromBody] ResourceBody model) { Console.WriteLine(model); var c = RestClient.Instance; c.SendResources(model); return(Ok(model)); }
private async Task <ResourceBody> ExecuteGetAsync(IRequestReader reader, ResponseBuilder response) { ResourceBody resourceBody = await Endpoint.GetAsync(reader.GetQuery()); response.AddResource(resourceBody); return(resourceBody); }
public async Task FieldEndpoint() { IRestEndpoint endpoint = _navigator.GetEndpointFromPath("artists/123/Name"); ResourceBody response = await endpoint.GetAsync(null); Assert.Equal(response.GetObject(), TestRepositories.ArtistName); }
public void AddResource(Response response, ResourceBody resourceBody) { object obj = resourceBody.GetObject(); response.ResourceBody = obj; response.StatusCode = obj != null ? HttpStatusCode.OK : HttpStatusCode.NoContent; // TODO: take move NoContent because there may be content added later in ExtraBody }
public void SendResources(ResourceBody model) { var request = new RestSharp.RestRequest(buildUrl, Method.POST); request.AddParameter("ft", "check"); // adds to POST or URL querystring based on Method request.AddParameter("id", model.id); // adds to POST or URL querystring based on Method request.AddParameter("r1", model.r1); // adds to POST or URL querystring based on Method request.AddParameter("r2", model.r2); // adds to POST or URL querystring based on Method request.AddParameter("r3", model.r3); // adds to POST or URL querystring based on Method request.AddParameter("r4", model.r4); // adds to POST or URL querystring based on Method request.AddParameter("x", model.x); // adds to POST or URL querystring based on Method request.AddParameter("y", model.y); // adds to POST or URL querystring based on Method request.AddParameter("send3", "1"); // adds to POST or URL querystring based on Method request.AddParameter("s1", "ok"); // adds to POST or URL querystring based on Method var user = User.Instance; var xxx = GetVillagePage(model.villageid); user.messages.Add("Wysyłam surowce"); IRestResponse response = client.Execute(request); if (response.IsSuccessful) { var content = response.Content; // raw content as string var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); var node = doc.DocumentNode.SelectSingleNode("//*[@id=\"build\"]/form/input[4]"); if (node != null) { var request2 = new RestSharp.RestRequest(buildUrl, Method.POST); request2.AddParameter("ft", "mk1"); // adds to POST or URL querystring based on Method request2.AddParameter("id", model.id); // adds to POST or URL querystring based on Method request2.AddParameter("r1", model.r1); // adds to POST or URL querystring based on Method request2.AddParameter("r2", model.r2); // adds to POST or URL querystring based on Method request2.AddParameter("r3", model.r3); // adds to POST or URL querystring based on Method request2.AddParameter("r4", model.r4); // adds to POST or URL querystring based on Method request2.AddParameter("x", model.x); // adds to POST or URL querystring based on Method request2.AddParameter("y", model.y); // adds to POST or URL querystring based on Method request2.AddParameter("send3", "1"); // adds to POST or URL querystring based on Method request2.AddParameter("s1", "ok"); // adds to POST or URL querystring based on Method request2.AddParameter("getwref", node.Attributes[2].Value); // adds to POST or URL querystring based on Method user.messages.Add("Wysyłam surowce.."); IRestResponse response2 = client.Execute(request2); if (response.IsSuccessful) { user.messages.Add("Wysyłano surowce"); content = response.Content; // raw content as string doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(content); GetVillagePage(); } } } }
private async Task <Feedback> ExecuteModifyAsync(IRequestReader reader, ResponseBuilder response) { var method = (UnsafeMethod)Enum.Parse(typeof(UnsafeMethod), reader.RequestMethod, true); ResourceBody requestBody = reader.GetRequestBody(); Feedback feedback = await Endpoint.CommandAsync(method, requestBody); response.AddFeedback(feedback); return(feedback); }
public void AddResource(Response response, ResourceBody resourceBody) { if (resourceBody is IPagedResourceBody pagedResourceBody) { var urlCalculator = new UrlCalculator(response.ResourcePath); var setter = new LinkHeaderBuilder(urlCalculator); setter.AddDetails(pagedResourceBody.PageLinks); setter.SetHeaders(response); } }
public bool WillAccept(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) return false; if (b.Type == ResourceType.Food) return FoodInBank < FoodLimit; if (b.Type == ResourceType.Wood) return true; return false; }
public async Task <object> GetAsync() { IRestEndpoint endpoint = GetEndpoint(); if (!endpoint.EvaluatePreconditions(GetPreconditions())) { return(StatusCode(HttpStatusCode.NotModified)); } ResourceBody resourceBody = await endpoint.GetAsync(GetQuery()); ResponseBuilder.AddResource(resourceBody); return(Response.ResourceBody); // TODO headers? }
internal async Task <string> CreateResource(SnapSession session) { string answer = string.Empty; try { log.Info($"Token = {this.token}"); ResourceBody body = new ResourceBody(); body.ResourceName = session.DbName; body.ResourceType = "Database"; body.HostName = session.HostName; body.RunAsNames = $"{session.DbName}_{session.Plugin}"; body.MountPaths = new System.Collections.Generic.List <MountInfo>(); MountInfo mi = new MountInfo(); mi.MountPath = session.MountPath; body.MountPaths.Add(mi); VolumeMapping vm = new VolumeMapping(); VolumeName vname = new VolumeName(); vname.Name = session.VolumeName; vm.VolumeName = vname; FootPrintObject fp = new FootPrintObject(); fp.SVMName = session.SvmName; fp.VolAndLunsMapping = new System.Collections.Generic.List <VolumeMapping>(); fp.VolAndLunsMapping.Add(vm); body.FootPrint = new System.Collections.Generic.List <FootPrintObject>(); body.FootPrint.Add(fp); PluginParams pluginParams = new PluginParams(); pluginParams.Data = new System.Collections.Generic.List <PluginData>(); PluginData ms = new PluginData(); ms.Key = "MASTER_SLAVE"; ms.Value = "N"; pluginParams.Data.Add(ms); body.PluginParams = pluginParams; var response = await this.SendRequestAsync <dynamic>(Method.POST, $"api/3.0/plugins/MySQL/resources", body, false); log.Info($"Payload: {response.Payload}"); string dbKey = string.Empty; answer = response.Response.Content.ToString(); } catch (Exception ex) { this.log.Error($"Error while getting creating resource key: {ex}"); } return(answer); }
public bool WillAccept(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) { return(false); } if (b.Type == ResourceType.Food) { return(FoodInBank < FoodLimit); } if (b.Type == ResourceType.Wood) { return(true); } return(false); }
public void MagazinePush(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) return; if (b.Type == ResourceType.Food) FoodInBank++; if (b.Type == ResourceType.Wood) { WoodInBank++; if (WoodInBank == WoodLimit) { WoodInBank = 0; LevelUp(); } } b.OnDeath(); }
private async Task <object> ExecuteWithRequeryAsync(IRequestReader reader, ResponseBuilder response) { object returnValue = await _executor.ExecuteAsync(reader, response); IRestEndpoint endpoint = _executor.Endpoint; if (returnValue is AcknowledgmentFeedback ackFeedback && ackFeedback.Acknowledgment is CreatedItemAcknowledgment created) { endpoint = endpoint.Next(new RawNextPath(created.NewIdentifier.ToString())); Debug.Assert(endpoint != null); } ResourceBody resourceBody = await endpoint.GetAsync(reader.GetQuery()); response.AddResource(resourceBody); return(returnValue); }
public void MagazinePush(EntityBody target) { ResourceBody b = target as ResourceBody; if (b == null) { throw new Exception("wat"); } if (b.Type == ResourceType.Food) { FoodInBank++; } if (b.Type == ResourceType.Wood) { WoodInBank++; if (WoodInBank == WoodLimit) { WoodInBank = 0; LevelUp(); } } b.OnDeath(); }
public async Task <Feedback> ExecuteAsync(IRestScalar scalar, IEndpointContext context, ResourceBody body) { Acknowledgment acknowledgment = await scalar.EditAsync(null); return(new AcknowledgmentFeedback(acknowledgment)); }
public async Task <Feedback> ExecuteAsync(IRestItem item, IEndpointContext context, ResourceBody body) { var itemBody = body as ItemBody; if (itemBody == null) { throw new ItemBodyNotSupportedException(body.ResourceType); } Acknowledgment acknowledgment = await item.EditAsync(itemBody.Item); return(new AcknowledgmentFeedback(acknowledgment)); }
private async Task <IHttpActionResult> GetResultFromMethodFeedbackAsync(UnsafeMethod method, ResourceBody body) { IRestEndpoint endpoint = GetEndpoint(); if (!endpoint.EvaluatePreconditions(GetPreconditions())) { return(StatusCode(HttpStatusCode.PreconditionFailed)); } Feedback feedback = await endpoint.CommandAsync(method, body); return(GetResultFromFeedback(feedback)); }
public async Task <IHttpActionResult> PatchAsync([FromBody] ResourceBody body) { return(await GetResultFromMethodFeedbackAsync(UnsafeMethod.Patch, body)); }
public Task <Feedback> CommandAsync(UnsafeMethod method, ResourceBody body) { ICommandStrategy <IRestCollection> strategy = Context.Services.Strategies.ForCollections.GetOrThrow(method); return(strategy.ExecuteAsync(Collection, Context, body)); }
public Task <Feedback> CommandAsync(UnsafeMethod method, ResourceBody body) { throw new NotImplementedException("Not implemented unsafe strategies on dictionaries yet."); // TODO could implement PUTs with multi updates ? }
public Resource(ResourceHeader Header = default, ResourceBody Body = default) { this.Header = Header; this.Body = Body; }
public void AddResource(ResourceBody resourceBody) { _modifier.AddResource(_response, resourceBody); }
public async Task <Feedback> ExecuteAsync(IRestCollection collection, IEndpointContext context, ResourceBody body) { var ack = await collection.DeleteAllAsync(null); // TODO query return(new AcknowledgmentFeedback(ack)); }
public async Task <Feedback> ExecuteAsync(IRestItem item, IEndpointContext context, ResourceBody body) { Acknowledgment acknowledgment = await item.DeleteAsync(); return(new AcknowledgmentFeedback(acknowledgment)); }
public async Task <Feedback> ExecuteAsync(IRestCollection collection, IEndpointContext context, ResourceBody body) { var collectionBody = body as CollectionBody; if (collectionBody != null) { var feedbackItems = new List <Feedback>(); foreach (RestItemData itemData in collectionBody.Items) { CreatedItemAcknowledgment acknowledgment = await collection.AddAsync(itemData); feedbackItems.Add(new AcknowledgmentFeedback(acknowledgment)); // TODO: catch exceptions } return(new MultiFeedback(feedbackItems)); } var itemBody = body as ItemBody; if (itemBody != null) { CreatedItemAcknowledgment acknowledgment = await collection.AddAsync(itemBody.Item); return(new AcknowledgmentFeedback(acknowledgment)); } throw new ItemBodyNotSupportedException(body.ResourceType); }
public void AddResource(Response response, ResourceBody resourceBody) { }
public async Task <Feedback> ExecuteAsync(IRestScalar scalar, IEndpointContext context, ResourceBody body) { var scalarBody = body as ScalarBody; if (scalarBody == null) { throw new InvalidCastException("Request body type must be a scalar value for this endpoint."); } Acknowledgment acknowledgment = await scalar.EditAsync(scalarBody.Scalar); return(new AcknowledgmentFeedback(acknowledgment)); }