Пример #1
0
        public static bool HasOpenSystemJobs(Guid regardingId, CrmService service)
        {
            QueryExpression qe = new QueryExpression("asyncoperation")
            {
                ColumnSet = new ColumnSet(false),
                TopCount  = 1
            };

            qe.Criteria.AddCondition("regardingobjectid", ConditionOperator.Equal, regardingId);
            qe.Criteria.AddCondition("statuscode", ConditionOperator.NotIn, new object[] { 10, 30, 31, 32 });

            return(service.RetrieveMultiple(qe).Entities.Count > 0);
        }
Пример #2
0
        /// <summary>
        /// Deletes are records from the cache and deletes them in CRM
        /// </summary>
        /// <param name="service"></param>
        public void DeleteAllCachedRecords(CrmService service)
        {
            Logger.WriteLine("Clearing cache");
            foreach (var record in _aliasedRecords)
            {
                if (_aliasesToIgnore.Contains(record.Key) || _entitiesToIgnore.Contains(record.Value.LogicalName))
                {
                    continue;
                }

                try
                {
                    Logger.WriteLine($"Deleting {record.Key}. ID: {record.Value.Id} Entity: {record.Value.LogicalName}");
                    service.Delete(record.Value);
                }
                // Some records can't be deleted due to cascading behavior
                catch (Exception ex)
                {
                    Logger.WriteLine($"Delete failed: Error: {ex.Message}");
                }
            }
            _aliasedRecords.Clear();
        }