/// <summary> /// Sets the communication package send flag to true. /// </summary> /// <param name="id">The communication package id.</param> private void SetXmlSentWithRetry(Guid id) { bool isSet = false; int retryCount = 0; using (IUnitOfWork uow = Manager.CreateUnitOfWork()) { uow.MapperFactory = this.mapperFactory; CommunicationPackageRepository repo = new CommunicationPackageRepository(uow); while (isSet == false && retryCount < 10) { try { repo.MarkAsSend(id); isSet = true; } catch (SqlException) { ++retryCount; Wait(); } } if (!isSet) { Log.Error("EXCEPTION: CRITICAL ERROR ALERT! What to do with unset (Sets the communication package send flag to true) SetXmlSentWithRetry(Guid id) PackageSender.cs"); } } }
/// <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(); } }