Beispiel #1
0
        void IViewTab.Fill(Protocol protocol, ViewerItem item)
        {
            ((IViewTab)this).Reset();

            m_strings     = ParsingHelper.ExtractStrings(protocol, item);
            m_binaryDatas = ParsingHelper.ExtractBinaryDatas(protocol, item);
            int nStrings = m_strings.Length;
            int count    = nStrings + m_binaryDatas.Length;

            if (count > 0)
            {
                ui_cbDatas.Items.Clear();

                for (int i = 0; i < count; i++)
                {
                    var obj = i >= nStrings ? m_binaryDatas[i - nStrings].Item1 : m_strings[i].Item1;
                    ui_cbDatas.Items.Add(ParsingHelper.GetContentName(obj, i));
                }

                ui_cbDatas.SelectedIndex = 0;

                if (count > 1)
                {
                    ui_cbDatas.IsEnabled = true;
                }

                //this.SelectData(0);
            }

            this.IsFilled = true;
        }
Beispiel #2
0
        void IViewTab.Fill(Protocol protocol, ViewerItem item)
        {
            ((IViewTab)this).Reset();

            m_images = ParsingHelper.ExtractImages(protocol, item, true);
            int count = m_images.Length;

            if (count > 0)
            {
                ui_cbImages.Items.Clear();

                for (int i = 0; i < count; i++)
                {
                    ui_cbImages.Items.Add(ParsingHelper.GetContentName(m_images[i].Item1, i));
                }

                ui_cbImages.SelectedIndex = 0;

                if (count > 1)
                {
                    ui_cbImages.IsEnabled = true;
                }

                //this.SelectImage(0);
            }

            this.IsFilled = true;
        }
Beispiel #3
0
        private void UpdateViewerMovingAverages(MovingAverageWrapper wrapper, string average, string averageMax, string Ftp, string heartRate)
        {
            lock (this.lvViewer)
            {
                ViewerListViewItem listViewItem = wrapper.ViewerListViewItem;
                ViewerItem         viewerItem   = listViewItem.ViewerItem;

                if (average != null)
                {
                    viewerItem.Average = average;
                }

                if (averageMax != null)
                {
                    viewerItem.AverageMax = averageMax;
                }

                if (Ftp != null)
                {
                    viewerItem.Ftp = Ftp;
                }

                if (heartRate != null)
                {
                    viewerItem.HeartRate = heartRate;
                }
            }
        }
Beispiel #4
0
        static PacketParser ParseIfNeed(Protocol protocol, ViewerItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (protocol == null)
            {
                throw new ArgumentNullException("protocol");
            }

            if (item.Parser == null)
            {
                protocol.CreateParser(item);
            }

            var parser = item.Parser;

            if (!parser.IsParsed)
            {
                parser.Parse();
            }

            return(parser);
        }
Beispiel #5
0
        public override void EnqueueParsing(ViewerItem item)
        {
            lock (m_parsingQueue)
                m_parsingQueue.Enqueue(item);

            this.StartParsing();
        }
        /// <summary>
        /// Add a viewer to the report
        /// </summary>
        /// <param name="name">Name of the viewer</param>
        /// <param name="type">Type of the class in the usual format: Fully Qualified Class Name, Assembly</param>
        /// <param name="parameters">Parameters as pipe separated: key=value|key2=value2</param>
        public void AddViewer(ViewerItem viewer)
        {
            Sitecore.Diagnostics.Assert.ArgumentNotNull(viewer, "viewer");

            if (!viewers.ContainsKey(viewer.ID.ToString()))
            {
                viewers.Add(viewer.ID.ToString(), viewer);
            }
        }
Beispiel #7
0
            /// <summary>
            /// Initializes a new instance of
            /// <see cref="Kamilla.Network.Protocols.DefaultProtocol.ItemVisualData"/> class.
            /// </summary>
            /// <param name="item">
            /// The underlying instance of <see cref="Kamilla.Network.Viewing.ViewerItem"/> class.
            /// </param>
            /// <exception cref="System.ArgumentNullException">
            /// <c>item</c> is null.
            /// </exception>
            public ItemVisualData(ViewerItem item)
            {
                if (item == null)
                {
                    throw new ArgumentNullException("item");
                }

                m_item = item;
            }
Beispiel #8
0
        protected override PacketParser InternalCreateParser(ViewerItem item)
        {
            var packet = item.Packet as WowPacket;

            if (packet == null)
            {
                return(null);
            }

            return(XmlParser.GetParser(packet) ?? base.InternalCreateParser(item));
        }
Beispiel #9
0
        void m_currentLog_PacketAdded(object sender, PacketAddedEventArgs e)
        {
            var item = new ViewerItem(this, (NetworkLog)sender, e.Packet, m_items.Count);

            m_items.Add(item);

            if (this.ItemAdded != null)
            {
                this.ItemAdded(this, new ViewerItemEventArgs(item));
            }
        }
 private static string[] SubItemStrings(ViewerItem item)
 {
     return(new string[]
     {
         item.Description,
         item.Average,
         item.AverageMax,
         item.Ftp,
         item.HeartRate
     });
 }
Beispiel #11
0
        void m_parsingWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            // THREADING DANGER ZONE!
            UICulture.Initialize();

            var worker       = (BackgroundWorker)sender;
            var protocol     = m_currentProtocol;
            int turnOffTimes = 0;

            while (!worker.CancellationPending)
            {
                ViewerItem item = null;

                lock (m_parsingQueue)
                {
                    if (m_parsingQueue.Count > 0)
                    {
                        item = m_parsingQueue.Dequeue();
                    }
                }

                if (item == null)
                {
                    ++turnOffTimes;
                    if (turnOffTimes == 50)
                    {
                        return;
                    }

                    Thread.Sleep(100);
                    continue;
                }

                if (item.Viewer != this || item.Log != m_currentLog)
                {
                    continue;
                }

                var parser = item.Parser;
                if (parser == null)
                {
                    turnOffTimes = 0;
                    protocol.CreateParser(item);
                    parser = item.Parser;
                }

                if (!parser.IsParsed)
                {
                    turnOffTimes = 0;
                    parser.Parse();
                }
            }
        }
Beispiel #12
0
 void FinishSearch(ViewerItem item)
 {
     if (item != null)
     {
         m_window.ui_lvPackets.SelectedIndex = item.Index;
         m_window.ui_lvPackets.ScrollIntoView(item);
     }
     else
     {
         MessageWindow.Show(this, Strings.Menu_Search, Strings.Search_NotFound);
     }
 }
        /// <summary>
        /// Occurs each time a collector's moving average changes.  Allows for UI update by marshalling the call accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MovingAverageChangedEventHandler(object sender, MovingAverage.MovingAverageChangedEventArgs e)
        {
            //if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread?
            //{
            //    // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit
            //    m_dispatcher.BeginInvoke(new MovingAverageChangedEventHandlerDelegate(MovingAverageChangedEventHandler), new object[] { sender, e });
            //    return;
            //}

            lock (lvViewer)
            {
                MovingAverageWrapper wrapper      = m_maCollection[e.DurationType];
                Collector            collector    = wrapper.Collector;
                ViewerListViewItem   listViewItem = wrapper.ViewerListViewItem;
                ViewerItem           viewerItem   = listViewItem.ViewerItem;

                switch (collector.FieldAvgType)
                {
                case FieldUomType.Watts:
                    viewerItem.Average = e.AveragePower.ToString();
                    break;

                case FieldUomType.Wkg:
                    if (m_currentUser.WeightAsKgs > 0)
                    {
                        viewerItem.Average = Math.Round(e.AveragePower / m_currentUser.WeightAsKgs, 2).ToString("#.00");
                    }
                    break;
                }

                viewerItem.HeartRate = e.AverageHR.ToString();

                // The FTP column will track the AvgPower until the time duration is satisfied.
                // This enables the rider to see what his FTP would be real-time.
                // Once the time duration is satisfied, we no longer will update using the AvgPower.
                if (!wrapper.MaxDurationTriggered)
                {
                    switch (collector.FieldFtpType)
                    {
                    case FieldUomType.Watts:
                        viewerItem.Ftp = Math.Round(e.AveragePower * 0.95, 0).ToString();
                        break;

                    case FieldUomType.Wkg:
                        if (m_currentUser.WeightAsKgs > 0)
                        {
                            viewerItem.Ftp = Math.Round((e.AveragePower / m_currentUser.WeightAsKgs) * 0.95, 2).ToString("#.00");
                        }
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Occurs each time a collector's moving average max value changes.  Allows for UI update by marshalling the call accordingly.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MovingAverageMaxChangedEventHandler(object sender, MovingAverage.MovingAverageMaxChangedEventArgs e)
        {
            //if (!m_dispatcher.CheckAccess()) // are we currently on the UI thread?
            //{
            //    // We're not in the UI thread, ask the dispatcher to call this same method in the UI thread, then exit
            //    m_dispatcher.BeginInvoke(new MovingAverageMaxChangedEventHandlerDelegate(MovingAverageMaxChangedEventHandler), new object[] { sender, e });
            //    return;
            //}

            lock (lvViewer)
            {
                MovingAverageWrapper wrapper      = m_maCollection[e.DurationType];
                Collector            collector    = wrapper.Collector;
                ViewerListViewItem   listViewItem = wrapper.ViewerListViewItem;
                ViewerItem           viewerItem   = listViewItem.ViewerItem;

                switch (collector.FieldAvgMaxType)
                {
                case FieldUomType.Watts:
                    viewerItem.AverageMax = e.MaxAvgPower.ToString();
                    break;

                case FieldUomType.Wkg:
                    if (m_currentUser.WeightAsKgs > 0)
                    {
                        viewerItem.AverageMax = Math.Round(e.MaxAvgPower / m_currentUser.WeightAsKgs, 2).ToString("#.00");
                    }
                    break;
                }

                // Save the fact that this moving average has fulfilled it's time duration
                wrapper.MaxDurationTriggered = true;

                // The FTP column will now track the MaxAvgPower now that the time duration is satisfied.
                switch (collector.FieldFtpType)
                {
                case FieldUomType.Watts:
                    viewerItem.Ftp = Math.Round(e.MaxAvgPower * 0.95, 0).ToString();
                    break;

                case FieldUomType.Wkg:
                    if (m_currentUser.WeightAsKgs > 0)
                    {
                        viewerItem.Ftp = Math.Round((e.MaxAvgPower / m_currentUser.WeightAsKgs) * 0.95, 2).ToString("#.00");
                    }
                    break;
                }
            }
        }
Beispiel #15
0
        void IViewTab.Fill(Protocol protocol, ViewerItem item)
        {
            var header = protocol.PacketContentsViewHeader(item);

            if (header != null && header != string.Empty)
            {
                ui_tbMain.Text = header + Environment.NewLine + item.Packet.Data.ToHexDump();
            }
            else
            {
                ui_tbMain.Text = item.Packet.Data.ToHexDump();
            }

            this.IsFilled = true;
        }
Beispiel #16
0
        protected override void OnItemParserChanged(ViewerItem item, PacketParser oldParser, PacketParser newParser)
        {
            base.OnItemParserChanged(item, oldParser, newParser);

            if (oldParser == null && newParser != null)
            {
                lock (m_parserItems)
                {
                    if (m_parserItems.Count >= s_maxAllocations)
                    {
                        m_parserItems.Dequeue().Parser = null;
                    }

                    m_parserItems.Enqueue(item);
                }
            }
        }
Beispiel #17
0
        public void CreateParser(ViewerItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            var parser = this.InternalCreateParser(item);

            if (parser == null)
            {
                parser = new UndefinedPacketParser();
            }

            parser.m_item = item;
            item.Parser   = parser;
        }
Beispiel #18
0
        protected override void OnItemVisualDataChanged(ViewerItem item, object oldData, object newData)
        {
            base.OnItemVisualDataChanged(item, oldData, newData);

            if (oldData == null && newData != null)
            {
                lock (m_dataItems)
                {
                    if (m_dataItems.Count >= s_maxAllocations)
                    {
                        m_dataItems.Dequeue().VisualData = null;
                    }

                    m_dataItems.Enqueue(item);
                }
            }
        }
Beispiel #19
0
        public override string PacketContentsViewHeader(ViewerItem item)
        {
            var parser       = item.Parser;
            var packet       = item.Packet;
            var wowPacket    = packet as WowPacket;
            var opcodePacket = packet as IPacketWithOpcode;

            int dataLength = packet.Data.Length;
            var builder    = new StringBuilder(128);

            builder
            .Append("Packet ")
            .Append((packet.Direction == TransferDirection.ToServer) ? "C->S" : "S->C");

            if (opcodePacket != null)
            {
                var intOpcode = opcodePacket.Opcode;
                var opcode    = (WowOpcodes)intOpcode;
                builder
                .Append(", ").Append(opcode.ToString())
                .Append(" (").Append(intOpcode)
                .Append(", 0x").Append(intOpcode.ToString("X4"))
                .Append(", ").Append(
                    (opcode.IsJamOpcode() ? "jam " + opcode.CondenseJamOpcode() :
                     (opcode.IsAuthOpcode() ? "auth " + opcode.CondenseAuthOpcode() :
                      (opcode.IsRegularOpcode() ? "cond " + opcode.CondenseOpcode() : "other")))
                    )
                .Append(")");
            }

            builder
            .Append(", ").Append(dataLength)
            .Append(" bytes");

            if (packet.Flags != 0)
            {
                builder.AppendLine().Append("Flags: ").Append(packet.Flags.ToString());
            }

            if (wowPacket != null && wowPacket.WowFlags != 0)
            {
                builder.AppendLine().Append("WoW Flags: ").Append(wowPacket.WowFlags.ToString());
            }

            return(builder.ToString());
        }
Beispiel #20
0
        protected virtual PacketParser InternalCreateParser(ViewerItem item)
        {
            var packet = item.Packet as IPacketWithOpcode;

            if (packet == null)
            {
                return(null);
            }

            Type parserType;

            if (m_wrapper.m_parsers.TryGetValue(packet.Opcode, out parserType))
            {
                return((PacketParser)Activator.CreateInstance(parserType));
            }

            return(null);
        }
Beispiel #21
0
        void IViewTab.Fill(Protocol protocol, ViewerItem item)
        {
            var parser = item.Parser;

            if (parser == null)
            {
                protocol.CreateParser(item);
                parser = item.Parser;
            }

            if (!parser.IsParsed)
            {
                parser.Parse();
            }

            ui_tbMain.Text = parser.ParsedText ?? string.Empty;
            this.IsFilled  = true;
        }
Beispiel #22
0
 protected override PacketParser InternalCreateParser(ViewerItem item)
 {
     return(null);
 }
 public ViewerListViewItem(ViewerItem item) : base(SubItemStrings(item))
 {
     this.ViewerItem = item;
 }
Beispiel #24
0
 public abstract string PacketContentsViewHeader(ViewerItem item);
Beispiel #25
0
 public override string PacketContentsViewHeader(ViewerItem item)
 {
     return(string.Empty);
 }
Beispiel #26
0
 protected override PacketParser InternalCreateParser(ViewerItem item)
 {
     return(new PoEGameParser());
 }
Beispiel #27
0
        public static ValueTuple <object, byte[]>[] ExtractBinaryDatas(Protocol protocol, ViewerItem item,
                                                                       Encoding stringEncoding = null, Type imageEncoderType = null)
        {
            var             parser = ParseIfNeed(protocol, item);
            ConstructorInfo ctor   = null;

            object[] ctorArgs = null;
            if (imageEncoderType != null)
            {
                ctor = imageEncoderType.GetConstructor(BindingFlags.Public, null,
                                                       new[] { typeof(Stream), typeof(BitmapCreateOptions), typeof(BitmapCacheOption) }, null);

                if (ctor == null)
                {
                    ctor = imageEncoderType.GetConstructor(BindingFlags.Public, null,
                                                           new[] { typeof(Stream) }, null);

                    ctorArgs = new object[]
                    {
                        null,
                        BitmapCreateOptions.PreservePixelFormat,
                        BitmapCacheOption.Default
                    };
                }
                else
                {
                    ctorArgs = new object[]
                    {
                        null
                    };
                }

                if (ctor == null)
                {
                    throw new ArgumentException("imageEncoderType");
                }
            }

            var result = new List <ValueTuple <object, byte[]> >(parser.ContainedData.Count);

            foreach (var obj in parser.ContainedData)
            {
                var bytes = obj as byte[];
                if (bytes != null)
                {
                    result.Add(new ValueTuple <object, byte[]>(obj, bytes));
                    continue;
                }

                if (stringEncoding != null)
                {
                    var str = obj as string;
                    if (str != null)
                    {
                        try
                        {
                            result.Add(new ValueTuple <object, byte[]>(obj, stringEncoding.GetBytes(str)));
                        }
                        catch
                        {
                        }
                        continue;
                    }
                }

                if (imageEncoderType != null)
                {
                    var img = obj as ImageSource;
                    if (img != null)
                    {
                        try
                        {
                            using (var stream = new MemoryStream())
                            {
                                ctorArgs[0] = stream;
                                var encoder = (BitmapEncoder)ctor.Invoke(ctorArgs);
                                encoder.Save(stream);
                                result.Add(new ValueTuple <object, byte[]>(obj, stream.ToArray()));
                            }
                        }
                        catch
                        {
                        }
                        continue;
                    }
                }

                // cannot interpret this
            }

            return(result.ToArray());
        }
Beispiel #28
0
        public static ValueTuple <object, ImageSource>[] ExtractImages(Protocol protocol, ViewerItem item,
                                                                       bool convertImages = false)
        {
            var parser = ParseIfNeed(protocol, item);

            var result = new List <ValueTuple <object, ImageSource> >(parser.ContainedData.Count);

            foreach (var obj in parser.ContainedData)
            {
                var img = obj as ImageSource;
                if (img != null)
                {
                    result.Add(new ValueTuple <object, ImageSource>(obj, img));
                    continue;
                }

                if (convertImages)
                {
                    var bytes = obj as byte[];
                    if (bytes != null)
                    {
                        try
                        {
                            using (var stream = new MemoryStream(bytes))
                            {
                                var decoder = BitmapDecoder.Create(stream,
                                                                   BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

                                result.Add(new ValueTuple <object, ImageSource>(obj, decoder.Frames[0]));
                            }
                        }
                        catch
                        {
                        }
                        continue;
                    }
                }

                // cannot interpret this
            }

            return(result.ToArray());
        }
Beispiel #29
0
        public static ValueTuple <object, string>[] ExtractStrings(Protocol protocol, ViewerItem item,
                                                                   Encoding stringEncoding = null)
        {
            var parser = ParseIfNeed(protocol, item);

            var result = new List <ValueTuple <object, string> >(parser.ContainedData.Count);

            foreach (var obj in parser.ContainedData)
            {
                var str = obj as string;
                if (str != null)
                {
                    result.Add(new ValueTuple <object, string>(obj, str));
                    continue;
                }

                var chars = obj as char[];
                if (chars != null)
                {
                    result.Add(new ValueTuple <object, string>(obj, new string(chars)));
                    continue;
                }

                if (stringEncoding != null)
                {
                    var bytes = obj as byte[];
                    if (bytes != null)
                    {
                        try
                        {
                            result.Add(new ValueTuple <object, string>(obj, stringEncoding.GetString(bytes)));
                            continue;
                        }
                        catch
                        {
                        }
                    }
                }

                // cannot interpret this
            }

            return(result.ToArray());
        }
Beispiel #30
0
 ItemVisualData CreateDataForItem(ViewerItem item)
 {
     return(new ItemVisualData(item));
 }