Exemple #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListStreamsResponse response = new ListStreamsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("LastEvaluatedStreamArn", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.LastEvaluatedStreamArn = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("Streams", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <StreamSummary, StreamSummaryUnmarshaller>(StreamSummaryUnmarshaller.Instance);
                    response.Streams = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemple #2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListStreamsResponse response = new ListStreamsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("StreamInfoList", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <StreamInfo, StreamInfoUnmarshaller>(StreamInfoUnmarshaller.Instance);
                    response.StreamInfoList = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonIoTConfig config = new AmazonIoTConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonIoTClient client = new AmazonIoTClient(creds, config);

            ListStreamsResponse resp = new ListStreamsResponse();

            do
            {
                ListStreamsRequest req = new ListStreamsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.ListStreams(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Streams)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Exemple #4
0
        public static List <string> GetDataStreamList()
        {
            List <string> streamList = null;

            try
            {
                AmazonKinesisClient kinesisClient;

                using (kinesisClient = new AmazonKinesisClient(Models.MyAWSConfigs.KinesisRegion))
                {
                    ListStreamsRequest  listStreamsRequest  = new ListStreamsRequest();
                    ListStreamsResponse listStreamsResponse = kinesisClient.ListStreams(listStreamsRequest);

                    if (listStreamsResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
                    {
                        streamList = listStreamsResponse.StreamNames;
                    }
                    else
                    {
                        Console.WriteLine("Error listing kinesis data streams");
                    }
                }
            }
            catch (AmazonKinesisException e)
            {
                Console.WriteLine("AmazonKinesisException: " + e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }

            return(streamList);
        }
Exemple #5
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListStreamsResponse response = new ListStreamsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("StreamNames", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <String, StringUnmarshaller>(
                        StringUnmarshaller.GetInstance());
                    response.StreamNames = unmarshaller.Unmarshall(context);

                    continue;
                }

                if (context.TestExpression("HasMoreStreams", targetDepth))
                {
                    response.HasMoreStreams = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonKinesisConfig config = new AmazonKinesisConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonKinesisClient client = new AmazonKinesisClient(creds, config);

            ListStreamsResponse resp = new ListStreamsResponse();

            do
            {
                ListStreamsRequest req = new ListStreamsRequest
                {
                    ExclusiveStartStreamName = resp.StreamNames[0]
                    ,
                    Limit = maxItems
                };

                resp = client.ListStreams(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.StreamNames)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.StreamNames[0]));
        }
Exemple #7
0
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            ListStreamsResponse response = new ListStreamsResponse();

            context.Read();

            UnmarshallResult(context, response);
            return(response);
        }
Exemple #8
0
        private static void UnmarshallResult(JsonUnmarshallerContext context, ListStreamsResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("StreamNames", targetDepth))
                {
                    context.Read();
                    response.StreamNames = new List <String>();
                    StringUnmarshaller unmarshaller = StringUnmarshaller.GetInstance();
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd)
                        {
                            break;
                        }
                        response.StreamNames.Add(unmarshaller.Unmarshall(context));
                    }
                    continue;
                }

                if (context.TestExpression("HasMoreStreams", targetDepth))
                {
                    context.Read();
                    response.HasMoreStreams = BoolUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
Exemple #9
0
        private static async Task <Stream> GetOrCreateStream(StreamAdminClient client, string compartmentId, string streamName, int partitions)
        {
            ListStreamsRequest listRequest = new ListStreamsRequest
            {
                CompartmentId  = compartmentId,
                LifecycleState = Stream.LifecycleStateEnum.Active,
                Name           = streamName
            };
            ListStreamsResponse listStreamsResponse = await client.ListStreams(listRequest);

            if (listStreamsResponse.Items.Count != 0)
            {
                // if we find an active stream with the correct name, we'll use it.
                logger.Info($"An active stream named {streamName} was found");

                string streamId = listStreamsResponse.Items[0].Id;
                return(await GetStream(client, streamId));
            }

            logger.Info($"No active stream named {streamName} was found; creating it now");
            Stream createdStream = await CreateStream(client, compartmentId, streamName, partitions);

            // GetStream provides details about a specific stream.
            // Since stream creation is asynchronous; we need to wait for the stream to become active.
            WaiterConfiguration waiterConfiguration = new WaiterConfiguration
            {
                MaxAttempts           = 20,
                GetNextDelayInSeconds = DelayStrategy.GetExponentialDelayInSeconds
            };
            GetStreamRequest streamRequest = new GetStreamRequest
            {
                StreamId = createdStream.Id
            };
            Stream activeStream = client.Waiters.ForStream(streamRequest, waiterConfiguration, Stream.LifecycleStateEnum.Active).Execute().Stream;

            // Give a little time for the stream to be ready.
            await Task.Delay(1000);

            return(activeStream);
        }
Exemple #10
0
        private void UpdateData()
        {
            using (IAmazonKinesis klient = new AmazonKinesisClient(_credentials, Amazon.RegionEndpoint.USWest2))
            {
                ListStreamsResponse   resp            = klient.ListStreams();
                DescribeStreamRequest describeRequest = new DescribeStreamRequest();
                describeRequest.StreamName = StreamName;

                DescribeStreamResponse describeResponse = klient.DescribeStream(describeRequest);
                List <Shard>           shards           = describeResponse.StreamDescription.Shards;

                foreach (Shard shard in shards)
                {
                    SequenceNumberRange range = shard.SequenceNumberRange;

                    GetShardIteratorRequest iteratorRequest = new GetShardIteratorRequest();
                    iteratorRequest.StreamName        = StreamName;
                    iteratorRequest.ShardId           = shard.ShardId;
                    iteratorRequest.ShardIteratorType = ShardIteratorType;

                    GetShardIteratorResponse iteratorResponse = klient.GetShardIterator(iteratorRequest);
                    string iteratorId = iteratorResponse.ShardIterator;
                    while (IsRunning && !string.IsNullOrEmpty(iteratorId))
                    {
                        Thread.Sleep(1);
                        GetRecordsRequest getRequest = new GetRecordsRequest();
                        getRequest.Limit         = 1000;
                        getRequest.ShardIterator = iteratorId;

                        GetRecordsResponse getResponse             = klient.GetRecords(getRequest);
                        string             nextIterator            = getResponse.NextShardIterator;
                        List <Amazon.Kinesis.Model.Record> records = getResponse.Records;

                        if (records.Count > 0)
                        {
                            if (IsDebug)
                            {
                                string message = string.Format("Received {0} records. ", records.Count);
                                Console.WriteLine(message);
                                foreach (IDebugObserver observer in _debugObservers)
                                {
                                    observer.WriteDebug(message);
                                }
                            }
                            foreach (Amazon.Kinesis.Model.Record record in records)
                            {
                                if (!IsRunning)
                                {
                                    break;
                                }
                                Thread.Sleep(1);
                                string json = Encoding.UTF8.GetString(record.Data.ToArray());
                                if (IsDebug)
                                {
                                    string message = "Json string: " + json;
                                    Console.WriteLine(message);
                                    foreach (IDebugObserver observer in _debugObservers)
                                    {
                                        observer.WriteDebug(message);
                                    }
                                }
                                T obj = JsonConvert.DeserializeObject <T>(json);
                                if (obj != null && _dataHandler != null)
                                {
                                    _dataHandler(obj);
                                }
                            }
                        }
                        iteratorId = nextIterator;
                    }

                    if (!IsRunning)
                    {
                        break;
                    }
                }
            }
        }