Esempio n. 1
0
        private void GetChannelData()
        {
            YouTubeDataSource yds = DroneDataSource as YouTubeDataSource;

            if (!Object.Equals(null, yds))
            {
                foreach (Competitor account in yds.GetCompetitorAccounts())
                {
                    if (!String.IsNullOrEmpty(account.YouTubeAccount))
                    {
                        ChannelManager cManager = new ChannelManager(new KeyValuePair <int, string>(account.ID, account.YouTubeAccount)
                                                                     , Utility.ApplicationName
                                                                     , XMLUtility.GetTextFromAccountNode(Xml, "token/devkey"));
                        Channel chan = cManager.GetUserChannel();

                        if (!Object.Equals(chan, null))
                        {
                            YouTubeDataComponent ydc = new YouTubeDataComponent();
                            ydc.YouTubeChannel = chan;
                            DroneDataSource.Process(ydc);
                        }
                        else
                        {
                            Utility.WriteToLogFile(String.Format("YouTube_ChannelNull_{0:M_d_yyyy}", DateTime.Today) + ".log", "No account info for: " + account.YouTubeAccount);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public override void ProcessMessage(object sender, MessageEventArgs args)
        {
            bool handled = false;

            try
            {
                string  msg = Encoding.UTF8.GetString(args.Message.BodyStream.ToByteArray());
                Channel ch  = Utility.DeserializeXMLString <Channel>(msg);

                if (!Object.Equals(ch, null))
                {
                    YouTubeDataComponent ytdc = new YouTubeDataComponent();
                    ytdc.YouTubeChannel = ch;

                    handled = true;
                    FireMessageProcessingEvent();
                    QueueComponentDataSource.Process(ytdc);
                    FireMessageProcessedEvent();
                }
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "QueueYouTube.ProcessMessage");

                if (Utility.IsCriticalDBError(e))
                {
                    FireShuttingDownEvent();
                }

                if (handled)
                {
                    FireMessageProcessedEvent();
                }
            }
        }
Esempio n. 3
0
        public override void Process(IDroneDataComponent component)
        {
            YouTubeDataComponent ytdc = component as YouTubeDataComponent;

            if (!Object.Equals(ytdc, null))
            {
                SaveChannelInfo(ytdc);
            }
        }
Esempio n. 4
0
        public override void Process(IDroneDataComponent component)
        {
            YouTubeDataComponent comp = component as YouTubeDataComponent;

            if (!Object.Equals(comp, null))
            {
                //For now do nothing, this is a blank datasource for unit testing.
                Utility.WriteToLogFile(String.Format("YouTube_TestDataRun_{0:M_d_yyyy}", DateTime.Today) + ".log", comp.YouTubeChannel.Feed.Count + ", " + DateTime.Now);
            }
        }
Esempio n. 5
0
        private void SendChannelInfo(YouTubeDataComponent ytdc)
        {
            //CreatePostRequest
            Uri apiuri = new Uri(XMLUtility.GetTextFromAccountNode(Xml, "apiuri"));

            //send
            try
            {
                HttpStatusCode code = SendRequest(apiuri, ytdc.YouTubeChannel, true);
            }
            catch (Exception e)
            {
                ExceptionExtensions.LogError(e, "YouTubeDataSource.SendRequest", ytdc.YouTubeChannel.Name);
            }
        }
Esempio n. 6
0
        private void GetSquatterData()
        {
            ChannelManager cManager = new ChannelManager();
            Channel        chanVids = cManager.GetSquatterVideos(GetAllSquatterVideoIds());

            if (!Object.Equals(chanVids, null))
            {
                YouTubeDataComponent ydc = new YouTubeDataComponent();
                ydc.YouTubeChannel = chanVids;
                DroneDataSource.Process(ydc);
            }
            else
            {
                Utility.WriteToLogFile(String.Format("YouTube_SquattersNull_{0:M_d_yyyy}", DateTime.Today) + ".log", "No videos found");
            }
        }
Esempio n. 7
0
        private static void SaveChannelInfo(YouTubeDataComponent ytdc)
        {
            ChannelVideo curVideo = null;

            if (!Object.Equals(ytdc.YouTubeChannel, null))
            {
                try
                {
                    //channel & competitors
                    if (ytdc.YouTubeChannel.ID != 0)                     //0 is squatter videos
                    {
                        DataFactory.ExecuteNonQuery("YouTubeCompetitorChannelInsert",
                                                    new KeyValuePair <string, object>("@CompetitorID", ytdc.YouTubeChannel.ID),
                                                    new KeyValuePair <string, object>("@Views", ytdc.YouTubeChannel.TotalVideoViews),
                                                    new KeyValuePair <string, object>("@Subscribers", ytdc.YouTubeChannel.TotalSubscribers),
                                                    new KeyValuePair <string, object>("@Likes", ytdc.YouTubeChannel.TotalLikes),
                                                    new KeyValuePair <string, object>("@Dislikes", ytdc.YouTubeChannel.TotalDislikes),
                                                    new KeyValuePair <string, object>("@Comments", ytdc.YouTubeChannel.TotalComments),
                                                    new KeyValuePair <string, object>("@ReportDate", DateTime.Today.AddDays(-1)));
                    }

                    //if its GD and we have videos.  To store video detail info from competitors too. remove this check for GD
                    if (ytdc.YouTubeChannel.ID <= 1 && !Object.Equals(ytdc.YouTubeChannel.Feed, null))                     //1 is GD, 0 is Squatters
                    {
                        foreach (var video in ytdc.YouTubeChannel.Feed)
                        {
                            curVideo = video;
                            DataFactory.ExecuteNonQuery("YouTubeVideoInsert",
                                                        new KeyValuePair <string, object>("@CommercialID", video.ChannelVideoID),
                                                        new KeyValuePair <string, object>("@CommercialName", video.Title),
                                                        new KeyValuePair <string, object>("@isGoDaddyChannel", ytdc.YouTubeChannel.ID == 1 ? 1 : 0));

                            DataFactory.ExecuteNonQuery("YouTubeVideoDetailInsert",
                                                        new KeyValuePair <string, object>("@CommercialID", video.ChannelVideoID),
                                                        new KeyValuePair <string, object>("@Views", video.ViewCount),
                                                        new KeyValuePair <string, object>("@Comments", video.CommentCount),
                                                        new KeyValuePair <string, object>("@Likes", video.Likes),
                                                        new KeyValuePair <string, object>("@Dislikes", video.Dislikes),
                                                        new KeyValuePair <string, object>("@DateUploaded", video.UploadedDate),
                                                        new KeyValuePair <string, object>("@ReportDate", DateTime.Today.AddDays(-1)));
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e.Message.Contains("deadlocked"))
                    {
                        SaveChannelInfo(ytdc);
                        ExceptionExtensions.LogInformation("YouTubeDataSource.SaveChannelInfo", "Deadlock encountered, trying again");
                    }
                    else
                    {
                        ExceptionExtensions.LogError(e, "YouTubeDataSource.SaveChannelInfo", "Video ID: " + curVideo.ChannelVideoID);

                        //if tempdb full or other critical db error, re-throw
                        if (Utility.IsCriticalDBError(e))
                        {
                            throw;
                        }
                    }
                }
            }
        }