Exemple #1
0
        private async Task InsertDownloadIntoCosmos(AinunuDownloadDTO movie)
        {
            try
            {
                // Read the item to see if it exists.
                ItemResponse <AinunuDownloadDTO> movieResponse = await this.downloadContainer.ReadItemAsync <AinunuDownloadDTO>(movie.id, new PartitionKey(movie.partitionKey));

                Console.WriteLine("Item in database with id: {0} already exists\n", movieResponse.Resource.id);
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                // Create an item in the container representing the Andersen family. Note we provide the value of the partition key for this item, which is "Andersen"
                ItemResponse <AinunuDownloadDTO> movieResponse = await this.downloadContainer.CreateItemAsync <AinunuDownloadDTO>(movie, new PartitionKey(movie.partitionKey));

                // Note that after creating the item, we can access the body of the item with the Resource property off the ItemResponse. We can also access the RequestCharge property to see the amount of RUs consumed on this request.
                Console.WriteLine("Created item in database with id: {0} Operation consumed {1} RUs.\n", movieResponse.Resource.id, movieResponse.RequestCharge);
            }
        }
Exemple #2
0
        public AinunuDownloadDTO GetMovieDownloadDetail(string downloadPageUrl, HtmlNodeCollection downloadNodes, string movieName, int MovieId)
        {
            HtmlNodeCollection nodes = null;

            if (downloadPageUrl != null && downloadPageUrl != "")
            {
                var          helper   = new CrawlerHelper();
                var          html     = helper.DownloadHtml(downloadPageUrl, Encoding.GetEncoding("UTF-8"));
                HtmlDocument document = new HtmlDocument();
                if (html == null || html == "")
                {
                    return(null);
                }
                document.LoadHtml(html);
                nodes = document.DocumentNode.SelectNodes("/html/body/div[1]/div[1]/div[1]/div[1]/article[1]/div[1]/div");
            }
            else
            {
                nodes = downloadNodes;
            }
            if (nodes == null || nodes.Count < 2)
            {
                return(null);
            }
            var Resources = new List <ResourceDTO>();

            for (int i = 0; i < nodes.Count; i = i + 2)//第一个是说明内容的div
            {
                HtmlNode node = nodes[i];
                if (i < nodes.Count)
                {
                    HtmlNode node2 = null;
                    if (i + 1 < nodes.Count)
                    {
                        node2 = nodes[i + 1];
                    }
                    string             formatName          = node.InnerHtml;
                    var                resourceLinks       = new List <ResourceLinkDTO>();
                    HtmlNodeCollection resourceNodes       = node2 == null ? null : node2.SelectNodes("child::a");
                    HtmlNodeCollection resourceOthersNodes = node2 == null ? null : node2.SelectNodes("child::text()");
                    if (resourceNodes != null)
                    {
                        for (int j = 0; j < resourceNodes.Count; j++)
                        {
                            string resourceLinkName  = resourceNodes[j].InnerHtml;
                            string resourceLinkUrl   = resourceNodes[j].GetAttributeValue("href", "");
                            string resourceLinkOther = resourceOthersNodes != null ? resourceOthersNodes[j].InnerHtml : "";
                            if (resourceLinkUrl != null)
                            {
                                var entity = new ResourceLinkDTO()
                                {
                                    Name   = resourceLinkName,
                                    Type   = "",
                                    Url    = resourceLinkUrl,
                                    Others = resourceLinkOther
                                };
                                resourceLinks.Add(entity);
                            }
                        }
                    }
                    var resource = new ResourceDTO()
                    {
                        Id            = i.ToString(),
                        FormatName    = formatName,
                        ResourceLinks = resourceLinks
                    };
                    Resources.Add(resource);
                }
            }
            var download = new AinunuDownloadDTO()
            {
                id           = MovieId.ToString(),
                MovieId      = MovieId,
                MovieName    = movieName,
                Resources    = Resources,
                UpdateDate   = "",
                CreateDate   = DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
                partitionKey = "download"
            };

            return(download);
        }