Exemple #1
0
        private void btn_SelectContent_Click(object sender, EventArgs e)
        {
            string        connectionString = "Data Source=mssql.by1880.hb.by;Initial Catalog=photocore;Persist Security Info=True;User ID=photocoreuser;Password=!Q@WAZSX3e4rdcfv;Pooling=True";
            SqlConnection connection       = new SqlConnection(connectionString);
            int           counter          = 0;

            try
            { // https://www.sqlservertutorial.net/sql-server-basics/sql-server-drop-table/
                connection.Open();
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "SELECT amazon_id FROM Content;";
                var reader = cmd.ExecuteReader();

                List <Guid> guids = new List <Guid>();

                if (reader.HasRows)       // если есть данные
                {
                    while (reader.Read()) // построчно считываем данные
                    {
                        Guid amazon_id = (Guid)reader.GetValue(0);
                        if (guids.Count < 3)
                        {
                            guids.Add(amazon_id);                  ///////////////////////////////////////////////////////////////////////////////////////
                        }
                        counter++;
                    }
                }
                reader.Close();

                List <string> dateMasks = new List <string>();
                dateMasks.Add("20200322");
                dateMasks.Add("20200323");
                dateMasks.Add("20200324");
                List <Guid>[] facesGuids = new List <Guid> [guids.Count];
                for (int i = 0; i < guids.Count; i++)
                {
                    facesGuids[i] = guids;
                }

                MsSqlDbExplorer dbExplorer = new MsSqlDbExplorer();

                DateTime dt1    = DateTime.Now;
                var      result = dbExplorer.SelectFromContent(facesGuids, "12345", dateMasks);
                DateTime dt2    = DateTime.Now;
            }
            catch (Exception exc)
            {
                // Invalid object name 'Content'.
            }
        }
        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;
            }
        }