예제 #1
0
        /// <summary>
        /// This is the method that is invoked on an IPacketFactory to create an IPacket
        /// from the data in an IFieldReader given a specified PacketDefinition.
        /// </summary>
        /// <param name="definition">Definition of the fields expected in the next packet</param>
        /// <param name="reader">Data stream to be read</param>
        /// <returns>An IPacket corresponding to the PacketDefinition and the stream data</returns>
        public IPacket CreatePacket(PacketDefinition definition, IFieldReader reader)
        {
            IPacket packet = (IPacket)m_Constructor.Invoke(new object[0]);

            definition.ReadFields(packet, reader);
            return(packet);
        }
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
                packet.GetField("name", out m_Name);

                string typeName;
                packet.GetField("valueType", out typeName);
                SetType(Type.GetType(typeName));

                packet.GetField("caption", out m_Caption);
                packet.GetField("description", out m_Description);

                int rawDefaultTrend;
                packet.GetField("defaultTrend", out rawDefaultTrend);
                m_DefaultTrend = (EventMetricValueTrend)rawDefaultTrend;

                packet.GetField("eventDefinitionPacketId", out m_EventDefinitionPacketId);
                packet.GetField("unitCaption", out m_UnitCaption);

                break;

            default:
                throw new GibraltarPacketVersionException(definition.Version);
            }
        }
예제 #3
0
        /// <summary>
        /// This is the method that is invoked on an IPacketFactory to create an IPacket
        /// from the data in an IFieldReader given a specified PacketDefinition.
        /// </summary>
        /// <param name="definition">Definition of the fields expected in the next packet</param>
        /// <param name="reader">Data stream to be read</param>
        /// <returns>An IPacket corresponding to the PacketDefinition and the stream data</returns>
        public IPacket CreatePacket(PacketDefinition definition, IFieldReader reader)
        {
            IPacket packet;

            //what we create varies by what specific definition they're looking for
            if (definition.TypeName == m_ThreadInfoPacketType)
            {
                packet = new ThreadInfoPacket();
            }
            else if (definition.TypeName == m_SessionStartInfoPacketType)
            {
                packet = new SessionSummaryPacket();
            }
            else if (definition.TypeName == m_SessionEndInfoPacketType)
            {
                packet = new SessionClosePacket();
            }
            else if (definition.TypeName == m_SessionFilePacketType)
            {
                packet = new SessionFragmentPacket();
            }
            else
            {
                //crap, we don't know what to do here.
                throw new ArgumentOutOfRangeException(nameof(definition), definition.TypeName, "This packet factory doesn't understand how to create packets for the provided type.");
            }

            //this feels a little crazy, but you have to do your own read call here - we aren't just creating the packet
            //object, we actually have to make the standard call to have it read data...
            definition.ReadFields(packet, reader);

            return(packet);
        }
예제 #4
0
 public void SendPacket(PacketDefinition packet, byte priority = 10)
 {
     if (!IsDisposing)
     {
         _client.SendPacket(PacketFactory.Serialize(packet), priority);
     }
 }
 void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
 {
     switch (definition.Version)
     {
     case 1:
         packet.GetField("ThreadId", out m_ThreadId);
         if (definition.Fields.ContainsKey("ThreadIndex"))
         {
             packet.GetField("ThreadIndex", out m_ThreadIndex);
             if (m_ThreadIndex == 0)
             {
                 m_ThreadIndex = m_ThreadId;     // Zero isn't legal, so it must not have had it.  Fall back to ThreadId.
             }
         }
         else
         {
             m_ThreadIndex = m_ThreadId;     // Use the "unique" ThreadId from older Agent code.
         }
         packet.GetField("ThreadName", out m_ThreadName);
         packet.GetField("DomainId", out m_DomainId);
         packet.GetField("DomainName", out m_DomainName);
         packet.GetField("IsBackground", out m_IsBackground);
         packet.GetField("IsThreadPoolThread", out m_IsThreadPoolThread);
         break;
     }
 }
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
                long baseValue;
                long counterTimeStamp;
                long counterFrequency;
                long systemFrequency;
                long timeStamp;
                long timeStamp100nSec;

                packet.GetField("baseValue", out baseValue);
                packet.GetField("counterTimeStamp", out counterTimeStamp);
                packet.GetField("counterFrequency", out counterFrequency);
                packet.GetField("systemFrequency", out systemFrequency);
                packet.GetField("timeStamp", out timeStamp);
                packet.GetField("timeStamp100nSec", out timeStamp100nSec);

                //conceptually we shouldn't persist this - it's always the same and it's always on our metric, however
                //we need it here for deserialization purposes because our metric packet object isn't available during
                //the deserialization process.
                int rawCounterType;
                packet.GetField("counterType", out rawCounterType);
                PerformanceCounterType counterType = (PerformanceCounterType)rawCounterType;

                //Now, create our sample object from this data
                m_Sample = new CounterSample((long)base.RawValue, baseValue, counterFrequency, systemFrequency, timeStamp, timeStamp100nSec, counterType, counterTimeStamp);
                break;

            default:
                throw new GibraltarPacketVersionException(definition.Version);
            }
        }
예제 #7
0
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
                packet.GetField("MetricTypeName", out m_MetricTypeName);
                packet.GetField("CategoryName", out m_CategoryName);
                packet.GetField("CounterName", out m_CounterName);

                int rawSampleType;
                packet.GetField("SampleType", out rawSampleType);
                m_SampleType = (SampleType)rawSampleType;

                packet.GetField("Caption", out m_Caption);
                packet.GetField("Description", out m_Description);

                int rawInterval;
                packet.GetField("Interval", out rawInterval);
                m_Interval = (MetricSampleInterval)rawInterval;

                //and our stuff that we have to calculate
                Name = MetricDefinition.GetKey(MetricTypeName, CategoryName, CounterName); //generate the name

                m_ReadOnly = true;                                                         //if we got read out of a file, we're read only.
                break;

            default:
                throw new GibraltarPacketVersionException(definition.Version);
            }

            //we are NOT live - we came from a serialization reader
            IsLive = false;
        }
예제 #8
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(LogMessagePacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, true);

            definition.Fields.Add("ID", FieldType.Guid);
            definition.Fields.Add("Caption", FieldType.String);
            definition.Fields.Add("Severity", FieldType.Int32);
            definition.Fields.Add("LogSystem", FieldType.String);
            definition.Fields.Add("CategoryName", FieldType.String);
            definition.Fields.Add("UserName", FieldType.String);
            definition.Fields.Add("Description", FieldType.String); // Added in version 2.
            definition.Fields.Add("Details", FieldType.String);     // Added in version 2.

            // ManagedThreadId isn't unique, so we need to add one that actually is (but not bumping version).
            definition.Fields.Add("ThreadIndex", FieldType.Int32);

            definition.Fields.Add("ThreadId", FieldType.Int32);
            definition.Fields.Add("MethodName", FieldType.String);
            definition.Fields.Add("ClassName", FieldType.String);
            definition.Fields.Add("FileName", FieldType.String);
            definition.Fields.Add("LineNumber", FieldType.Int32);


            // Now the Exception info, split into four arrays of strings to serialize better.
            definition.Fields.Add("TypeNames", FieldType.StringArray);
            definition.Fields.Add("Messages", FieldType.StringArray);
            definition.Fields.Add("Sources", FieldType.StringArray);
            definition.Fields.Add("StackTraces", FieldType.StringArray);

            // Added in version 3
            definition.Fields.Add("ApplicationUserId", FieldType.Guid);

            return(definition);
        }
 void IPacket.WriteFields(PacketDefinition definition, SerializedPacket packet)
 {
     packet.SetField("TypeName", TypeName);
     packet.SetField("Message", Message);
     packet.SetField("Source", Source);
     packet.SetField("StackTrace", StackTrace);
 }
예제 #10
0
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
                packet.GetField("Key", out m_Key);
                packet.GetField("UserName", out m_FullyQualifiedUserName);
                packet.GetField("Caption", out m_Caption);
                packet.GetField("Title", out m_Title);
                packet.GetField("Organization", out m_Organization);
                packet.GetField("Role", out m_Role);
                packet.GetField("Tenant", out m_Tenant);
                packet.GetField("TimeZoneCode", out m_TimeZoneCode);
                packet.GetField("EmailAddress", out m_EmailAddress);
                packet.GetField("Phone", out m_Phone);

                string[] propertyNames;
                packet.GetField("PropertyNames", out propertyNames);

                string[] propertyValues;
                packet.GetField("PropertyValues", out propertyValues);

                for (int index = 0; index < propertyNames.Length; index++)
                {
                    var propertyName  = propertyNames[index];
                    var propertyValue = propertyValues[index];
                    m_Properties.Add(propertyName, propertyValue);
                }

                break;
            }
        }
        void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
        {
            switch (definition.Version)
            {
            case 1:
                //read the values by our definition
                Values = new object[definition.Fields.Count];

                for (int valueIndex = 0; valueIndex < definition.Fields.Count; valueIndex++)
                {
                    FieldDefinition fieldDefinition = definition.Fields[valueIndex];
                    object          fieldValue;
                    packet.GetField(fieldDefinition.Name, out fieldValue);
                    Values[valueIndex] = fieldValue;
                }

                break;

            default:
                throw new GibraltarPacketVersionException(definition.Version);
            }

            //Now we need to go off and find our value definition so we can be serialized out gain
            IMetric ourMetric;

            if (Session.MetricDefinitions.TryGetMetricValue(MetricId, out ourMetric) == false)
            {
                //BIG problems- no metric for our metric ID?
                throw new ArgumentException("Unable to read event metric sample because the associated metric couldn't be found.");
            }
            m_ValueDefinitions = (EventMetricValueDefinitionCollection)((EventMetric)ourMetric).Definition.Values;
        }
        void IPacket.WriteFields(PacketDefinition definition, SerializedPacket packet)
        {
            packet.SetField("Id", m_ID);
            packet.SetField("metricPacketId", m_MetricPacket.ID);

            //and now we HAVE persisted
            Persisted = true;
        }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(CustomSampledMetricDefinitionPacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("metricSampleType", FieldType.Int32);
            return(definition);
        }
예제 #14
0
        void IPacket.WriteFields(PacketDefinition definition, SerializedPacket packet)
        {
            packet.SetField("instanceName", m_InstanceName);
            packet.SetField("definitionId", m_DefinitionId);

            //and now we HAVE persisted
            Persisted = true;
        }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(SampledMetricDefinitionPacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("unitCaption", FieldType.String);
            return(definition);
        }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            string           typeName   = MethodBase.GetCurrentMethod().DeclaringType.Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("counterType", FieldType.Int32);
            return(definition);
        }
예제 #17
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(CustomSampledMetricSamplePacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("baseValue", FieldType.Double);
            return(definition);
        }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(EventMetricPacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, true);

            //we only exist to do the required packet thing
            return(definition);
        }
예제 #19
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(EventMetricDefinitionPacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("DefaultValueName", FieldType.String);
            return(definition);
        }
예제 #20
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(EventMetricPacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, true);

            //we only exist to do the required packet thing
            return(definition);
        }
예제 #21
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(GenericPacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, Version, false);

            definition.Fields.Add("Sequence", m_Sequence.GetType());
            definition.Fields.Add("TimeStamp", m_TimeStamp.GetType());
            return(definition);
        }
 void IPacket.WriteFields(PacketDefinition definition, SerializedPacket packet)
 {
     //iterate our array, writing out each value.
     for (int valueIndex = 0; valueIndex < definition.Fields.Count; valueIndex++)
     {
         FieldDefinition fieldDefinition = definition.Fields[valueIndex];
         packet.SetField(fieldDefinition.Name, Values[valueIndex]);
     }
 }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(SampledMetricSamplePacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("rawTimeStamp", FieldType.DateTimeOffset);
            definition.Fields.Add("rawValue", FieldType.Double);
            return(definition);
        }
예제 #24
0
 void IPacket.ReadFields(PacketDefinition definition, SerializedPacket packet)
 {
     switch (definition.Version)
     {
     case 1:
         packet.GetField("DefaultValueName", out m_DefaultValueName);
         break;
     }
 }
예제 #25
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(MetricSamplePacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, true);

            definition.Fields.Add("Id", FieldType.Guid);
            definition.Fields.Add("metricPacketId", FieldType.Guid);
            return(definition);
        }
예제 #26
0
 public void SendPacket(PacketDefinition packet)
 {
     if (packet == null)
     {
         return;
     }
     _channel?.WriteAndFlushAsync(PacketFactory.Serialize(packet));
     _channel?.Flush();
 }
예제 #27
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(GenericPacket);
            var          definition = new PacketDefinition(typeName, Version, false);

            definition.Fields.Add("Sequence", m_Sequence.GetType());
            definition.Fields.Add("TimeStamp", m_TimeStamp.GetType());
            return(definition);
        }
예제 #28
0
        PacketDefinition IPacket.GetPacketDefinition()
        {
            var typeName = typeof(MetricPacket).Name;
            PacketDefinition definition = new PacketDefinition(typeName, SerializationVersion, true);

            definition.Fields.Add("instanceName", FieldType.String);
            definition.Fields.Add("definitionId", FieldType.Guid);
            return(definition);
        }
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(MetricSamplePacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, true);

            definition.Fields.Add("Id", FieldType.Guid);
            definition.Fields.Add("metricPacketId", FieldType.Guid);
            return(definition);
        }
예제 #30
0
        /// <summary>
        /// Get a new, populated definition for this packet.
        /// </summary>
        /// <returns>A new Packet Definition object</returns>
        /// <remarks>Once a definition is cached by the packet writer it won't be requested again.
        /// Packet Definitions must be invariant for an entire data stream.</remarks>
        PacketDefinition IPacket.GetPacketDefinition()
        {
            const string typeName   = nameof(SessionFragmentPacket);
            var          definition = new PacketDefinition(typeName, SerializationVersion, false);

            definition.Fields.Add("FileStartDateTime", FieldType.DateTimeOffset);
            definition.Fields.Add("FileEndDateTime", FieldType.DateTimeOffset);
            definition.Fields.Add("IsLastFile", FieldType.Bool);
            return(definition);
        }
예제 #31
0
 public void Broadcast(PacketDefinition packet)
 {
     Broadcast(null, packet);
 }
예제 #32
0
 public void Broadcast(PacketDefinition packet, int xRangeCoordinate, int yRangeCoordinate)
 {
     Broadcast(new BroadcastPacket(null, PacketFactory.Serialize(packet), ReceiverType.AllInRange, xCoordinate: xRangeCoordinate, yCoordinate: yRangeCoordinate));
 }
예제 #33
0
 public void Broadcast(ClientSession client, PacketDefinition packet, ReceiverType receiver = ReceiverType.All, string characterName = "", long characterId = -1)
 {
     Broadcast(client, PacketFactory.Serialize(packet), receiver, characterName, characterId);
 }
예제 #34
0
 public void SendPacket(PacketDefinition packet, byte priority = 10)
 {
     if (!IsDisposing)
     {
         _client.SendPacket(PacketFactory.Serialize(packet), priority);
     }
 }
예제 #35
0
 /// <summary>
 /// Send a packet to the Server as the Fake client receives it and triggers a Handler method.
 /// </summary>
 /// <param name="packet">Packet created thru PacketFactory.</param>
 public void ReceivePacket(PacketDefinition packet)
 {
     ReceivePacket(PacketFactory.Serialize(packet));
 }