private static string GetServiceKey(CrmService settings)
        {
            int start = settings.CrmServerUrl.IndexOf(@"//") + 2; // @"//".Length
            int end = settings.CrmServerUrl.LastIndexOf('/');

            return String.Format("{0}|{1}|",
                settings.CrmServerUrl.Substring(start, end - start),
                settings.CrmOrganization);
        }
Exemplo n.º 2
0
        private static string GetServiceKey(CrmService settings)
        {
            int start = settings.CrmServerUrl.IndexOf(@"//") + 2; // @"//".Length
            int end   = settings.CrmServerUrl.LastIndexOf('/');

            return(String.Format("{0}|{1}|",
                                 settings.CrmServerUrl.Substring(start, end - start),
                                 settings.CrmOrganization));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Factory method for creating CrmService objects
        /// </summary>
        /// <returns></returns>
        public static CrmService CreateCrmService()
        {
            var crmService = new CrmService();

            crmService.IsIfdDeployment = bool.Parse(ConfigurationManager.AppSettings.Get("isIfdDeployment") ?? "false");

            if (crmService.IsIfdDeployment)
            {
                crmService.IfdUserName = ConfigurationManager.AppSettings.Get("IfdUserName");
                crmService.IfdPassword = ConfigurationManager.AppSettings.Get("IfdPassword");
            }

            return(crmService);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns the OptionMetadataCollection for a global option set
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="optionSetName">Name of the option set.</param>
        /// <returns></returns>
        public static OptionMetadataCollection GetOptionSet(this CrmService settings, string optionSetName)
        {
            string key = GetOptionSetKey(GetServiceKey(settings), optionSetName);
            OptionMetadataCollection options;

            if (_optionSets.TryGetValue(key, out options))
            {
                return(options);
            }
            else
            {
                using (var service = CrmService.CreateOrgProxy(settings))
                {
                    return(GetOptionSet(service, optionSetName));
                }
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets an option set value's int value based on its text value.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="optionSetName">Name of the option set.</param>
 /// <param name="optionTextValue">The text value of the OptionSetValue.</param>
 /// <returns></returns>
 public static int GetOptionValue(this CrmService settings, string optionSetName, string optionTextValue)
 {
     return(settings.GetOption(optionSetName, optionTextValue).Value.GetValueOrDefault());
 }
Exemplo n.º 6
0
        private static Uri GetDiscoveryServiceUri()
        {
            var crmService = CrmService.CreateCrmService();

            return(GetDiscoveryServiceUri(crmService.CrmSdkServerUrl));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Gets an option set meta data value based on its int value.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="optionSetName">Name of the option set.</param>
        /// <param name="value">The int value of the OptionSetValue.</param>
        /// <returns></returns>
        public static OptionMetadata GetOption(this CrmService settings, string optionSetName, int value)
        {
            var options = GetOptionSet(settings, optionSetName);

            return(options.FirstOrDefault(v => v.Value == value));
        }
Exemplo n.º 8
0
 /// <summary>
 /// Gets an option set value's text value based on its int value.
 /// </summary>
 /// <param name="settings">The settings.</param>
 /// <param name="optionSetName">Name of the option set.</param>
 /// <param name="value">The int value of the OptionSetValue.</param>
 /// <returns></returns>
 public static string GetOptionText(this CrmService settings, string optionSetName, int value)
 {
     return(settings.GetOption(optionSetName, value).GetText());
 }
Exemplo n.º 9
0
 /// <summary>
 /// Gets the entity's option set value's int value based on its text value.
 /// </summary>
 /// <param name="settings">The CrmService settings.</param>
 /// <param name="entityName">Logical name of the entity.</param>
 /// <param name="attributeName">Name of the attribute.</param>
 /// <param name="optionTextValue">The text value of the OptionSetValue.</param>
 /// <returns></returns>
 public static int GetEntityOptionValue(this CrmService settings, string entityName, string attributeName, string optionTextValue)
 {
     return(settings.GetEntityOption(entityName, attributeName, optionTextValue).Value.GetValueOrDefault());
 }
Exemplo n.º 10
0
        /// <summary>
        /// Gets an option set meta data value based on its text value.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="optionSetName">Name of the option set.</param>
        /// <param name="optionTextValue">The text value of the OptionSetValue.</param>
        /// <returns></returns>
        public static OptionMetadata GetOption(this CrmService settings, string optionSetName, string optionTextValue)
        {
            var options = GetOptionSet(settings, optionSetName);

            return(options.FirstOrDefault(v => String.Equals(v.GetText(), optionTextValue, StringComparison.CurrentCultureIgnoreCase)));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the entity option meta data for a single OptionSetValue, for the specified entity's OptionSet, based on the int value of the OptionSetValue.
        /// </summary>
        /// <param name="settings">The CrmService settings.</param>
        /// <param name="entityName">Logical name of the entity.</param>
        /// <param name="attributeName">Name of the attribute that stores the option set.</param>
        /// <param name="value">The option set value's int value.</param>
        /// <returns></returns>
        public static OptionMetadata GetEntityOption(this CrmService settings, string entityName, string attributeName, int value)
        {
            var options = GetEntityOptionSet(settings, entityName, attributeName);

            return(options.FirstOrDefault(v => v.Value == value));
        }
Exemplo n.º 12
0
 /// <summary>
 /// Gets the entity's option set value's text value based on its int value.
 /// </summary>
 /// <param name="settings">The CrmService settings.</param>
 /// <param name="entityName">Logical name of the entity.</param>
 /// <param name="attributeName">Name of the attribute.</param>
 /// <param name="value">The int value of the OptionSetValue.</param>
 /// <returns></returns>
 public static string GetEntityOptionText(this CrmService settings, string entityName, string attributeName, int value)
 {
     return(settings.GetEntityOption(entityName, attributeName, value).GetText());
 }
 /// <summary>
 /// Attempts to delete the entity with the given id. If it doesn't exist, false is returned.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="settings">The crm service settings.</param>
 /// <param name="entities">The entities to delete if any exist.</param>
 public static void DeleteAnyIfExists(this IOrganizationService service, CrmService settings, IEnumerable <Entity> entities)
 {
     System.Threading.Tasks.Parallel.Invoke(
         entities.Select(e => (Action)(() => DeleteIfExists(settings, e.LogicalName, e.Id))).ToArray());
 }
Exemplo n.º 14
0
 /// <summary>
 /// Creates a Discovery Service Proxy
 /// </summary>
 /// <param name="crmService"></param>
 /// <returns></returns>
 public static DiscoveryServiceProxy CreateDiscoveryProxy(CrmService crmService)
 {
     return CreateDiscoveryProxy(crmService.CrmSdkServerUrl, crmService.IsIfdDeployment, crmService.IfdUserName, crmService.IfdPassword);
 }
Exemplo n.º 15
0
 /// <summary>
 /// Creates a Discovery Service Proxy
 /// </summary>
 /// <param name="crmService"></param>
 /// <returns></returns>
 public static DiscoveryServiceProxy CreateDiscoveryProxy(CrmService crmService)
 {
     return(CreateDiscoveryProxy(crmService.CrmSdkServerUrl, crmService.IsIfdDeployment, crmService.IfdUserName, crmService.IfdPassword));
 }
Exemplo n.º 16
0
 /// <summary>
 /// Creates a Discovery Service Proxy
 /// </summary>
 /// <returns></returns>
 public static DiscoveryServiceProxy CreateDiscoveryProxy()
 {
     return(CreateDiscoveryProxy(CrmService.CreateCrmService()));
 }
Exemplo n.º 17
0
 /// <summary>
 /// Creates an OrganizationServiceProxy using the specified settings.  This should always be wrapped in a using statement so the dispose method is called.
 /// </summary>
 /// <param name="settings">The settings .</param>
 /// <returns></returns>
 public static OrganizationServiceProxy CreateOrgProxy(CrmService settings)
 {
     return(CreateOrgProxy(settings.CrmServerUrl, settings.CrmSdkServerUrl, settings.CrmOrganization, settings.ImpersonationUserId,
                           settings.EnableProxyTypes, settings.IsIfdDeployment, settings.IfdUserName, settings.IfdPassword));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Creates an OrganizationServiceProxy.  This should always be wrapped in a using statement so the dispose method is called.
 /// </summary>
 /// <returns></returns>
 public static OrganizationServiceProxy CreateOrgProxy()
 {
     return(CrmService.CreateOrgProxy(CrmService.CreateCrmService()));
 }
Exemplo n.º 19
0
        /// <summary>
        /// Factory method for creating CrmService objects
        /// </summary>
        /// <returns></returns>
        public static CrmService CreateCrmService()
        {
            var crmService = new CrmService();
            crmService.IsIfdDeployment = bool.Parse(ConfigurationManager.AppSettings.Get("isIfdDeployment") ?? "false");

            if (crmService.IsIfdDeployment)
            {
                crmService.IfdUserName = ConfigurationManager.AppSettings.Get("IfdUserName");
                crmService.IfdPassword = ConfigurationManager.AppSettings.Get("IfdPassword");
            }

            return crmService;
        }
 /// <summary>
 /// Attempts to delete the entity with the given id. If it doesn't exist, false is returned.
 /// </summary>
 /// <param name="service">The service.</param>
 /// <param name="settings">The crm service settings.</param>
 /// <param name="entityName">Logical name of the entity.</param>
 /// <param name="id">The list of ids to search for.</param>
 public static void DeleteAnyIfExists(this IOrganizationService service, CrmService settings, string entityName, IEnumerable <Guid> id)
 {
     System.Threading.Tasks.Parallel.Invoke(id.Select(i => (Action)(() => DeleteIfExists(settings, entityName, i))).ToArray());
 }
Exemplo n.º 21
0
 /// <summary>
 /// Creates an OrganizationServiceProxy using the specified settings.  This should always be wrapped in a using statement so the dispose method is called.
 /// </summary>
 /// <param name="settings">The settings .</param>
 /// <returns></returns>
 public static OrganizationServiceProxy CreateOrgProxy(CrmService settings)
 {
     return CreateOrgProxy(settings.CrmServerUrl, settings.CrmSdkServerUrl, settings.CrmOrganization, settings.ImpersonationUserId,
                           settings.EnableProxyTypes, settings.IsIfdDeployment, settings.IfdUserName, settings.IfdPassword);
 }