private static Resource CreateResource(Type type, object value, HateoasOptions options, IActionDescriptorCollectionProvider actionDescriptorProvider, IUrlHelper urlHelper) { var resourceOptions = options.Requirements.Where(r => r.ResourceType == type); var isEnumerable = type.GetInterfaces().Contains(typeof(IEnumerable)); var resource = default(Resource); if (isEnumerable) { resource = new ListItemResource(value); } else { resource = new ObjectResource(value); } foreach (var option in resourceOptions) { var route = actionDescriptorProvider.ActionDescriptors.Items.FirstOrDefault(i => i.AttributeRouteInfo.Name == option.Name); var method = route.ActionConstraints.OfType <HttpMethodActionConstraint>().First().HttpMethods.First(); var routeValues = default(object); if (!isEnumerable) { routeValues = option.RouteValues(value); } var url = urlHelper.Link(option.Name, routeValues).ToLower(); resource.Links.Add(new Link(option.Name, url, method)); } return(resource); }
/// <inheritdoc /> /// <summary> /// Update an object <b>Permissions Needed:</b> INVENTORY_ADMIN /// </summary> /// <param name="templateId">The id of the template this object is part of</param> /// <param name="objectId">The id of the object</param> /// <param name="cascade">Whether to cascade group changes, such as in the limited gettable behavior. A 400 error will return otherwise if the group is already in use with different values.</param> /// <param name="objectItem">The object item object</param> public void UpdateObjectItem(string templateId, int?objectId, bool?cascade, ObjectResource objectItem) { // verify the required parameter 'templateId' is set if (templateId == null) { throw new KnetikException(400, "Missing required parameter 'templateId' when calling UpdateObjectItem"); } // verify the required parameter 'objectId' is set if (objectId == null) { throw new KnetikException(400, "Missing required parameter 'objectId' when calling UpdateObjectItem"); } mWebCallEvent.WebPath = "/objects/{template_id}/{object_id}"; if (!string.IsNullOrEmpty(mWebCallEvent.WebPath)) { mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{format}", "json"); } mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "template_id" + "}", KnetikClient.ParameterToString(templateId)); mWebCallEvent.WebPath = mWebCallEvent.WebPath.Replace("{" + "object_id" + "}", KnetikClient.ParameterToString(objectId)); mWebCallEvent.HeaderParams.Clear(); mWebCallEvent.QueryParams.Clear(); mWebCallEvent.AuthSettings.Clear(); mWebCallEvent.PostBody = null; if (cascade != null) { mWebCallEvent.QueryParams["cascade"] = KnetikClient.ParameterToString(cascade); } mWebCallEvent.PostBody = KnetikClient.Serialize(objectItem); // http body (model) parameter // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_client_credentials_grant"); // authentication settings mWebCallEvent.AuthSettings.Add("oauth2_password_grant"); // make the HTTP request mUpdateObjectItemStartTime = DateTime.Now; mWebCallEvent.Context = mUpdateObjectItemResponseContext; mWebCallEvent.RequestType = KnetikRequestType.PUT; KnetikLogger.LogRequest(mUpdateObjectItemStartTime, "UpdateObjectItem", "Sending server request..."); KnetikGlobalEventSystem.Publish(mWebCallEvent); }
private void OnValidate() { if (addTree != null) { ObjectResource treeResource = new ObjectResource { prefab = addTree }; treeSpawnSettings.resources.Add(treeResource); addTree = null; } if (addObject != null) { ObjectResource objectResource = new ObjectResource { prefab = addObject }; objectSpawnSettings.resources.Add(objectResource); addObject = null; } }
private async Task HandlePaymentResponse(Payment payment, ObjectResource <PaymentResource> result) { await unitOfWork.CommitAsync(); result.Data = PaymentMapper.ConvertFrom(payment); }
private Resource CreateObjectResource(Type type, object value) { var resource = new ObjectResource(value); return(AppendLinksToResource(type, resource, false)); }
private void DrawTreeList() { GUILayout.Space(10); GUIStyle toogleStyle = new GUIStyle(GUI.skin.button) { fixedHeight = 25 }; ObjectSpawnSettings treeSpawnSettings = voxelEngine.treeSpawnSettings; EditorGUILayout.BeginVertical(); { for (int i = 0; i < treeSpawnSettings.resources.Count; i++) { ObjectResource spawnResource = treeSpawnSettings.resources[i]; if (spawnResource.prefab == null) { continue; } if (i == selectedTreeIndex) { GUILayout.Toggle(true, spawnResource.prefab.name, toogleStyle); } else { if (GUILayout.Toggle(false, spawnResource.prefab.name, toogleStyle)) { selectedTreeIndex = i; } } } } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); { if (selectedTreeIndex >= 0) { if (GUILayout.Button("Remove")) { SerializedProperty treeResourcesProperty = treeSpawnSettingsProperty.FindPropertyRelative("resources"); treeResourcesProperty.DeleteArrayElementAtIndex(selectedTreeIndex); selectedTreeIndex = -1; } } if (treeSpawnSettings.resources.Count > 0) { if (GUILayout.Button("Remove All")) { SerializedProperty treeResourcesProperty = treeSpawnSettingsProperty.FindPropertyRelative("resources"); treeResourcesProperty.ClearArray(); selectedTreeIndex = -1; } } } GUILayout.EndHorizontal(); }
public void SpawnObject(string path, SpawnData data) { ObjectResource obj = FindResource(path); if (!obj.Equals(default))
public override Task Process(ObjectResource <CatalogDto> resource, HttpContext context) { resource.Links.Add(new Link("self", _linkGenerator.GetPathByName(context, "catalog#sku", new { sku = resource.Data.Sku }))); return(Task.CompletedTask); }
private void SpawnObject(Vector3 spawnPos, int chunkSize, List <PoolObject> trees) { const float NoisePositionOffset = 0.5f; // offset for noise input. noise would be always 0 for integers float spawnProbability = objectSpawnSettings.spawnProbability; float terrainMaxHeight = objectSpawnSettings.maxHeight; float seaLevel = objectSpawnSettings.seaLevel; var noisePos = new Vector3(spawnPos.x + NoisePositionOffset, 0, spawnPos.z + NoisePositionOffset); float noise = (float)noiseGenerator.GetValue(noisePos); // normalize to [0,1] noise = (noise + 1) / 2; if (noise > spawnProbability) { return; } ObjectResource spawnResource = GetObjectType(noise); Vector2 spawnSlopeRange = spawnResource.spawnSlopeRange; Vector2 spawnHeightRange = spawnResource.spawnHeightRange; RaycastHit hit; const int ChunkMask = 8; const int LayerMask = 1 << ChunkMask; // ignore all collider except for the chunk collider if (!Physics.Raycast(spawnPos, Vector3.down, out hit, chunkSize - 1, LayerMask)) { return; } float angle = Vector3.Angle(hit.normal, Vector3.up); float minSlope = spawnSlopeRange.x; float maxSlope = spawnSlopeRange.y; if (angle < minSlope || angle > maxSlope) { // Don't spawn tree when not in slope range return; } float height = spawnPos.y - hit.distance; float minHeight = spawnHeightRange.x * terrainMaxHeight; float maxHeight = spawnHeightRange.y * terrainMaxHeight; if (height < minHeight || height > maxHeight) { // Don't spawn when not in spawn criteria return; } spawnPos.y = height; // Don't spawn trees in water if (height > seaLevel) { GameObject spawnObject = PlaceObject(spawnPos, spawnResource.type); Random.InitState((int)(noise * 100)); int rotation = Random.Range(0, 360); spawnObject.transform.Rotate(new Vector3(0, rotation, 0)); trees.Add(new PoolObject(spawnResource.type, spawnObject)); } }