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

            try
            {
                while (true)
                {
                    Console.WriteLine("Starting");
                    Console.Write("Posting Detail ID (-1 to exit): ");
                    string input           = Console.ReadLine();
                    int    postingDetailID = 0;
                    int.TryParse(input, out postingDetailID);
                    if (postingDetailID == -1)
                    {
                        break;
                    }
                    AutoMaxContext db = new AutoMax.Models.AutoMaxContext();
                    Library.SystemLogLevel = LogLevel.Debug;

                    var pd = db.PostingDetail
                             .Include("PostingSite")
                             .Include("VehicleWizard")
                             .Include("VehicleWizard.VehicleType")
                             .Include("VehicleWizard.Maker")
                             .Include("VehicleWizard.AutoModel")
                             .Include("VehicleWizard.SubModel")
                             .Include("VehicleWizard.Year")
                             .Include("VehicleWizard.VehclieTitle")
                             .Include("VehicleWizard.AutoCondition")
                             .Include("VehicleWizard.AutoBodyStyle")
                             .Include("VehicleWizard.AutoAirBag")
                             .Include("VehicleWizard.AutoInteriorColor")
                             .Include("VehicleWizard.AutoDoor")
                             .Include("VehicleWizard.AutoExteriorColor")
                             .Include("VehicleWizard.AutoEngine")
                             .Include("VehicleWizard.EngineCapacity")
                             .Include("VehicleWizard.DriveType")
                             .Include("VehicleWizard.FuelType")
                             .Include("VehicleWizard.AutoTransmission")
                             .Include("VehicleWizard.MediaPlayer")
                             .Include("VehicleWizard.RoofType")
                             .Include("VehicleWizard.Upholstery")
                             .Where(p => p.PostingDetailID == postingDetailID).FirstOrDefault();

                    WebsiteBot bot = WebsiteBotFactory.Instance.GetWebsiteBot(pd.PostingSite.PostingSiteName);
                    bot.SetContext(db);
                    bot.SetPostingDetails(pd);

                    if (bot.PostAd())
                    {
                        Library.WriteLog(methodName, "Posting successfull", LogLevel.Information);
                        pd.PostingStatus = db.PostingStatus.FirstOrDefault(p => p.StatusName == "Posted");
                        pd.UpdatedDate   = DateTime.Now;
                        db.SaveChanges();
                    }
                    else
                    {
                        Library.WriteLog(methodName, "Posting failed", LogLevel.Information);
                    }
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            Console.ReadLine();
        }
Example #2
0
        void executePosting()
        {
            string methodName = "executePosting";

            Library.WriteLog(methodName, "Entered");
            try
            {
                AutoMaxContext db = new AutoMaxContext();

                Library.WriteLog(methodName, "Fetching posting with status 1 (Pending)");
                var postingDetails = db.PostingDetail
                                     .Include("PostingSite")
                                     .Include("VehicleWizard")
                                     .Include("VehicleWizard.VehicleType")
                                     .Include("VehicleWizard.Maker")
                                     .Include("VehicleWizard.AutoModel")
                                     .Include("VehicleWizard.SubModel")
                                     .Include("VehicleWizard.Year")
                                     .Include("VehicleWizard.VehclieTitle")
                                     .Include("VehicleWizard.AutoCondition")
                                     .Include("VehicleWizard.AutoBodyStyle")
                                     .Include("VehicleWizard.AutoAirBag")
                                     .Include("VehicleWizard.AutoInteriorColor")
                                     .Include("VehicleWizard.AutoDoor")
                                     .Include("VehicleWizard.AutoExteriorColor")
                                     .Include("VehicleWizard.AutoEngine")
                                     .Include("VehicleWizard.EngineCapacity")
                                     .Include("VehicleWizard.DriveType")
                                     .Include("VehicleWizard.FuelType")
                                     .Include("VehicleWizard.AutoTransmission")
                                     .Include("VehicleWizard.MediaPlayer")
                                     .Include("VehicleWizard.RoofType")
                                     .Include("VehicleWizard.Upholstery")
                                     .Where(p => p.PostingStatus.StatusName != "Posted" && p.RetryCount < p.Retries).ToList();

                Library.WriteLog(methodName, string.Format("Fetch count {0}", postingDetails.Count), postingDetails.Count > 0 ? LogLevel.Information : LogLevel.Debug);

                foreach (PostingDetail pd in postingDetails)
                {
                    WebsiteBot bot = WebsiteBotFactory.Instance.GetWebsiteBot(pd.PostingSite.PostingSiteName);
                    bot.SetContext(db);
                    bot.SetPostingDetails(pd);

                    if (bot.PostAd())
                    {
                        Library.WriteLog(methodName, "Posting successfull", LogLevel.Information);
                        pd.PostingStatus   = db.PostingStatus.FirstOrDefault(p => p.StatusName == "Posted");
                        pd.UpdatedDate     = DateTime.Now;
                        pd.PostingSiteUser = bot.PostingSiteUser;
                        pd.RetryCount++;
                        pd.PostingError = "Success";
                        db.SaveChanges();
                    }
                    else
                    {
                        Library.WriteLog(methodName, "Posting failed", LogLevel.Information);
                        pd.PostingStatus = db.PostingStatus.FirstOrDefault(p => p.StatusName == "Failed");
                        pd.UpdatedDate   = DateTime.Now;
                        pd.RetryCount++;
                        pd.PostingError = bot.Error;
                        db.SaveChanges();
                    }
                }
                Library.WriteLog(methodName, "Loop completed");
            }
            catch (Exception ex)
            {
                Library.WriteLog(methodName, ex.ToString());
            }
        }