public void TestToString() { FaultException <int> e = new FaultException <int> (0); Assert.AreEqual( String.Format("{0}: {1} (Fault Detail is equal to {2}).", e.GetType(), e.Message, e.Detail), e.ToString()); }
static void PrintError(Exception ex) { FaultException <ConfigStoreFault> fault = ex as FaultException <ConfigStoreFault>; if (fault != null) { CommandUI.PrintBold("CONFIGSTOREERROR={0}", fault.Detail.Error); System.Console.WriteLine(fault.Detail.Message); CommandUI.PrintSectionBreak(); System.Console.WriteLine(fault.ToString()); } else { System.Console.WriteLine(ex.Message); } }
public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { // Obtain the target entity from the input parameters. Entity entity = (Entity)context.InputParameters["Target"]; // Verify that the target entity represents an account. // If not, this plug-in was not registered correctly. if (entity.LogicalName != "new_inquiry") { return; } //using (WebClient client = new WebClient()) //{ try { FaultException ex = new FaultException(); var response = entity.GetAttributeValue <string>("new_response"); tracingService.Trace("Plugin is working"); //throw new InvalidPluginExecutionException("Plugin is working", ex); CreateResponse(entity.Id, response); } catch (FaultException <OrganizationServiceFault> ex) { throw new InvalidPluginExecutionException("An error occurred in the FollowupPlugin plug-in.", ex); } catch (Exception ex) { tracingService.Trace("FollowupPlugin: {0}", ex.ToString()); throw; } //} } }
/// <summary> /// 解析异常类型 /// </summary> /// <param name="innerExp">Exception对象</param> /// <returns>返回详细信息</returns> private static string HandleException(Exception innerExp) { StringBuilder builder = new StringBuilder(); while (innerExp != null) { //服务端异常 FaultException <string> faultEx = innerExp as FaultException <string>; if (faultEx != null) { builder.AppendFormat("-------------------{0}:{1}-----------------\r\n", faultEx.GetType().Name, faultEx.Message); builder.AppendLine(faultEx.Detail); break; } //SOAP 错误 FaultException faultEx1 = innerExp as FaultException; if (faultEx1 != null) { builder.AppendLine(faultEx1.ToString()); break; } //给进程或操作分配的时间过期时引发的异常 TimeoutException timeoutEx = innerExp as TimeoutException; if (timeoutEx != null) { builder.AppendLine("连接服务器发生异常,超时!"); builder.AppendLine(timeoutEx.ToString()); break; } //服务或客户端应用程序中的通信错误。 CommunicationException commuEx = innerExp as CommunicationException; if (commuEx != null) { builder.AppendLine("连接服务器发生异常,通信错误!"); builder.AppendLine(commuEx.ToString()); break; } builder.AppendFormat("-----------------{0} : {1}--------------------\r\n{2}", innerExp.GetType().Name, innerExp.Message, innerExp.StackTrace); innerExp = innerExp.InnerException; } return(builder.ToString()); }
/// <summary> /// The behaviour to perform when a fault exception occurs while the service operation is called. /// </summary> /// <param name="exception">The exception.</param> public void PerformFaultExceptionBehaviour(FaultException exception) { Console.Error.WriteLine(exception == null ? NullPhrase : exception.ToString()); }
public void Execute(IServiceProvider serviceProvider) { //Extract the tracing service for use in debugging sandboxed plug-ins. ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); // Obtain the execution context from the service provider. IPluginExecutionContext context = (IPluginExecutionContext) serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); var service = serviceFactory.CreateOrganizationService(context.UserId); OrganizationServiceContext ctx = new OrganizationServiceContext(service); FaultException ex1 = new FaultException(); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { try { Entity entity = (Entity)context.InputParameters["Target"]; var entityName = entity.LogicalName; var publisherPrefix = entityName.Split('_')[0]; tracingService.Trace("pub prefix {0}", publisherPrefix); QueryExpression qe = new QueryExpression(); qe.EntityName = "fp_fieldnamepopulator"; qe.ColumnSet = new ColumnSet(); qe.ColumnSet.AddColumns("fp_name", "fp_fieldnames"); qe.Criteria.AddCondition("fp_name", ConditionOperator.Equal, entityName.ToString().ToLower()); var results = service.RetrieveMultiple(qe); if (results.Entities.ToArray().Count() > 0) { Entity referenceEntity = results.Entities.First(); string fieldNames = referenceEntity.GetAttributeValue <string>("fp_fieldnames"); char[] comma = { ',' }; var fieldNameArr = fieldNames.Split(comma).ToList(); if (fieldNameArr.Count() > 2) { throw new InvalidPluginExecutionException("You can only add 2 fields", ex1); } string nameToUse; if (publisherPrefix == entityName) { nameToUse = "name"; } else { nameToUse = publisherPrefix + "_name"; } if (string.IsNullOrWhiteSpace(fieldNames)) { throw new InvalidPluginExecutionException("null", ex1); } string refName = ""; string refName1 = ""; Entity entityToUse; if (context.MessageName.ToUpper() == "UPDATE") { var columns = new ColumnSet(); foreach (string fieldName in fieldNameArr) { string fn = fieldName.Trim(); columns.AddColumn(fn); } entityToUse = service.Retrieve(entityName, entity.Id, columns); } else { entityToUse = entity; } foreach (string fieldName in fieldNameArr) { string fn = fieldName.Trim(); if (entityToUse.Attributes.Contains(fn)) { if (entityToUse.Attributes[fn] is EntityReference) { tracingService.Trace("pub prefix {0}", publisherPrefix); var refId = entityToUse.GetAttributeValue <EntityReference>(fn).Id; tracingService.Trace("ref ID {0}", refId); var nameToUseOfContext = nameToUse; if (fn == "contact") { fn = "contact"; nameToUseOfContext = "fullname"; } if (fn == "account") { fn = "account"; nameToUseOfContext = "name"; } var valToUse = service.Retrieve(fn, refId, new ColumnSet(nameToUseOfContext)).GetAttributeValue <string>(nameToUseOfContext); if (string.IsNullOrEmpty(refName)) { refName = valToUse; } else { refName1 = valToUse; }; fn = fieldName.Trim(); } if (entityToUse.Attributes[fn] is string) { var valToUse = entityToUse.GetAttributeValue <string>(fn); if (string.IsNullOrEmpty(refName)) { refName = valToUse; } else { refName1 = valToUse; }; } if (entityToUse.Attributes[fn] is OptionSetValue) { var val = new OptionSetHelper(); OptionSetHelper labelFromInput = new OptionSetHelper(); var valToUse = labelFromInput.getLabelFromField(entityToUse, fn, service); //var valToUse = entityToUse.GetAttributeValue<OptionSetValue>(fn).Value.ToString(); //var valToUse1 = entityToUse.FormattedValues[fn]; //throw new InvalidPluginExecutionException(label, ex1); if (string.IsNullOrEmpty(refName)) { refName = valToUse; } else { refName1 = valToUse; }; } if (entityToUse.Attributes[fn] is bool) { var valToUse = entityToUse.GetAttributeValue <bool>(fn).ToString(); if (string.IsNullOrEmpty(refName)) { refName = valToUse; } else { refName1 = valToUse; }; } } else { //add to TRACE log // throw new InvalidPluginExecutionException("none2", ex1); tracingService.Trace("(inside try block) Field Name Populator Helper Plugin: {0}", ex1.ToString()); } } MetadataHelper meta = new MetadataHelper(service, entity); int fieldLength = meta.getMaxLength(nameToUse).GetValueOrDefault(); StringHelper helper = new StringHelper(); var newStr = helper.concatenateAfterCalc(refName, refName1, fieldLength, " "); if (publisherPrefix == entityName) { entity["name"] = newStr; } else { entity[publisherPrefix + "_name"] = newStr; } // if (context.MessageName.ToUpper() == "UPDATE") // { if (context.Depth > 1) { return; } service.Update(entity); // } } } catch (Exception ex) { tracingService.Trace("Field Name Populator Helper Plugin: {0}", ex.ToString()); throw; } } }
/// <summary> /// The behaviour to perform when a fault exception occurs while the service operation is called. /// </summary> /// <param name="exception">The exception.</param> public void PerformFaultExceptionBehaviour(FaultException exception) { Console.Out.WriteLine(exception == null ? NullPhrase : Prefix + "Fault: " + exception.ToString()); }