/// <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 FabricEvent GetFromJsonProperties(JsonReader reader)
        {
            FabricEvent obj      = null;
            var         propName = reader.ReadPropertyName();

            if (!propName.Equals("Kind", StringComparison.OrdinalIgnoreCase))
            {
                throw new JsonReaderException($"Incorrect discriminator property name {propName}, Expected discriminator property name is Kind.");
            }

            var propValue = reader.ReadValueAsString();

            if (propValue.Equals("ApplicationEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ContainerInstanceEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = ContainerInstanceEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionAnalysisEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionAnalysisEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ReplicaEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = ReplicaEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ServiceEvent", StringComparison.OrdinalIgnoreCase))
            {
                obj = ServiceEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationCreated", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationCreatedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationDeleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationDeletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationUpgradeCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationUpgradeCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationUpgradeDomainCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationUpgradeDomainCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationUpgradeRollbackCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationUpgradeRollbackCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationUpgradeRollbackStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationUpgradeRollbackStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationUpgradeStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationUpgradeStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("DeployedApplicationNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = DeployedApplicationNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("DeployedApplicationHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = DeployedApplicationHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationProcessExited", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationProcessExitedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ApplicationContainerInstanceExited", StringComparison.OrdinalIgnoreCase))
            {
                obj = ApplicationContainerInstanceExitedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeAborted", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeAbortedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeAddedToCluster", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeAddedToClusterEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeClosed", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeClosedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeDeactivateCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeDeactivateCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeDeactivateStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeDeactivateStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeDown", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeDownEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeOpenSucceeded", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeOpenSucceededEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeOpenFailed", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeOpenFailedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeRemovedFromCluster", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeRemovedFromClusterEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("NodeUp", StringComparison.OrdinalIgnoreCase))
            {
                obj = NodeUpEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionReconfigured", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionReconfiguredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("PartitionPrimaryMoveAnalysis", StringComparison.OrdinalIgnoreCase))
            {
                obj = PartitionPrimaryMoveAnalysisEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ServiceCreated", StringComparison.OrdinalIgnoreCase))
            {
                obj = ServiceCreatedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ServiceDeleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ServiceDeletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ServiceNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = ServiceNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ServiceHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = ServiceHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("DeployedServicePackageNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = DeployedServicePackageNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("DeployedServicePackageHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = DeployedServicePackageHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("StatefulReplicaNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatefulReplicaNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("StatefulReplicaHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatefulReplicaHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("StatelessReplicaNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatelessReplicaNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("StatelessReplicaHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = StatelessReplicaHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterNewHealthReport", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterNewHealthReportEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterHealthReportExpired", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterUpgradeCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterUpgradeCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterUpgradeDomainCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterUpgradeDomainCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterUpgradeRollbackCompleted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterUpgradeRollbackCompletedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterUpgradeRollbackStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterUpgradeRollbackStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ClusterUpgradeStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ClusterUpgradeStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosStopped", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosStoppedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosStarted", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosStartedEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosCodePackageRestartScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosCodePackageRestartScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosReplicaRemovalScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosReplicaRemovalScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosPartitionSecondaryMoveScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosPartitionSecondaryMoveScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosPartitionPrimaryMoveScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosPartitionPrimaryMoveScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosReplicaRestartScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosReplicaRestartScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else if (propValue.Equals("ChaosNodeRestartScheduled", StringComparison.OrdinalIgnoreCase))
            {
                obj = ChaosNodeRestartScheduledEventConverter.GetFromJsonProperties(reader);
            }
            else
            {
                throw new InvalidOperationException("Unknown Kind.");
            }

            return(obj);
        }
Example #2
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 ServiceEvent GetFromJsonProperties(JsonReader reader)
        {
            var eventInstanceId = default(Guid?);
            var category = default(string);
            var timeStamp = default(DateTime?);
            var hasCorrelatedEvents = default(bool?);
            var serviceId = default(string);

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

                    if (propValue.Equals("ServiceCreated", StringComparison.Ordinal))
                    {
                        return ServiceCreatedEventConverter.GetFromJsonProperties(reader);
                    }
                    else if (propValue.Equals("ServiceDeleted", StringComparison.Ordinal))
                    {
                        return ServiceDeletedEventConverter.GetFromJsonProperties(reader);
                    }
                    else if (propValue.Equals("ServiceNewHealthReport", StringComparison.Ordinal))
                    {
                        return ServiceNewHealthReportEventConverter.GetFromJsonProperties(reader);
                    }
                    else if (propValue.Equals("ServiceHealthReportExpired", StringComparison.Ordinal))
                    {
                        return ServiceHealthReportExpiredEventConverter.GetFromJsonProperties(reader);
                    }
                    else if (propValue.Equals("ServiceEvent", 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("ServiceId", propName, StringComparison.Ordinal) == 0)
                    {
                        serviceId = reader.ReadValueAsString();
                    }
                    else
                    {
                        reader.SkipPropertyValue();
                    }
                }
            }
            while (reader.TokenType != JsonToken.EndObject);

            return new ServiceEvent(
                kind: Common.FabricEventKind.ServiceEvent,
                eventInstanceId: eventInstanceId,
                category: category,
                timeStamp: timeStamp,
                hasCorrelatedEvents: hasCorrelatedEvents,
                serviceId: serviceId);
        }