Ejemplo n.º 1
0
        internal void OdesliPacketu(PacketID id)
        {
            Packeta pac = Packety.ZiskejPacketu(id);

            if (pac == null)
            {
                ZalogujChybu("Neznámá packeta k odeslání: " + id.ToString());
                UkonciSpojeni();
                return;
            }

            if (OdeslanaPacketaUdalost != null)
            {
                OdeslanaPacketaUdalost(id);
            }

            m_RizeniOdesilani.WaitOne();

            try
            {
                pac.ZapisPacketu();
            }
            catch (IndexOutOfRangeException ex)
            {
                ZalogujChybu(ex.ToString());
                UkonciSpojeni();

                return;
            }

            try
            {
                m_Socket.BeginSend(m_Writer.Packeta, 0, m_Writer.Delka, SocketFlags.None, m_OdesliData, null);
            }
            catch (SocketException ex)
            {
                ZalogujChybu(ex.ToString());
                UkonciSpojeni();
            }
            catch (ObjectDisposedException)
            {
            }
        }
Ejemplo n.º 2
0
        public bool CompileData(PacketLogFileFormats plff)
        {
            if (RawBytes.Count < 4)
            {
                PacketID       = 0xFFFF;
                PacketDataSize = 0;
                HeaderText     = "Invalid Packet Size < 4";
                return(false);
            }
            PacketID       = (UInt16)(GetByteAtPos(0) + ((GetByteAtPos(1) & 0x01) * 0x100));
            PacketDataSize = (UInt16)((GetByteAtPos(1) & 0xFE) * 2);
            PacketSync     = (UInt16)(GetByteAtPos(2) + (GetByteAtPos(3) * 0x100));
            string TS = "";

            if (TimeStamp.Ticks > 0)
            {
                TS = TimeStamp.ToString("HH:mm:ss");
            }
            if (plff == PacketLogFileFormats.AshitaPacketeer)
            {
                // Packeteer doesn't have time info (yet)
                TimeStamp          = new DateTime(0);
                OriginalTimeString = "0000-00-00 00:00";
            }
            if (plff == PacketLogFileFormats.WindowerPacketViewer)
            {
                // Try to determine timestamp from header
                var P1 = OriginalHeaderText.IndexOf('[');
                var P2 = OriginalHeaderText.IndexOf(']');
                if ((P1 >= 0) && (P2 >= 0) && (P2 > P1))
                {
                    OriginalTimeString = OriginalHeaderText.Substring(P1 + 1, P2 - P1 - 1);
                    if (OriginalTimeString.Length > 0)
                    {
                        try
                        {
                            // try quick-parse first
                            DateTime dt;
                            if (DateTimeParse(OriginalTimeString, out dt))
                            {
                                TimeStamp = dt;
                            }
                            else
                            {
                                TimeStamp = DateTime.Parse(OriginalTimeString, cultureForDateTimeParse, stylesForDateTimeParse);
                            }
                            TS = TimeStamp.ToString("HH:mm:ss");
                        }
                        catch (FormatException)
                        {
                            TimeStamp          = new DateTime(0);
                            TS                 = "";
                            OriginalTimeString = "0000-00-00 00:00";
                        }
                    }
                }
            }
            VirtualTimeStamp = TimeStamp;
            if (TimeStamp.Ticks == 0)
            {
                TS = "";
            }

            string S = "";

            switch (PacketLogType)
            {
            case PacketLogTypes.Outgoing:
                S = "OUT ";
                break;

            case PacketLogTypes.Incoming:
                S = "IN  ";
                break;

            default:
                S = "??? ";
                break;
            }
            S          = TS + " : " + S + "0x" + PacketID.ToString("X3") + " - ";
            HeaderText = S + DataLookups.PacketTypeToString(PacketLogType, PacketID);
            return(true);
        }