Exemplo n.º 1
0
        protected HealthEvaluation PopulateInstanceUsingJObjectCore(JObject jObject, HealthEvaluation targetObject, JsonSerializer serializer)
        {
            JToken jHealthEvaluationCore;

            jObject.TryGetValue("HealthEvaluation", out jHealthEvaluationCore);

            // Retrieve "Kind"
            if (!(jHealthEvaluationCore as JObject).TryGetValue("Kind", out jHealthEvaluationCore))
            {
                return(null);
            }

            HealthEvaluationKind kind = jHealthEvaluationCore.ToObject <HealthEvaluationKind>(serializer);
            Type targetType           = HealthEvaluation.GetDerivedHealthEvaluationClassTypeFromKind(kind);
            var  result = (HealthEvaluation)Activator.CreateInstance(targetType, true);

            if (true)
            {
                foreach (var tok in jHealthEvaluationCore.Children())
                {
                }
                var contract = serializer.ContractResolver.ResolveContract(targetType) as JsonObjectContract;
                foreach (var p in contract.Properties)
                {
                    // value for this property in given healthEvaluation instance
                    var jtoken = jHealthEvaluationCore.SelectToken(p.PropertyName);
                    if (jtoken != null)
                    {
                        targetType.GetProperty(p.UnderlyingName).SetValue(result, jtoken.ToObject(p.PropertyType, serializer));
                    }
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        public static HealthEvaluation CreateRandomHealthEvaluation(this Random random)
        {
            var chooseEvent           = random.Next() % 3 == 0;
            HealthEvaluationKind kind = chooseEvent ? HealthEvaluationKind.Event : CreateRandom <HealthEvaluationKind>(random);
            Type targetType           = HealthEvaluation.GetDerivedHealthEvaluationClassTypeFromKind(kind);

            return((HealthEvaluation)random.CreateRandom(targetType));
        }
Exemplo n.º 3
0
        internal static Type GetDerivedHealthEvaluationClassTypeFromKind(HealthEvaluationKind kind)
        {
            var targetTypeName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}HealthEvaluation", typeof(HealthEvaluationKind).Namespace, kind);
            var targetType     = Type.GetType(targetTypeName);

            if (targetType == null)
            {
                AppTrace.TraceSource.WriteError("HealthEvaluation.GetDerivedHealthEvaluationClassTypeFromKind():", "Could not find derived class related to unknown FABRIC_HEALTH_EVALUATION_KIND: {0}", kind);
                ReleaseAssert.Failfast(
                    string.Format(
                        CultureInfo.CurrentCulture,
                        StringResources.Error_EnumInvalid_Formatted,
                        kind,
                        "HealthEvaluationKind"));
            }

            return(targetType);
        }
Exemplo n.º 4
0
        protected override HealthEvaluation PopulateInstanceUsingJObject(JObject jObject, HealthEvaluation targetObject, JsonSerializer serializer)
        {
            JToken jToken;

            // Remove wrapper property HealthEvaluation (added from native serializer).
            if (jObject.TryGetValue("HealthEvaluation", out jToken))
            {
                return(jToken.ToObject <HealthEvaluation>(serializer));
            }

            // Retrieve "Kind"
            if (!jObject.TryGetValue("Kind", out jToken))
            {
                return(null);
            }

            HealthEvaluationKind kind = jToken.ToObject <HealthEvaluationKind>(serializer);
            Type targetType           = HealthEvaluation.GetDerivedHealthEvaluationClassTypeFromKind(kind);

            return((HealthEvaluation)jObject.ToObject(targetType, serializer));
        }
Exemplo n.º 5
0
 /// <summary>
 /// <para>Initializes a new instance of the <see cref="System.Fabric.Health.HealthEvaluation" /> class.</para>
 /// </summary>
 /// <param name="kind">
 /// <para>The <see cref="System.Fabric.Health.HealthEvaluationKind" /> of the evaluation.</para>
 /// </param>
 protected HealthEvaluation(HealthEvaluationKind kind)
 {
     this.Kind = kind;
 }