public AmazonSearcher(List <string> faceFileNames, List <string> dates, ProjectConfigData configData)
        {
            this.dates                 = dates;
            this.awsAccessKeyId        = configData.awsAccessKeyId;
            this.awsSecretAccessKey    = configData.awsSecretAccessKey;
            this.awsRegionEndpoint     = Amazon.RegionEndpoint.GetBySystemName(configData.awsEndpoint);//("eu-west-1");
            this.awsCollectionId       = configData.awsCollectionId;
            this.awsFaceMatchThreshold = configData.awsFaceMatchThreshold;
            this.awsSimilarityLevel    = configData.awsSimilarityLevel;

            if (faceFileNames.Count > 1)
            {
                var tasks = new List <Task <List <Guid> > >();

                for (int i = 0; i < faceFileNames.Count; i++)
                {
                    tasks.Add(Task.Run(async() => SearchOneFace(faceFileNames[i])));
                }

                searchedFaceIds = Task.WhenAll(tasks).Result; // количество списков равное кол-ву поисковых лиц
            }
            else
            {
                searchedFaceIds = new List <Guid>[] { SearchOneFace(faceFileNames[0]) }
            };
        }
        public OrderPayment(OrderPaymentRequestFrontEnd request, string sessionInfo, ProjectConfigData configData)
        {
            response = new OrderPaymentResponseBackEnd();
            if (String.IsNullOrEmpty(request.requestId))
            {
                response.requestId = Guid.NewGuid().ToString();
            }
            else
            {
                response.requestId = request.requestId;
            }

            try
            {
                if (!String.IsNullOrEmpty(request.orderNumber) && !String.IsNullOrEmpty(request.mainEmail))
                {
                    string pattern     = @"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
                    Regex  r           = new Regex(pattern, RegexOptions.IgnoreCase);
                    bool   mainMatched = r.Match(request.mainEmail).Success; // true в случае подтверждения совпадения

                    bool backupMatched = false;
                    if (!String.IsNullOrEmpty(request.backupEmail))
                    {
                        backupMatched = r.Match(request.backupEmail).Success; // true в случае подтверждения совпадения
                    }
                    if (mainMatched || backupMatched)
                    {
                        // 1. Вычитать данные по заказу и извлечь его параметры
                        int    amount;
                        Int16  currency;
                        string description;

                        MsSqlDbExplorer msSqlDbExplorer = new MsSqlDbExplorer();

                        // извлекаем данные по заказу для формирования запроса в банк
                        if (msSqlDbExplorer.Orders_GetReservedOrderInfo(request.orderNumber, out amount, out currency, out description) && amount > 0 && currency > 0 && String.IsNullOrEmpty(description))
                        {
                            // 2. Зарезервировать в банке заказ

                            BillingBGPB billingBGPB = new BillingBGPB();
                            billingBGPB.Register(request.orderNumber, description, amount, new ProjectConfigData());

                            var registerResponse = JsonConvert.DeserializeObject <RegisterResult>(billingBGPB.Answer);

                            if (registerResponse.errorCode == 0) // заказ на оплату принят
                            {
                                if (msSqlDbExplorer.Orders_UpdateAddressAndOrderId(request.orderNumber, DateTime.Now, request.mainEmail, request.backupEmail, request.phone, request.messangers, registerResponse.orderId))
                                {
                                    response.errorCode = 0;
                                    response.formUrl   = registerResponse.formUrl;
                                    response.orderId   = registerResponse.orderId;
                                }
                                else
                                {
                                    response.errorCode = 7;
                                }
                            }
                            else
                            {
                                if (msSqlDbExplorer.Orders_UpdateAddressAndOrderId(request.orderNumber, DateTime.Now, request.mainEmail, request.backupEmail, request.phone, request.messangers, registerResponse.orderId))
                                {
                                    response.errorCode = (byte)registerResponse.errorCode; ///////////////////////////////////////////////////////
                                    response.formUrl   = registerResponse.formUrl;
                                    response.orderId   = registerResponse.orderId;
                                }
                                else
                                {
                                    response.errorCode = 7;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exc)
            {
            }
        }
Exemple #3
0
        // https://csharp.hotexamples.com/ru/examples/SeasideResearch.LibCurlNet/Easy/SetOpt/php-easy-setopt-method-examples.html
        // billingBGPB.Register(Guid.NewGuid().ToString().Replace("-", ""), "testovaya pokupka", 19.635f, "Testing", "Testing123", "finish.html", "error.html", "mpi-test.bgpb.by.crt", "mpi.test.key", "Bgpb2019");


        public void Register(string orderNumber, string description, int amount, ProjectConfigData config)
        {
            Register(orderNumber, description, amount, config.billUserName, config.billPassword, config.billReturnUrl, config.billFailUrl, config.billSslCertPath, config.billSslKeyPath, config.billSslKeyPass);
        }
Exemple #4
0
        public OrderReservation(OrderReservationRequestFrontEnd request, string sessionInfo, ProjectConfigData configData)
        {
            response = new OrderReservationResponseBackEnd();
            if (String.IsNullOrEmpty(request.requestId))
            {
                response.requestId = Guid.NewGuid().ToString();
            }
            else
            {
                response.requestId = request.requestId;
            }

            try
            {
                if (request.photoProcessId != null && request.photoProcessId.Count > 0)
                {
                    int photoCounter = request.photoProcessId.Count;

                    float amountValue = 0;
                    if (photoCounter > configData.billCosts.Length - 1)
                    {
                        amountValue = (float)Math.Round(configData.billCosts[configData.billCosts.Length - 1], 2);
                    }
                    else
                    {
                        amountValue = (float)Math.Round(configData.billCosts[photoCounter]);
                    }

                    if (amountValue > 0)
                    {
                        response.amount = String.Format("{0} {1}", amountValue, configData.billCurrency);

                        double delta = TimeSpan.FromTicks(DateTime.UtcNow.Ticks - 636710112000000000).TotalSeconds;
                        response.orderNumber = String.Format("{0}{1}", configData.billOrderPrefix, (((UInt64)(delta)).ToString("X") + ((byte)(delta % 1 * 16)).ToString("X")).Replace("0", "G").Replace("A", "S").Replace("B", "V").Replace("C", "R").Replace("E", "Z"));

                        if (photoCounter == 1 || photoCounter == 21 || photoCounter == 31 || photoCounter == 41 || photoCounter == 51 || photoCounter == 61 || photoCounter == 71 || photoCounter == 81 || photoCounter == 91 || photoCounter == 101)
                        {
                            response.description = String.Format("Покупка {0} фотографии.", photoCounter);
                        }
                        else
                        {
                            response.description = String.Format("Покупка {0} фотографий.", photoCounter);
                        }

                        MsSqlDbExplorer mySqlDbExplorer = new MsSqlDbExplorer();
                        mySqlDbExplorer.Orders_AddNewRecord(response.orderNumber, DateTime.Now, request.photoProcessId, (int)(amountValue * 100), 933, response.description, "user", request.sessionId);
                    }
                    else
                    {
                        response.description = "Нет фотографий для приобретения.";
                    }
                }
                else
                {
                    response.description = "Нет фотографий для приобретения.";
                }
            }
            catch (Exception exc) { }
        }
        public SearchPhotos(SearchPhotosRequestFrontEnd request, string sessionInfo, string faceDir, ProjectConfigData configData)
        {
            response = new SearchPhotosResponseBackEnd();

            List <Guid>[] searchedFaceIds = null;

            this.awsAccessKeyId        = configData.awsAccessKeyId;
            this.awsSecretAccessKey    = configData.awsSecretAccessKey;
            this.awsRegionEndpoint     = Amazon.RegionEndpoint.GetBySystemName(configData.awsEndpoint);//("eu-west-1");
            this.awsCollectionId       = configData.awsCollectionId;
            this.awsFaceMatchThreshold = configData.awsFaceMatchThreshold;

            if (request != null)
            {
                if (request.requestId == null)
                {
                    response.requestId = Guid.NewGuid().ToString();
                }
                else
                {
                    response.requestId = request.requestId;
                }

                if (request.faces == null || request.faces.Count == 0)
                {
                    if (sessionInfo != null)
                    {
                        log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null faces. Session info: {1}.", response.requestId, sessionInfo.Replace("\n", "; ")));
                    }
                    else
                    {
                        log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null faces. Session info: NULL.", response.requestId));
                    }
                    response.photos = null;
                    log.Debug(String.Format("SearchPhotos. Response. Id={0}. Null result. Reason = \"No faces\".", response.requestId));
                }
                else if (request.searchDates == null || request.searchDates.Count == 0) // пустой список дат
                {
                    if (sessionInfo != null)
                    {
                        log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null dates. Session info: {1}.", response.requestId, sessionInfo.Replace("\n", "; ")));
                    }
                    else
                    {
                        log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null dates. Session info: NULL.", response.requestId));
                    }
                    response.photos = null;
                    log.Debug(String.Format("SearchPhotos. Response. Id={0}. Null result. Reason = \"No dates\".", response.requestId));
                }
                else
                {
                    dates = new List <string>();
                    for (int i = 0; i < request.searchDates.Count; i++)
                    {
                        if (request.searchDates[i] != null && request.searchDates[i].Length == 8)
                        {
                            bool isCorrect = true;
                            for (int c = 0; c < 8; c++)
                            {
                                if (request.searchDates[i][c] < 0x30 || request.searchDates[i][c] > 0x39)
                                {
                                    isCorrect = false; break;
                                }
                            }
                            if (isCorrect)
                            {
                                dates.Add(request.searchDates[i]);
                            }
                        }
                    }
                    if (dates.Count == 0)
                    {
                        if (sessionInfo != null)
                        {
                            log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null dates. Session info: {1}.", response.requestId, sessionInfo.Replace("\n", "; ")));
                        }
                        else
                        {
                            log.Debug(String.Format("SearchPhotos. Request. Id={0}. Null dates. Session info: NULL.", response.requestId));
                        }
                        response.photos = null;
                        log.Debug(String.Format("SearchPhotos. Response. Id={0}. Null result. Reason = \"No dates\".", response.requestId));
                    }
                    else
                    {
                        response.photos = null;
                        List <string> faceFileNames = new List <string>();
                        for (int i = 0; i < request.faces.Count; i++)
                        {
                            string faceFile = String.Format("{0}{1}.jpg", faceDir, request.faces[i]);
                            if (System.IO.File.Exists(faceFile))
                            {
                                faceFileNames.Add(faceFile);
                            }
                        }

                        if (faceFileNames != null && faceFileNames.Count > 0 && dates != null && dates.Count > 0)
                        {
                            if (sessionInfo != null)
                            {
                                log.Debug(String.Format("SearchPhotos. Request. Id={0}. Total faces={1}. Total dates={2}. Session info: {3}.", response.requestId, sessionInfo.Replace("\n", "; "), faceFileNames.Count, dates.Count));
                            }
                            else
                            {
                                log.Debug(String.Format("SearchPhotos. Request. Id={0}. Total faces={1}. Total dates={2}. Session info: NULL.", response.requestId, faceFileNames.Count, dates.Count));
                            }
                            response.photos = null;
                            AmazonSearcher amazonSearcher = new AmazonSearcher(faceFileNames, dates, configData);
                            searchedFaceIds = amazonSearcher.SearchedFaceIds;
                            amazonSearcher  = null;

                            if (searchedFaceIds != null && searchedFaceIds.Length > 0)
                            {
                                MsSqlDbExplorer mySqlDbExplorer = new MsSqlDbExplorer(new ProjectConfigData());
                                response.photos = mySqlDbExplorer.SelectFromContent(searchedFaceIds, request.locationId, dates);

                                //log.Debug(String.Format("SearchPhotos. Response. Id={0}. Null result. Reason = \"No dates\".", response.requestId));
                            }
                            else
                            {
                            }
                        }
                        else
                        {
                            // дописать логирование
                        }
                    }
                }
            }
            else
            {
                log.Debug("SearchPhotos. Null request.");
                response.requestId = Guid.NewGuid().ToString();
                response.photos    = null;
            }
        }