public void Execute(IServiceProvider serviceProvider)
{
// Extract the tracing service.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (tracingService == null)
throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
try
{
tracingService.Trace("Posting the execution context.");
if (tracingService == null)
throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
string city = string.Empty;
if (context.MessageName == "RetrieveMultiple")
{
if (context.Depth <= 1)
{
IOrganizationServiceFactory factory =
(IOrganizationServiceFactory)
serviceProvider.GetService(typeof (IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(null);
if (context.InputParameters.Contains("Query"))
{
// Get the query
// Get the query
QueryExpression query = (QueryExpression)context.InputParameters["Query"];
// get the conditions passed by the user
ConditionExpression[] filters = query.Criteria.Conditions.ToArray();
foreach (var filter in filters)
{
if (filter.AttributeName == "new_city")
city = filter.Values[0].ToString();
//check if the query has city filter
if (!string.IsNullOrEmpty(city) && city == "MyCity")
{
// write your logic, adding additional filters conditionally or performing other tasks etc..
}
}
}
}
}
}
catch (FaultException<OrganizationServiceFault> e)
{
tracingService.Trace("Exception occured in the Plugin:" + e.ToString());
// Handle the exception.
throw;
}
catch (Exception ex)
{
tracingService.Trace("Exception: {0}", ex.ToString());
throw;
}
}
Hope it helps!!!
hi Guru this is an old post but just wanted to know what do you register this plugin against? Is it the entity or a view ?
ReplyDeleteHi, I have registered this plugin against an entity. when someone queries this entity either from code/gridview, plugin gets triggered.
Deletehi Guru,
ReplyDeleteI want to restrict Offline Mode in Dynamics CRM 2011 for Outlook client , for the machines that are not in my domain.
I mean i want to do device authentication when a user logons from home.
How can i achieve this requirement ? Is it possible through plugin ?
Why do you need offline mode if you wants to restrict user's accessing CRM outside the domain.
DeleteI think you can write some offline plugin to check the user system details.