public void Save(DataEntityCollectionDTO entitys, SecurityToken sessionToken, string applicationServerURL, List <string> saveScope) { CallStatus callStatus = new CallStatus(); using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory(applicationServerURL)) { DataEntityDTOChangeBatchCollection changes = new DataEntityDTOChangeBatchCollection { Batches = new List <DataEntityDTOChangeBatch>() }; DataEntityDTO.DataModelTypeDTO dataModelType = new DataEntityDTO.DataModelTypeDTO { SchemaName = "dbo", DataModelPurpose = "BusinessDataModel" }; changes.DataModelType = dataModelType; DataEntityDTOChangeBatch batch = new DataEntityDTOChangeBatch { EntitiesToSave = entitys }; DataEntitySaveContext batchSaveContext = new DataEntitySaveContext(); List <string> alternateKeys = new List <string>(); List <string> batchSaveScope = new List <string>(); if (_changedFields.Any()) { batchSaveScope = _changedFields; } else if (saveScope.Any()) { batchSaveScope = saveScope; } batchSaveContext.SaveScope = batchSaveScope; batchSaveContext.AlternateKeyFields = alternateKeys; batchSaveContext.CustomWorkflows = new List <WorkflowPackage>(); batchSaveContext.CustomDeleteWorkflows = new List <WorkflowPackage>(); batch.SaveContext = batchSaveContext; changes.Batches.Add(batch); factory.Credentials.UseIdentityConfiguration = true; IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken); secureConnection.SaveEntityCollection(changes, ref callStatus); if (callStatus.Result == CallStatusenumCallResult.Success) { return; } StringBuilder sb = new StringBuilder(); foreach (ValidationError error in callStatus.Messages) { sb.AppendLine(error.Message); } throw new Exception("Call did not complete successfully" + Environment.NewLine + sb); } }
internal void Save(DataEntityCollectionDTO entitys, SecurityToken sessionToken) { // Almost all iSIMS calls fill a callStatus response message in with status and error messages. CallStatus callStatus = new CallStatus(); // Create a communication channel factory to communicate with the iSIMS application server using (ChannelFactory <IDataEntityIO> factory = GetApplicationServerChannelFactory()) { // Because our communication now will be secured using our Identity Token we need to use some WIF extension methods to make sure the identity token // is sent as a Cookie on the SOAP call that WCF will be generating. factory.Credentials.UseIdentityConfiguration = true; IDataEntityIO secureConnection = factory.CreateChannelWithIssuedToken(sessionToken); DataEntityDTOChangeBatchCollection changes = new DataEntityDTOChangeBatchCollection { Batches = new List <DataEntityDTOChangeBatch>() }; DataEntityDTO.DataModelTypeDTO dataModelType = new DataEntityDTO.DataModelTypeDTO { SchemaName = "dbo", DataModelPurpose = "BusinessDataModel" }; changes.DataModelType = dataModelType; DataEntityDTOChangeBatch batch = new DataEntityDTOChangeBatch { EntitiesToSave = entitys }; DataEntitySaveContext batchSaveContext = new DataEntitySaveContext(); List <string> alternateKeys = new List <string>(); // Simplest thing to do is declare which field we believe we have changed List <string> batchSaveScope = new List <string> { "Learner.PreferredForename" }; List <WorkflowPackage> customWorkflows = new List <WorkflowPackage>(); batchSaveContext.SaveScope = batchSaveScope; batchSaveContext.AlternateKeyFields = alternateKeys; batchSaveContext.CustomWorkflows = customWorkflows; batchSaveContext.CustomDeleteWorkflows = new List <WorkflowPackage>(); batch.SaveContext = batchSaveContext; changes.Batches.Add(batch); secureConnection.SaveEntityCollection(changes, ref callStatus); // Handle an unsuccessful call. if (callStatus.Result != CallStatusenumCallResult.Success) { StringBuilder sb = new StringBuilder(); foreach (ValidationError error in callStatus.Messages) { sb.AppendLine(error.Message); } throw new Exception("Call did not complete successfully" + Environment.NewLine + sb); } } }