Esempio n. 1
0
        private static Assembly GetEarlyBoundProxyAssembly(CrmServiceInfo info)
        {
            if (String.IsNullOrWhiteSpace(info.ProxyTypeAssembly))
            {
                return(GetEarlyBoundProxyAssembly());
            }

            return(GetEarlyBoundProxyAssembly(info.ProxyTypeAssembly));
        }
 /// <summary>
 /// Determines whether the specified object is equal to the current object.
 /// </summary>
 /// <param name="p">The p.</param>
 /// <returns></returns>
 public bool Equals(CrmServiceInfo p)
 {
     return
         (p != null &&
          CrmServerUrl == p.CrmServerUrl &&
          CrmDiscoveryServerUrl == p.CrmDiscoveryServerUrl &&
          CrmOrganization == p.CrmOrganization &&
          ImpersonationUserId == p.ImpersonationUserId &&
          EnableProxyTypes == p.EnableProxyTypes &&
          Timeout == p.Timeout);
 }
Esempio n. 3
0
        private static ClientCredentials GetCredentials(CrmServiceInfo info)
        {
            var cred     = new ClientCredentials();
            var userName = String.Empty;
            var password = String.Empty;
            var domain   = String.Empty;

            if (info == null)
            {
                if (!Debugger.IsAttached)
                {
                    return(cred);
                }
            }
            else
            {
                userName = info.UserName;
                password = info.UserPassword;
                domain   = info.UserDomainName;
            }

            // If the caller hasn't explicitly set the user name and password, user the Debug credentials
            if (Debugger.IsAttached && String.IsNullOrWhiteSpace(userName) && String.IsNullOrWhiteSpace(password))
            {
                userName = ConfigurationManager.AppSettings["DebugUserAccountName"];
                password = ConfigurationManager.AppSettings["DebugUserAccountPassword"];
                domain   = ConfigurationManager.AppSettings["DebugUserAccountDomain"];
            }

            // If UserName or Password is null, return standard Client Credentials
            if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password))
            {
                return(cred);
            }

            // If there is a domain, use Network Credentials.  If there is not a domain just set client credentials
            if (String.IsNullOrWhiteSpace(domain))
            {
                cred.UserName.UserName = userName;
                cred.UserName.Password = password;
            }
            else
            {
                cred.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
            }

            return(cred);
        }
Esempio n. 4
0
        private static IClientSideOrganizationService CreateService(CrmServiceInfo info)
        {
            var url = info.CrmServerUrl + "/" + info.CrmOrganization;

            if (info.CrmServerUrl.Contains("crm.dynamics.com"))
            {
                const string onlinePrefix = "https://";
                url = onlinePrefix + info.CrmOrganization + "." + info.CrmServerUrl.Substring(onlinePrefix.Length);
            }

            var client = new CrmConnection
            {
                CallerId           = info.ImpersonationUserId == Guid.Empty ? null : new Guid?(info.ImpersonationUserId),
                ClientCredentials  = GetCredentials(info),
                ProxyTypesAssembly = info.EnableProxyTypes ? GetEarlyBoundProxyAssembly(info) : null,
                ProxyTypesEnabled  = info.EnableProxyTypes,
                ServiceUri         = new Uri(url),
                Timeout            = info.Timeout.Ticks == 0 ? null : new TimeSpan?(info.Timeout),
            };

            return(new ClientSideOrganizationService(new OrganizationService(client)));
        }
Esempio n. 5
0
 public static IClientSideOrganizationService GetOrganizationService(CrmServiceInfo info)
 {
     return(CreateService(info));
 }
Esempio n. 6
0
 public static Uri GetOrganizationServiceUri(CrmServiceInfo info)
 {
     return(new Uri(String.Format(@"{0}/{1}/XRMServices/2011/Organization.svc",
                                  info.CrmServerUrl,
                                  info.CrmOrganization)));
 }
 public bool Equals(CrmServiceInfo p)
 {
     return
         p != null &&
         CrmServerUrl == p.CrmServerUrl &&
         CrmDiscoveryServerUrl == p.CrmDiscoveryServerUrl &&
         CrmOrganization == p.CrmOrganization &&
         ImpersonationUserId == p.ImpersonationUserId &&
         EnableProxyTypes == p.EnableProxyTypes &&
         Timeout == p.Timeout;
 }
 public ClientSideOrganizationService(CrmServiceInfo info) :
     this(CrmServiceUtility.GetOrganizationService(info))
 {
 }
 public static Uri GetOrganizationServiceUri(CrmServiceInfo info)
 {
     return new Uri(String.Format(@"{0}/{1}/XRMServices/2011/Organization.svc",
         info.CrmServerUrl,
         info.CrmOrganization));
 }
        private static IClientSideOrganizationService CreateService(CrmServiceInfo info)
        {
            var url = info.CrmServerUrl + "/" + info.CrmOrganization;
            if(info.CrmServerUrl.Contains("crm.dynamics.com"))
            {
                const string onlinePrefix = "https://";
                url = onlinePrefix + info.CrmOrganization + "." + info.CrmServerUrl.Substring(onlinePrefix.Length);
            }

            var client = new CrmConnection
            {
                CallerId = info.ImpersonationUserId == Guid.Empty ? null : new Guid?(info.ImpersonationUserId),
                ClientCredentials = GetCredentials(info),
                ProxyTypesAssembly = info.EnableProxyTypes ? GetEarlyBoundProxyAssembly(info) : null,
                ProxyTypesEnabled = info.EnableProxyTypes,
                ServiceUri = new Uri(url),
                Timeout =  info.Timeout.Ticks == 0 ? null : new TimeSpan?(info.Timeout),
            };

            return new ClientSideOrganizationService(new OrganizationService(client));
        }
 public static IClientSideOrganizationService GetOrganizationService(CrmServiceInfo info)
 {
     return CreateService(info);
 }
        private static Assembly GetEarlyBoundProxyAssembly(CrmServiceInfo info)
        {
            if (String.IsNullOrWhiteSpace(info.ProxyTypeAssembly))
            {
                return GetEarlyBoundProxyAssembly();
            }

            return GetEarlyBoundProxyAssembly(info.ProxyTypeAssembly);
        }
        private static ClientCredentials GetCredentials(CrmServiceInfo info)
        {
            var cred = new ClientCredentials();
            var userName = String.Empty;
            var password = String.Empty;
            var domain = String.Empty;

            if (info == null)
            {
                if (!Debugger.IsAttached)
                {
                    return cred;
                }
            }
            else
            {
                userName = info.UserName;
                password = info.UserPassword;
                domain = info.UserDomainName;
            }

            // If the caller hasn't explicitly set the user name and password, user the Debug credentials
            if (Debugger.IsAttached && String.IsNullOrWhiteSpace(userName) && String.IsNullOrWhiteSpace(password))
            {
                userName = ConfigurationManager.AppSettings["DebugUserAccountName"];
                password = ConfigurationManager.AppSettings["DebugUserAccountPassword"];
                domain = ConfigurationManager.AppSettings["DebugUserAccountDomain"];
            }

            // If UserName or Password is null, return standard Client Credentials
            if (String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(password))
            {
                return cred;
            }

            // If there is a domain, use Network Credentials.  If there is not a domain just set client credentials
            if (String.IsNullOrWhiteSpace(domain))
            {
                cred.UserName.UserName = userName;
                cred.UserName.Password = password;
            }
            else
            {
                cred.Windows.ClientCredential = new System.Net.NetworkCredential(userName, password, domain);
            }

            return cred;
        }
 public ClientSideOrganizationService(CrmServiceInfo info)
     : this(CrmServiceUtility.GetOrganizationService(info))
 {
 }
Esempio n. 15
0
 /// <summary>
 /// Gets the organization service URI.
 /// </summary>
 /// <param name="info">The information.</param>
 /// <returns></returns>
 public static Uri GetOrganizationServiceUri(CrmServiceInfo info)
 {
     return(new Uri($@"{info.CrmServerUrl}/{info.CrmOrganization}/XRMServices/2011/Organization.svc"));
 }