using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System.ServiceModel;
namespace Patient_registration_number
{
public class Patient_registration_number : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
try
{
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.MessageName == "Create")
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"]
is Entity)
{
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service =
(IOrganizationService)serviceFactory.CreateOrganizationService(context.UserId);
Entity accountentity = context.InputParameters["Target"] as Entity;
if (accountentity.LogicalName == "account")
{
Entity Update_current_number = new
Entity("preetham_patient_auto_number_registration");
StringBuilder autonumber = new StringBuilder();
DateTime date = DateTime.Now;
string prefix;
string suffix;
string separator;
string current;
string year;
string month;
string day;
day = date.Day.ToString("00");
year = date.Year.ToString();
month = date.Month.ToString("00");
QueryExpression query = new QueryExpression()
{
EntityName = "preetham_patient_auto_number_registration",
ColumnSet = new ColumnSet("preetham_name", "preetham_prefix",
"preetham_separator", "preetham_sufix", "preetham_currentnumber")
};
EntityCollection patient_register_number = service.RetrieveMultiple(query);
if (patient_register_number.Entities.Count == 0)
{
return;
}
foreach (Entity number_format in patient_register_number.Entities)
{
if (number_format.Attributes.Contains("preetham_name"))
{
prefix = number_format.GetAttributeValue<string>("preetham_prefix");
suffix = number_format.GetAttributeValue<string>("preetham_sufix");
separator = number_format.GetAttributeValue<string>("preetham_separator");
current = number_format.GetAttributeValue<string>("preetham_currentnumber");
int temcurrent = int.Parse(current);
temcurrent++;
current = temcurrent.ToString("000000");
Update_current_number.Id = number_format.Id;
Update_current_number.Attributes["preetham_currentnumber"] = temcurrent.ToString();
service.Update(Update_current_number);
autonumber.Append(prefix + separator + date + month + year + separator + suffix + separator + current);
accountentity.Attributes["preetham_registrationnumber"] = autonumber;
}
}
}
}
}
}
catch (Exception ex)
{
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
tracingService.Trace("Exception", ex);
}
}
}
}
contains data from a type that maps to the name 'System.Text:StringBuilder'. The deserializer has no knowledge of any type that maps to this name. Consider changing the implementation of the ResolveName method on your DataContractResolver to return a non-null value for name 'StringBuilder' and namespace 'System.Text'.
question from:
https://stackoverflow.com/questions/65831631/datacontractresolver-to-return-a-non-null-value-for-name-stringbuilder-and-nam 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…