Exemplo n.º 1
0
        public static string SerializeChaosEvents(ChaosEventsSegment events)
        {
            // we will convert the chaos events to a dto that follows the required format in native.
            JsonSerializer serializer = JsonSerializer.Create(chaosEventsDescriptionSerializationSettings);

            JObject eventsDTO = JObject.FromObject(events, serializer);

            for (int i = 0; i < ((JArray)eventsDTO["History"]).Count; ++i)
            {
                // turns each ChaosEvent in history from { ChaosEvent stuff} into { ChaosEvent: { ChaosEvent stuff } }
                JObject chaosEventWrapper = new JObject();
                JObject chaosEventDTO     = (JObject)((JArray)eventsDTO["History"])[i];

                // Reason needs to be no multiple of four so it doesnt cause decompression error
                IDictionary <string, JToken> chaosEventDict = chaosEventDTO;
                if (chaosEventDict.ContainsKey("Reason"))
                {
                    chaosEventDTO["Reason"] = ChaosUtility.MakeLengthNotMultipleOfFourIgnoreReasonLength(chaosEventDTO.GetValue("Reason").Value <string>());
                }

                JProperty kindProperty = new JProperty(chaosEventDTO.Property("Kind"));
                chaosEventDTO.Property("Kind").Remove();
                chaosEventDTO.AddFirst(kindProperty);

                chaosEventWrapper["ChaosEvent"]   = chaosEventDTO;
                ((JArray)eventsDTO["History"])[i] = chaosEventWrapper;
            }

            return(JsonConvert.SerializeObject(eventsDTO, chaosEventsDescriptionSerializationSettings));
        }
Exemplo n.º 2
0
            internal static unsafe ChaosEventsSegment CreateFromNative(NativeClient.IFabricChaosEventsSegmentResult nativeResult)
            {
                if (nativeResult == null)
                {
                    return(null);
                }

                var chaosEventsSegment = ChaosEventsSegment.FromNative(nativeResult.get_ChaosEventsSegmentResult());

                GC.KeepAlive(nativeResult);
                return(chaosEventsSegment);
            }
Exemplo n.º 3
0
        /// <summary>
        /// Serializes the object to JSON.
        /// </summary>
        /// <param name="writer">The <see cref="T: Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="obj">The object to serialize to JSON.</param>
        internal static void Serialize(JsonWriter writer, ChaosEventsSegment obj)
        {
            // Required properties are always serialized, optional properties are serialized when not null.
            writer.WriteStartObject();
            if (obj.ContinuationToken != null)
            {
                writer.WriteProperty(obj.ContinuationToken, "ContinuationToken", ContinuationTokenConverter.Serialize);
            }

            if (obj.History != null)
            {
                writer.WriteEnumerableProperty(obj.History, "History", ChaosEventWrapperConverter.Serialize);
            }

            writer.WriteEndObject();
        }
Exemplo n.º 4
0
        protected override void ProcessRecord()
        {
            var clusterConnection = this.GetClusterConnection();

            try
            {
                ChaosEventsSegment report = null;

                if (string.IsNullOrEmpty(this.ContinuationToken))
                {
                    report = clusterConnection.GetChaosEventsAsync(
                        this.CreateChaosEventsSegmentFilter(),
                        this.GetMaxResults(),
                        this.GetTimeout(),
                        this.GetCancellationToken()).Result;
                }
                else
                {
                    report = clusterConnection.GetChaosEventsAsync(
                        this.ContinuationToken,
                        this.GetMaxResults(),
                        this.GetTimeout(),
                        this.GetCancellationToken()).Result;
                }

                this.WriteObject(this.FormatOutput(report));
            }
            catch (AggregateException aggregateException)
            {
                aggregateException.Handle((ae) =>
                {
                    this.ThrowTerminatingError(
                        ae,
                        Constants.GetChaosEventsCommandErrorId,
                        clusterConnection);
                    return(true);
                });
            }
        }
Exemplo n.º 5
0
        public static string SerializeChaosEvents(ChaosEventsSegment events)
        {
            // we will convert the chaos events to a dto that follows the required format in native.
            JsonSerializer serializer = JsonSerializer.Create(chaosEventsDescriptionSerializationSettings);

            JObject eventsDTO = JObject.FromObject(events, serializer);

            for (int i = 0; i < ((JArray)eventsDTO["History"]).Count; ++i)
            {
                // turns each ChaosEvent in history from { ChaosEvent stuff} into { ChaosEvent: { ChaosEvent stuff } }
                JObject chaosEventWrapper = new JObject();
                JObject chaosEventDTO     = (JObject)((JArray)eventsDTO["History"])[i];

                JProperty kindProperty = new JProperty(chaosEventDTO.Property("Kind"));
                chaosEventDTO.Property("Kind").Remove();
                chaosEventDTO.AddFirst(kindProperty);

                chaosEventWrapper["ChaosEvent"]   = chaosEventDTO;
                ((JArray)eventsDTO["History"])[i] = chaosEventWrapper;
            }

            return(JsonConvert.SerializeObject(eventsDTO, chaosEventsDescriptionSerializationSettings));
        }