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

            return(GetEarlyBoundProxyAssembly(info.ProxyTypeAssembly));
        }
Exemplo n.º 2
0
 /// <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);
 }
Exemplo 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);
        }
Exemplo 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)));
        }
Exemplo n.º 5
0
 public static IClientSideOrganizationService GetOrganizationService(CrmServiceInfo info)
 {
     return(CreateService(info));
 }
Exemplo n.º 6
0
 public static Uri GetOrganizationServiceUri(CrmServiceInfo info)
 {
     return(new Uri(String.Format(@"{0}/{1}/XRMServices/2011/Organization.svc",
                                  info.CrmServerUrl,
                                  info.CrmOrganization)));
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
 public static IClientSideOrganizationService GetOrganizationService(CrmServiceInfo info)
 {
     return CreateService(info);
 }
Exemplo n.º 12
0
        private static Assembly GetEarlyBoundProxyAssembly(CrmServiceInfo info)
        {
            if (String.IsNullOrWhiteSpace(info.ProxyTypeAssembly))
            {
                return GetEarlyBoundProxyAssembly();
            }

            return GetEarlyBoundProxyAssembly(info.ProxyTypeAssembly);
        }
Exemplo n.º 13
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;
        }
 public ClientSideOrganizationService(CrmServiceInfo info)
     : this(CrmServiceUtility.GetOrganizationService(info))
 {
 }
Exemplo 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"));
 }