Esempio n. 1
0
        private static void TimeEvent(object source, ElapsedEventArgs e)
        {
            if (SingletonInfo.GetInstance().FileDic.Count > 0)
            {
                lock (locker)
                {
                    foreach (var item in SingletonInfo.GetInstance().FileDic)
                    {
                        if (item.Value.DataList.Count > 0)
                        {
                            if (DateTime.Compare(DateTime.Now, item.Value.ReceiveTime) > 0)//接收超时了 则立即组装成文件
                            {
                                List <DataDetail> CompleteList = SortList(item.Value.DataList);
                                Thread            SaveFile     = new Thread(new ParameterizedThreadStart(SaveFiletoMP3));
                                SaveFile.Start((object)CompleteList);
                            }
                            else
                            {
                                bool flag = false;

                                //没有超时 只需考虑接收完成的情况
                                foreach (DataDetail dd in item.Value.DataList)
                                {
                                    if (dd.PackageNum == "FFFFFFFF")
                                    {
                                        flag = true;
                                        break;
                                    }
                                }

                                if (flag)
                                {
                                    List <DataDetail> CompleteList = SortList(item.Value.DataList);
                                    Thread            SaveFile     = new Thread(new ParameterizedThreadStart(SaveFiletoMP3));
                                    SaveFile.Start((object)CompleteList);
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static void SaveFiletoMP3(object ob)
        {
            try
            {
                List <DataDetail> CompleteList = (List <DataDetail>)ob;
                List <byte>       DataList     = new List <byte>();
                if (CompleteList.Count > 0)
                {
                    foreach (DataDetail item in CompleteList)
                    {
                        foreach (byte bt in item.AudioData)
                        {
                            DataList.Add(bt);
                        }
                    }
                    string     filename = CompleteList[0].FileName + ".mp3";
                    byte[]     buffer   = DataList.ToArray();
                    string     path     = SavePath + "\\" + filename;
                    FileStream fs       = new FileStream(path, FileMode.Create);//新建文件
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Flush();
                    fs.Close();
                    SingletonInfo.GetInstance().FileDic.Remove(CompleteList[0].FileName);

                    Thread.Sleep(1000);
                    #region   ftp上传
                    ftppath = filename;
                    ftphelper.UploadFile(path, ftppath);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 数据解析
        /// </summary>
        public void DealStatus()
        {
            while (true)
            {
                try
                {
                    if (!beforeAnalysisQueue.IsEmpty)
                    {
                        byte[] data;
                        beforeAnalysisQueue.TryDequeue(out data); //拿出数据
                        string dadada = "";
                        for (int i = 0; i < data.Length; i++)
                        {
                            dadada += " " + data[i].ToString("X2");
                        }

                        if (data != null && data.Length > 0)
                        {
                            //解析数据
                            List <DataDetail> dataNew = HandlerQueue(data); //解析数据
                            if (dataNew != null)
                            {
                                string filename = dataNew[0].FileName;

                                string filepath = Directory.GetCurrentDirectory();
                                if (Directory.EnumerateFiles(filepath, filename + ".*", SearchOption.AllDirectories).Any())
                                {
                                    break;
                                }
                                if (SingletonInfo.GetInstance().FileDic.ContainsKey(filename))
                                {
                                    FileAll file = SingletonInfo.GetInstance().FileDic[filename];
                                    file.ReceiveTime = file.ReceiveTime.AddSeconds(3);
                                    foreach (DataDetail item in dataNew)
                                    {
                                        file.DataList.Add(item);
                                    }
                                }
                                else
                                {
                                    FileAll file = new FileAll();
                                    file.ReceiveTime = DateTime.Now.AddSeconds(3);

                                    file.DataList = new List <DataDetail>();
                                    foreach (DataDetail item in dataNew)
                                    {
                                        file.DataList.Add(item);
                                    }
                                    SingletonInfo.GetInstance().FileDic.Add(filename, file);
                                }
                            }
                        }
                    }
                    else
                    {
                    }

                    Thread.Sleep(200);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
        }