public void DoAutoReversal()
        {
            var allLogsThatNeedsReversal = new TransactionLogManager().GetAllThatNeedsReversal();
               Iso8583Message msgFromFEP = null;
               bool needReversal = true;
               Dictionary<string, SinkNode> allSinkNodes = new SinkNodeManager().GetAllSinkNode().ToDictionary(x => x.Name);
               Dictionary<string, SourceNode> allSourceNodes = new SourceNodeManager().RetrieveAll().ToDictionary(x => x.Name);
               foreach (var log in allLogsThatNeedsReversal)
               {
               if (!log.IsReversed && log.IsReversePending)
               {
                   Iso8583Message revMsg = BuildReversalIsoMessage(log);
                   Logger.LogTransaction(revMsg);
                   if (log.SinkNode != null)
                   {
                       var sinkNode = allSinkNodes[log.SinkNode];
                       msgFromFEP = ToFEP(revMsg, sinkNode, out needReversal); //TOFEP should set needReversal to false

                       if (msgFromFEP.Fields[39].ToString() == "00")
                       {
                           Logger.LogTransaction(msgFromFEP, allSourceNodes[log.SourceNode], null, null, needReversal);
                       }
                   }

                   if (!needReversal)
                   {
                       log.IsReversePending = false;
                       log.IsReversed = true;
                       new TransactionLogManager().Update(log);
                       Logger.Log("Auto Reversal done for: " + log.OriginalDataElement);
                   }
               }
               if (log.IsReversed)
               {
                   log.IsReversePending = false;
                   log.IsReversed = true;
                   new TransactionLogManager().Update(log);
               }
               }
        }
        private Iso8583Message GetReversalMessage(Iso8583Message isoMessage, out bool conReversal)
        {
            conReversal = true;
               string originalDataElement;
               try
               {
               originalDataElement = isoMessage.Fields[90].ToString();
               }
               catch (Exception)
               {
               Logger.Log("Original data element is empty");
               conReversal = false;
               SetReponseMessage(isoMessage, "12");
               isoMessage.MessageTypeIdentifier = 430;
               return isoMessage;
               }

               //originalDataElement = originalDataElement.Remove(0, 23);
               TransactionLog transactionLog = new TransactionLogManager().GetByOriginalDataElement(originalDataElement, out originalDataElement);
               Logger.Log("Original Data Element: " + originalDataElement);
               if (transactionLog == null)
               {
               Logger.Log("\n Transaction log not found");
               conReversal = false;
               SetReponseMessage(isoMessage, "25");
               isoMessage.MessageTypeIdentifier = 430;
               return isoMessage;
               }

               if (transactionLog.IsReversed)
               {
               Logger.Log("\n Transaction has already been reversed");
               conReversal = false;
               SetReponseMessage(isoMessage, "94");
               return isoMessage;
               }

               Logger.Log("\n Continue with reversal");
               isoMessage.Fields.Add(102, transactionLog.Account2);
               isoMessage.Fields.Add(103, transactionLog.Account1);

               return isoMessage;
        }