Esempio n. 1
0
        /// <summary>
        /// Activates a log action.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="selectedPacket">The selected packet.</param>
        /// <returns><c>true</c> if log data tab should be updated.</returns>
        public override bool Activate(IExecutionContext context, PacketLocation selectedPacket)
        {
            // Create log
            PacketLog            log     = new PacketLog();
            ICollection <Packet> packets = SelectPacketContext(context, selectedPacket);

            savedPacket = context.LogManager.GetPacket(selectedPacket);
            log.AddRange(packets);
            PacketLog selectedLog = context.LogManager.GetPacketLog(selectedPacket.LogIndex);

            log.StreamName           = "(packet context) " + selectedLog.StreamName;
            log.IgnoreVersionChanges = false;
            log.Version = selectedLog.Version;

            // Show form in another thread
            Thread t = new Thread(ShowNewForm);

            lock (m_startedThreads)
            {
                m_startedThreads.Add(t);
                t.SetApartmentState(ApartmentState.STA);
                t.Name = "Packet context";
                t.Start(log);
            }

            return(false);
        }
        /// <summary>
        /// Activates a log action.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="selectedPacket">The selected packet.</param>
        /// <returns><c>true</c> if log data tab should be updated.</returns>
        public bool Activate(IExecutionContext context, PacketLocation selectedPacket)
        {
            PacketLog selectedLog = context.LogManager.GetPacketLog(selectedPacket.LogIndex);
            int selectedIndex = selectedPacket.PacketIndex;
            Packet originalPak = selectedLog[selectedIndex];
            ushort objectId = 0;
            if (originalPak is IObjectIdPacket && (originalPak as IObjectIdPacket).ObjectIds.Length > 0)
                objectId = (originalPak as IObjectIdPacket).ObjectIds[0];
            if (objectId == 0)
                return false;
            // Create log
            PacketLog			log = new PacketLog();
            ICollection<Packet>	packets = SelectPacketContext(context, selectedPacket, objectId);
            log.AddRange(packets);
            log.Version					= selectedLog.Version;
            log.StreamName				= "(context OID:0x" + objectId.ToString("X4") + ") " + selectedLog.StreamName;
            log.IgnoreVersionChanges	= false;

            // Show form in another thread
            Thread t = new Thread(ShowNewForm);
            lock (m_startedThreads)
            {
                m_startedThreads.Add(t);
                t.SetApartmentState(ApartmentState.STA);
                t.Name = "context OID:0x" + objectId.ToString("X4");
                t.Start(log);
            }

            return false;
        }
        /// <summary>
        /// Activates a log action.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="selectedPacket">The selected packet.</param>
        /// <returns><c>true</c> if log data tab should be updated.</returns>
        public bool Activate(IExecutionContext context, PacketLocation selectedPacket)
        {
            PacketLog selectedLog   = context.LogManager.GetPacketLog(selectedPacket.LogIndex);
            int       selectedIndex = selectedPacket.PacketIndex;
            Packet    originalPak   = selectedLog[selectedIndex];
            ushort    objectId      = 0;

            if (originalPak is IObjectIdPacket && (originalPak as IObjectIdPacket).ObjectIds.Length > 0)
            {
                objectId = (originalPak as IObjectIdPacket).ObjectIds[0];
            }
            if (objectId == 0)
            {
                return(false);
            }
            // Create log
            PacketLog            log     = new PacketLog();
            ICollection <Packet> packets = SelectPacketContext(context, selectedPacket, objectId);

            log.AddRange(packets);
            log.Version              = selectedLog.Version;
            log.StreamName           = "(context OID:0x" + objectId.ToString("X4") + ") " + selectedLog.StreamName;
            log.IgnoreVersionChanges = false;

            // Show form in another thread
            Thread t = new Thread(ShowNewForm);

            lock (m_startedThreads)
            {
                m_startedThreads.Add(t);
                t.SetApartmentState(ApartmentState.STA);
                t.Name = "context OID:0x" + objectId.ToString("X4");
                t.Start(log);
            }

            return(false);
        }
        /// <summary>
        /// Activates a log action.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="selectedPacket">The selected packet.</param>
        /// <returns><c>true</c> if log data tab should be updated.</returns>
        public override bool Activate(IExecutionContext context, PacketLocation selectedPacket)
        {
            // Create log
            PacketLog			log = new PacketLog();
            ICollection<Packet>	packets = SelectPacketContext(context, selectedPacket);
            savedPacket = context.LogManager.GetPacket(selectedPacket);
            log.AddRange(packets);
            PacketLog selectedLog = context.LogManager.GetPacketLog(selectedPacket.LogIndex);
            log.StreamName				= "(packet context) " + selectedLog.StreamName;
            log.IgnoreVersionChanges	= false;
            log.Version					= selectedLog.Version;

            // Show form in another thread
            Thread t = new Thread(ShowNewForm);
            lock (m_startedThreads)
            {
                m_startedThreads.Add(t);
                t.SetApartmentState(ApartmentState.STA);
                t.Name = "Packet context";
                t.Start(log);
            }

            return false;
        }
        /// <summary>
        /// Loads the files.
        /// </summary>
        /// <param name="reader">The log reader.</param>
        /// <param name="logs">The list to add open logs to.</param>
        /// <param name="files">The files too open.</param>
        /// <param name="initialVersion">The initial log version.</param>
        /// <param name="ignoreVersionChanges">If set to <c>true</c> version information in the log is ignored.</param>
        /// <param name="progress">The progress.</param>
        private void LoadFiles(ILogReader reader,
            ICollection<PacketLog> logs,
            string[] files,
            float initialVersion,
            bool ignoreVersionChanges,
            ProgressCallback progress)
        {
            foreach (string fileName in files)
            {
                try
                {
                    // Create new log for each file
                    PacketLog log = new PacketLog();
                    log.Version = initialVersion;
                    log.IgnoreVersionChanges = ignoreVersionChanges;

                    m_progress.SetDescription("Loading file: " + fileName + "...");

                    // Check if file exists
                    FileInfo fileInfo = new FileInfo(fileName);
                    if (!fileInfo.Exists)
                    {
                        Log.Info("File \"" + fileInfo.FullName + "\" doesn't exist, ignored.");
                        continue;
                    }

                    // Add all packets
                    using(FileStream stream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        log.AddRange(reader.ReadLog(new BufferedStream(stream, 64*1024), progress));
                    }

                    // Initialize log
                    m_progress.SetDescription("Initializing log and packets...");
                    log.Init(LogManager, 3, progress);

                    // Set stream name
                    log.StreamName = fileInfo.FullName;

                    AddRecentFile(fileInfo.FullName);
                    logs.Add(log);
                }
                catch (Exception e)
                {
                    Log.Error("loading files", e);
                }
            }
        }