Ejemplo n.º 1
0
 /// <summary>
 /// The function delete a file.
 /// </summary>
 /// <param name="photoNum">the photo index inside the list</param>
 public void DeleteFile(int photoNum)
 {
     lock (thisLock)
     {
         if (photos == null)
         {
             return;
         }
         PhotoStruct photo = photos[photoNum];
         // delete the file
         File.Delete(HttpContext.Current.Server.MapPath(photo.Thumbnail));
         File.Delete(HttpContext.Current.Server.MapPath(photo.Photo));
     }
 }
Ejemplo n.º 2
0
        private int PreparePhotoBath(out List <PhotoStruct> photoListImg,
                                     out DateTime strtDT_out, out DateTime stopDT_out, out bool isToday_out)
        {
            // Console.WriteLine("PreparePhotoBath()");
            Int32.TryParse(myParams.Value("MarkExceptions"), out int markExceptions);

            Int32.TryParse(myParams.Value("UseMultyProc"), out int useMultyProc);
            Int32.TryParse(myParams.Value("IDsBathSize"), out int idsBathSize);
            Int32.TryParse(myParams.Value("IDsBathSize_today"), out int idsBathSize_today);
            Int32.TryParse(myParams.Value("TodayTimeLag_ms"), out int todayTimeLag_ms);
            string sqlReadIDs = myParams.Value("SqlReadIDs");

            int cnt = 0;
            List <PhotoStruct> photoList = new List <PhotoStruct>();

            DateTime strtDT  = DateTime.Today;
            DateTime stopDT  = DateTime.Today;
            bool     isToday = true;
            string   idLast  = "0";

            {
                string dateTime_From = readParamFromDB(_myName + "_DateTime_From", "-");
                string dateTime_To   = readParamFromDB(_myName + "_DateTime_To", "-");
                long   idFrom        = Int64.Parse(readParamFromDB(_myName + "_ID_From", "-1"));
                long   idTo          = Int64.Parse(readParamFromDB(_myName + "_ID_To", "-1"));

                if (dateTime_From != "-" &&
                    dateTime_To != "-" &&
                    idFrom >= 0 &&
                    idTo >= 0)
                {
                    // диапазон выделен - выберем пачку IDs
                    strtDT = StringToDateTime(dateTime_From);
                    stopDT = StringToDateTime(dateTime_To);
                    idLast = (idFrom - 1).ToString() + " and info.id <= " + idTo.ToString();
                }
                else
                {
                    photoListImg = new List <PhotoStruct>();
                    strtDT_out   = strtDT;
                    stopDT_out   = stopDT;
                    isToday_out  = isToday;
                    return(0);
                }
            }

            isToday = strtDT >= DateTime.Today;

            if (conn == null)
            {
                RestoreConnection();
            }

            try
            {
                Log("[[ PREPARE ... ]]   time interval   " + DateTimeToString(stopDT) + " - " + DateTimeToString(stopDT), 2);

                sqlReadIDs = sqlReadIDs
                             .Replace("##idsBathSize##", isToday ? idsBathSize_today.ToString() : idsBathSize.ToString())
                             //.Replace("##idsBathSize##", idsBathSize.ToString())
                             .Replace("##dateTimeFrom##", DateTimeToString(strtDT))
                             .Replace("##dateTimeTo##", DateTimeToString(stopDT))
                             .Replace("##lastId##", idLast);

                Log(sqlReadIDs, 2);

                // Создать объект Command
                SqlCommand cmd = new SqlCommand
                {
                    Connection     = conn,
                    CommandText    = sqlReadIDs,
                    CommandTimeout = 36000
                };

                using (DbDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            // IDs
                            var    targetInfoID = reader.GetInt64("TargetInfoID");
                            var    dateFix      = reader.GetDateTime("DateFix");
                            string fileName     = targetInfoID + " - " + reader.GetDateTime(1).ToString("u").Substring(0, 19).Replace(":", ".");

                            photoList.Add(new PhotoStruct()
                            {
                                TargetInfoID = targetInfoID, DateFix = dateFix, TargetImageID = -1, ImgFileName = fileName
                            });
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (markExceptions > 0)
                {
                    Console.WriteLine(new string("Reading IDs from DB Error: " + e));
                }
            }
            finally
            {
                // Закрыть соединение.
                //conn.Close();
                // Разрушить объект, освободить ресурс.
                //conn.Dispose();
                //conn = null;
            }

            photoListImg = new List <PhotoStruct>();
            for (int i = 0; i < photoList.Count; i++)
            {
                Log("i = " + i, 2);

                var    rec = photoList[i];
                byte[] buf = null;


                Stopwatch sw_queryImage = new Stopwatch();
                sw_queryImage.Start();
                int resImg = QueryImageByteArr(rec.TargetInfoID, ref buf, out long bufLen);


                PhotoStruct recImg = new PhotoStruct()
                {
                    TargetInfoID  = rec.TargetInfoID,
                    DateFix       = rec.DateFix,
                    TargetImageID = -1,
                    ImgFileName   = rec.ImgFileName,
                    buf           = buf,
                    bufLen        = bufLen
                };

                photoListImg.Add(recImg);
            }

            cntPrep = photoList.Count;

            strtDT_out  = strtDT;
            stopDT_out  = stopDT;
            isToday_out = isToday;

            Log("cntAll = " + cntPrep, 2);

            return(cntPrep);
        }
Ejemplo n.º 3
0
        private static int SaveResultRec(PhotoStruct rec, bool success, CarDataStruct answer)
        {
            if (!success)
            {
                return(0);
            }

            Int32.TryParse(myParams.Value("MarkExceptions"), out int markExceptions);

            int resIns = -1;

            Int32.TryParse(myParams.Value("RecognizeBorder"), out int recognizeBorder);
            Int32.TryParse(myParams.Value("MarkSaveID"), out int markSaveID);
            Int32.TryParse(myParams.Value("MarkLockID"), out int markLockID);

            string str1     = MyTrim(answer.MarkProbStr, 0, 10);
            int    probMark =
                str1.Length > 0
                ? Int32.Parse(str1)
                : 0;
            string str2     = MyTrim(answer.TypeProbStr, 0, 10);
            int    probType =
                str2.Length > 0
                ? Int32.Parse(str2)
                : 0;

            if ((probMark >= recognizeBorder) ||
                (probType >= recognizeBorder))
            {
                string sqlSave = myParams.Value("SqlSaveImageRes");

                string mark        = MyTrim(answer.Mark, 0, 50);
                string modl        = MyTrim(answer.Modl, 0, 50);
                string probMarkStr = probMark.ToString();
                string type        = MyTrim(answer.Type, 0, 50);
                string side        = MyTrim(answer.Side, 0, 50);
                string probTypeStr = probType.ToString();

                string brand = mark + ", " + modl /*+ " " + MyTrim(ans.Generation, 0, 250)*/;
                if (brand == ",  ")
                {
                    brand = string.Empty;
                }

                if (CarTypes.Keys.Contains(type))
                {
                    type = CarTypes[type];
                }

                if (CarTypes.Keys.Contains(side))
                {
                    side = CarTypes[side];
                }

                sqlSave = sqlSave
                          .Replace("##ID##", rec.TargetInfoID.ToString());

                if (probMark >= recognizeBorder)
                {
                    sqlSave = sqlSave
                              .Replace("##brand##", "'" + brand + "'")
                              .Replace("##brandProb##", "'" + probMarkStr + "'");
                }
                else
                {
                    sqlSave = sqlSave
                              .Replace("##brand##", "''")
                              .Replace("##brandProb##", "''");
                }

                if (probType >= recognizeBorder)
                {
                    sqlSave = sqlSave
                              .Replace("##type##", "'" + type + "'")
                              .Replace("##typeProb##", "'" + probTypeStr + "'");
                }
                else
                {
                    sqlSave = sqlSave
                              .Replace("##type##", "''")
                              .Replace("##typeProb##", "''");
                }

                // Console.WriteLine("sqlSave = '" + sqlSave + "'");

                Log(sqlSave, 2);

                bool ok = false;

                try
                {
                    if (conn == null)
                    {
                        RestoreConnection();
                    }

                    SqlCommand command = new SqlCommand(null, conn);
                    command.CommandText = sqlSave;

                    command.Prepare();
                    resIns = command.ExecuteNonQuery();

                    cntSave++;
                    ok = true;
                }
                catch (Exception e)
                {
                    cntLock++;
                    ok = false;
                }
                finally
                {
                    // Console.WriteLine(" -> -> finally ");
                }

                if (ok)
                {
                    if (markSaveID > 0)
                    {
                        Console.Write("+ " + (markSaveID > 1 ? (rec.TargetInfoID.ToString() + ", ") : ""));
                    }
                }
                else
                {
                    if (markLockID > 0)
                    {
                        Console.Write("X " + (markSaveID > 1 ? (rec.TargetInfoID.ToString() + ", ") : ""));
                    }
                }
            }

            return(resIns);
        }