/// <summary> /// Process data that was received by web service method. /// </summary> /// <param name="data">The data received via web service method call.</param> /// <returns>Response to web service client.</returns> public object DataReceived(object data) { SendDataParameters methodParams = (SendDataParameters)data; if (methodParams == null) { return(null); } SendDataResponse response = new SendDataResponse(); ICommunicationPackage communicationPackage = (methodParams.Xml == null) ? null : CreateCommunicationPackage(methodParams); DatabaseConnector.DatabaseConnectorManager dbm = GetDatabaseConnector(); dbm.StartModule(); try { using (IUnitOfWork uow = new UnitOfWork(dbm)) { uow.MapperFactory = IoC.Get <IMapperFactory>(); uow.StartTransaction(IsolationLevel.Serializable); CommunicationPackageRepository repo = new CommunicationPackageRepository(uow); if (communicationPackage != null) { repo.Add(communicationPackage); } if (methodParams.IsLastInTransaction) { repo.MarkTransactionAsCompleted(communicationPackage.XmlData.LocalTransactionId); } if (methodParams.Statistics != null) { repo.UpdateStatistics(methodParams.Statistics, methodParams.DepartmentIdentifier); } uow.SubmitChanges(); } } catch (System.Data.SqlClient.SqlException e) { response.Result = false; Log.Error(e.ToString(), false); return(response); } catch (CommunicationPackageExistsException e) //Xml already in database. { Log.Info(e.ToString(), false); } finally { dbm.StopModule(); } response.Result = true; return(response); }
private ICommunicationPackage CreateCommunicationPackage(SendDataParameters methodParams) { ICommunicationPackage communicationPackage = IoC.Get <ICommunicationPackageFactory>().CreatePackage(methodParams.Xml); communicationPackage.DatabaseId = methodParams.DepartmentIdentifier; communicationPackage.Decompress(); //log when package is invalid but save it anyway if (communicationPackage.CheckSyntax() == false) { Log.Error("Invalid xml received - syntax error. Xml Id=" + communicationPackage.XmlData.Id); } return(communicationPackage); }