/// <summary> /// Retrives new portion of undelivered packages. /// </summary> private void GetNewXmlPackages(Guid databaseId) { if (this.XmlList.Count == 0) { using (IUnitOfWork uow = Manager.CreateUnitOfWork()) { uow.MapperFactory = this.mapperFactory; CommunicationPackageRepository repo = new CommunicationPackageRepository(uow); this.XmlList = repo.FindUndeliveredPackages(Manager.TransmitterConfiguration.MaxTransactionCount, databaseId); if (this.XmlList.Count > 0) { this.WaitingPackages = repo.GetUndeliveredPackagesQuantity(); } else { this.WaitingPackages = 0; } } } }
/// <summary> /// Respond to request for data received by web service method call. /// (TODO wtf translate the above comment to english please :) ) /// </summary> /// <param name="data">The data received via web service method call.</param> /// <returns>Response to web service client.</returns> public object DataRequested(object data) { GetDataParameters methodParams = (GetDataParameters)data; if (methodParams == null) { return(null); } DatabaseConnector.DatabaseConnectorManager dbm = GetDatabaseConnector(); dbm.StartModule(); //ICommunicationPackageMapper mapper = NullMapperFactory.Instance.CreateMapper<ICommunicationPackageMapper>(dbm); List <ICommunicationPackage> packagesQueue = null; try { using (IUnitOfWork uow = new UnitOfWork(dbm)) { uow.MapperFactory = IoC.Get <IMapperFactory>(); CommunicationPackageRepository repo = new CommunicationPackageRepository(uow); if (methodParams.LastReceivedXmlId != null) { repo.MarkAsSend(methodParams.LastReceivedXmlId.Value); } packagesQueue = repo.FindUndeliveredPackages(1, methodParams.LastReceivedXmlId, methodParams.DatabaseId); if (packagesQueue.Count == 0) { return(null); } ICommunicationPackage pkg = packagesQueue.Single(cPkg => cPkg.OrderNumber == packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber)); //IEnumerable<ICommunicationPackage> tmp = packagesQueue.Where(cPkg => cPkg.BranchId == methodParams.DatabaseId); //ICommunicationPackage pkg = tmp.Single(cPkg => cPkg.OrderNumber == tmp.Min(communicationPackage => communicationPackage.OrderNumber)); //from pkg2 in packagesQueue where pkg2.OrderNumber == packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber) select pkg2; //packagesQueue[packagesQueue.Min(communicationPackage => communicationPackage.OrderNumber) - 1]; if (pkg.CheckSyntax() == false) { Log.Error("Invalid xml in outgoing queue.- syntax error. Xml Id=" + pkg.XmlData.Id); return(null); } if (isValidationEnabled) { if (validator == null) { object context = IoC.Get <IContextProvider>().CreateContext(IoC.Container(), "IDatabaseConnectionManager", uow.ConnectionManager); //throws XmlSchemaValidationException this.validator = IoC.Get <IPackageValidator>(context); } this.validator.ConnectionManager = uow.ConnectionManager; this.validator.Validate(pkg); } pkg.Compress(); GetDataResponse response = new GetDataResponse(); response.XmlData = pkg.XmlData; response.DatabaseId = pkg.DatabaseId; response.AdditionalData = GetUndeliveredPackagesQuantity(response.AdditionalData, repo, methodParams); return(response); } } finally { dbm.StopModule(); } }