Example #1
0
        static void Main(string[] args)
        {
            string Hashtag = "";

            if (args.Length == 1)
            {
                Hashtag = args[0];
            }
            else
            {
                while (string.IsNullOrEmpty(Hashtag))
                {
                    Console.WriteLine("Enter a hashtag to search for: ");
                    Hashtag = Console.ReadLine();
                }
            }

            if (!Hashtag.StartsWith("#"))
            {
                Hashtag = $"#{Hashtag}";
            }

            IDataConnector Connector = DataConnectorFactory.CreateDataConnector("Twitter");

            Task <int> GetResult = Connector.RetrieveData(Hashtag);

            Task.WaitAll(GetResult);

            int DataCount = GetResult.Result;

            Console.WriteLine($"Number of Tweets received: {DataCount}.");
            Console.ReadKey();
        }
Example #2
0
        private void ProcessGamertag(GamervineDataContext DataContext, Gamertag Gamertag)
        {
            XDocument xdLatestData = null;

            IDataConnector dataConnector = DataConnectorFactory.GetDataConnectorForType(Gamertag.Type);
            int            count         = 0;

            do
            {
                count++;
                xdLatestData = dataConnector.GetLatestTagData(Gamertag);
            }while (xdLatestData == null && count < 5);

            if (xdLatestData == null)
            {
                Debug.WriteLine("Unable to retrieve data from gamertag \"" + Gamertag.Tag + "\".");
                return;
            }

            IHandler dataHandler = HandlerFactory.GetHandlerForType(Gamertag.Type);

            dataHandler.ProcessData(DataContext, Gamertag, xdLatestData);

            try
            {
                DataContext.SubmitChanges();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception occurred in DataService.DoWork:" + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
            }
        }
        public async Task TestConnector()
        {
            IDataConnector Connector = DataConnectorFactory.CreateDataConnector("twitter");

            Assert.IsNotNull(Connector);

            Assert.IsInstanceOfType(Connector, typeof(IDataConnector), $"{nameof(Connector)} must inherit {nameof(IDataConnector)}");
            Assert.IsInstanceOfType(Connector, typeof(BaseComponents.DataConnector), $"{nameof(Connector)} must inherit {nameof(BaseComponents.DataConnector)}");
            Assert.IsInstanceOfType(Connector, typeof(TwitterConnector), $"{nameof(Connector)} must be a {nameof(Connectors.TwitterConnector)}");

            TwitterConnector TwitterConnector = (TwitterConnector)Connector;

            Assert.IsNotNull(TwitterConnector.ProviderName, $"{nameof(TwitterConnector)} must have a value (\"Twitter\") assigned.");
            Assert.AreEqual("Twitter", TwitterConnector.ProviderName, $"{nameof(TwitterConnector.ProviderName)} is not the expected value (\"Twitter\").");

            int DataCount = await TwitterConnector.RetrieveData("#felixbaumgartner");

            Assert.IsTrue(DataCount > 0, $"{nameof(DataCount)} must have a value greater than 0. If the value is 0, it means no search results where returned.");
        }