public void ThreadRepinMethod(Pins pin, PinInterestUser objPinUser) { try { try { lstThreadsAddPinWithNewBoard.Add(Thread.CurrentThread); lstThreadsAddPinWithNewBoard.Distinct().ToList(); Thread.CurrentThread.IsBackground = true; } catch (Exception ex) { }; Board = Regex.Split(pin.Board, ":")[0]; if (!string.IsNullOrEmpty(Board)) { //Board = pin.Board; BoardNumber = objAddNewPinManager.GetBoardId(Board, ref objPinUser); if (string.IsNullOrEmpty(BoardNumber)) { GlobusLogHelper.log.Info(" => [ " + Board + " Not Found. Creating Board ]"); BoardNumber = CreateBoard_new(Board, "Other", ref objPinUser); BoardNumber = objAddNewPinManager.GetBoardId(Board, ref objPinUser); } } else { if (objPinUser.Boards.Count <= 0) { objAddNewPinManager.GetBoards(ref objPinUser); } if (objPinUser.Boards.Count > 0) { Random Boardrnd = new Random(); int BoardNum = 0; try { BoardNum = Boardrnd.Next(0, objPinUser.Boards.Count - 1); BoardNumber = objPinUser.Boards[BoardNum]; } catch (Exception ex) { //GlobusFileHelper.AppendStringToTextfileNewLine("Error --> StartNewPinCreationMultiThreaded() 1--> " + ex.Message, ApplicationData.ErrorLogFile); } } } ImageUrl = pin.ImageUrl; Desc = pin.Description; string Data = objAddNewPinManager.NewPin(BoardNumber, Desc, ImageUrl, ref objPinUser); if (Data.Equals("true")) { #region AccountReport string module = "AddPinWithNewBoard"; string status = "Added"; objqm.insertAccRePort(objPinUser.Username, module, "", Board, "", Desc, "", ImageUrl, status, "", "", DateTime.Now); objAddPinWithBoardDelegate(); #endregion //GlobusLogHelper.log.Info(" => [ Pin Added To " + Board + " From " + objPinUser.Username + " ]"); try { string CSV_Header = "Date" + "," + "UserName" + "," + "Board" + "," + "Description" + "," + "ImageUrl"; string CSV_Data = System.DateTime.Now.ToString() + "," + objPinUser.Username + "," + Board.Replace(",", " ").Replace("'", "") + "," + Desc.Replace(",", " ").Replace("'", "") + "," + ImageUrl.Replace(",", " ").Replace("'", ""); PDGlobals.ExportDataCSVFile(CSV_Header, CSV_Data, Pinpath + "\\NewPin.csv"); } catch (Exception ex) { } } else { GlobusLogHelper.log.Info(" => [ Pin Not Added To " + Board + " From " + objPinUser.Username + " ]"); } } catch (Exception ex) { //GlobusFileHelper.AppendStringToTextfileNewLine("Error --> StartNewPinCreationMultiThreaded() 2 --> " + ex.Message, ApplicationData.ErrorLogFile); } finally { try { if (countThreadControllerAddPinWithNewBoard > Nothread_AddPinWithNewBoard) { lock (AddPinWithNewBoardObjThread) { Monitor.Pulse(AddPinWithNewBoardObjThread); } AddPinWithNewBoarddata_count--; } } catch (Exception ex) { GlobusLogHelper.log.Error(" Error : " + ex.StackTrace); } countThreadControllerAddPinWithNewBoard--; GlobusLogHelper.log.Info(" => [ PROCESS COMPLETED " + " For " + objPinUser.Username + " ]"); GlobusLogHelper.log.Info("---------------------------------------------------------------------------------------------------------------------------"); } }
public void BoardMethod(string BoardName, string BoardUrl, ref PinInterestUser objPinInUser) { try { try { lstThreadsBoards.Add(Thread.CurrentThread); lstThreadsBoards.Distinct().ToList(); Thread.CurrentThread.IsBackground = true; } catch (Exception ex) { }; lock (this) { string BoardId = string.Empty; AddNewPinManager objaddnewPin = new AddNewPinManager(); RePinManager objRepin = new RePinManager(); try { boardinput.Add(Thread.CurrentThread); boardinput.Distinct(); Thread.CurrentThread.IsBackground = true; } catch (Exception ex) { }; if (string.IsNullOrEmpty(BoardName)) { try { List <string> baordnames = GetAllBoardNames_new(ref objPinInUser); BoardName = baordnames[RandomNumberGenerator.GenerateRandom(0, baordnames.Count - 1)]; BoardId = objaddnewPin.GetBoardId(BoardName, ref objPinInUser); } catch (Exception ex) { }; } else { //testing GlobusHttpHelper objHttp = new GlobusHttpHelper(); try { BoardId = objaddnewPin.GetBoardId_Board(BoardName, ref objPinInUser); } catch (Exception ex) { Console.Write(ex.Message); } } if (string.IsNullOrEmpty(BoardId)) { BoardId = objaddnewPin.GetBoardId(BoardName, ref objPinInUser); } int counter = 0; int RepinCounter = 0; if (!BoardId.Contains("failure")) { if (!string.IsNullOrEmpty(BoardId)) { if (PDGlobals.ValidateNumber(BoardId)) { GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Adding Pins From Board :" + BoardUrl + " ]"); clsSettingDB db = new clsSettingDB(); List <string> lstPins = new List <string>(); lstPins = GetBoardPinsNew(BoardId, BoardUrl, 10, ref objPinInUser); lstPins.Distinct(); List <string> lstOfRepin = new List <string>(); lstOfRepin.AddRange(lstPins); string[] lstPinNo = null; lstPinNo = lstPins.ToArray(); //getting lstPins length int lenOFlstPins = lstOfRepin.Count; foreach (string Pins in lstPinNo) { if (MaxRePinCount > RepinCounter) { string Message = string.Empty; if (ClGlobul.lstBoardRepinMessage.Count > 0) { if (counter < ClGlobul.lstBoardRepinMessage.Count) { Message = ClGlobul.lstBoardRepinMessage[counter]; } else { counter = 0; Message = ClGlobul.lstBoardRepinMessage[counter]; } } bool IsReppined = false; if (!Pins.Contains("n")) { try { int index = lstOfRepin.Where(x => x == Pins).Select(x => lstOfRepin.IndexOf(x)).Single <int>(); string NoOfPages = Convert.ToString(index / lenOFlstPins); IsReppined = objRepin.RepinwithMessage(Pins, Message, BoardId, NoOfPages, ref objPinInUser); } catch { } if (IsReppined) { //GlobusLogHelper.log.Info("[ => [ Repin Id : " + Pins + " ]"); #region AccountReport string module = "Boards"; string status = "Repined"; Qm.insertAccRePort(objPinInUser.Username, module, "https://www.pinterest.com/pin/" + Pins, BoardName, "", "", "", "", status, "", "", DateTime.Now); objBoardDelegate(); #endregion GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Repin Pin : " + Pins + " to Account : " + objPinInUser.Username + " In " + BoardName + " ]"); try { string CSV_Header = "Date" + "," + "UserName" + "," + "Message" + "," + "Pin" + "Board Id"; string CSV_Data = System.DateTime.Now.ToString() + "," + objPinInUser.Username + "," + Message + "," + "https://www.pinterest.com/pin/" + Pins + "," + BoardId; PDGlobals.ExportDataCSVFile(CSV_Header, CSV_Data, Boardpath + "\\Board.csv"); RepinCounter++; } catch (Exception ex) { Console.Write(ex.Message); } //kept here int delay = RandomNumberGenerator.GenerateRandom(minDelayBoards, maxDelayBoards); GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ Delay for " + delay + " Seconds ]"); Thread.Sleep(delay * 1000); } else { } counter++; } } else { GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ PROCESS COMPLETED " + " For " + objPinInUser.Username + " In " + BoardName + "]"); GlobusLogHelper.log.Info("-----------------------------------------------------------------------------"); break; } } } } } else { GlobusLogHelper.log.Info("[ " + DateTime.Now + " ] => [ You already have a board with that name. " + objPinInUser.Username + " ]"); } } } catch (Exception ex) { GlobusLogHelper.log.Error(" Error :" + ex.StackTrace); } }