/// <summary> /// Map ARM metadata schema to the AzureEnvironment object. /// </summary> /// <param name="armMetadata">ARM cloud metadata</param> /// <returns></returns> private static AzureEnvironment MapArmToAzureEnvironment(ArmMetadata armMetadata) { var azureEnvironment = new AzureEnvironment { Name = armMetadata.Name, PublishSettingsFileUrl = GetPublishSettingsFileUrl(armMetadata.Name), ServiceManagementUrl = armMetadata.Authentication.Audiences[0], ResourceManagerUrl = armMetadata.ResourceManager, ManagementPortalUrl = armMetadata.Portal, ActiveDirectoryAuthority = armMetadata.Authentication.LoginEndpoint, ActiveDirectoryServiceEndpointResourceId = armMetadata.Authentication.Audiences[0], StorageEndpointSuffix = armMetadata.Suffixes.Storage, GalleryUrl = armMetadata.Gallery, SqlDatabaseDnsSuffix = armMetadata.Suffixes.SqlServerHostname, GraphUrl = armMetadata.Graph, TrafficManagerDnsSuffix = GetTrafficManagerDnsSuffix(armMetadata.Name), AzureKeyVaultDnsSuffix = armMetadata.Suffixes.KeyVaultDns, AzureKeyVaultServiceEndpointResourceId = GetKeyVaultServiceEndpointResourceId(armMetadata.Name), AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = armMetadata.Suffixes.AzureDataLakeAnalyticsCatalogAndJob, AzureDataLakeStoreFileSystemEndpointSuffix = armMetadata.Suffixes.AzureDataLakeStoreFileSystem, DataLakeEndpointResourceId = armMetadata.ActiveDirectoryDataLake, GraphEndpointResourceId = armMetadata.Graph, BatchEndpointResourceId = armMetadata.Batch, AdTenant = armMetadata.Authentication.Tenant }; return(azureEnvironment); }
/// <summary> /// Serializes the object to JSON. /// </summary> /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param> /// <param name="obj">The object to serialize to JSON.</param> internal static void Serialize(JsonWriter writer, ArmMetadata obj) { // Required properties are always serialized, optional properties are serialized when not null. writer.WriteStartObject(); if (obj.ArmResourceId != null) { writer.WriteProperty(obj.ArmResourceId, "ArmResourceId", JsonWriterExtensions.WriteStringValue); } writer.WriteEndObject(); }
/// <summary> /// Map ARM metadata schema to the AzureEnvironment object. /// </summary> /// <param name="armMetadata">ARM cloud metadata</param> /// <returns></returns> private static AzureEnvironment MapArmToAzureEnvironment(ArmMetadata armMetadata) { var azureEnvironment = new AzureEnvironment { Name = armMetadata.Name, PublishSettingsFileUrl = GetPublishSettingsFileUrl(armMetadata.Name), ServiceManagementUrl = armMetadata.Authentication.Audiences[0], ResourceManagerUrl = armMetadata.ResourceManager, ManagementPortalUrl = armMetadata.Portal, ActiveDirectoryAuthority = armMetadata.Authentication.LoginEndpoint, ActiveDirectoryServiceEndpointResourceId = armMetadata.Authentication.Audiences[0], StorageEndpointSuffix = armMetadata.Suffixes.Storage, GalleryUrl = armMetadata.Gallery, SqlDatabaseDnsSuffix = armMetadata.Suffixes.SqlServerHostname, GraphUrl = armMetadata.Graph, //TODO, ARM endpoint doesn't have TrafficManagerDnsSuffix TrafficManagerDnsSuffix = GetTrafficManagerDnsSuffix(armMetadata.Name), AzureKeyVaultDnsSuffix = armMetadata.Suffixes.KeyVaultDns, //Default ARM endpoint doens't provide KeyVault service resource id. Keep it here just in case. AzureKeyVaultServiceEndpointResourceId = GetKeyVaultServiceEndpointResourceId(armMetadata.Name), AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix = armMetadata.Suffixes.AzureDataLakeAnalyticsCatalogAndJob, AzureDataLakeStoreFileSystemEndpointSuffix = armMetadata.Suffixes.AzureDataLakeStoreFileSystem, DataLakeEndpointResourceId = armMetadata.ActiveDirectoryDataLake, GraphEndpointResourceId = armMetadata.Graph, BatchEndpointResourceId = armMetadata.Batch, AdTenant = armMetadata.Authentication.Tenant, ContainerRegistryEndpointSuffix = armMetadata.Suffixes.AcrLoginServer }; //We reuse the value of KeyVaultDns if (string.IsNullOrEmpty(azureEnvironment.AzureKeyVaultServiceEndpointResourceId)) { azureEnvironment.AzureKeyVaultServiceEndpointResourceId = $"https://{azureEnvironment.AzureKeyVaultDnsSuffix}"; } // There are mismatches between metadata built in Azure PowerShell/CLI and from ARM endpoint. // Considering compatibility, below hard coded logic accommodates those mismatches // SqlDatabaseDnsSuffix requires value leading with period // ServiceManagementUrl as audience needs to end with slash if (azureEnvironment.SqlDatabaseDnsSuffix != null && !azureEnvironment.SqlDatabaseDnsSuffix.StartsWith(".")) { azureEnvironment.SqlDatabaseDnsSuffix = "." + azureEnvironment.SqlDatabaseDnsSuffix; } if (azureEnvironment.ServiceManagementUrl != null && !azureEnvironment.ServiceManagementUrl.EndsWith("/")) { azureEnvironment.ServiceManagementUrl += "/"; } return(azureEnvironment); }
/// <inheritdoc/> protected override void ProcessRecordInternal() { var armMetadata = new ArmMetadata( armResourceId: this.ArmResourceId); this.ServiceFabricClient.ApplicationTypes.UpdateApplicationArmMetadataAsync( applicationId: this.ApplicationId, applicationArmMetadataUpdateDescription: armMetadata, serverTimeout: this.ServerTimeout, force: this.Force, cancellationToken: this.CancellationToken).GetAwaiter().GetResult(); Console.WriteLine("Success!"); }
/// <inheritdoc /> public Task UpdateApplicationTypeArmMetadataAsync( string applicationTypeName, string applicationTypeVersion, ArmMetadata applicationTypeArmMetadataUpdateDescription, long?serverTimeout = 60, bool?force = default(bool?), CancellationToken cancellationToken = default(CancellationToken)) { applicationTypeName.ThrowIfNull(nameof(applicationTypeName)); applicationTypeVersion.ThrowIfNull(nameof(applicationTypeVersion)); applicationTypeArmMetadataUpdateDescription.ThrowIfNull(nameof(applicationTypeArmMetadataUpdateDescription)); serverTimeout?.ThrowIfOutOfInclusiveRange("serverTimeout", 1, 4294967295); var requestId = Guid.NewGuid().ToString(); var url = "ApplicationTypes/{applicationTypeName}/$/UpdateArmMetadata"; url = url.Replace("{applicationTypeName}", Uri.EscapeDataString(applicationTypeName)); var queryParams = new List <string>(); // Append to queryParams if not null. applicationTypeVersion?.AddToQueryParameters(queryParams, $"ApplicationTypeVersion={applicationTypeVersion}"); serverTimeout?.AddToQueryParameters(queryParams, $"timeout={serverTimeout}"); force?.AddToQueryParameters(queryParams, $"Force={force}"); queryParams.Add("api-version=9.0"); url += "?" + string.Join("&", queryParams); string content; using (var sw = new StringWriter()) { ArmMetadataConverter.Serialize(new JsonTextWriter(sw), applicationTypeArmMetadataUpdateDescription); content = sw.ToString(); } HttpRequestMessage RequestFunc() { var request = new HttpRequestMessage() { Method = HttpMethod.Post, Content = new StringContent(content, Encoding.UTF8), }; request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); return(request); } return(this.httpClient.SendAsync(RequestFunc, url, requestId, cancellationToken)); }
Vector3 Follow(HingeJoint joint, Vector3 target) { Vector3 a = Vector3.up, b = joint.connectedBody.transform.InverseTransformPoint(target); float err = Vector3.Angle(a, b) * Mathf.Sign(Vector3.Cross(a, b).x); // print (string.Format("a:{0} b:{1}, err:{2}", a, b, err)); this.OnRobotArmAction(gameObject, err); JointSpring s = joint.spring; s.targetPosition -= Mathf.Rad2Deg * OddErp(Mathf.Deg2Rad * 0.75f * err, Mathf.PI); joint.spring = s; ArmMetadata connectedMetadata = joint.connectedBody.GetComponent <ArmMetadata> (); if (connectedMetadata == null) { throw new MissingComponentException("ArmMetadata not found"); } return(target - joint.connectedBody.transform.TransformVector(b.normalized * connectedMetadata.Length)); }
public ArmMetadata GenerateMetadata() { ArmMetadata meta = new ArmMetadata(); // meta.handTarget = armTarget.position; Transform joint = transform; List <JointMetadata> joints = new List <JointMetadata>(); // Declare variables used for processing metadata Transform parentJoint; float angleRot; Vector3 vectorRot; Quaternion currentRotation; // Assign joint metadata to remaining joints, which all have identical hierarchies for (int i = 1; i <= 4; i++) { joint = joint.Find("robot_arm_" + i + "_jnt"); JointMetadata jointMeta = new JointMetadata(); // JOINT NAME jointMeta.name = joint.name; // WORLD RELATIVE POSITION jointMeta.position = joint.position; // ROOT-JOINT RELATIVE POSITION // Parent-relative position of joint is meaningless because it never changes relative to its parent joint, so we use rootRelative instead jointMeta.rootRelativePosition = FirstJoint.InverseTransformPoint(joint.position); // WORLD RELATIVE ROTATION // GetChild grabs angler since that is what actually changes the geometry angle currentRotation = joint.GetChild(0).rotation; // Check that world-relative rotation is angle-axis-notation-compatible if (currentRotation != new Quaternion(0, 0, 0, -1)) { currentRotation.ToAngleAxis(angle: out angleRot, axis: out vectorRot); // Debug.Log(joint.name + "'s euler-angles of " + joint.GetChild(0).eulerAngles + " resulted in Quaternion " + Quaternion.Euler(joint.GetChild(0).eulerAngles) + " which should either be the same as or a corrected version of " + joint.GetChild(0).rotation); jointMeta.rotation = new Vector4(vectorRot.x, vectorRot.y, vectorRot.z, angleRot); } else { // Debug.Log(joint.name + "'s world-rotation of " + currentRotation + " is EVILLLLL!"); jointMeta.rotation = new Vector4(1, 0, 0, 0); } // ROOT-JOINT RELATIVE ROTATION // Root-forward and agent-forward are always the same // GetChild grabs angler since that is what actually changes the geometry angle currentRotation = Quaternion.Euler(FirstJoint.InverseTransformDirection(joint.GetChild(0).eulerAngles)); // Check that root-relative rotation is angle-axis-notation-compatible if (currentRotation != new Quaternion(0, 0, 0, -1)) { currentRotation.ToAngleAxis(angle: out angleRot, axis: out vectorRot); jointMeta.rootRelativeRotation = new Vector4(vectorRot.x, vectorRot.y, vectorRot.z, angleRot); } else { // Debug.Log(joint.name + "'s root-rotation of " + currentRotation + " is EVILLLLL!"); jointMeta.rootRelativeRotation = new Vector4(1, 0, 0, 0); } // PARENT-JOINT RELATIVE ROTATION if (i != 1) { parentJoint = joint.parent; // Grab rotation of current joint's angler relative to parent joint's angler, and convert it to a quaternion currentRotation = Quaternion.Euler( parentJoint.GetChild(0).InverseTransformDirection( joint.GetChild(0).eulerAngles ) ); // Check that parent-relative rotation is angle-axis-notation-compatible if (currentRotation != new Quaternion(0, 0, 0, -1)) { // Convert parent-relative rotation to angle-axis notation currentRotation.ToAngleAxis(angle: out angleRot, axis: out vectorRot); jointMeta.localRotation = new Vector4(vectorRot.x, vectorRot.y, vectorRot.z, angleRot); } else { // Debug.Log(joint.name + "'s parent-rotation of " + currentRotation + " is EVILLLLL!"); jointMeta.localRotation = new Vector4(1, 0, 0, 0); } } else { // Special case for robot_arm_1_jnt because it has no parent-joint jointMeta.localRotation = jointMeta.rootRelativeRotation; } joints.Add(jointMeta); } meta.joints = joints.ToArray(); // metadata for any objects currently held by the hand on the arm // note this is different from objects intersecting the hand's sphere, // there could be a case where an object is inside the sphere but not picked up by the hand List <string> heldObjectIDs = new List <string>(); if (heldObjects != null) { foreach (KeyValuePair <SimObjPhysics, List <Collider> > sop in heldObjects) { heldObjectIDs.Add(sop.Key.objectID); } } meta.heldObjects = heldObjectIDs; meta.handSphereCenter = transform.TransformPoint(magnetSphere.center); meta.handSphereRadius = magnetSphere.radius; meta.pickupableObjects = WhatObjectsAreInsideMagnetSphereAsObjectID(); return(meta); }