Exemplo n.º 1
0
        public void SubscribeToNewsHeadlineStream()
        {
            //First we need a valid session, obtained from the Rpc client
            var ctx = new CIAPI.Rpc.Client(RPC_URI);
            ctx.LogIn(USERNAME, PASSWORD);

            //Next we create a connection to the streaming api, using the authenticated session
            //You application should only ever have one of these
            var streamingClient = StreamingClientFactory.CreateStreamingClient(STREAMING_URI, USERNAME, ctx.Session);
            

            //And instantiate a listener for news headlines on the appropriate topic
            //You can have multiple listeners on one connection
            var newsListener = streamingClient.BuildNewsHeadlinesListener("UK");
            

            //The MessageReceived event will be triggered every time a new News headline is available,
            //so attach a handler for that event, and wait until something comes through
            var gate = new ManualResetEvent(false);
            NewsDTO receivedNewsHeadline = null;
            newsListener.MessageReceived += (s, e) =>
            {
                receivedNewsHeadline = e.Data;
                //Do something with the new News headline data - perhaps update a news ticker?
                gate.Set();
            };
            gate.WaitOne();

            //Shut down the connection
            streamingClient.Dispose();

            //Destroy your session
            ctx.LogOut();
        }
Exemplo n.º 2
0
        /// <summary>
        /// While the code is drastically simplified in comparison to the async pattern, you will typically
        /// want to do this on another thread and use BeingInvoke on the UI to marshal UI updates to the UI thread.
        /// This is probably the simplest pattern.
        /// </summary>
        private static void GetNewsSynchronously()
        {
            try
            {
                var ctx = new CIAPI.Rpc.Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), AppKey);

                ctx.LogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword);

                var headlinesResponse = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);

                foreach (var item in headlinesResponse.Headlines)
                {
                    // item contains id, date and headline.
                    Console.WriteLine("{0} {1} {2}\r\n", item.StoryId, item.Headline, item.PublishDate);

                    // fetch details to get all of the above and the body of the story
                    var detailResponse = ctx.News.GetNewsDetail("dj", item.StoryId.ToString());

                    Console.WriteLine("{0}", detailResponse.NewsDetail.Story.Substring(0, 35) + "...");
                    Console.WriteLine("\r\n-----------------------------------------------------------------------------\r\n");
                }

                ctx.LogOut();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("\r\nPress enter to continue\r\n");
                Console.ReadLine();
            }

            #endregion
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                var adapter = new MyLoggerFactoryAdapter(null) { OnMessage = AddLogMessage };
                LogManager.Adapter = adapter;

                _client = new CIAPI.Rpc.Client(RPC_URI);
                _client.LogIn(USERNAME, PASSWORD);

                for (int i = 0; i < 100; i++)
                {
                    ThreadPool.QueueUserWorkItem(s => EndlessTest());
                }

                Console.ReadKey();

                _client.LogOut();
                _client.Dispose();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                var listeners = new[] { new TextWriterTraceListener(Console.Out) };
                Debug.Listeners.AddRange(listeners);

                var adapter = new MyLoggerFactoryAdapter(null)
                {
                    OnMessage = AddLogMessage
                };
                LogManager.Adapter = adapter;

                var client = new CIAPI.Rpc.Client(RPC_URI);
                client.LogIn(USERNAME, PASSWORD);

                var news = client.News.ListNewsHeadlinesWithSource("mni", "ALL", 10);

                client.LogOut();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
Exemplo n.º 5
0
        public static void DisConnectCIAPI()
        {
            StreamingClient.Disconnect();
            CIAPI_Client.LogOut();
            CIAPI_Client.Dispose();

            IsConnected = false;
        }
Exemplo n.º 6
0
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI);
            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);
            
            //do something with the news

            ctx.LogOut();
        }
Exemplo n.º 7
0
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI, STREAMING_URI, AppKey);

            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);

            //do something with the news

            ctx.LogOut();
        }
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI);

            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.ListNewsHeadlines("UK", 10);

            //do something with the news

            ctx.LogOut();
        }
        public void SubscribeToNewsHeadlineStream()
        {
            //First we need a valid session, obtained from the Rpc client
            var ctx = new CIAPI.Rpc.Client(RPC_URI);

            ctx.LogIn(USERNAME, PASSWORD);

            //Next we create a connection to the streaming api, using the authenticated session
            //You application should only ever have one of these
            var streamingClient = StreamingClientFactory.CreateStreamingClient(STREAMING_URI, USERNAME, ctx.SessionId);

            streamingClient.Connect();

            //And instantiate a listener for news headlines on the appropriate topic
            //You can have multiple listeners on one connection
            var newsListener = streamingClient.BuildNewsHeadlinesListener("NEWS.MOCKHEADLINES.UK");

            newsListener.Start();

            //The MessageReceived event will be triggered every time a new News headline is available,
            //so attach a handler for that event, and wait until something comes through
            var     gate = new ManualResetEvent(false);
            NewsDTO receivedNewsHeadline = null;

            newsListener.MessageReceived += (s, e) =>
            {
                receivedNewsHeadline = e.Data;
                //Do something with the new News headline data - perhaps update a news ticker?
                gate.Set();
            };
            gate.WaitOne();

            //Clean up
            //Stop any listeners
            newsListener.Stop();
            //Shut down the connection
            streamingClient.Disconnect();
            //Destroy your session
            ctx.LogOut();
        }
Exemplo n.º 10
0
		static void Main(string[] args)
		{
			try
			{
				var listeners = new[] { new TextWriterTraceListener(Console.Out) };
				Debug.Listeners.AddRange(listeners);

				var adapter = new MyLoggerFactoryAdapter(null) { OnMessage = AddLogMessage };
				LogManager.Adapter = adapter;

				var client = new CIAPI.Rpc.Client(RPC_URI);
				client.LogIn(USERNAME, PASSWORD);

				var news = client.News.ListNewsHeadlinesWithSource("mni", "ALL", 10);

				client.LogOut();
			}
			catch (Exception exc)
			{
				Console.WriteLine(exc);
			}
		}
Exemplo n.º 11
0
        public void YouCanForceYourSessionToExpireByLoggingOut()
        {
            _rpcClient.LogIn(USERNAME, PASSWORD);

            KoanAssert.That(_rpcClient.Session, Is.Not.Null, "You should have a valid sessionId after logon");
            var oldSessionId = _rpcClient.Session;

            //Logging out force expires your session token on the server
            _rpcClient.LogOut();

            //So that future requests with your old token will fail.
            try
            {
                _rpcClient.Session = oldSessionId;
                var headlines2 = _rpcClient.News.ListNewsHeadlinesWithSource("dj", "AUS", 4);
                KoanAssert.Fail("the previous line should have thrown an (401) Unauthorized exception");
            }
            catch (ReliableHttpException e)
            {
                KoanAssert.That(e.Message, Is.StringContaining("Session is not valid"), "The error message should contain something about 'Session is not valid'");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// While the code is drastically simplified in comparison to the async pattern, you will typically
        /// want to do this on another thread and use BeingInvoke on the UI to marshal UI updates to the UI thread.
        /// This is probably the simplest pattern.
        /// </summary>
        private static void GetNewsSynchronously()
        {
            try
            {
                var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.RpcUrl));

                ctx.LogIn(TestConfig.ApiUsername, TestConfig.ApiPassword);

                var headlinesResponse = ctx.ListNewsHeadlines("UK", 10);

                foreach (var item in headlinesResponse.Headlines)
                {
                    // item contains id, date and headline.
                    Console.WriteLine("{0} {1} {2}\r\n", item.StoryId, item.Headline, item.PublishDate);

                    // fetch details to get all of the above and the body of the story
                    var detailResponse = ctx.GetNewsDetail(item.StoryId.ToString());

                    Console.WriteLine("{0}", detailResponse.NewsDetail.Story.Substring(0, 35) + "...");
                    Console.WriteLine("\r\n-----------------------------------------------------------------------------\r\n");
                }

                ctx.LogOut();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("\r\nPress enter to continue\r\n");
                Console.ReadLine();
            }

        #endregion
        }