예제 #1
0
        /// <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);
            }
        }
예제 #2
0
        /// <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);
            }
        }