private static bool SendTransaction(PCSStagingDataContext dc, Transaction _Transaction)
        {
            Log.LogInfoMessage(string.Format("[Enter] sending previously sent transaction Lane{0} Sequence{1}", _Transaction.LaneCode, _Transaction.LaneTransSeqNr));

            var syncTransaction = new Intertoll.Data.Transaction();

            // Account user details
            if (!(string.IsNullOrWhiteSpace(_Transaction.FrequentUserPANNumber)))
            {
                var accountuser = dc.GetAccountUserDetails(_Transaction.FrequentUserPANNumber);

                if (accountuser == null)
                {
                    Log.LogFatal("Account user details not found PAN: " + _Transaction.FrequentUserPANNumber);
                    return(false);
                }
                syncTransaction.AccountGUID     = accountuser.AccountGUID;
                syncTransaction.AccountUserGUID = accountuser.AccountUserGUID;
            }

            Log.LogTrace("SessioGuid: " + _Transaction.SessionGuid);

            //add transaction
            syncTransaction.AppliedClassGUID = _Transaction.CollectorClass;
            syncTransaction.AVCClassGUID     = _Transaction.AVCClass;
            syncTransaction.AVCSeqNr         = _Transaction.AVCSeqNr;
            syncTransaction.ColClassGUID     = _Transaction.CollectorClass;
            syncTransaction.CurrencyGUID     = new Guid("942190CD-5053-41B4-9A08-CD472C99ECAF");
            syncTransaction.ExchangeRate     = new Guid("5A5AE37F-AABC-428D-B4DC-2B4C87B8646C");
            syncTransaction.IsKeyed          = _Transaction.IsKeyed.HasValue && (bool)_Transaction.IsKeyed;

            syncTransaction.LaneTransSeqNr = (int)(_Transaction.LaneTransSeqNr);
            syncTransaction.LicensePlate   = _Transaction.LicensePlate;
            syncTransaction.PaymentDetail  = EncryptString(_Transaction.LaneCode, _Transaction.BankCardNumber, GetExpiryDateFromTrack2(_Transaction.BankCardExpiryDate, _Transaction.BankCardNumber));


            syncTransaction.PaymentGroupGUID          = new Guid(_Transaction.PaymentGroup);
            syncTransaction.PaymentMechGUID           = new Guid(_Transaction.PaymentMech);
            syncTransaction.PaymentMethodGUID         = new Guid(_Transaction.PaymentMethod);
            syncTransaction.PaymentTypeGUID           = new Guid(_Transaction.PaymentType);
            syncTransaction.PreviousLicensePlate      = null;
            syncTransaction.PreviousPaymentMethodGUID = null;
            syncTransaction.RealClassGUID             = null;
            syncTransaction.ReceiptCount          = _Transaction.ReceiptCount.HasValue ? _Transaction.ReceiptCount : null;
            syncTransaction.ReceiptTaxInvoiceDate = _Transaction.ReceiptTaxInvoiceDate;
            syncTransaction.SessionGUID           = _Transaction.SessionGuid;
            syncTransaction.TariffAmount          = _Transaction.TariffAmount;
            syncTransaction.TariffGUID            = _Transaction.TariffGuid;
            syncTransaction.TariffVat             = 0;
            syncTransaction.TaxInvNr             = _Transaction.TaxInvNr;
            syncTransaction.TotalInLocalCurrency = _Transaction.TariffAmount;
            syncTransaction.TransDate            = _Transaction.TransactionDate;
            syncTransaction.TransStartDate       = _Transaction.TransactionStartDate;
            syncTransaction.TransGUID            = _Transaction.TransGuid;
            syncTransaction.AVCDetail            = _Transaction.AvcStatus;

            if (_Transaction.ETCTransactionGUID.HasValue)
            {
                var etcTransaction = new Intertoll.Data.ETCTransaction();
                var IAuthenticator = new Intertoll.Data.ETCIAuthenticator();
                var OAuthenticator = new Intertoll.Data.ETCOAuthenticator();

                IAuthenticator.Authenticator     = _Transaction.IssuerAuthenticator_DData;
                IAuthenticator.AuthenticatorGuid = _Transaction.IssuerAuthenticatorGuid.Value;
                IAuthenticator.KeyRef            = _Transaction.IssuerAuthenticator_KRef;
                IAuthenticator.Nonce             = _Transaction.IssuerAuthenticator_MAC; //TODO ??Confirm

                OAuthenticator.Authenticator     = _Transaction.OperatorAuthenticator_DData;
                OAuthenticator.AuthenticatorGuid = _Transaction.OperatorAuthenticatorGuid.Value;
                OAuthenticator.KeyRef            = _Transaction.OperatorAuthenticator_KRef;
                OAuthenticator.Nonce             = _Transaction.OperatorAuthenticator_MAC; //TODO ??Confirm

                etcTransaction.ClassGUID = _Transaction.TagClass.HasValue ? LookupManager.Classes((Int32)_Transaction.TagClass) :
                                           new Guid("57C3EBAF-AD68-46CB-B048-3E9E9F1D5F74");
                etcTransaction.ContextMarkId      = short.Parse(_Transaction.ContextMark);
                etcTransaction.ETCTransactionGuid = _Transaction.ETCTransactionGUID.Value;
                etcTransaction.ExpiryDate         = string.Empty;
                etcTransaction.IDVL = (long)_Transaction.IDVL;
                etcTransaction.IssuerAuthenticatorGuid   = IAuthenticator.AuthenticatorGuid;
                etcTransaction.LaneTransSeqNr            = _Transaction.LaneTransSeqNr;
                etcTransaction.LicensePlate              = _Transaction.LicensePlate;
                etcTransaction.OperatorAuthenticatorGuid = OAuthenticator.AuthenticatorGuid;
                etcTransaction.PAN           = long.Parse(_Transaction.PAN);
                etcTransaction.VehichleState = _Transaction.TagStatus;

                syncTransaction.ETCTransactionGuid = etcTransaction.ETCTransactionGuid;

                Sync.Client.SyncClient.SubmitETCTransaction(syncTransaction, etcTransaction, IAuthenticator, OAuthenticator);
            }
            else
            {
                Sync.Client.SyncClient.SubmitTransaction(syncTransaction);
            }

            Log.LogInfoMessage(string.Format("[Exit] sending previously sent transaction Lane{0} Sequence{1}", _Transaction.LaneCode, _Transaction.LaneTransSeqNr));

            return(true);
        }
        private static bool SendTransaction(PCSStagingDataContext dc, uspGetTransactionByLaneAndSeq_Result TransactionData)
        {
            Log.LogInfoMessage(string.Format("[Enter] sending transaction Lane{0} Sequence{1}", TransactionData.LaneCode, TransactionData.LaneTransSeqNr));

            var syncTransaction = new Intertoll.Data.Transaction();

            // Account user details
            if (!(string.IsNullOrWhiteSpace(TransactionData.FrequentUserPANNumber)))
            {
                var accountuser = dc.GetAccountUserDetails(TransactionData.FrequentUserPANNumber);

                if (accountuser == null)
                {
                    Log.LogFatal("Account user details not found PAN: " + TransactionData.FrequentUserPANNumber);
                    return(false);
                }
                syncTransaction.AccountGUID     = accountuser.AccountGUID;
                syncTransaction.AccountUserGUID = accountuser.AccountUserGUID;
            }

            // Session
            var session = dc.Sessions.FirstOrDefault(x => x.StartDate <= TransactionData.TransactionDate &&
                                                     (x.EndDate >= TransactionData.TransactionDate || x.EndDate == null) &&
                                                     x.LaneCode == TransactionData.LaneCode)
            ;

            if (session == null)
            {
                Log.LogFatal(string.Format("Session not found: time({0}),lane({1})", TransactionData.TransactionDate, TransactionData.LaneCode));
                return(false);
            }

            Log.LogTrace("SessioGuid: " + session.SessionGUID);

            //add transaction
            syncTransaction.AppliedClassGUID = TransactionData.CollectorClass.MappedClass();
            syncTransaction.AVCClassGUID     = TransactionData.AVCClass.MappedClass();
            syncTransaction.AVCSeqNr         = (int)TransactionData.AVCSeqNr;
            syncTransaction.ColClassGUID     = TransactionData.CollectorClass.MappedClass();
            syncTransaction.CurrencyGUID     = new Guid("942190CD-5053-41B4-9A08-CD472C99ECAF");
            syncTransaction.ExchangeRate     = new Guid("5A5AE37F-AABC-428D-B4DC-2B4C87B8646C");
            syncTransaction.IsKeyed          = TransactionData.IsKeyed.HasValue && (bool)TransactionData.IsKeyed;

            syncTransaction.LaneTransSeqNr = (int)(TransactionData.LaneTransSeqNr);
            syncTransaction.LicensePlate   = TransactionData.LicensePlate;
            syncTransaction.PaymentDetail  = EncryptString(TransactionData.LaneCode, TransactionData.BankCardNumber, GetExpiryDateFromTrack2(TransactionData.BankCardExpiryDate, TransactionData.BankCardNumber));


            syncTransaction.PaymentGroupGUID          = TransactionData.PaymentGroup.MappedPaymentGroup();
            syncTransaction.PaymentMechGUID           = TransactionData.PaymentMech.MappedPaymentMech();
            syncTransaction.PaymentMethodGUID         = TransactionData.PaymentMethod.MappedPaymentMethod();
            syncTransaction.PaymentTypeGUID           = TransactionData.PaymentType.MappedPaymentType();
            syncTransaction.PreviousLicensePlate      = null;
            syncTransaction.PreviousPaymentMethodGUID = null;
            syncTransaction.RealClassGUID             = null;
            syncTransaction.ReceiptCount          = TransactionData.ReceiptCount.HasValue ? (int)TransactionData.ReceiptCount : (int?)null;
            syncTransaction.ReceiptTaxInvoiceDate = TransactionData.ReceiptTaxInvoiceDate;
            syncTransaction.SessionGUID           = session.SessionGUID;
            syncTransaction.TariffAmount          = (decimal)TransactionData.TariffAmount;
            syncTransaction.TariffGUID            = TransactionData.VirtualPlazaID.MappedTariff(TransactionData.CollectorClass, TransactionData.TollTariffPlanID);;
            syncTransaction.TariffVat             = 0;
            syncTransaction.TaxInvNr             = TransactionData.TaxInvNr;
            syncTransaction.TotalInLocalCurrency = (decimal)TransactionData.TariffAmount;
            syncTransaction.TransDate            = TransactionData.TransactionDate;
            syncTransaction.TransStartDate       = TransactionData.TransactionStartDate;
            syncTransaction.TransGUID            = Guid.NewGuid();
            syncTransaction.AVCDetail            = TransactionData.AvcStatus;

            if (!(string.IsNullOrWhiteSpace(TransactionData.ETCTransactionGUID)))
            {
                var etcTransaction = new Intertoll.Data.ETCTransaction();
                var IAuthenticator = new Intertoll.Data.ETCIAuthenticator();
                var OAuthenticator = new Intertoll.Data.ETCOAuthenticator();

                IAuthenticator.Authenticator     = TransactionData.IssuerAuthenticator_DData;
                IAuthenticator.AuthenticatorGuid = Guid.NewGuid();
                IAuthenticator.KeyRef            = TransactionData.IssuerAuthenticator_KRef.ToString();
                IAuthenticator.Nonce             = TransactionData.IssuerAuthenticator_MAC; //TODO ??Confirm

                OAuthenticator.Authenticator     = TransactionData.OperatorAuthenticator_DData;
                OAuthenticator.AuthenticatorGuid = Guid.NewGuid();
                OAuthenticator.KeyRef            = TransactionData.OperatorAuthenticator_KRef.ToString();
                OAuthenticator.Nonce             = TransactionData.OperatorAuthenticator_MAC; //TODO ??Confirm

                etcTransaction.ClassGUID = TransactionData.TagClass.HasValue ? LookupManager.Classes((Int32)TransactionData.TagClass) :
                                           new Guid("57C3EBAF-AD68-46CB-B048-3E9E9F1D5F74");
                etcTransaction.ContextMarkId      = short.Parse(TransactionData.ContextMark);
                etcTransaction.ETCTransactionGuid = Guid.Parse(TransactionData.ETCTransactionGUID);
                etcTransaction.ExpiryDate         = string.Empty;
                etcTransaction.IDVL = (long)TransactionData.IDVL;
                etcTransaction.IssuerAuthenticatorGuid   = IAuthenticator.AuthenticatorGuid;
                etcTransaction.LaneTransSeqNr            = TransactionData.LaneTransSeqNr;
                etcTransaction.LicensePlate              = TransactionData.LicensePlate;
                etcTransaction.OperatorAuthenticatorGuid = OAuthenticator.AuthenticatorGuid;
                etcTransaction.PAN           = long.Parse(TransactionData.PAN);
                etcTransaction.VehichleState = TransactionData.TagStatus;

                syncTransaction.ETCTransactionGuid = etcTransaction.ETCTransactionGuid;

                SaveTransaction(syncTransaction, etcTransaction, IAuthenticator, OAuthenticator, TransactionData);
                Sync.Client.SyncClient.SubmitETCTransaction(syncTransaction, etcTransaction, IAuthenticator, OAuthenticator);
            }
            else
            {
                SaveTransaction(syncTransaction, new Intertoll.Data.ETCTransaction(), new Intertoll.Data.ETCIAuthenticator(), new Intertoll.Data.ETCOAuthenticator(), TransactionData);
                Sync.Client.SyncClient.SubmitTransaction(syncTransaction);
            }

            Log.LogInfoMessage(string.Format("[Exit] sending transaction Lane{0} Sequence{1}", TransactionData.LaneCode, TransactionData.LaneTransSeqNr));

            return(true);
        }