Exemplo n.º 1
0
 /// <summary>
 /// 将当前数据转为字符串表达形式
 /// </summary>
 /// <returns>字符串</returns>
 public override string ToString()
 {
     if (DataType == StoreDataType.NotSet)
     {
         return(" [StoreData NotSet]");
     }
     if (DataType == StoreDataType.Array)
     {
         return(DataArray.Count + " [StoreData Array]");
     }
     if (DataRaw == null)
     {
         return("[StoreData Null]");
     }
     return(DataRaw.ToString() + " [StoreData " + DataType + "]");
 }
Exemplo n.º 2
0
        // Read and Handle the csv-Result File (Multi-Line)
        public static void HandleCSV_multiLine(object param)
        {
            HandleCSVParam hcsv_param = (HandleCSVParam)param;
            MetroTunnelDB  database   = new MetroTunnelDB();
            int            record_id  = hcsv_param.record_id;
            string         filepath   = hcsv_param.filepath;
            MainWindow     mw         = hcsv_param.mw;
            FileStream     fs         = new FileStream(filepath, FileMode.Open, System.IO.FileAccess.Read);
            StreamReader   sr         = new StreamReader(fs);

            // Record the Line once
            string strline;

            string[] arrline     = null;
            string[] tablehead   = null;
            int      columncount = 0;
            bool     isfirst     = true;
            int      linecount   = 0;

            // Multi-Line Param
            const int         line_query_once = 50;
            List <ResPackage> LinePackList    = new List <ResPackage>();


            while ((strline = sr.ReadLine()) != null)
            {
                //Handle one line each time
                ResPackage LinePack = new ResPackage();
                LinePack.x = new float[DataRows];
                LinePack.y = new float[DataRows];
                //CalResPackage LineCalPack = new CalResPackage();
                //LineCalPack.s = new float[DataRows];
                //LineCalPack.a = new float[DataRows];
                arrline = strline.Split(',');
                if (isfirst)
                {
                    columncount = arrline.Length;
                    isfirst     = false;
                }
                for (int i = 0; i < columncount; i++)
                {
                    try
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            LinePack.SerialNum = arrline[0].ToCharArray();
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            LinePack.Timestamp = Convert.ToInt32(arrline[1]);
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = Convert.ToSingle(arrline[i]);
                            }
                            //y
                            else
                            {
                                // LinePack.y[count] = Convert.ToSingle(arrline[i]);
                                LinePack.y[count] = Convert.ToSingle(count);
                            }
                        }
                    }
                    catch (System.NullReferenceException)
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            continue;
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            continue;
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = 0;
                            }
                            //y
                            else
                            {
                                LinePack.y[count] = 0;
                            }
                        }
                    }
                    catch (System.IndexOutOfRangeException)
                    {
                        //SerialNum
                        if (i == 0)
                        {
                            continue;
                        }
                        //Timestamp
                        else if (i == 1)
                        {
                            continue;
                        }
                        else
                        {
                            int count = i / 2 - 1;
                            //x
                            if (i % 2 == 0)
                            {
                                LinePack.x[count] = 0;
                            }
                            //y
                            else
                            {
                                LinePack.y[count] = 0;
                            }
                        }
                    }
                }

                LinePackList.Add(LinePack);
                //Convert to s-a
                //bool ret = false;
                //ret = ModelHandler.ConvertRes(LinePack, ref LineCalPack);
                //if (!ret)
                //{
                //    Console.WriteLine("Covertion Failed ! ! !\n");
                //}

                if (LinePackList.Count % line_query_once == 0)
                {
                    DataRaw[] dataRaws = new DataRaw[LinePackList.Count];
                    for (int l = 0; l < LinePackList.Count; l++)
                    {
                        //Get DataRaw
                        dataRaws[l] = new DataRaw(record_id, LinePackList[l].Timestamp, ConfigHandler.GetCameraNum(LinePackList[l].SerialNum), LinePackList[l].x, LinePackList[l].y);
                        mw.line_counter++;
                    }
                    //Send to MySQL
                    int retm = 0;
                    try
                    {
                        retm = database.InsertIntoDataRaw(dataRaws);
                    }
                    catch (System.Exception)
                    {
                        mw.DebugWriteLine("截面数据库插入异常");
                    }
                    if (!Convert.ToBoolean(retm))
                    {
                        mw.DebugWriteLine("截面数据库插入异常");
                    }
                    linecount = 0;
                    LinePackList.Clear();
                }
                // mw.SubProcessReport(mw.line_counter++);
            }
            if (LinePackList.Count > 0)
            {
                DataRaw[] dataRaws = new DataRaw[LinePackList.Count];
                for (int l = 0; l < LinePackList.Count; l++)
                {
                    //Get DataRaw
                    dataRaws[l] = new DataRaw(record_id, LinePackList[l].Timestamp, ConfigHandler.GetCameraNum(LinePackList[l].SerialNum), LinePackList[l].x, LinePackList[l].y);
                    mw.line_counter++;
                }
                //Send to MySQL
                int retm = 0;
                try
                {
                    retm = database.InsertIntoDataRaw(dataRaws);
                }
                catch (System.Exception)
                {
                    mw.DebugWriteLine("截面数据库插入异常");
                }
                if (!Convert.ToBoolean(retm))
                {
                    mw.DebugWriteLine("截面数据库插入异常");
                }
            }

            DataAnalyze.threadControlCounter += 1;
        }