static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Sessions.GetSession()) { // Open the session session.Open(); // Create an MRN definition var mrn = MachineReadableNews.Definition(); // Choose the type of data feed from the MRN service string input; do { Console.Write("\nChoose an MRN Data Feed (0 - Story, 1 - Analytics Assets, 2 - Analytics Events) [Enter to Exit]: "); input = Console.ReadLine(); if (input.Length > 0) { try { // Validate the selection var feed = (MachineReadableNews.Datafeed)Enum.Parse(typeof(MachineReadableNews.Datafeed), input); if (Enum.IsDefined(typeof(MachineReadableNews.Datafeed), feed)) { // Set the datafeed then retrieve a streaming object. using (var stream = mrn.NewsDatafeed(feed).GetStream()) { // Define our real-time processing then open the stream... stream.OnError((err, s) => Console.WriteLine($"{DateTime.Now}:{err}")) .OnStatus((status, s) => Console.WriteLine($"Status for feed: {s.Definition.DataFeed} => {status}")) .OnNewsStory((newsItem, s) => OnNewsStory(newsItem)) .OnNewsAnalyticsAssets((newsItem, s) => OnNewsAnalyticsAssets(newsItem)) .OnNewsAnalyticsEvents((newsItem, s) => OnNewsAnalyticsEvents(newsItem)) .Open(); Console.ReadLine(); } } } catch (ArgumentException) { } } } while (input.Length > 0); } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main() { // Set Logger level to Trace Log.Level = NLog.LogLevel.Trace; bool useRDP = true; ISession session; if (!useRDP) { System.Console.WriteLine("Start DeploytedPlatformSession"); session = CoreFactory.CreateSession(new DeployedPlatformSession.Params() .Host(WebSocketHost) .WithDacsUserName(RTDSUser) .WithDacsApplicationID(appID) .WithDacsPosition(position) .OnState((s, state, msg) => { Console.WriteLine($"{DateTime.Now}: {msg}. (State: {state})"); _sessionState = state; }) .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})"))); } else { System.Console.WriteLine("Start RDP PlatformSession"); session = CoreFactory.CreateSession(new PlatformSession.Params() .WithOAuthGrantType(new GrantPassword().UserName(RDPUser) .Password(RDPPassword)) .AppKey(RDPAppKey) .WithTakeSignonControl(true) .OnState((s, state, msg) => { Console.WriteLine($"{DateTime.Now}: {msg}. (State: {state})"); _sessionState = state; }) .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})"))); } session.Open(); if (_sessionState == Session.State.Opened) { System.Console.WriteLine("Session is now Opened"); System.Console.WriteLine("Sending MRN_STORY request"); using var mrnNews = MachineReadableNews.Definition().OnError((stream, err) => Console.WriteLine($"{DateTime.Now}:{err}")) .OnStatus((stream, status) => Console.WriteLine(status)) .NewsDatafeed(MachineReadableNews.Datafeed.MRN_STORY) .OnNewsStory((stream, newsItem) => ProcessNewsContent(newsItem.Raw)); { mrnNews.Open(); Thread.Sleep(runtime); } } }
static void Main(string[] _) { try { // Create a session into the platform... using (ISession session = Configuration.Sessions.GetSession()) { // Open the session session.Open(); // Choose the type of data feed from the MRN service string input; do { Console.Write("\nChoose an MRN Data Feed (0 - Story, 1 - TRNA, 2- TRSI) (Enter to Exit): "); input = Console.ReadLine(); if (input.Length > 0) { try { // Validate the selection var feed = (MachineReadableNews.Datafeed)Enum.Parse(typeof(MachineReadableNews.Datafeed), input); if (Enum.IsDefined(typeof(MachineReadableNews.Datafeed), feed)) { // Create a Machine Readable News (MRN) Item request using (var mrn = MachineReadableNews.Definition().OnError((stream, err) => Console.WriteLine($"{DateTime.Now}:{err}")) .OnStatus((stream, status) => Console.WriteLine(status)) .NewsDatafeed(feed) .OnNewsStory((stream, newsItem) => OnNewsStory(newsItem)) .OnNewsTrna((stream, newsItem) => OnNewsTrna(newsItem)) .OnNewsTrsi((stream, newsItem) => OnNewsTrsi(newsItem))) { mrn.Open(); Console.ReadKey(); } } } catch (ArgumentException) { } } } while (input.Length > 0); } } catch (Exception e) { Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************"); } }
static void Main() { Console.WriteLine("Start retrieving MRN Story data. Press Ctrl+C to exit"); // Set RDP.NET Logger level to Trace Log.Level = NLog.LogLevel.Trace; FileStream fileStream = null; StreamWriter streamWriter = null; var @out = Console.Out; if (redirectOutputToFile) { Console.WriteLine("Redirect Output to file Output.txt"); try { fileStream = new FileStream("./Output.txt", FileMode.OpenOrCreate, FileAccess.Write); streamWriter = new StreamWriter(fileStream); } catch (Exception e) { Console.WriteLine("Cannot open Output.txt for writing"); Console.WriteLine(e.Message); return; } Console.SetOut(streamWriter); @out = Console.Out; } ISession session; if (!useRDP) { System.Console.WriteLine("Start Deployed PlatformSession"); session = CoreFactory.CreateSession(new DeployedPlatformSession.Params() .Host(WebSocketHost) .WithDacsUserName(TREPUser) .WithDacsApplicationID(appID) .WithDacsPosition(position) .OnState((s, state, msg) => { Console.WriteLine($"{DateTime.Now}: {msg}. (State: {state})"); _sessionState = state; }) .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})"))); } else { System.Console.WriteLine("Start RDP PlatformSession"); session = CoreFactory.CreateSession(new PlatformSession.Params() .WithOAuthGrantType(new GrantPassword().UserName(RDPUser) .Password(RDPPassword)) .AppKey(RDPAppKey) .WithTakeSignonControl(true) .OnState((s, state, msg) => { Console.WriteLine($"{DateTime.Now}: {msg}. (State: {state})"); _sessionState = state; }) .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})"))); } session.Open(); if (_sessionState == Session.State.Opened) { System.Console.WriteLine("Session is now Opened"); // Validate the selection System.Console.WriteLine("Sending MRN_STORY request"); using var mrn = MachineReadableNews.Definition().OnError((stream, err) => Console.WriteLine($"{DateTime.Now}:{err}")) .OnStatus((stream, status) => Console.WriteLine(status)) .NewsDatafeed(MachineReadableNews.Datafeed.MRN_STORY) .OnNewsStory((stream, newsItem) => ProcessNewsContent(newsItem.Raw)); mrn.Open(); Thread.Sleep(runtime); } if (redirectOutputToFile) { streamWriter?.Close(); if (fileStream != null) { fileStream.Close(); } } Console.WriteLine("Stop and Quit the applicaiton"); }