public void ScheduleTwitterMessage()
        {
            while (true)
            {
                try
                {
                    DatabaseRepository dbr = new DatabaseRepository();
                    List <Domain.Socioboard.Models.ScheduledMessage> lstScheduledMessage = dbr.Find <Domain.Socioboard.Models.ScheduledMessage>(t => (t.status == Domain.Socioboard.Enum.ScheduleStatus.Pending && t.profileType == Domain.Socioboard.Enum.SocialProfileType.Twitter) && t.scheduleTime <= DateTime.UtcNow).ToList();
                    //lstScheduledMessage = lstScheduledMessage.Where(t => t.profileId.Contains("847698757219106817")).ToList();
                    var newlstScheduledMessage = lstScheduledMessage.GroupBy(t => t.profileId).ToList();

                    foreach (var items in newlstScheduledMessage)
                    {
                        try
                        {
                            Domain.Socioboard.Models.TwitterAccount _TwitterAccount = dbr.Single <Domain.Socioboard.Models.TwitterAccount>(t => t.twitterUserId == items.Key && t.isActive);
                            if (_TwitterAccount != null)
                            {
                                foreach (var item in items)
                                {
                                    try
                                    {
                                        Console.WriteLine(item.socialprofileName + "Scheduling Started");
                                        TwitterScheduler.PostTwitterMessage(item, _TwitterAccount);
                                        Console.WriteLine(item.socialprofileName + "Scheduling");
                                    }
                                    catch (Exception)
                                    {
                                        Thread.Sleep(60000);
                                    }
                                }
                                _TwitterAccount.SchedulerUpdate = DateTime.UtcNow;
                                dbr.Update <Domain.Socioboard.Models.TwitterAccount>(_TwitterAccount);
                                Thread.Sleep(60000);
                            }
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(60000);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("issue in web api calling" + ex.StackTrace);
                    Thread.Sleep(60000);
                }
            }
        }
Ejemplo n.º 2
0
        private static void TwitterSchedulemessage(object o)
        {
            try
            {
                Console.WriteLine(Thread.CurrentThread.Name + " Is Entered in Method");
                object[] arr = o as object[];
                Model.DatabaseRepository dbr = (Model.DatabaseRepository)arr[0];
                IGrouping <string, Domain.Socioboard.Models.ScheduledMessage> items = (IGrouping <string, Domain.Socioboard.Models.ScheduledMessage>)arr[1];

                Domain.Socioboard.Models.TwitterAccount _TwitterAccount = dbr.Single <Domain.Socioboard.Models.TwitterAccount>(t => t.twitterUserId == items.Key && t.isActive);

                Domain.Socioboard.Models.User _user = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == _TwitterAccount.userId);

                if (_TwitterAccount != null)
                {
                    foreach (var item in items)
                    {
                        try
                        {
                            Console.WriteLine(item.socialprofileName + "Scheduling Started");
                            TwitterScheduler.PostTwitterMessage(item, _TwitterAccount, _user);
                            Console.WriteLine(item.socialprofileName + "Scheduling");
                        }
                        catch (Exception)
                        {
                            Thread.Sleep(60000);
                        }
                    }
                    _TwitterAccount.SchedulerUpdate = DateTime.UtcNow;
                    dbr.Update <Domain.Socioboard.Models.TwitterAccount>(_TwitterAccount);
                }
            }
            catch (Exception)
            {
                Thread.Sleep(60000);
            }
            finally
            {
                noOfthreadRunning--;
                objSemaphore.Release();
                Console.WriteLine(Thread.CurrentThread.Name + " Is Released");
            }
        }