private static void schedulemessages(DatabaseRepository dbr, IGrouping <string, Domain.Socioboard.Models.ScheduledMessage> items)
 {
     try
     {
         Domain.Socioboard.Models.Facebookaccounts _facebook = dbr.Single <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == items.Key && t.IsActive);
         if (_facebook != null)
         {
             foreach (var item in items)
             {
                 try
                 {
                     Console.WriteLine(item.socialprofileName + "Scheduling Started");
                     FacebookScheduler.PostFacebookMessage(item, _facebook);
                     Console.WriteLine(item.socialprofileName + "Scheduling");
                 }
                 catch (Exception)
                 {
                 }
             }
             _facebook.SchedulerUpdate = DateTime.UtcNow;
             dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(_facebook);
         }
     }
     catch (Exception ex)
     {
         //  Thread.Sleep(60000);
     }
 }
        private static void schedulemessages(object o)
        {
            try
            {
                Console.WriteLine(Thread.CurrentThread.Name + " Is Entered in Method");

                var arr = o as object[];

                var dbr = (DatabaseRepository)arr[0];

                var items = (IGrouping <string, Domain.Socioboard.Models.ScheduledMessage>)arr[1];

                var facebook = dbr.Find <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == items.Key && t.IsActive).FirstOrDefault();

                var user = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == facebook.UserId);

                if (facebook == null)
                {
                    return;
                }

                foreach (var item in items)
                {
                    try
                    {
                        Console.WriteLine(item.socialprofileName + "Scheduling Started");
                        FacebookScheduler.PostFacebookMessage(item, facebook, user);
                        Console.WriteLine(item.socialprofileName + "Scheduling");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                facebook.SchedulerUpdate = DateTime.UtcNow;
                dbr.Update(facebook);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                noOfthreadRunning--;
                objSemaphore.Release();
                Console.WriteLine(Thread.CurrentThread.Name + " Is Released");
            }
        }
Esempio n. 3
0
        private static void daywiseSchedulemessages(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.DaywiseSchedule> items = (IGrouping <string, Domain.Socioboard.Models.DaywiseSchedule>)arr[1];
                Domain.Socioboard.Models.Facebookaccounts _facebook = dbr.Find <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == items.Key && t.IsActive).FirstOrDefault();
                Domain.Socioboard.Models.User             _user     = dbr.Single <Domain.Socioboard.Models.User>(t => t.Id == _facebook.UserId);
                if (_facebook != null)
                {
                    foreach (var item in items)
                    {
                        try
                        {
                            Console.WriteLine(item.socialprofileName + "Scheduling Started");
                            FacebookScheduler.PostDaywiseFacebookMessage(item, _facebook, _user);
                            Console.WriteLine(item.socialprofileName + "Scheduling");
                        }
                        catch (Exception)
                        {
                        }

                        item.scheduleTime = DateTime.UtcNow;
                        dbr.Update <Domain.Socioboard.Models.DaywiseSchedule>(item);
                    }
                    //_facebook.SchedulerUpdate = DateTime.UtcNow;

                    //dbr.Update<Domain.Socioboard.Models.Facebookaccounts>(_facebook);
                }
            }
            catch (Exception ex)
            {
                //  Thread.Sleep(60000);
            }
            finally
            {
                noOfthreadRunning--;
                objSemaphore.Release();
                Console.WriteLine(Thread.CurrentThread.Name + " Is Released");
            }
        }
        public void ScheduleFacebookMessage()
        {
            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.Facebook || t.profileType == Domain.Socioboard.Enum.SocialProfileType.FacebookFanPage) && t.scheduleTime <= DateTime.UtcNow).ToList();
                    var newlstScheduledMessage = lstScheduledMessage.GroupBy(t => t.profileId).ToList();

                    foreach (var items in newlstScheduledMessage)
                    {
                        try
                        {
                            Domain.Socioboard.Models.Facebookaccounts _facebook = dbr.Single <Domain.Socioboard.Models.Facebookaccounts>(t => t.FbUserId == items.Key && t.IsAccessTokenActive);
                            if (_facebook != null)
                            {
                                foreach (var item in items)
                                {
                                    Console.WriteLine(item.socialprofileName + "Scheduling Started");
                                    FacebookScheduler.PostFacebookMessage(item, _facebook);
                                    Console.WriteLine(item.socialprofileName + "Scheduling");
                                }
                                _facebook.SchedulerUpdate = DateTime.UtcNow;
                                dbr.Update <Domain.Socioboard.Models.Facebookaccounts>(_facebook);
                            }
                        }
                        catch (Exception ex)
                        {
                            //  Thread.Sleep(60000);
                        }
                    }
                    Thread.Sleep(TimeSpan.FromMinutes(1));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("issue in web api calling" + ex.StackTrace);
                    Thread.Sleep(TimeSpan.FromMinutes(1));
                }
            }
        }