13.11.2008, 22:06 | #1 |
Участник
|
Microsoft Dynamics CRM Team Blog: Leveraging bulk delete jobs to manage System Job log records
Источник: http://blogs.msdn.com/crm/archive/20...g-records.aspx
============== New to Microsoft Dynamics CRM 4 is the concept of having a single windows service that will manage all asynchronous operations. Each time an asynchronous operation takes place a number of log entries are created in the tables that support asynchronous operations. Some examples of asynchronous operations are:
So, now you’re asking, “what can I do to control this or clear these out?”. You can use the Bulk Delete feature ( http://msdn.microsoft.com/en-us/library/cc155955.aspx) as documented in the CRM SDK. You can issue bulk deletes for out of the box and custom entities which includes the AsyncOperation entity otherwise known as the “System Job” entity. The bulk delete operation takes as input a QueryExpression and deletes the records returned by the query. Any QueryExpression you write could be used as part of a bulk delete. After creating the bulk delete job CRM will execute the deletes one after the other (the deletes are not set based) each delete will be evaluated against the business logic in the system just as if you were deleting records in the application. This means that any plugins you’ve registered will fire, cascading will occur, etc. It also means that the delete jobs may take some time to process before all the records are cleared out. There are some prerequisites when trying to delete asyncoperation records using bulk delete.
The following sample builds off the article written by Mahesh (link). In my sample I’ve included the following helper files provided in the CRM SDK:
1: static void runBulkDelete() 2: { 3: 4: CrmAuthenticationToken token = new CrmAuthenticationToken(); 5: token.AuthenticationType = 0; 6: token.OrganizationName = "AdventureWorksCycle"; 7: CrmService service = new CrmService(); 8: service.Url = "http://crmserver/mscrmservices/2007/crmservice.asmx"; 9: service.CrmAuthenticationTokenValue = token; 10: service.Credentials = System.Net.CredentialCache.DefaultCredentials; 11: //create a QueryExpression using the helper 12: QueryExpressionHelper expression = new QueryExpressionHelper("asyncoperation"); 13: expression.Columns.AddColumn("asyncoperationid"); 14: expression.Criteria.Conditions.AddCondition("statecode", ConditionOperator.Equal, (int)AsyncOperationState.Completed); 15: expression.Criteria.Conditions.AddCondition("completedon", ConditionOperator.OlderThanXMonths, 1); 16: expression.Criteria.Conditions.AddCondition("operationtype", ConditionOperator.NotEqual, (int)AsyncOperationType.Workflow); 17: Guid[] emptyRecipients = new Guid[0]; 18: //Create a BulkDeleteRequest 19: BulkDeleteRequest request = new BulkDeleteRequest(); 20: request.JobName = "Bulk delete completed asyncoperations to free up space"; 21: request.QuerySet = new QueryBase[] { expression.Query }; 22: request.ToRecipients = emptyRecipients; 23: request.CCRecipients = emptyRecipients; 24: request.SendEmailNotification = false; 25: request.RecurrencePattern = string.Empty; 26: request.StartDateTime = CrmDateTime.Now; 27: BulkDeleteResponse response = (BulkDeleteResponse)service.Execute(request); 28: Console.WriteLine("Bulk delete job with id: {0} has been created", response.JobId); 29: } Additional notes regarding Bulk Delete jobs:
Cheers, Sean McNellis Источник: http://blogs.msdn.com/crm/archive/20...g-records.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
Опции темы | Поиск в этой теме |
Опции просмотра | |
|