public string ToXMLNoParent() { string contactURIStr = (m_contactURI != null) ? m_contactURI.ToString() : null; string mangledContactURIStr = (m_mangledContactURI != null) ? m_mangledContactURI.ToString() : null; string registrarBindingXML = " <id>" + Id + "</id>" + m_newLine + " <sipaccountid>" + SIPAccountId + "</sipaccountid>" + m_newLine + " <sipaccountname>" + SIPAccountName + "</sipaccountname>" + m_newLine + " <owner>" + Owner + "</owner>" + m_newLine + " <adminmemberid>" + AdminMemberId + "</adminmemberid>" + m_newLine + " <contacturi>" + contactURIStr + "</contacturi>" + m_newLine + " <mangledcontacturi>" + mangledContactURIStr + "</mangledcontacturi>" + m_newLine + " <expiry>" + Expiry + "</expiry>" + m_newLine + " <useragent>" + SafeXML.MakeSafeXML(UserAgent) + "</useragent>" + m_newLine + " <remotesipsocket>" + RemoteSIPSocket + "</remotesipsocket>" + m_newLine + " <proxysipsocket>" + ProxySIPSocket + "</proxysipsocket>" + m_newLine + " <registrarsipsocket>" + RegistrarSIPSocket + "</registrarsipsocket>" + m_newLine + " <lastupdate>" + m_lastUpdate.ToString("o") + "</lastupdate>" + m_newLine + " <expirytime>" + ExpiryTime.ToString("o") + "</expirytime>" + m_newLine; return(registrarBindingXML); }
public override void ExecuteCmdlet() { try { LocalResourceIdentifier identifier = new LocalResourceIdentifier(AuthorizationRuleId); string resourceUri = string.Empty, strPolicyName = string.Empty, sakey = string.Empty; PSListKeysAttributes listkeys; if (identifier.ParentResource1 != null) { listkeys = Client.GetEventHubListKeys(identifier.ResourceGroupName, identifier.ParentResource, identifier.ParentResource1, identifier.ResourceName); } else { listkeys = Client.GetNamespaceListKeys(identifier.ResourceGroupName, identifier.ParentResource, identifier.ResourceName); } string[] connectionstring = KeyType == "Primary" ? listkeys.PrimaryConnectionString.Split(';') : listkeys.SecondaryConnectionString.Split(';'); switch (connectionstring.Length) { case 4: { resourceUri = connectionstring[0].Replace("Endpoint=sb://", "") + connectionstring[3].Replace("EntityPath=", ""); strPolicyName = connectionstring[1].Replace("SharedAccessKeyName=", ""); sakey = connectionstring[2].Replace("SharedAccessKey=", ""); break; } case 3: { resourceUri = connectionstring[0].Replace("Endpoint=sb://", ""); strPolicyName = connectionstring[1].Replace("SharedAccessKeyName=", ""); sakey = connectionstring[2].Replace("SharedAccessKey=", ""); break; } default: { break; } } string stringToSign = StartTime.HasValue ? StartTime.ToString() + "\n" + System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + ExpiryTime.ToString() : System.Web.HttpUtility.UrlEncode(resourceUri) + "\n" + ExpiryTime.ToString(); HMACSHA256 hmac = new HMACSHA256(System.Text.Encoding.UTF8.GetBytes(sakey)); var signature = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(stringToSign))); string sasToken = String.Format(CultureInfo.InvariantCulture, "SharedAccessSignature sr={0}&sig={1}&se={2}&skn={3}", HttpUtility.UrlEncode(resourceUri), HttpUtility.UrlEncode(signature), ExpiryTime, KeyType); PSSharedAccessSignatureAttributes psSastoken = new PSSharedAccessSignatureAttributes(sasToken); WriteObject(psSastoken, true); } catch (Management.EventHub.Models.ErrorResponseException ex) { WriteError(Eventhub.EventHubsClient.WriteErrorforBadrequest(ex)); } }