Ejemplo n.º 1
0
        /// <summary>
        /// Updates the attributes of type "string" corresponding to the entity passed as parameter with a default value.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        private static Entity UpdateStringAttributes(Entity entity, List<string> updatedAttributes)
        {
            string[] attributeKeysToBeUpdated = RetrieveHelperMethods.ConvertKeyStringToList("AttributesToUpdate");

            // Attributes passed through the fetchXML (Filters by string)
            foreach (KeyValuePair<string, object> attribute in entity.Attributes.ToList())
            {
                if (attribute.Value is string)
                {
                    entity.Attributes[attribute.Key] = attribute.Key + ":" + entity.Id;

                    if (!updatedAttributes.Contains(attribute.Key))
                    {
                        updatedAttributes.Add(attribute.Key); // Add the updated attribute to be logged.
                    }               
                }
            }
            
            // Attributes keys passed through the App.config (Does not filter by string, platform will throw a silent error)
            for (int i = 0; i < attributeKeysToBeUpdated.Length; i++)
            {
                if (!entity.Attributes.ContainsKey(attributeKeysToBeUpdated[i]))
                {
                    entity.Attributes.Add(attributeKeysToBeUpdated[i], attributeKeysToBeUpdated[i] + ":" + entity.Id);

                    if (!updatedAttributes.Contains(attributeKeysToBeUpdated[i]))
                    {
                        updatedAttributes.Add(attributeKeysToBeUpdated[i]); // Add the updated attribute to be logged.
                    }
                }
            }
            return entity;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Determines which retrieve operation should be performed: Retrieve Multiple | FetchXML.
        /// </summary>
        /// <param name="serviceClient"></param>
        private static void DetermineRetrieveOperationType(CrmServiceClient serviceClient)
        {
            Console.WriteLine("\nThe following retrieve operation types are available: ");
            Console.WriteLine("(0) Retrieve Multiple | FetchXML");
 
            Console.Write("Specify the desired retrieve operation type: ");
            string response = Console.ReadLine();
            int retrieveOperationType = int.Parse(response);

            switch (retrieveOperationType)
            {
                case 0: // Retrieve Multiple | FetchXML
                    RetrieveHelperMethods.RetrieveMultipleFetchXml(serviceClient);
                    break;
                default:
                    throw new InvalidOperationException("The specified retrieve operation type is not valid: " + response);
            }
            return;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Determines the operation type to be performed: Create, Update or Delete.
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <param name="serviceManager"></param>
        private static void DetermineOperationType(CrmServiceClient serviceClient, OrganizationServiceManager serviceManager)
        {
            Console.WriteLine("\nThe following operation types are available: ");

            Console.WriteLine("(0) Create");
            Console.WriteLine("(1) Retrieve");
            Console.WriteLine("(2) Update");
            Console.WriteLine("(3) Delete");

            Console.Write("Specify the desired operation type: ");

            string response = Console.ReadLine();
            int createOperationType = int.Parse(response);
          
            switch (createOperationType)
            {
                case 0: // Create
                    log.Info("Selected operation: Create");
                    bool isOob = DetermineEntityType(); 
                    Tuple<EntityMetadata, Entity> entityTuple = RetrieveHelperMethods.RetrieveEntityList(serviceClient, isOob);
                    DetermineCreateOperationType(serviceClient, serviceManager, entityTuple);
                    break;
                case 1: // Retrieve
                    log.Info("Selected operation: Retrieve");
                    DetermineRetrieveOperationType(serviceClient);
                    break;
                case 2: // Update
                    log.Info("Selected operation: Update");
                    DetermineUpdateOperationType(serviceClient, serviceManager);
                    break;
                case 3: // Delete
                    log.Info("Selected operation: Delete");
                    DetermineDeleteOperationType(serviceClient, serviceManager);
                    break;
                default:
                    throw new InvalidOperationException("The specified operation type is not valid: " + response);
            }
            return;
        }
        /// <summary>
        /// Executes multiple deletes concurrently within one or more Batches, with each batch limited to 1000 records, based on the provided FetchXML.
        /// </summary>
        /// <param name="serviceClient"></param>
        /// <param name="serviceManager"></param>
        /// <param name="totalRequestsPerBatch"></param>
        /// <returns></returns>
        public static List <Guid> DeleteFetchXml(CrmServiceClient serviceClient, OrganizationServiceManager serviceManager, int totalRequestsPerBatch)
        {
            EntityCollection recordsToBeDeleted = RetrieveHelperMethods.RetrieveMultipleFetchXml(serviceClient);

            return(DeleteParallelExecuteMultiple(serviceManager, recordsToBeDeleted, totalRequestsPerBatch));
        }