async Task <SdkMessages> IMetadataProviderQueryService.RetrieveSdkRequestsAsync(IOrganizationService service) { await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStartAsync("Entering {0}", MethodBase.GetCurrentMethod().Name); const string text = "<fetch distinct='true' version='1.0'>\r\n\t<entity name='sdkmessage'>\r\n\t\t<attribute name='name'/>\r\n\t\t<attribute name='isprivate'/>\r\n\t\t<attribute name='sdkmessageid'/>\r\n\t\t<attribute name='customizationlevel'/>\r\n\t\t<link-entity name='sdkmessagepair' alias='sdkmessagepair' to='sdkmessageid' from='sdkmessageid' link-type='inner'>\r\n\t\t\t<filter>\r\n\t\t\t\t<condition alias='sdkmessagepair' attribute='endpoint' operator='eq' value='2011/Organization.svc' />\r\n\t\t\t</filter>\r\n\t\t\t<attribute name='sdkmessagepairid'/>\r\n\t\t\t<attribute name='namespace'/>\r\n\t\t\t<link-entity name='sdkmessagerequest' alias='sdkmessagerequest' to='sdkmessagepairid' from='sdkmessagepairid' link-type='outer'>\r\n\t\t\t\t<attribute name='sdkmessagerequestid'/>\r\n\t\t\t\t<attribute name='name'/>\r\n\t\t\t\t<link-entity name='sdkmessagerequestfield' alias='sdkmessagerequestfield' to='sdkmessagerequestid' from='sdkmessagerequestid' link-type='outer'>\r\n\t\t\t\t\t<attribute name='name'/>\r\n\t\t\t\t\t<attribute name='optional'/>\r\n\t\t\t\t\t<attribute name='position'/>\r\n\t\t\t\t\t<attribute name='publicname'/>\r\n\t\t\t\t\t<attribute name='clrparser'/>\r\n\t\t\t\t\t<order attribute='sdkmessagerequestfieldid' descending='false' />\r\n\t\t\t\t</link-entity>\r\n\t\t\t\t<link-entity name='sdkmessageresponse' alias='sdkmessageresponse' to='sdkmessagerequestid' from='sdkmessagerequestid' link-type='outer'>\r\n\t\t\t\t\t<attribute name='sdkmessageresponseid'/>\r\n\t\t\t\t\t<link-entity name='sdkmessageresponsefield' alias='sdkmessageresponsefield' to='sdkmessageresponseid' from='sdkmessageresponseid' link-type='outer'>\r\n\t\t\t\t\t\t<attribute name='publicname'/>\r\n\t\t\t\t\t\t<attribute name='value'/>\r\n\t\t\t\t\t\t<attribute name='clrformatter'/>\r\n\t\t\t\t\t\t<attribute name='name'/>\r\n\t\t\t\t\t\t<attribute name='position' />\r\n\t\t\t\t\t</link-entity>\r\n\t\t\t\t</link-entity>\r\n\t\t\t</link-entity>\r\n\t\t</link-entity>\r\n\t\t<link-entity name='sdkmessagefilter' alias='sdmessagefilter' to='sdkmessageid' from='sdkmessageid' link-type='inner'>\r\n\t\t\t<filter>\r\n\t\t\t\t<condition alias='sdmessagefilter' attribute='isvisible' operator='eq' value='1' />\r\n\t\t\t</filter>\r\n\t\t\t<attribute name='sdkmessagefilterid'/>\r\n\t\t\t<attribute name='primaryobjecttypecode'/>\r\n\t\t\t<attribute name='secondaryobjecttypecode'/>\r\n\t\t</link-entity>\r\n\t\t<order attribute='sdkmessageid' descending='false' />\r\n\t </entity>\r\n</fetch>"; MessagePagingInfo messagePagingInfo = null; var num = 1; var sdkMessages = new SdkMessages(null); var organizationRequest = new OrganizationRequest("ExecuteFetch"); while (messagePagingInfo == null || messagePagingInfo.HasMoreRecords) { var value = text; if (messagePagingInfo != null) { value = this.SetPagingCookie(text, messagePagingInfo.PagingCookie, num); } organizationRequest.Parameters["FetchXml"] = value; var organizationResponse = service.Execute(organizationRequest); messagePagingInfo = SdkMessages.FromFetchResult(sdkMessages, (string)organizationResponse.Results["FetchXmlResult"]); num++; } await CrmSvcUtil.CrmSvcUtilLogger.TraceMethodStopAsync("Exiting {0}", MethodBase.GetCurrentMethod().Name); return(sdkMessages); }
public SdkMessages RetrieveSdkRequests(IOrganizationService service) { SdkMessages messages = new SdkMessages(null); foreach (string messageLogicalName in _messageFilter) { string fetchQuery = @"<fetch distinct='true' version='1.0'> <entity name='sdkmessage'> <attribute name='name'/> <attribute name='isprivate'/> <attribute name='sdkmessageid'/> <attribute name='customizationlevel'/> <filter> <condition alias='sdmessagefilter' attribute='name' operator='eq' value='" + messageLogicalName.ToLower() + @"'/> </filter> <link-entity name='sdkmessagepair' alias='sdkmessagepair' to='sdkmessageid' from='sdkmessageid' link-type='inner'> <filter> <condition alias='sdkmessagepair' attribute='endpoint' operator='eq' value='2011/Organization.svc' /> </filter> <attribute name='sdkmessagepairid'/> <attribute name='namespace'/> <link-entity name='sdkmessagerequest' alias='sdkmessagerequest' to='sdkmessagepairid' from='sdkmessagepairid' link-type='outer'> <attribute name='sdkmessagerequestid'/> <attribute name='name'/> <link-entity name='sdkmessagerequestfield' alias='sdkmessagerequestfield' to='sdkmessagerequestid' from='sdkmessagerequestid' link-type='outer'> <attribute name='name'/> <attribute name='optional'/> <attribute name='position'/> <attribute name='publicname'/> <attribute name='clrparser'/> <order attribute='sdkmessagerequestfieldid' descending='false' /> </link-entity> <link-entity name='sdkmessageresponse' alias='sdkmessageresponse' to='sdkmessagerequestid' from='sdkmessagerequestid' link-type='outer'> <attribute name='sdkmessageresponseid'/> <link-entity name='sdkmessageresponsefield' alias='sdkmessageresponsefield' to='sdkmessageresponseid' from='sdkmessageresponseid' link-type='outer'> <attribute name='publicname'/> <attribute name='value'/> <attribute name='clrformatter'/> <attribute name='name'/> <attribute name='position' /> </link-entity> </link-entity> </link-entity> </link-entity> <link-entity name='sdkmessagefilter' alias='sdmessagefilter' to='sdkmessageid' from='sdkmessageid' link-type='inner'> <filter> <condition alias='sdmessagefilter' attribute='isvisible' operator='eq' value='1' /> </filter> <attribute name='sdkmessagefilterid'/> <attribute name='primaryobjecttypecode'/> <attribute name='secondaryobjecttypecode'/> </link-entity> <order attribute='sdkmessageid' descending='false' /> </entity> </fetch>"; MessagePagingInfo pageInfo = null; int pageNumber = 1; var request = new ExecuteFetchRequest(); while ((pageInfo == null) || pageInfo.HasMoreRecords) { string fetch = fetchQuery; if (pageInfo != null) { fetch = this.SetPagingCookie(fetchQuery, pageInfo.PagingCookig, pageNumber); } request.FetchXml = fetch; var response = (ExecuteFetchResponse)service.Execute(request); pageInfo = SdkMessages.FromFetchResult(messages, (string)response.FetchXmlResult); pageNumber++; } } return(messages); }