예제 #1
0
        private static List<CardDetails> RunIndividualHandler(string link)
        {
            var indivHandler = new IndividualHandler();
            HtmlNode docNode = CommonHelpers.GetHtmlDocumentFromLink(link).DocumentNode;
            IndividualHandler.CardType cardType = indivHandler.DetermineCardType(docNode, 0);
            var detailsList = new List<CardDetails>();
            if (cardType == IndividualHandler.CardType.StandardCard)
            {
                var cardDetails = new CardDetails();
                indivHandler.Handle(CommonHelpers.GetHtmlDocumentFromLink(link).DocumentNode, 0, cardDetails,
                                    IndividualHandler.AttributeCardType.Standard);
                CommonHelpers.SerializeToXML(cardDetails);
                detailsList.Add(cardDetails);
            }
            else
            {
                var cardDetails = new CardDetails();
                indivHandler.Handle(CommonHelpers.GetHtmlDocumentFromLink(link).DocumentNode, 0, cardDetails,
                                    IndividualHandler.AttributeCardType.FlipCardDefault);
                CommonHelpers.SerializeToXML(cardDetails);
                detailsList.Add(cardDetails);

                var cardDetailsFlip = new CardDetails();
                indivHandler.Handle(CommonHelpers.GetHtmlDocumentFromLink(link).DocumentNode, 0, cardDetailsFlip,
                                    IndividualHandler.AttributeCardType.FlipCardAlternate);
                CommonHelpers.SerializeToXML(cardDetailsFlip);
                detailsList.Add(cardDetailsFlip);
            }
            return detailsList;
        }
예제 #2
0
        public void Handle(HtmlNode node, int level, CardDetails cardDetails, AttributeCardType attributeType)
        {
            VisitedNodes.Clear();

            ProcessPage(node, 0, ProcessPass.Details, cardDetails,attributeType);

            Debug.WriteLine("Processing: " + cardDetails.Expansion.Value + " " + cardDetails.CardName.Value);
            VisitedNodes.Clear();
            ProcessPage(node, 0, ProcessPass.Image, cardDetails,attributeType);

            DownloadAllImages(cardDetails);
        }
예제 #3
0
        private void DownloadAllImages(CardDetails details)
        {
            if (details.ManaCost != null) // Land won't have mana cost
            {
                DownloadImagesForDetailEntrySequence(details.ManaCost);
            }
            if (details.CardText != null) // Some cards don't have body text
            {
                DownloadImagesForDetailEntrySequence(details.CardText);
            }
            DownloadImagesForDetailEntrySequence(details.Expansion);

            // Image
            details.LocalImagePath = new CardDetailEntryString {FieldName = CardFieldName.LocalImagePath};
            details.LocalImagePath.AddData(
                new CardFieldDataLink
                    {
                        Data =
                            DownloadImageHelper.DownloadImageAsync(details.ImageUrl.Value,
                                                                   CommonHelpers.RemoveInvalidFilenameCharacters(details.Expansion.ToString()) + " " + CommonHelpers.RemoveInvalidFilenameCharacters(details.CardName.Value) +
                                                                   ".jpg",
                                                                   CommonHelpers.ImagesFolder)
                    });
        }
예제 #4
0
        private void ProcessPage(HtmlNode node, int level, ProcessPass pass, CardDetails cardDetails, AttributeCardType attributeType)
        {
            if (VisitedNodes.Contains(node))
                return;
            VisitedNodes.Add(node);
            switch (pass)
            {
                case ProcessPass.Details:
                    if (NodeHasCardAttributeOfValue(node,attributeType))
                    {
                        var resultNodes = new List<HtmlNode>();
                        HtmlNodeHelpers.FindChildNodesInOrderBelowLevel(node.ChildNodes.First(), 0, new List<HtmlNode>(),
                                                                        resultNodes);
                        CardDetailEntry entry = ExtractCardFieldFromNodeListHelper.Extract(resultNodes);
                        cardDetails.AddEntry(entry);
                    }
                    break;
                case ProcessPass.Image:
                    if (NodeHasAssetAttributeOfInterest(node,attributeType))
                    {
                        //((CardDetailEntryString)cardDetails.GetEntry(CardFieldName.CardName)).Value
                        CardDetailEntry entry = ExtractImagePathFromHtmlHelper.ExtractImagePath(node.OuterHtml);
                        cardDetails.AddEntry(entry);
                    }
                    break;
            }

            foreach (HtmlNode child in node.ChildNodes)
            {
                ProcessPage(child, level + 1, pass, cardDetails,attributeType);
            }

            if (node.NextSibling != null)
            {
                ProcessPage(node.NextSibling, level, pass, cardDetails,attributeType);
            }
        }
예제 #5
0
        public static void SerializeToXML(CardDetails details)
        {
            var serializer = new XmlSerializer(typeof (CardDetails));

            string path = Path.Combine(Directory.GetCurrentDirectory(),
                                       XmlFolder + Path.DirectorySeparatorChar +
                                       RemoveInvalidFilenameCharacters(details.Expansion.ToString()) + " " +
                                       RemoveInvalidFilenameCharacters(details.CardName.Value) + ".xml");

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            string directoryName = Path.GetDirectoryName(path);
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            TextWriter textWriter = new StreamWriter(path, false);
            serializer.Serialize(textWriter, details);
            textWriter.Close();
        }