private IOrganizationService GetCRMClientServiceProxy() { try { IOrganizationService service = CRM2011Connection.GetServiceProxy(Connection.GetConnectionString()); log.Info("Successfully connected to CRM client service"); return(service); } catch (System.IO.FileNotFoundException) { // FileNotFound is sometimes thrown from within Microsoft.Xrm.Tooling.Connector, probably when the connection info is invalid. // (This Dynamics 2011 version no longer uses Microsoft.Xrm.Tooling.Connector, but it's unknown whether CrmConnection will throw the same exception.) throw new InvalidOperationException("Connection could not be made - check connection info or retry."); } }
public void RetrieveEntityList() { try { Log log = new Log("CRMConnection"); string trimmedConnectionString = GetConnectionString(); trimmedConnectionString = trimmedConnectionString.Substring(0, trimmedConnectionString.IndexOf("Password")); log.Debug($"Making connection for '{this.connectionName}' ({this.connectionId}) with connection info \"{trimmedConnectionString}\"."); IOrganizationService serviceProxy = CRM2011Connection.GetServiceProxy(GetConnectionString()); if (serviceProxy != null) { RetrieveAllEntitiesRequest req = new RetrieveAllEntitiesRequest() { EntityFilters = EntityFilters.Entity }; RetrieveAllEntitiesResponse res = (RetrieveAllEntitiesResponse)serviceProxy.Execute(req); this.allEntityNames = res.EntityMetadata.Select(x => x.LogicalName).ToArray(); this.allEntityDisplayNames = res.EntityMetadata.Select(x => { string displayName; if (x.DisplayName.LocalizedLabels != null && x.DisplayName.LocalizedLabels.Count > 0) { displayName = x.DisplayName.LocalizedLabels[0].Label; } else { displayName = x.LogicalName; } return(displayName); }).ToArray(); /*log.Debug($"Checksum for all entity names: {allEntityNames.SelectMany(x => x).Select(x => (int)x).Sum()}"); * log.Debug($"All entity names: {string.Join(", ", allEntityNames)}");*/ } } catch (System.IO.FileNotFoundException) { // FileNotFound is sometimes thrown from within Microsoft.Xrm.Tooling.Connector, probably when the connection info is invalid. this.allEntityNames = null; this.allEntityDisplayNames = null; throw new InvalidOperationException("Connection could not be made - check connection info or retry."); } }
protected IOrganizationService GetServiceProxy() { return(CRM2011Connection.GetServiceProxy(GetConnectionString())); }