/// <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> /// Asks web service for next communication package. /// </summary> /// <param name="lastReceivedXmlId">The last received communication package id.</param> /// <param name="databaseId">The database id.</param> private GetDataResponse GetNextXmlPackage(Guid?lastReceivedXmlId, Guid databaseId) { bool facadehelper_DisableThisCodeForDebugCondition = facadehelper_DisableThisCodeForDebugConditionSwitch; if (!facadehelper_DisableThisCodeForDebugCondition) { try { RoboFramework.Tools.RandomLogHelper.GetLog().Debug("PackageReceiver.cs - CommunicationServiceProxy.Instance.GetData(data)"); using (Message data = SynchronizationHelper.CreateMessage(new GetDataParameters { LastReceivedXmlId = lastReceivedXmlId, DatabaseId = databaseId }, "GetData", CommunicationServiceProxy.ProxyFactory.Endpoint.Binding.MessageVersion)) { GetDataResponse response = SynchronizationHelper.GetData <GetDataResponse>(CommunicationServiceProxy.Instance.GetData(data)); if (response == null) { return(GetDataResponse.EmptyResponse); } else { return(response); } } } 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 how often this happens. return(GetDataResponse.ExceptionResponse); } catch (CommunicationException e) { Log.Error(e.ToString()); return(GetDataResponse.ExceptionResponse); } } else { return(GetDataResponse.EmptyResponse); } }
/// <summary> /// Task main method. /// </summary> /// <remarks> /// Run method steps: /// 1. Sends gathered communication statistics. /// ... where are 2 and 3? /// 4. Waits before repeating process. /// </remarks> protected override void Run() { bool facadehelper_DisableThisCodeForDebugCondition = facadehelper_DisableThisCodeForDebugConditionSwitch; if (!facadehelper_DisableThisCodeForDebugCondition) { while (IsEnabled) { try { Wait(); lock (Makolab.Fractus.Communication.Transmitter.TransmitterSemaphore.locker) { CommunicationStatistics stats = GetStatistics(); stats.CurrentTime = DateTime.Now; RoboFramework.Tools.RandomLogHelper.GetLog().Debug("StatisticsUpdater: CommunicationServiceProxy.Instance.SendData(...)"); CommunicationServiceProxy.Instance.SendData(SynchronizationHelper.CreateMessage(new SendDataParameters { Statistics = stats, DepartmentIdentifier = this.Manager.DatabaseId }, "SendData", CommunicationServiceProxy.ProxyFactory.Endpoint.Binding.MessageVersion)); } } catch (TimeoutException e) { if (this.SenderLogger != null) { this.SenderLogger.Log.Error(e.ToString()); // TODO -1 change to false when we will have a general view often this happens. } } catch (System.ServiceModel.CommunicationException e) { if (this.SenderLogger != null) { this.SenderLogger.Log.Error(e.ToString()); } } catch (Exception e) { SenderLogger.Error(String.Format(CultureInfo.InvariantCulture, "Uncaught exception in StatisticsUpdater: {0}", e.ToString())); //throw; } } } }