コード例 #1
0
        // step ready to be parsed collection
        public void parseAllReadyData(DBWriter myDBWriter)
        {
            if (!closing)
            {
                DateTime start          = DateTime.Now;
                var      parseDurations = new List <double>();
                lock (currentlyParsingLock)
                {
                    lock (failedParsing)
                    {
                        currentlyParsingIndex = 0;

                        // Parse all data
                        currentlyParsing.ForEach(delegate(RawData obj)
                        {
                            try
                            {
                                Logger.GetInstance().WritePayloadToLogFile(obj.rawData, obj.rawDataLength, LogType.RawData);
                                Logger.GetInstance().WritePayloadBinaryToLogFile(obj.rawData, obj.rawDataLength, LogType.RawBinary);
                            }
                            catch (Exception ex)
                            {
                                Logger.GetInstance().Exception("Failed to write the log file", ex, EventLogPostfix);
                            }

                            bool moreDataExpected      = false; // currently ignored
                            bool packetParsedOK        = false;
                            IPacketParser packetParser = PacketParserCommon.selectPacketParser(obj.rawData, obj.rawDataLength);

                            currentlyParsingIndex++;

                            var parseStart = DateTime.Now;

                            if (packetParser != null)
                            {
                                packetParser.TrackerID = obj.trackerID;
                                packetParsedOK         = packetParser.Parse(myDBWriter, obj.rawData, obj.rawDataLength, ref moreDataExpected);
                                obj.parsedOK           = packetParsedOK;
                                if (!packetParsedOK)
                                {
                                    obj.parseRetryCount++;
                                }
                            }

                            parseDurations.Add((DateTime.Now - parseStart).TotalMilliseconds);
                        });

                        currentlyParsing.Clear();
                    }
                }
                previousParseDurationAverage = Average(parseDurations);
                previousParseDuration        = DateTime.Now - start;
            }
        }
コード例 #2
0
        private void ParseData(DBWriter myDBWriter, RawData obj, List <double> parseDurations)
        {
            bool          moreDataExpected = false; // currently ignored
            bool          packetParsedOK   = false;
            IPacketParser packetParser     = PacketParserCommon.selectPacketParser(obj.rawData, obj.rawDataLength);

            currentlyParsingIndex++;

            var parseStart = DateTime.Now;

            if (packetParser != null)
            {
                packetParser.TrackerID = obj.trackerID;
                packetParsedOK         = packetParser.Parse(myDBWriter, obj.rawData, obj.rawDataLength, ref moreDataExpected);
                obj.parsedOK           = packetParsedOK;
                if (!packetParsedOK)
                {
                    obj.parseRetryCount++;
                }
            }

            parseDurations.Add((DateTime.Now - parseStart).TotalMilliseconds);
        }
コード例 #3
0
        /// <summary>
        /// Call back for received data.
        /// </summary>
        public void OnDataReceived(IAsyncResult asyn)
        {
            bool packetParsedOK = false;

            //Logger.GetInstance().Message(string.Format("ID: {0};", m_WorkerTCPSocketID));

            lock (parserlock)
            {
                bool moreDataExpected = false;

                // Mark the age of this worker object
                connectionTime = DateTime.Now;

                try
                {
                    // finish the rx process and get the count of bytes in buffer
                    int iRx = myTCPSocket.EndReceive(asyn);

                    try
                    {
                        Logger.GetInstance().WritePayloadToLogFile(dataBuffer, iRx, LogType.RawData);
                    }
                    catch (Exception ex)
                    {
                        Logger.GetInstance().Exception("Failed to write the log file", ex, EventLogPostfix);
                    }


                    if ((packetParser == null))
                    {
                        packetParser = PacketParserCommon.selectPacketParser(dataBuffer, iRx);
                    }

                    if (packetParser != null)
                    {
                        if (packetParser.IsContinuous)
                        {
                            if (packetParser.Validate(dataBuffer, iRx, ref moreDataExpected))
                            {
                                myRawDataManager.addNewRawData(dataBuffer, iRx, packetParser.TrackerID);
                            }
                            sendACK_NACK(packetParser.getPacketACK_NACK());
                            moreDataExpected = true;
                        }
                        else
                        {
                            if (firstChunk && packetParser.IsMultiChunk) // this should be a method of the selected packet parser that tells us if we need more data
                            {
                                moreChunksExpected = true;
                                // for now the only end condition for this is to allow the socket to timeout and save the data on socket close
                                // JL also doesn't have an ACK scheme here!
                            }

                            if (!moreChunksExpected)
                            {
                                // original behaviour before freeze frame data
                                packetParsedOK = packetParser.Validate(dataBuffer, iRx, ref moreDataExpected);
                                if (packetParsedOK)
                                {
                                    myRawDataManager.addNewRawData(dataBuffer, iRx);
                                }
                                sendACK_NACK(packetParser.getPacketACK_NACK());
                            }
                            else
                            {
                                //Logger.GetInstance().Warning(string.Format("ID: {0}; TCP, More Chunks; {1}", m_WorkerTCPSocketID, dataBufferIndex));
                                // more chunks expected
                                if (firstChunk)
                                {
                                    dataBufferAllChunks = new byte[32 * 1024]; //Needs to be bigger for F blobs
                                }
                                Array.Copy(dataBuffer, 0, dataBufferAllChunks, dataBufferIndex, iRx);
                                dataBufferIndex += iRx;

                                if (iRx == 0)
                                {
                                    emptyRxCount++;
                                    if (emptyRxCount > 10)
                                    {
                                        allChunksReceived = true;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Logger.GetInstance().Message("OnReceiveData, no packet parser selected.", EventLogPostfix);
                    }
                }
                catch (ObjectDisposedException)
                {
                    // Socket was closed unexpectadly just ignore?
                    // Should we remove / dispose of worker object?
                }
                catch (SocketException se)
                {
                    if (se.ErrorCode == 10054) // error code for connection reset by peer
                    {
                        // no error just remove worker object?
                    }
                    else
                    {
                        Logger.GetInstance().Exception("OnReceiveData, socket error", se, EventLogPostfix);
                        // Should we remove / dispose of worker object?
                    }
                }
                catch (Exception e)
                {
                    Logger.GetInstance().Exception("OnDataReceive, general", e, EventLogPostfix);
                    // Should we remove / dispose of worker object?
                    // timer task ill tidy us up
                }
                finally
                {
                    firstChunk = false; // no longer first Chunk

                    if (moreChunksExpected)
                    {
                        // New method for large single packets from (freeze frame data)
                        if (allChunksReceived)
                        {
                            // all done
                            packetParsedOK = packetParser.Validate(dataBufferAllChunks, dataBufferIndex, ref moreDataExpected);
                            if (packetParsedOK)
                            {
                                myRawDataManager.addNewRawData(dataBufferAllChunks, dataBufferIndex);
                            }
                            sendACK_NACK(packetParser.getPacketACK_NACK());
                            // don't bother with command sending on FF data blobs
                            packetParser = null;
                            CloseAndDestroy();
                        }
                        else
                        {
                            WaitForData();
                        }
                    }
                    else if (moreDataExpected)
                    {
                        // old method for multi line packets from C-Series
                        WaitForData();
                    }
                    else
                    {
                        packetParser = null;
                        CloseAndDestroy();
                    }
                }
            }
        }