示例#1
0
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from.</param>
        /// <returns>The object Value.</returns>
        internal static PartitionAnalysisEvent GetFromJsonProperties(JsonReader reader)
        {
            var eventInstanceId     = default(Guid?);
            var category            = default(string);
            var timeStamp           = default(DateTime?);
            var hasCorrelatedEvents = default(bool?);
            var partitionId         = default(PartitionId);
            var metadata            = default(AnalysisEventMetadata);

            do
            {
                var propName = reader.ReadPropertyName();
                if (propName.Equals("Kind", StringComparison.Ordinal))
                {
                    var propValue = reader.ReadValueAsString();

                    if (propValue.Equals("PartitionPrimaryMoveAnalysis", StringComparison.Ordinal))
                    {
                        return(PartitionPrimaryMoveAnalysisEventConverter.GetFromJsonProperties(reader));
                    }
                    else if (propValue.Equals("PartitionAnalysisEvent", StringComparison.Ordinal))
                    {
                        // kind specified as same type, deserialize using properties.
                    }
                    else
                    {
                        throw new InvalidOperationException("Unknown Discriminator.");
                    }
                }
                else
                {
                    if (string.Compare("EventInstanceId", propName, StringComparison.Ordinal) == 0)
                    {
                        eventInstanceId = reader.ReadValueAsGuid();
                    }
                    else if (string.Compare("Category", propName, StringComparison.Ordinal) == 0)
                    {
                        category = reader.ReadValueAsString();
                    }
                    else if (string.Compare("TimeStamp", propName, StringComparison.Ordinal) == 0)
                    {
                        timeStamp = reader.ReadValueAsDateTime();
                    }
                    else if (string.Compare("HasCorrelatedEvents", propName, StringComparison.Ordinal) == 0)
                    {
                        hasCorrelatedEvents = reader.ReadValueAsBool();
                    }
                    else if (string.Compare("PartitionId", propName, StringComparison.Ordinal) == 0)
                    {
                        partitionId = PartitionIdConverter.Deserialize(reader);
                    }
                    else if (string.Compare("Metadata", propName, StringComparison.Ordinal) == 0)
                    {
                        metadata = AnalysisEventMetadataConverter.Deserialize(reader);
                    }
                    else
                    {
                        reader.SkipPropertyValue();
                    }
                }
            }while (reader.TokenType != JsonToken.EndObject);

            return(new PartitionAnalysisEvent(
                       kind: Common.FabricEventKind.PartitionAnalysisEvent,
                       eventInstanceId: eventInstanceId,
                       category: category,
                       timeStamp: timeStamp,
                       hasCorrelatedEvents: hasCorrelatedEvents,
                       partitionId: partitionId,
                       metadata: metadata));
        }
        /// <summary>
        /// Gets the object from Json properties.
        /// </summary>
        /// <param name="reader">The <see cref="T: Newtonsoft.Json.JsonReader" /> to read from, reader must be placed at first property.</param>
        /// <returns>The object Value.</returns>
        internal static PartitionPrimaryMoveAnalysisEvent GetFromJsonProperties(JsonReader reader)
        {
            var eventInstanceId     = default(Guid?);
            var category            = default(string);
            var timeStamp           = default(DateTime?);
            var hasCorrelatedEvents = default(bool?);
            var partitionId         = default(PartitionId);
            var metadata            = default(AnalysisEventMetadata);
            var whenMoveCompleted   = default(DateTime?);
            var previousNode        = default(NodeName);
            var currentNode         = default(NodeName);
            var moveReason          = default(string);
            var relevantTraces      = default(string);

            do
            {
                var propName = reader.ReadPropertyName();
                if (string.Compare("EventInstanceId", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    eventInstanceId = reader.ReadValueAsGuid();
                }
                else if (string.Compare("Category", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    category = reader.ReadValueAsString();
                }
                else if (string.Compare("TimeStamp", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    timeStamp = reader.ReadValueAsDateTime();
                }
                else if (string.Compare("HasCorrelatedEvents", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    hasCorrelatedEvents = reader.ReadValueAsBool();
                }
                else if (string.Compare("PartitionId", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    partitionId = PartitionIdConverter.Deserialize(reader);
                }
                else if (string.Compare("Metadata", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    metadata = AnalysisEventMetadataConverter.Deserialize(reader);
                }
                else if (string.Compare("WhenMoveCompleted", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    whenMoveCompleted = reader.ReadValueAsDateTime();
                }
                else if (string.Compare("PreviousNode", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    previousNode = NodeNameConverter.Deserialize(reader);
                }
                else if (string.Compare("CurrentNode", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    currentNode = NodeNameConverter.Deserialize(reader);
                }
                else if (string.Compare("MoveReason", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    moveReason = reader.ReadValueAsString();
                }
                else if (string.Compare("RelevantTraces", propName, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    relevantTraces = reader.ReadValueAsString();
                }
                else
                {
                    reader.SkipPropertyValue();
                }
            }while (reader.TokenType != JsonToken.EndObject);

            return(new PartitionPrimaryMoveAnalysisEvent(
                       eventInstanceId: eventInstanceId,
                       category: category,
                       timeStamp: timeStamp,
                       hasCorrelatedEvents: hasCorrelatedEvents,
                       partitionId: partitionId,
                       metadata: metadata,
                       whenMoveCompleted: whenMoveCompleted,
                       previousNode: previousNode,
                       currentNode: currentNode,
                       moveReason: moveReason,
                       relevantTraces: relevantTraces));
        }