public CrmConnectionInfo GetConnectionInfo(CrmDbConnection connection) { var connInfo = _Cache.GetOrAdd(connection.ConnectionString, f => { WhoAmIRequest whoRequest = new WhoAmIRequest(); WhoAmIResponse whoResponse = (WhoAmIResponse)connection.OrganizationService.Execute(whoRequest); var info = new CrmConnectionInfo(); if (whoResponse != null) { info.OrganisationId = whoResponse.OrganizationId; info.UserId = whoResponse.UserId; info.BusinessUnitId = whoResponse.BusinessUnitId; } var orgEntity = connection.OrganizationService.Retrieve("organization", info.OrganisationId, new ColumnSet("name")); if (orgEntity != null) { info.OrganisationName = (string)orgEntity["name"]; } var versionReq = new RetrieveVersionRequest(); var versionResponse = (RetrieveVersionResponse)connection.OrganizationService.Execute(versionReq); if (versionResponse != null) { info.ServerVersion = versionResponse.Version; } return(info); }); return(connInfo); }
public CrmConnectionInfo GetConnectionInfo(CrmDbConnection connection) { var connInfo = _Cache.GetOrAdd(connection.ConnectionString, f => { WhoAmIRequest whoRequest = new WhoAmIRequest(); WhoAmIResponse whoResponse = (WhoAmIResponse)connection.OrganizationService.Execute(whoRequest); var info = new CrmConnectionInfo(); if (whoResponse != null) { info.OrganisationId = whoResponse.OrganizationId; info.UserId = whoResponse.UserId; info.BusinessUnitId = whoResponse.BusinessUnitId; } var orgEntity = connection.OrganizationService.Retrieve("organization", info.OrganisationId, new ColumnSet("name")); if (orgEntity != null) { info.OrganisationName = (string)orgEntity["name"]; } var versionReq = new RetrieveVersionRequest(); var versionResponse = (RetrieveVersionResponse)connection.OrganizationService.Execute(versionReq); if (versionResponse != null) { info.ServerVersion = versionResponse.Version; } return info; }); return connInfo; }
public override void Open() { if (_State == ConnectionState.Closed) { ExecuteWithinStateTransition( ConnectionState.Connecting, f => { _OrganizationService = CrmServiceProvider.GetOrganisationService(); _ConnectionInfo = _ConnectionCache.GetConnectionInfo(this); }, ConnectionState.Open); } else { throw new InvalidOperationException("Connection can only be opened if it is currently in the closed state."); } }