static void Main(string[] args) { // Set Logger level to Trace Log.Level = NLog.LogLevel.Trace; bool useRDP = false; ISession session; if (!useRDP) { System.Console.WriteLine("Start DeploytedPlatformSession"); 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() .OAuthGrantType(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 (MachineReadableNews mrnNews = ContentFactory.CreateMachineReadableNews(new MachineReadableNews.Params() .Session(session) .WithNewsDatafeed("MRN_STORY") .OnError((e, msg) => Console.WriteLine(msg)) .OnStatus((e, msg) => Console.WriteLine(msg)) .OnNews((e, msg) => ProcessNewsContent(msg)))) { mrnNews.Open(); Thread.Sleep(runtime); } } }
static void Main(string[] args) { 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() .OAuthGrantType(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 = ContentFactory.CreateMachineReadableNews(new MachineReadableNews.Params() .Session(session) .WithNewsDatafeed("MRN_STORY") .OnError((e, msg) => Console.WriteLine(msg)) .OnStatus((e, msg) => Console.WriteLine(msg)) .OnNews((e, msg) => ProcessNewsContent(msg))); mrnNews.Open(); Thread.Sleep(runtime); } if (redirectOutputToFile) { streamWriter?.Close(); if (fileStream != null) { fileStream.Close(); } } Console.WriteLine("Stop and Quit the applicaiton"); }