/// <summary> /// Sends specified communication package. /// </summary> /// <param name="xml">The comunication package.</param> /// <param name="isLastPackage">if set to <c>true</c> it's last package in transaction.</param> /// <returns><c>true</c> if send is successful; otherwise, <c>false</c>.</returns> private bool SendPackage(ICommunicationPackage xml, bool isLastPackage) { xml.Compress(); try { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("PackageSender.cs - SendPackage(ICommunicationPackage xml, bool isLastPackage)"); Message result = CommunicationServiceProxy.Instance.SendData( SynchronizationHelper.CreateMessage( new SendDataParameters { Xml = xml.XmlData, IsLastInTransaction = isLastPackage, DepartmentIdentifier = xml.DatabaseId.Value }, "SendData", CommunicationServiceProxy.ProxyFactory.Endpoint.Binding.MessageVersion)); SendDataResponse response = SynchronizationHelper.GetData <SendDataResponse>(result); if (response == null) { return(false); } if (response.AdditionalData != null && response.AdditionalData.UndeliveredPackagesQuantity != null) { Manager.Receiver.WaitingPackages = response.AdditionalData.UndeliveredPackagesQuantity.Value; } return(response.Result); } catch (MessageSecurityException mse) { Log.Info("WCF MessageSecurityException"); Log.Info(mse.ToString()); Log.Info("================================================================="); try { CommunicationServiceProxy.ProxyFactory.Close(); } catch { try { CommunicationServiceProxy.ProxyFactory.Abort(); } catch { } } throw; } catch (TimeoutException e) { Log.Error(e.ToString(), true); // TODO -1 change to false when we will have a general view often this happens. return(false); } catch (System.ServiceModel.CommunicationException e) { Log.Error(e.ToString()); return(false); } }
/// <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(); } }