private EntityReference ConvertURLtoEntityReference(string recordContextRecordURL) { Uri validatedRecordContextRecordURL; if (Uri.TryCreate(recordContextRecordURL, UriKind.Absolute, out validatedRecordContextRecordURL)) { const string guidStart = "%7b"; const string guidEnd = "%7d"; string id = QueryStringHelper.GetQueryStringParameter(recordContextRecordURL, "id").Replace(guidStart, string.Empty).Replace(guidEnd, string.Empty); string etn = QueryStringHelper.GetQueryStringParameter(recordContextRecordURL, "etn"); if (string.IsNullOrEmpty(etn)) { string etc = QueryStringHelper.GetQueryStringParameter(recordContextRecordURL, "etc"); int etcInteger; if (int.TryParse(etc, out etcInteger)) { etn = CRMMetadataHelper.GetEntityNameFromETC(etcInteger, this.OrganizationService); } else { throw new ArgumentException(string.Format("Record Context URL has an unexpected etc parameter. Object Type Code '{0}' must be an integer", etc)); } } return(new EntityReference(etn, new Guid(id))); } else { throw new ArgumentException(string.Format("Invalid Record Context URL '{0}'", recordContextRecordURL)); } }
public void RetrieveParameter() { string url = "https://customemails.crm4.dynamics.com:443//main.aspx?etc=10005&id=00c9121e-2698-e311-b8ea-d89d67635d80&histKey=234045132&newWindow=true&pagetype=entityrecord"; string expectedParameter1 = "10005"; string actualParameter1 = QueryStringHelper.GetQueryStringParameter(url, "etc"); string expectedParameter2 = "00c9121e-2698-e311-b8ea-d89d67635d80"; string actualParameter2 = QueryStringHelper.GetQueryStringParameter(url, "id"); Assert.AreEqual(expectedParameter1, actualParameter1); Assert.AreEqual(expectedParameter2, actualParameter2); }