public IActionResult ApproveReferenceOrder(ApproveIdRequest request)
        {
            if (ModelState.IsValid)
            {
                var response = new SingleResponse <long>();

                ReferenceOrder order  = _cacheHelper.GetApprovalOrder <ReferenceOrder>(request.Id);
                ActionResult   result = _xbService.ApproveReferenceOrder(order);
                response.Result      = result.Id;
                response.ResultCode  = ResultCodeFormatter.FromPersonalAccountSecurityService(result.ResultCode);
                response.Description = utils.GetActionResultErrors(result.Errors);
                return(ResponseExtensions.ToHttpResponse(response));
            }
            else
            {
                return(ValidationError.GetValidationErrorResponse(ModelState));
            }
        }
Beispiel #2
0
        ///<summary>
        /// This method launches DocProcessor and handles document processing.
        /// </summary>
        /// <remarks>
        /// Each *FileName parameter is converted to full file path inside of this method. In other 
        /// case this may lead to file-not-found exception during Word or Excel interoperation (external 
        /// processes may have different current directories, that's why relative pathes may not work).
        /// </remarks>
        private static void ProcessDoc(string sourceFileName, string destFileName, string refFileName, ReferenceOrder order)
        {
            var refFile = Path.GetFullPath(refFileName);
            var srcFile = Path.GetFullPath(sourceFileName);
            var destFile = Path.GetFullPath(destFileName);

            LogWriteLine("{0} % {1} -> {2}".Fill(Path.GetFileName(sourceFileName),
                Path.GetFileName(refFileName), Path.GetFileName(destFileName)));

            LogWrite("Reading references from {0} ({1})... ".
                Fill(Path.GetFileName(refFile), refFile.GetFileSize().ToFormattedFileSize()));

            var refs = ReadReferences(refFile);

            try
            {
                ValidateReferences(refs);
            }
            catch(Exception ex)
            {
                LogWriteLine("\n{0}\n{1}".Fill(ex.Message, "Processing stopped."));
                return;
            }

            LogWriteLine("Done. Got {0} records.".Fill(refs.Count));
            LogWriteLine("Opening {0} ({1})...".Fill(Path.GetFileName(srcFile), srcFile.GetFileSize().ToFormattedFileSize()));

            using (var proc = new DocProcessor(srcFile, refs, order))
            {
                proc.Message += OnMessage;
                ReportProcState(proc);

                try
                {
                    proc.Process(destFile);
                }
                catch (Exception ex)
                {
                    LogWriteLine("Error: " + ex.Message);
                }
            }
        }
Beispiel #3
0
        public DocProcessor(string fileName, ReferenceCollection refs, ReferenceOrder order)
        {
            if (fileName.IsNullOrBlank()) throw new ArgumentException("fileName");
            if (refs.IsNullOrEmpty()) throw new ArgumentException("refs");

            _word = new Application {Visible = false};
            _refs = refs;
            _order = order;

            try
            {
                _doc = _word.Documents.Open(fileName, ReadOnly: true);
            }
            catch(Exception ex)
            {
                throw new Exception("Error opening Word document", ex);
            }

            _rep = new ReferenceReplacer(_doc.Content.Text, ref _refs, _order);
        }
Beispiel #4
0
        public ReferenceReplacer(string text, ref ReferenceCollection references, ReferenceOrder order)
        {
            _usedReferences = new ReferenceCollection();
            _badIds = new HashSet<string>();
            _unknownIds = new HashSet<int>();
            _unknownTags = new HashSet<string>();
            _replacements = new Dictionary<string, Reference[]>();

            var re = new Regex(@"\[\[(([" + RefIdPrefix + @"\d\w\s" + RefDelimiter + @"]+)?)\]\]", RegexOptions.IgnoreCase);

            foreach (Match match in re.Matches(text))
            {
                var refText = match.Groups[0].Captures[0].Value;
                var refList = match.Groups[1].Captures[0].Value;

                if (_replacements.ContainsKey(refText)) continue;

                var parts = refList.Split(new[] {RefDelimiter}, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length < 1)
                {
                    // Replacements with no references supposed to be deleted from document
                    _replacements.Add(refText, null);
                    continue;
                }

                var refs = new HashSet<Reference>();

                foreach (var part in parts.Select(part => part.Trim()).Where(p => p.Length != 0))
                {
                    Reference reference;
                    if (part[0] == '#')
                    {
                        int id;
                        if (!Int32.TryParse(part.Substring(1), NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.InvariantCulture, out id))
                        {
                            _badIds.Add(part);
                            continue;
                        }

                        reference = references.GetById(id);

                        if (reference == null)
                        {
                            _unknownIds.Add(id);
                            continue;
                        }
                    }
                    else
                    {
                        reference = references.GetByTag(part);

                        if (reference == null)
                        {
                            _unknownTags.Add(part);
                            continue;
                        }
                    }

                    refs.Add(reference);
                    if (!_usedReferences.Contains(reference))
                    {
                        _usedReferences.Add(reference);
                    }
                }

                _replacements.Add(refText, refs.ToArray());
            }

            _usedReferences.Sort(order);
            for (var i = 0; i < _usedReferences.Count; i++)
            {
                _usedReferences[i].RefNum = i + 1;
            }
        }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            ApproveIdRequest                     request          = null;
            ProductIdApproveRequest              productIdRequest = null;
            ApproveLoanProductOrderRequest       approveLoan      = null;
            ListDocIdRequest                     listRequest      = null;
            Dictionary <long, ApprovalOrderType> Types            = new Dictionary <long, ApprovalOrderType>();
            string sessionId = "";
            string otp       = "";
            byte   language  = 0;
            bool   isSigned  = false;
            string ipAddress = "";
            Dictionary <string, string> signData = null;
            SourceType sourceType = SourceType.NotSpecified;

            // հայտի մուտքագրման աղբյուրի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["SourceType"]))
            {
                Enum.TryParse(context.HttpContext.Request.Headers["SourceType"], out sourceType);
            }


            // Սեսիայի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["SessionId"]))
            {
                sessionId = context.HttpContext.Request.Headers["SessionId"];
            }


            // Լեզվի ստացում Header-ից
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["language"]))
            {
                byte.TryParse(context.HttpContext.Request.Headers["language"], out language);
            }

            // IP հասցեի ստացում
            if (!string.IsNullOrEmpty(context.HttpContext.Request.Headers["LocalIPAddress"]))
            {
                ipAddress = context.HttpContext.Request.Headers["LocalIPAddress"];
            }

            // Փոխանցված պարամետրի ստացում
            var argument = context.ActionArguments.Values.First();

            //Approve մեթոդների համար
            if (argument is ApproveIdRequest)
            {
                request = argument as ApproveIdRequest;
                Types.Add(request.Id, _type);
                otp = request.OTP;
            }
            //ApproveOrders մեթոդի համար
            else if (argument is ListDocIdRequest)
            {
                listRequest = argument as ListDocIdRequest;
                foreach (var item in listRequest.ListDocId)
                {
                    Types.Add(item, GetOrderType(_xbService.GetDocumentType(item)));
                }
                otp = listRequest.OTP;
            }
            else if (argument is ProductIdApproveRequest)
            {
                productIdRequest = argument as ProductIdApproveRequest;
                Types.Add((long)productIdRequest.ProductId, _type);
                otp = productIdRequest.OTP;
            }
            else if (argument is ApproveLoanProductOrderRequest)
            {
                approveLoan = argument as ApproveLoanProductOrderRequest;
                Types.Add(approveLoan.Id, _type);
                otp = approveLoan.OTP;
            }

            //Հայտի ստեղծում, քեշավորում, և Sign լինող պարամետրերի փոխանցում
            foreach (var x in Types)
            {
                switch (x.Value)
                {
                case ApprovalOrderType.PaymentOrder:
                {
                    PaymentOrder order = (PaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), order.ReceiverAccount.AccountNumber.ToString(),
                                      Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PlasticCardOrder:
                {
                    PlasticCardOrder order = (PlasticCardOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPlasticCardOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.PlasticCard.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.UtilityPaymentOrder:
                {
                    UtilityPaymentOrder order = (UtilityPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetUtilityPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.MatureOrder:
                {
                    MatureOrder order = (MatureOrder)_cacheHelper.SetApprovalOrder(_xbService.GetMatureOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.Account.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReferenceOrder:
                {
                    ReferenceOrder order = (ReferenceOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReferenceOrder(x.Key));
                    if (order.FeeAccount != null)
                    {
                        CollectParameters(order.Id.ToString(), order.FeeAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.LoanProductOrder:
                {
                    LoanProductOrder order = null;
                    var type = _xbService.GetDocumentType((int)x.Key);
                    switch (type)
                    {
                    case OrderType.CreditSecureDeposit:
                        order = (LoanProductOrder)_cacheHelper.SetApprovalOrder(_xbService.GetLoanOrder(x.Key));
                        break;

                    default:
                        order = (LoanProductOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCreditLineOrder(x.Key));
                        break;
                    }
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReceivedFastTransferPaymentOrder:
                {
                    ReceivedFastTransferPaymentOrder order = (ReceivedFastTransferPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReceivedFastTransferPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", order.ReceiverAccount.AccountNumber.ToString(), Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountClosingOrder:
                {
                    AccountClosingOrder order = (AccountClosingOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountClosingOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.SwiftCopyOrder:
                {
                    SwiftCopyOrder order = (SwiftCopyOrder)_cacheHelper.SetApprovalOrder(_xbService.GetSwiftCopyOrder(x.Key));
                    if (order.FeeAccount != null)
                    {
                        CollectParameters(order.Id.ToString(), order.FeeAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.CredentialOrder:
                {
                    CredentialOrder order = (CredentialOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCredentialOrder(x.Key));
                    if (order.Fees != null && order.Fees[0] != null && order.Fees[0].Account != null)
                    {
                        CollectParameters(order.Id.ToString(), order.Fees[0].Account.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                    else
                    {
                        CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                    }
                }
                break;

                case ApprovalOrderType.DepositOrder:
                {
                    DepositOrder order = (DepositOrder)_cacheHelper.SetApprovalOrder(_xbService.GetDepositorder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountOrder:
                {
                    AccountOrder order = (AccountOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.CashOrder:
                {
                    CashOrder order = (CashOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCashOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CreditLineTerminationOrder:
                {
                    CreditLineTerminationOrder order = (CreditLineTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCreditLineTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Currency, ipAddress);
                }
                break;

                case ApprovalOrderType.CardClosingOrder:
                {
                    CardClosingOrder order = (CardClosingOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardClosingOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CustomerDataOrder:
                {
                    CustomerDataOrder order = (CustomerDataOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCustomerDataOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.Password, ipAddress);
                }
                break;

                case ApprovalOrderType.StatmentByEmailOrder:
                {
                    StatmentByEmailOrder order = (StatmentByEmailOrder)_cacheHelper.SetApprovalOrder(_xbService.GetStatmentByEmailOrder(x.Key));
                }
                break;

                case ApprovalOrderType.DepositTerminationOrder:
                {
                    DepositTerminationOrder order = (DepositTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetDepositTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ReestrTransferOrder:
                {
                    ReestrTransferOrder order = (ReestrTransferOrder)_cacheHelper.SetApprovalOrder(_xbService.GetReestrTransferOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.ArcaCardsTransactionOrder:
                {
                    ArcaCardsTransactionOrder order = (ArcaCardsTransactionOrder)_cacheHelper.SetApprovalOrder(_xbService.GetArcaCardsTransactionOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.CardNumber.Substring(0, 10), "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.CardToCardOrder:
                {
                    CardToCardOrder order = (CardToCardOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardToCardOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitCardNumber.Substring(0, 10), order.CreditCardNumber, Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CardLimitChangeOrder:
                {
                    CardLimitChangeOrder order = (CardLimitChangeOrder)_cacheHelper.SetApprovalOrder(_xbService.GetCardLimitChangeOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", Math.Truncate(order.Limits[0].LimitValue).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicPaymentOrder:
                {
                    PaymentOrder order = (PaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), "0", Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.InternationalPaymentOrder:
                {
                    InternationalPaymentOrder order = (InternationalPaymentOrder)_cacheHelper.SetApprovalOrder(_xbService.GetInternationalPaymentOrder(x.Key));
                    CollectParameters(order.Id.ToString(), order.DebitAccount.AccountNumber.ToString(), order.ReceiverAccount.AccountNumber.ToString(),
                                      Math.Truncate(order.Amount).ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.AccountReOpenOrder:
                {
                    AccountReOpenOrder order = (AccountReOpenOrder)_cacheHelper.SetApprovalOrder(_xbService.GetAccountReOpenOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.PlasticCardSmsServiceOrder:
                {
                    PlasticCardSMSServiceOrder order = (PlasticCardSMSServiceOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPlasticCardSMSServiceOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductID.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.RemovalOrder:
                {
                    RemovalOrder order = context.ActionArguments.Values.First() as RemovalOrder;
                    CollectParameters("0", order.RemovingOrderId.ToString(), "0", "0", ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicTerminationOrder:
                {
                    PeriodicTerminationOrder order = (PeriodicTerminationOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPeriodicTerminationOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.PeriodicDataChangeOrder:
                {
                    PeriodicTransferDataChangeOrder order = (PeriodicTransferDataChangeOrder)_cacheHelper.SetApprovalOrder(_xbService.GetPeriodicDataChangeOrder(x.Key));
                    CollectParameters(order.Id.ToString(), "0", "0", order.ProductId.ToString(), ipAddress);
                }
                break;

                case ApprovalOrderType.CardActivationOrder:
                {
                    CollectParameters(x.Key.ToString(), "0", "0", "0", ipAddress);
                }
                break;

                default:
                    break;
                }
            }
            ;

            //CheckSign Filter-ն անհրաժեշտ է աշխատի միայն sourceType-ը 5-ի՝ MobileBanking-ի դեպքում
            if (sourceType != SourceType.MobileBanking)
            {
                return;
            }
            else
            {
                signData = this.GenerateSignData(TransactionID, SenderAccount, RecepientAccount, Amount, IpAddress);
            }

            isSigned = _xbSecurityService.SingData(sessionId, otp, signData, language);

            //թեստային միջավայրի համար
            if ((sessionId == "ba0f312d-8487-445e-aee2-d5877ac1d4de" || otp == "0123456") && Convert.ToBoolean(_config["TestVersion"]))
            {
                return;
            }
            if (!isSigned)
            {
                Response response = new Response();
                response.ResultCode  = ResultCodes.validationError;
                response.Description = (Languages)language == Languages.hy ? "Սխալ PIN կոդ։" : "Incorrect PIN code.";
                context.Result       = ResponseExtensions.ToHttpResponse(response);
            }
        }