コード例 #1
0
 public static S3EventNotification ParseJson(string json)
 {
     //IL_0044: Unknown result type (might be due to invalid IL or missing references)
     //IL_004a: Expected O, but got Unknown
     //IL_03e6: Unknown result type (might be due to invalid IL or missing references)
     try
     {
         JsonData            val = JsonMapper.ToObject(json);
         S3EventNotification s3EventNotification = new S3EventNotification
         {
             Records = new List <S3EventNotificationRecord>()
         };
         if (val.get_Item("Records") != null)
         {
             foreach (JsonData item in (IEnumerable)val.get_Item("Records"))
             {
                 JsonData val2 = item;
                 S3EventNotificationRecord s3EventNotificationRecord = new S3EventNotificationRecord();
                 s3EventNotificationRecord.EventVersion = GetValueAsString(val2, "eventVersion");
                 s3EventNotificationRecord.EventSource  = GetValueAsString(val2, "eventSource");
                 s3EventNotificationRecord.AwsRegion    = GetValueAsString(val2, "awsRegion");
                 s3EventNotificationRecord.EventVersion = GetValueAsString(val2, "eventVersion");
                 if (val2.get_Item("eventTime") != null)
                 {
                     s3EventNotificationRecord.EventTime = DateTime.Parse((string)val2.get_Item("eventTime"), CultureInfo.InvariantCulture);
                 }
                 if (val2.get_Item("eventName") != null)
                 {
                     string text = (string)val2.get_Item("eventName");
                     if (!text.StartsWith("s3:", StringComparison.OrdinalIgnoreCase))
                     {
                         text = "s3:" + text;
                     }
                     s3EventNotificationRecord.EventName = EventType.FindValue(text);
                 }
                 if (val2.get_Item("userIdentity") != null)
                 {
                     JsonData data = val2.get_Item("userIdentity");
                     s3EventNotificationRecord.UserIdentity             = new UserIdentityEntity();
                     s3EventNotificationRecord.UserIdentity.PrincipalId = GetValueAsString(data, "principalId");
                 }
                 if (val2.get_Item("requestParameters") != null)
                 {
                     JsonData data2 = val2.get_Item("requestParameters");
                     s3EventNotificationRecord.RequestParameters = new RequestParametersEntity();
                     s3EventNotificationRecord.RequestParameters.SourceIPAddress = GetValueAsString(data2, "sourceIPAddress");
                 }
                 if (val2.get_Item("responseElements") != null)
                 {
                     JsonData data3 = val2.get_Item("responseElements");
                     s3EventNotificationRecord.ResponseElements = new ResponseElementsEntity();
                     s3EventNotificationRecord.ResponseElements.XAmzRequestId = GetValueAsString(data3, "x-amz-request-id");
                     s3EventNotificationRecord.ResponseElements.XAmzId2       = GetValueAsString(data3, "x-amz-id-2");
                 }
                 if (val2.get_Item("s3") != null)
                 {
                     JsonData val3 = val2.get_Item("s3");
                     s3EventNotificationRecord.S3 = new S3Entity();
                     s3EventNotificationRecord.S3.S3SchemaVersion = GetValueAsString(val3, "s3SchemaVersion");
                     s3EventNotificationRecord.S3.ConfigurationId = GetValueAsString(val3, "configurationId");
                     if (val3.get_Item("bucket") != null)
                     {
                         JsonData val4 = val3.get_Item("bucket");
                         s3EventNotificationRecord.S3.Bucket      = new S3BucketEntity();
                         s3EventNotificationRecord.S3.Bucket.Name = GetValueAsString(val4, "name");
                         s3EventNotificationRecord.S3.Bucket.Arn  = GetValueAsString(val4, "arn");
                         if (val4.get_Item("ownerIdentity") != null)
                         {
                             JsonData data4 = val4.get_Item("ownerIdentity");
                             s3EventNotificationRecord.S3.Bucket.OwnerIdentity             = new UserIdentityEntity();
                             s3EventNotificationRecord.S3.Bucket.OwnerIdentity.PrincipalId = GetValueAsString(data4, "principalId");
                         }
                     }
                     if (val3.get_Item("object") != null)
                     {
                         JsonData data5 = val3.get_Item("object");
                         s3EventNotificationRecord.S3.Object           = new S3ObjectEntity();
                         s3EventNotificationRecord.S3.Object.Key       = GetValueAsString(data5, "key");
                         s3EventNotificationRecord.S3.Object.Size      = GetValueAsLong(data5, "size");
                         s3EventNotificationRecord.S3.Object.ETag      = GetValueAsString(data5, "eTag");
                         s3EventNotificationRecord.S3.Object.VersionId = GetValueAsString(data5, "versionId");
                     }
                 }
                 s3EventNotification.Records.Add(s3EventNotificationRecord);
             }
         }
         return(s3EventNotification);
     }
     catch (Exception ex)
     {
         throw new AmazonClientException("Failed to parse json string: " + ex.Message, ex);
     }
 }
コード例 #2
0
        /// <summary>
        /// Parse the JSON string into a S3EventNotification object.
        /// <para>
        /// The function will try its best to parse input JSON string as best as it can. 
        /// It will not fail even if the JSON string contains unknown properties.
        /// </para>
        /// <exception cref="Amazon.Runtime.AmazonClientException">For any parsing errors</exception>
        /// </summary>
        public static S3EventNotification ParseJson(string json) 
        {
            try
            {
                var data = JsonMapper.ToObject(json);
                var s3Event = new S3EventNotification { Records = new List<S3EventNotificationRecord>() };

                if (data["Records"] != null)
                {
                    foreach (JsonData jsonRecord in data["Records"])
                    {
                        var record = new S3EventNotificationRecord();

                        record.EventVersion = GetValueAsString(jsonRecord, "eventVersion");
                        record.EventSource = GetValueAsString(jsonRecord, "eventSource");
                        record.AwsRegion = GetValueAsString(jsonRecord, "awsRegion");
                        record.EventVersion = GetValueAsString(jsonRecord, "eventVersion");

                        if (jsonRecord["eventTime"] != null)
                            record.EventTime = DateTime.Parse((string)jsonRecord["eventTime"], CultureInfo.InvariantCulture);
                        if (jsonRecord["eventName"] != null)
                        {
                            var eventName = (string)jsonRecord["eventName"];
                            if (!eventName.StartsWith("s3:", StringComparison.OrdinalIgnoreCase))
                                eventName = "s3:" + eventName;

                            record.EventName = EventType.FindValue(eventName);
                        }

                        if (jsonRecord["userIdentity"] != null)
                        {
                            var jsonUserIdentity = jsonRecord["userIdentity"];
                            record.UserIdentity = new UserIdentityEntity();
                            record.UserIdentity.PrincipalId = GetValueAsString(jsonUserIdentity, "principalId");
                        }

                        if (jsonRecord["requestParameters"] != null)
                        {
                            var jsonRequestParameters = jsonRecord["requestParameters"];
                            record.RequestParameters = new RequestParametersEntity();
                            record.RequestParameters.SourceIPAddress = GetValueAsString(jsonRequestParameters, "sourceIPAddress");
                        }

                        if (jsonRecord["responseElements"] != null)
                        {
                            var jsonResponseElements = jsonRecord["responseElements"];
                            record.ResponseElements = new ResponseElementsEntity();

                            record.ResponseElements.XAmzRequestId = GetValueAsString(jsonResponseElements, "x-amz-request-id");
                            record.ResponseElements.XAmzId2 = GetValueAsString(jsonResponseElements, "x-amz-id-2");
                        }

                        if (jsonRecord["s3"] != null)
                        {
                            var jsonS3 = jsonRecord["s3"];
                            record.S3 = new S3Entity();

                            record.S3.S3SchemaVersion = GetValueAsString(jsonS3, "s3SchemaVersion");
                            record.S3.ConfigurationId = GetValueAsString(jsonS3, "configurationId");

                            if (jsonS3["bucket"] != null)
                            {
                                var jsonBucket = jsonS3["bucket"];
                                record.S3.Bucket = new S3BucketEntity();

                                record.S3.Bucket.Name = GetValueAsString(jsonBucket, "name");
                                record.S3.Bucket.Arn = GetValueAsString(jsonBucket, "arn");


                                if (jsonBucket["ownerIdentity"] != null)
                                {
                                    var jsonOwnerIdentity = jsonBucket["ownerIdentity"];
                                    record.S3.Bucket.OwnerIdentity = new UserIdentityEntity();
                                    record.S3.Bucket.OwnerIdentity.PrincipalId = GetValueAsString(jsonOwnerIdentity, "principalId");
                                }
                            }

                            if (jsonS3["object"] != null)
                            {
                                var jsonObject = jsonS3["object"];
                                record.S3.Object = new S3ObjectEntity();

                                record.S3.Object.Key = GetValueAsString(jsonObject, "key");
                                record.S3.Object.Size = GetValueAsLong(jsonObject, "size");
                                record.S3.Object.ETag = GetValueAsString(jsonObject, "eTag");
                                record.S3.Object.VersionId = GetValueAsString(jsonObject, "versionId");
                            }
                        }

                        s3Event.Records.Add(record);
                    }
                }

                return s3Event;
            }
            catch(Exception e)
            {
                throw new AmazonClientException("Failed to parse json string: " + e.Message, e);
            }
        }
コード例 #3
0
        /// <summary>
        /// Parse the JSON string into a S3EventNotification object.
        /// <para>
        /// The function will try its best to parse input JSON string as best as it can.
        /// It will not fail even if the JSON string contains unknown properties.
        /// </para>
        /// <exception cref="Amazon.Runtime.AmazonClientException">For any parsing errors</exception>
        /// </summary>
        public static S3EventNotification ParseJson(string json)
        {
            try
            {
                var data    = JsonMapper.ToObject(json);
                var s3Event = new S3EventNotification {
                    Records = new List <S3EventNotificationRecord>()
                };

                if (data["Records"] != null)
                {
                    foreach (JsonData jsonRecord in data["Records"])
                    {
                        var record = new S3EventNotificationRecord();

                        record.EventVersion = GetValueAsString(jsonRecord, "eventVersion");
                        record.EventSource  = GetValueAsString(jsonRecord, "eventSource");
                        record.AwsRegion    = GetValueAsString(jsonRecord, "awsRegion");
                        record.EventVersion = GetValueAsString(jsonRecord, "eventVersion");

                        if (jsonRecord["eventTime"] != null)
                        {
                            record.EventTime = DateTime.Parse((string)jsonRecord["eventTime"], CultureInfo.InvariantCulture);
                        }
                        if (jsonRecord["eventName"] != null)
                        {
                            var eventName = (string)jsonRecord["eventName"];
                            if (!eventName.StartsWith("s3:", StringComparison.OrdinalIgnoreCase))
                            {
                                eventName = "s3:" + eventName;
                            }

                            record.EventName = EventType.FindValue(eventName);
                        }

                        if (jsonRecord["userIdentity"] != null)
                        {
                            var jsonUserIdentity = jsonRecord["userIdentity"];
                            record.UserIdentity             = new UserIdentityEntity();
                            record.UserIdentity.PrincipalId = GetValueAsString(jsonUserIdentity, "principalId");
                        }

                        if (jsonRecord["requestParameters"] != null)
                        {
                            var jsonRequestParameters = jsonRecord["requestParameters"];
                            record.RequestParameters = new RequestParametersEntity();
                            record.RequestParameters.SourceIPAddress = GetValueAsString(jsonRequestParameters, "sourceIPAddress");
                        }

                        if (jsonRecord["responseElements"] != null)
                        {
                            var jsonResponseElements = jsonRecord["responseElements"];
                            record.ResponseElements = new ResponseElementsEntity();

                            record.ResponseElements.XAmzRequestId = GetValueAsString(jsonResponseElements, "x-amz-request-id");
                            record.ResponseElements.XAmzId2       = GetValueAsString(jsonResponseElements, "x-amz-id-2");
                        }

                        if (jsonRecord["s3"] != null)
                        {
                            var jsonS3 = jsonRecord["s3"];
                            record.S3 = new S3Entity();

                            record.S3.S3SchemaVersion = GetValueAsString(jsonS3, "s3SchemaVersion");
                            record.S3.ConfigurationId = GetValueAsString(jsonS3, "configurationId");

                            if (jsonS3["bucket"] != null)
                            {
                                var jsonBucket = jsonS3["bucket"];
                                record.S3.Bucket = new S3BucketEntity();

                                record.S3.Bucket.Name = GetValueAsString(jsonBucket, "name");
                                record.S3.Bucket.Arn  = GetValueAsString(jsonBucket, "arn");


                                if (jsonBucket["ownerIdentity"] != null)
                                {
                                    var jsonOwnerIdentity = jsonBucket["ownerIdentity"];
                                    record.S3.Bucket.OwnerIdentity             = new UserIdentityEntity();
                                    record.S3.Bucket.OwnerIdentity.PrincipalId = GetValueAsString(jsonOwnerIdentity, "principalId");
                                }
                            }

                            if (jsonS3["object"] != null)
                            {
                                var jsonObject = jsonS3["object"];
                                record.S3.Object = new S3ObjectEntity();

                                record.S3.Object.Key       = GetValueAsString(jsonObject, "key");
                                record.S3.Object.Size      = GetValueAsLong(jsonObject, "size");
                                record.S3.Object.ETag      = GetValueAsString(jsonObject, "eTag");
                                record.S3.Object.VersionId = GetValueAsString(jsonObject, "versionId");
                            }
                        }

                        s3Event.Records.Add(record);
                    }
                }

                return(s3Event);
            }
            catch (Exception e)
            {
                throw new AmazonClientException("Failed to parse json string: " + e.Message, e);
            }
        }