コード例 #1
0
        public static IOrganizationService CreateCrmService(string connectionString)
        {
            CrmServiceClient service;

            lock (lockObject)
            {
                if (latestStringUsed != connectionString &&
                    !connectionString.ToLower().Contains("requirenewinstance"))
                {
                    latestStringUsed  = connectionString;
                    connectionString  = connectionString.Trim(';', ' ');
                    connectionString += ";RequireNewInstance=true";
                }

                service = new CrmServiceClient(connectionString);
            }

            var escapedString = Regex.Replace(connectionString, @"Password\s*?=.*?(?:;{0,1}$|;)",
                                              "Password=********;");

            try
            {
                if (!string.IsNullOrEmpty(service.LastCrmError) || service.LastCrmException != null)
                {
                    throw new ServiceActivationException(
                              $"Can't create connection to: \"{escapedString}\" due to \"{service.LastCrmError}\"");
                }

                return(service);
            }
            catch (Exception ex)
            {
                var errorMessage = service.LastCrmError
                                   ?? (service.LastCrmException != null ? CrmHelpers.BuildExceptionMessage(service.LastCrmException) : null)
                                   ?? CrmHelpers.BuildExceptionMessage(ex);
                throw new ServiceActivationException($"Can't create connection to: \"{escapedString}\" due to\r\n{errorMessage}");
            }
        }
コード例 #2
0
        public IOrganizationService CreateCrmService()
        {
            var service       = new CrmServiceClient(parameters.ConnectionString);
            var escapedString = Regex.Replace(parameters.ConnectionString, @"Password\s*?=.*?(?:;{0,1}$|;)",
                                              "Password=********;");

            try
            {
                if (!string.IsNullOrEmpty(service.LastCrmError) || service.LastCrmException != null)
                {
                    throw new ServiceActivationException(
                              $"Can't create connection to: \"{escapedString}\" due to \"{service.LastCrmError}\"");
                }

                return(service);
            }
            catch (Exception ex)
            {
                var errorMessage = service.LastCrmError
                                   ?? (service.LastCrmException != null ? CrmHelpers.BuildExceptionMessage(service.LastCrmException) : null)
                                   ?? CrmHelpers.BuildExceptionMessage(ex);
                throw new ServiceActivationException($"Can't create connection to: \"{escapedString}\" due to\r\n{errorMessage}");
            }
        }