Example #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);
            }
        }
Example #2
0
        /// <summary>
        /// Process data that was received by web service method.
        /// </summary>
        /// <param name="data">The data received via web service method call.</param>
        /// <returns>Response to web service client.</returns>
        public object DataReceived(object data)
        {
            SendDataParameters methodParams = (SendDataParameters)data;

            if (methodParams == null)
            {
                return(null);
            }

            SendDataResponse response = new SendDataResponse();

            ICommunicationPackage communicationPackage = (methodParams.Xml == null) ? null : CreateCommunicationPackage(methodParams);

            DatabaseConnector.DatabaseConnectorManager dbm = GetDatabaseConnector();
            dbm.StartModule();
            try
            {
                using (IUnitOfWork uow = new UnitOfWork(dbm))
                {
                    uow.MapperFactory = IoC.Get <IMapperFactory>();
                    uow.StartTransaction(IsolationLevel.Serializable);

                    CommunicationPackageRepository repo = new CommunicationPackageRepository(uow);
                    if (communicationPackage != null)
                    {
                        repo.Add(communicationPackage);
                    }
                    if (methodParams.IsLastInTransaction)
                    {
                        repo.MarkTransactionAsCompleted(communicationPackage.XmlData.LocalTransactionId);
                    }
                    if (methodParams.Statistics != null)
                    {
                        repo.UpdateStatistics(methodParams.Statistics, methodParams.DepartmentIdentifier);
                    }

                    uow.SubmitChanges();
                }
            }
            catch (System.Data.SqlClient.SqlException e)
            {
                response.Result = false;
                Log.Error(e.ToString(), false);
                return(response);
            }
            catch (CommunicationPackageExistsException e) //Xml already in database.
            {
                Log.Info(e.ToString(), false);
            }
            finally
            {
                dbm.StopModule();
            }

            response.Result = true;
            return(response);
        }