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));
            }
        }
Пример #2
0
        public void GetEntityNameFromETC()
        {
            string expectedValue = "contact";
            string actualValue   = CRMMetadataHelper.GetEntityNameFromETC(2, CrmOrganisationService);

            Assert.AreEqual(expectedValue, actualValue);
        }