コード例 #1
0
        // ** CHANGES BELOW ARE NOT REQUIRED

        // GetSession
        // Based on the above Session Type, retrieve the Session used to define how you want to access the platform.
        //
        public static ISession GetSession()
        {
            switch (SessionType)
            {
            case SessionTypeEnum.RDP:
                // Createn and return an RDP Session
                return(CoreFactory.CreateSession(new PlatformSession.Params()
                                                 .OAuthGrantType(new GrantPassword().UserName(Credentials.EDPUser)
                                                                 .Password(Credentials.EDPPassword))
                                                 .AppKey(Credentials.AppKey)
                                                 .WithTakeSignonControl(true)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            case SessionTypeEnum.TREP:
                return(CoreFactory.CreateSession(new DeployedPlatformSession.Params().Host(Credentials.TREPHost)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            case SessionTypeEnum.EIKON:
                return(CoreFactory.CreateSession(new DesktopSession.Params().AppKey(Credentials.AppKey)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            default:
                throw new IndexOutOfRangeException($"Unknown Session Type: {SessionType}");
            }
        }
コード例 #2
0
        public Task InitWebSocketConnectionAsync(bool useRdp)
        {
            return(Task.Run(() =>
            {
                Log.Level = NLog.LogLevel.Trace;

                if (!useRdp)
                {
                    _session = CoreFactory.CreateSession(new DeployedPlatformSession.Params()
                                                         .Host(WebSocketHost)
                                                         .WithDacsUserName(TrepUsername)
                                                         .WithDacsApplicationID(TrepAppid)
                                                         .WithDacsPosition(TrepPosition)
                                                         .OnState(processOnState)
                                                         .OnEvent(processOnEvent));
                }
                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(processOnState)
                                                         .OnEvent(processOnEvent));
                }
                _session.OpenAsync().ConfigureAwait(false);
            }));
        }
コード例 #3
0
        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 (IStream stream = DeliveryFactory.CreateStream(
                           new ItemStream.Params().Session(session)
                           .Name("MRN_STORY")
                           .WithDomain("NewsTextAnalytics")
                           .OnRefresh((s, msg) => Console.WriteLine($"{msg}\n\n"))
                           .OnUpdate((s, msg) => ProcessMRNUpdateMessage(msg))
                           .OnError((s, msg) => Console.WriteLine(msg))
                           .OnStatus((s, msg) => Console.WriteLine($"{msg}\n\n"))))
                {
                    stream.Open();
                    Thread.Sleep(runtime);
                }
            }
        }
        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);
                }
            }
        }
コード例 #5
0
        // ** CHANGES BELOW ARE NOT REQUIRED UNLESS YOUR ACCESS REQUIRES ADDITIONAL PARAMETERS **

        // GetSession
        // Based on the above Session Type, retrieve the Session used to define how you want to access the platform.
        //
        public static ISession GetSession(bool overrideWebSocketIfNecessary = true)
        {
            if (overrideWebSocketIfNecessary)
            {
                // Note:
                // The default RDP Library for .NET WebSocket implementation is based on Microsoft's WebSocketClient.  This implementation
                // is only available on Windows 8 and above or if an application targets .NET Core 2.1 or greater.  Because all example
                // applications within this package are built using .NET Framework 4.5.2, if the Windows OS is anything less than Windows 8,
                // the WebSocket4Net implementation will be used.
                var ver = Environment.OSVersion.Version;
                if (ver.Major <= 6 && ver.Minor <= 1)
                {
                    DeliveryFactory.RegisterWebSocket(DeliveryFactory.WebSocketImpl.WebSocket4Net);
                }
            }

            switch (SessionType)
            {
            case SessionTypeEnum.RDP:
                return(CoreFactory.CreateSession(new PlatformSession.Params()
                                                 .WithOAuthGrantType(new GrantPassword().UserName(Credentials.RDPUser)
                                                                     .Password(Credentials.RDPPassword))
                                                 .AppKey(Credentials.AppKey)
                                                 .WithTakeSignonControl(true)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            case SessionTypeEnum.DEPLOYED:
                return(CoreFactory.CreateSession(new PlatformSession.Params().WithHost(Credentials.TREPHost)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}: State: {state}. {msg}"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: Event: {eventCode}. {msg}"))));

            case SessionTypeEnum.DESKTOP:
                return(CoreFactory.CreateSession(new DesktopSession.Params().AppKey(Credentials.AppKey)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            case SessionTypeEnum.DEPLOYED_DEPRECATED:
                return(CoreFactory.CreateSession(new DeployedPlatformSession.Params().Host(Credentials.TREPHost)
                                                 .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                 .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})"))));

            default:
                throw new IndexOutOfRangeException($"Unknown Session Type: {SessionType}");
            }
        }
コード例 #6
0
        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");
        }
コード例 #7
0
        static void Main(string[] args)
        {
            #region SessionManagement

            var session = CoreFactory.CreateSession(new PlatformSession.Params()
                                                    .WithOAuthGrantType(new GrantPassword().UserName(UserName)
                                                                        .Password(Password))
                                                    .AppKey(AppKey)
                                                    .WithTakeSignonControl(true)
                                                    .OnState((s, state, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (State: {state})"))
                                                    .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}:{msg}. (Event: {eventCode})")));
            session.Open();

            if (session.OpenState == Session.State.Opened)
            {
                Console.WriteLine("Session is now open");
            }
            else if (session.OpenState == Session.State.Pending)
            {
                Console.WriteLine("Session state is pending");
            }
            if (session.OpenState == Session.State.Closed)
            {
                Console.WriteLine("Session is now closed");
                return;
            }

            #endregion


            #region GetTopNewsPackage
            // Call Endpoint.SendRequestAsync to get TopNews from TopNewsEndpoint
            var topNewsPkgResp = Endpoint.SendRequestAsync(session, new Uri(TopNewsEndpoint)).GetAwaiter().GetResult();

            // Parse TopNewsPackage from data element
            var data = topNewsPkgResp.Data.Raw["data"]?.ToObject <IList <TopNewsPackage> >();
            if (data != null)
            {
                foreach (var package in data)
                {
                    Console.WriteLine($"Package Name:{package.Name} Number of Pages: {package.Pages?.Count}");
                    if (!package.Pages !.Any())
                    {
                        continue;
                    }
                    foreach (var subPackage in package.Pages)
                    {
                        // Retrieve Top News Headlines for each underlying Page using specified TopNewsId
                        #region GetTopNewsHedlines

                        Console.WriteLine($"\t\t{subPackage.Name} [{subPackage.TopNewsId}]");
                        var topNewsHeadlinesResp = Endpoint.SendRequestAsync(session,
                                                                             new Uri($"{TopNewsEndpoint}/{subPackage.TopNewsId}"))
                                                   .GetAwaiter().GetResult();

                        var headlinesList = topNewsHeadlinesResp.Data.Raw["data"]?.ToObject <IList <TopNewsData> >();
                        if (!headlinesList.Any())
                        {
                            continue;
                        }

                        foreach (var topHeadline in headlinesList)
                        {
                            Console.WriteLine(
                                $"\t\t\t{topHeadline.text} storyId:[{topHeadline.storyId}] imageId:[{topHeadline.image?.id}]");

                            #region GetImages

                            if (b_SaveImagesToFile)
                            {
                                if (topHeadline.image != null && !string.IsNullOrEmpty(topHeadline.image.id.Trim()))
                                {
                                    // Retrieve Headlines Images and save it to images_save_path
                                    var image = Image.Definition(topHeadline.image?.id).Rendition("thumbnail")
                                                .GetData();
                                    if (image.IsSuccess)
                                    {
                                        Console.WriteLine(
                                            $"\t\t\tGet Image Id: [{topHeadline.image?.id}] Image represented as a: {image.Data.Image} of length: {image.Data.Image.Length} bytes.\n");

                                        using var ms = new MemoryStream(image.Data.Image);
                                        using var fs = new FileStream($"{images_save_path}{topHeadline.image.id}.jpg",
                                                                      FileMode.Create);
                                        ms.WriteTo(fs);
                                    }
                                    else
                                    {
                                        Console.WriteLine(
                                            $"Failed to retrieve image ID: {topHeadline.image?.id}\n{image.Status}");
                                    }
                                }
                            }

                            #endregion
                            #region  GetStory

                            if (b_ShowNewsStory)
                            {
                                // Retrieve News Story using Story class. It required storyId from the Top News headline.
                                if (!string.IsNullOrEmpty(topHeadline.storyId))
                                {
                                    var story = Story.Definition(topHeadline.storyId).GetData();
                                    Console.WriteLine(story.IsSuccess
                                        ? $"\n\t\t\t Retrieving Story Id:{topHeadline.storyId}\n{story.Data.NewsStory}\n"
                                        : $"\n\t\t\tProblem retrieving the story: {story.Status}\n");
                                }
                                else
                                {
                                    Console.WriteLine("\n\t\t\tStory Id is empty skipped\n");
                                }
                            }

                            #endregion
                        }
                        #endregion
                    }
                }
            }

            #endregion

            Console.ReadKey();
        }