public static void SetValueToContextOrImage(Entity contextRecord, string fieldName, object value)
{
if (contextRecord != null)
{
if (contextRecord.Contains(fieldName))
contextRecord.Attributes[fieldName] = value;
else
contextRecord.Attributes.Add(fieldName, value);
}
else
{
throw new Exception("Record is null");
}
}
///////////////////////////////////////////////////
public static Entity GetCurrentEntityForRetrieve(IPluginExecutionContext context, IOrganizationService service, params string[] columns)
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
{
return service.Retrieve(((EntityReference)context.InputParameters["Target"]).LogicalName, ((EntityReference)context.InputParameters["Target"]).Id, new ColumnSet(columns));
}
else
{
throw new Exception("Error: the context input parameter didn't return the target EntityReference");
}
}////////////////////
internal static void ThrowException(Exception exception, ITracingService trace, string pluginName)
{
exception = exception.InnerException != null ? exception.InnerException : exception;
trace.Trace("Error message: {0}", exception.Message);
trace.Trace("Error StackTrace: {0}", exception.StackTrace);
trace.Trace("Error Source: {0}", exception.Source);
trace.Trace("Error TargetSite: {0}", exception.TargetSite);
throw new InvalidPluginExecutionException(string.Format("An error has occured in the {0} plugin. Please download the error trace and contact the system administrator. Message: {1}", pluginName, exception.Message), exception);
}
{
if (contextRecord != null)
{
if (contextRecord.Contains(fieldName))
contextRecord.Attributes[fieldName] = value;
else
contextRecord.Attributes.Add(fieldName, value);
}
else
{
throw new Exception("Record is null");
}
}
///////////////////////////////////////////////////
public static Entity GetCurrentEntityForRetrieve(IPluginExecutionContext context, IOrganizationService service, params string[] columns)
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
{
return service.Retrieve(((EntityReference)context.InputParameters["Target"]).LogicalName, ((EntityReference)context.InputParameters["Target"]).Id, new ColumnSet(columns));
}
else
{
throw new Exception("Error: the context input parameter didn't return the target EntityReference");
}
}////////////////////
internal static void ThrowException(Exception exception, ITracingService trace, string pluginName)
{
exception = exception.InnerException != null ? exception.InnerException : exception;
trace.Trace("Error message: {0}", exception.Message);
trace.Trace("Error StackTrace: {0}", exception.StackTrace);
trace.Trace("Error Source: {0}", exception.Source);
trace.Trace("Error TargetSite: {0}", exception.TargetSite);
throw new InvalidPluginExecutionException(string.Format("An error has occured in the {0} plugin. Please download the error trace and contact the system administrator. Message: {1}", pluginName, exception.Message), exception);
}
/////////////////
public static void CreateErrorLog(string functionalityName, Exception ex, IOrganizationService service, ITracingService tracing, IPluginExecutionContext context)
{
tracing.Trace("In CreateErrorLog method.");
tracing.Trace(ex.Message);
Entity errorLog = new Entity("hppscm_errorlog");
Hand.SetValueToContextOrImage(errorLog, "hvvv_name", functionalityName);
Hand.SetValueToContextOrImage(errorLog, "hvvv_errordatetime", Handler.GetLocalTime(tracing, service, context, DateTime.UtcNow));
Hand.SetValueToContextOrImage(errorLog, "hvvv_message", ex.Message);
Hand.SetValueToContextOrImage(errorLog, "hvvv_stacktrace", ex.StackTrace);
Guid errorLogId = service.Create(errorLog);
tracing.Trace("Error Log ID: " + errorLogId);
}
No comments:
Post a Comment