public static void Main() { var baseUrl = "http://localhost:37328/api/"; var requester = new HttpRequester(baseUrl); var newStudent = new Student() { FirstName = "Vladimir", LastName = "Georgiev" }; var createStudentTask = requester.PostAsync<Student>("students", newStudent); createStudentTask.GetAwaiter() .OnCompleted(() => { Console.WriteLine("Student {0} created!", createStudentTask.Result.FullName); var students = requester.Get<IEnumerable<Student>>("students"); foreach (var student in students) { Console.WriteLine(student.FullName); } }); while (true) { Console.ReadLine(); } }
private async Task SendSelectionProtokol(MQEpep mq) { try { var model = await initModel((int)mq.SourceId); //HttpRequester http = new HttpRequester(); //http.ValidateServerCertificate = false; //http.CertificatePath = this.CertificatePath; //http.CertificatePassword = this.CertificatePassword; //var response = http.PostAsync(serviceUri.AbsoluteUri, model).Result; var response = await requester.PostAsync(serviceUri.AbsoluteUri, model); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); if (!string.IsNullOrEmpty(content)) { long assignmentId = long.Parse(content); if (assignmentId > 0) { mq.IntegrationStateId = IntegrationStates.TransferOK; mq.DateTransfered = DateTime.Now; mq.ReturnGuidId = assignmentId.ToString(); repo.Update(mq); repo.SaveChanges(); return; } } } else { logger.LogError("CSRDService: Responce code:{code}, Message: {message}, MqID: {id}", response.StatusCode, response.ReasonPhrase, mq.Id); mq.ErrorDescription = "Грешка при извикване на услуга към ЦСРД"; } SetErrorToMQ(mq, IntegrationStates.TransferError); } catch (Exception ex) { logger.LogError(ex, ex.Message); var innerException = ex.InnerException; while (innerException != null) { logger.LogError(innerException.Message); innerException = innerException.InnerException; } mq.ErrorDescription = ex.Message; SetErrorToMQ(mq, IntegrationStates.TransferError); } }
public async Task TestMQ() { var model = new MQEpep(); model.ParentSourceId = 561; var resultCase = FillCaseAll(model); Transfer result = new Transfer(); result.program = "ЕИСС"; result.version = 1.8088; result.Case = resultCase; XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); XmlSerializer x = new XmlSerializer(typeof(Transfer)); var stream = new MemoryStream(); TextWriter writer = new StreamWriter(stream); x.Serialize(writer, result, ns); stream.Position = 0; StreamReader reader = new StreamReader(stream); string text = reader.ReadToEnd(); HttpRequester http = new HttpRequester(); var uploadUrl = new Uri(""); //още не работи var response = await http.PostAsync(uploadUrl.AbsoluteUri, text); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); } else { } }
public async override Task <IEnumerable <MovieTorrent> > GetMovieTorrentsAsync(string title, int year, bool exactTitle) { var imdbMoviesInfo = await ImdbRequester.GetImdbMoviesInfoAsync(title); var imdbMovieInfo = imdbMoviesInfo?.SingleOrDefault(m => m.OriginalTitle.StartsWith(title, StringComparison.OrdinalIgnoreCase) && m.Year == year.ToString()); if (imdbMovieInfo == null) { return(null); } var searchUrl = baseUrl + "index.php?do=search&subaction=search"; var htmlPage = await HttpRequester.PostAsync(searchUrl, new { search = imdbMovieInfo.FrenchTitle }); if (string.IsNullOrEmpty(htmlPage)) { return(null); } var doc = new HtmlDocument(); doc.LoadHtml(htmlPage); var searchResultList = doc.DocumentNode.SelectNodes("//table[contains(@class,'film-table')]"); var result = new List <MovieTorrent>(); if (searchResultList == null) { return(result); } var getTorrentTasks = new List <Task>(); foreach (var node in searchResultList) { doc = new HtmlDocument(); doc.LoadHtml(node.InnerHtml); var linkNode = doc.DocumentNode.SelectSingleNode("/a"); if (linkNode != null && ((exactTitle && linkNode.InnerText.Contains(imdbMovieInfo.FrenchTitle, StringComparison.OrdinalIgnoreCase)) || linkNode.InnerText.ContainsWords(title.Split(" "))) && linkNode.InnerText.Contains("FRENCH") && linkNode.InnerText.EndsWith(year.ToString()) && !linkNode.InnerText.Contains("MD") && (linkNode.InnerText.Contains("720p") || linkNode.InnerText.Contains("1080p") || linkNode.InnerText.Contains("DVDRIP") || linkNode.InnerText.Contains("WEBRIP")) ) { getTorrentTasks.Add(new Task(() => { var torrentLink = GetTorrentLink(linkNode.Attributes["href"].Value); if (!string.IsNullOrEmpty(torrentLink)) { result.Add(new MovieTorrent() { Quality = linkNode.InnerText.GetMovieQuality(), DownloadUrl = torrentLink }); } })); } } getTorrentTasks.ForEach(t => t.Start()); Task.WaitAll(getTorrentTasks.ToArray()); return(result); }