//метод логирования public async Task LogIn() { if (Api == null) { Biueld(); } if (Api.IsUserAuthenticated) { Helper.AddEvent("Событие", ChartID.ToString(), String.Format("Аккаунт {0} уже залогирован!!!", UserName)); } else { var eee = await Api.LoginAsync(); if (eee.Succeeded) { Helper.AddEvent("Событие", ChartID.ToString(), String.Format("Авторизация аккаунта {0} прошла успешно", UserName)); } else { Helper.AddEvent("Внимание", ChartID.ToString(), String.Format("При авторизации аккаунта {0} произошла ошибка: {1}", UserName, eee.Info.Message)); } } }
} = DateTime.MinValue; //время стопа //Biulder public void Biueld() { var userSession = new UserSessionData { UserName = UserName, Password = Password }; //Api = new InstaApiBuilder().SetUser(userSession).Build(); using (var db = new AppContext()) { var CurrentProxyDB = db.ProxyDBs.SingleOrDefault(p => p.ChartID == ChartID); if (CurrentProxyDB == null) { var CurrentProxyDB1 = db.ProxyDBs.Where(p => p.ChartID == 0).FirstOrDefault(); if (CurrentProxyDB1 == null) { Helper.AddEvent("Внимание", ChartID.ToString(), "Кончились прокси"); } else { CurrentProxyDB1.ChartID = ChartID; //-------------------------------- var httpHndler = new HttpClientHandler(); httpHndler.Proxy = new WebProxy(CurrentProxyDB1.IpAdress, Convert.ToInt32(CurrentProxyDB1.Port)); httpHndler.Proxy.Credentials = new NetworkCredential(CurrentProxyDB1.Login, CurrentProxyDB1.Pass); HttpClient client = new HttpClient(httpHndler) { BaseAddress = new Uri(String.Format("http://{0}:{1}/", CurrentProxyDB1.IpAdress, Convert.ToInt32(CurrentProxyDB1.Port))) }; Api = new InstaApiBuilder() .SetUser(userSession) .UseHttpClient(client) .UseHttpClientHandler(httpHndler) .Build(); } } else { var httpHndler = new HttpClientHandler(); httpHndler.Proxy = new WebProxy(CurrentProxyDB.IpAdress, Convert.ToInt32(CurrentProxyDB.Port)); httpHndler.Proxy.Credentials = new NetworkCredential(CurrentProxyDB.Login, CurrentProxyDB.Pass); HttpClient client = new HttpClient(httpHndler) { BaseAddress = new Uri(String.Format("http://{0}:{1}/", CurrentProxyDB.IpAdress, Convert.ToInt32(CurrentProxyDB.Port))) }; Api = new InstaApiBuilder() .SetUser(userSession) .UseHttpClient(client) .UseHttpClientHandler(httpHndler) .Build(); //Используем CurrentProxyDB } db.SaveChanges(); } }
//метод ЗАДАЧИ добавление юзеров public async Task FollowUsers() { try { using (var db = new AppContext()) { var Follow = db.Follows.SingleOrDefault(p => p.UserName == UserName); IList <string> UsersDB = new List <string>(); if (Follow != null) { UsersDB = (List <string>)Follow.Listing.DeseriaBinar(); } else { db.Follows.Add(new Follow() { UserName = UserName, Listing = (new List <string>()).SeriaBinar() }); await db.SaveChangesAsync(); Follow = db.Follows.SingleOrDefault(p => p.UserName == UserName); } Console.WriteLine(UsersDB.Count); //!!!!!!!!!!!!!!!!!!! удалить потом if (UsersDB.Count >= 50) { IsUp = false; } else if (UsersDB.Count == 0) { IsUp = true; } if (IsUp == true) { string Pk_toFollow = String.Empty; string UserName_toFollow = String.Empty; foreach (var tag in Tags) { var resultTag = await Api.GetTagFeedAsync(tag, 3); IList <InstaUserShort> Users = resultTag.Succeeded ? resultTag.Value.Medias.Select(p => p.User).Distinct().ToList() : new List <InstaUserShort>(); foreach (var user in Users) { if (UsersDB.SingleOrDefault(p => p == user.Pk) == null || UsersDB.Count == 0) { Pk_toFollow = user.Pk; UserName_toFollow = user.UserName; break; } else { break; } } if (Pk_toFollow != String.Empty) { break; } } Tags.Add(Tags.First()); Tags.Remove(Tags.First()); var resultAdd = await Api.FollowUserAsync(Convert.ToInt64(Pk_toFollow)); if (resultAdd.Succeeded) { Helper.AddEvent("Событие", ChartID.ToString(), String.Format("Мой юзер {0} добавил юзера {1} ({2}) + таг: {3}", UserName, UserName_toFollow, Pk_toFollow, Tags.First())); UsersDB.Add(Pk_toFollow); Follow.Listing = UsersDB.SeriaBinar(); await db.SaveChangesAsync(); } else { Helper.AddEvent("Внимание", ChartID.ToString(), String.Format("При добавлении аккаунта {0} произошла ошибка: {1}", UserName, resultAdd.Info.Message)); } //----------------------------- await Task.Delay(2000); //--------@@@@@@@@@@@@@@@@@@@ //----------------------------- //ЛАЙКИ var mediaToLike = await Api.GetUserMediaAsync(UserName_toFollow, 3); var mediaToLikeArray = mediaToLike.Value.ToArray(); if (mediaToLikeArray.Count() != 0) { var resultLike = await Api.LikeMediaAsync(mediaToLikeArray.First().InstaIdentifier); if (resultLike.Succeeded) { Helper.AddEvent("Событие", ChartID.ToString(), String.Format("Мой пользователь {0} лайкнул {1} пользоваеля {2}", UserName, mediaToLikeArray.First().InstaIdentifier, UserName_toFollow)); } //else // Helper.AddEvent("Событие", ChartID.ToString(), String.Format("При лайке аккаунта {0} произошла ошибка: {1}", UserName, resultLike.Info.Message)); } else { Helper.AddEvent("Внимание", ChartID.ToString(), String.Format("У пользователя {0} нет медия в акаунте. Возможно это фейковый аккаунт", UserName_toFollow)); } } else { var followers = await Api.GetCurrentUserFollowersAsync(); string UnfollowUser = String.Empty; foreach (var item1 in UsersDB.ToArray()) { UnfollowUser = item1; var result = await Api.UnFollowUserAsync(Convert.ToInt64(item1)); if (result.Succeeded) { Helper.AddEvent("Событие", ChartID.ToString(), String.Format("Мой юзер {0} отписался от {1}", UserName, item1)); UsersDB.Remove(item1); Follow.Listing = UsersDB.SeriaBinar(); await db.SaveChangesAsync(); } else { Helper.AddEvent("Внимание", ChartID.ToString(), String.Format("Во время отписки юзера {0} произошла ошибка: {1}", UserName, result.Info.Message)); } break; } } } } catch (Exception ex) { Helper.AddEvent("Внимание", ChartID.ToString(), String.Format("Произошла ошибка в сценарии добавления/удалегия/лайка пользователя: " + ex.Message)); } }
/// <summary> /// Create all your controls here for rendering. /// Try to avoid using the RenderWebPart() method. /// </summary> protected override void CreateChildControls() { if (!_error) { try { base.CreateChildControls(); // We create literal control that will display the HTML needed to chart string chartHtml = Utils.RenderChartHTML(ChartType, ChartXmlUrl, ChartXmlContent, ChartID.ToString(), ChartWidth.ToString(), ChartHeight.ToString(), false); LiteralControl lc = new LiteralControl(chartHtml); this.Controls.Add(lc); // display (or not, depending of the user choice option) the button "export to xml" if (this._xmlExport) { Button btnXML = new Button(); btnXML.Text = "Export chart to XML file"; btnXML.Click += new System.EventHandler(this.ExportXmlButtonClick); btnXML.Style.Add("font-size", "10"); btnXML.Style.Add("margin", "10"); this.Controls.Add(btnXML); } } catch (Exception ex) { HandleException(ex); } } }
/// <summary> /// Create all your controls here for rendering. /// Try to avoid using the RenderWebPart() method. /// </summary> protected override void CreateChildControls() { if (!_error) { try { base.CreateChildControls(); // Your code here... // We first check all settings CheckSettings(); // We transform the list into XML Input ListToXmlConverter conv = new ListToXmlConverter(_listName, _viewName); string chartXmlContent = conv.GenerateXml(ChartTitle, XValue, XTitle, YValue, YTitle, Action, Colors); // We generate the graph string chartHtml = Utils.RenderChartHTML(ChartType, chartXmlContent, ChartID.ToString(), ChartWidth.ToString(), ChartHeight.ToString(), false); LiteralControl lc = new LiteralControl(chartHtml); this.Controls.Add(lc); // We add a cariage return to display correctly export buttons if (this._excelExport || this._xmlExport) { this.Controls.Add(new LiteralControl("<br />")); } // display (or not, depending of the user choice option) the button "export to excel" if (this._excelExport) { Button btnExcel = new Button(); btnExcel.Text = "Export chart to Excel"; btnExcel.Click += new System.EventHandler(this.ExportExcelButtonClick); btnExcel.Style.Add("font-size", "10"); btnExcel.Style.Add("margin", "10"); this.Controls.Add(btnExcel); } // display (or not, depending of the user choice option) the button "export to xml" if (this._xmlExport) { Button btnXML = new Button(); btnXML.Text = "Export chart to XML file"; btnXML.Click += new System.EventHandler(this.ExportXmlButtonClick); btnXML.Style.Add("font-size", "10"); btnXML.Style.Add("margin", "10"); this.Controls.Add(btnXML); } } catch (Exception ex) { HandleException(ex); } } }