Example #1
0
        private static List<ItemBuild> GetBuilds(Champion champion, HtmlDocument document)
        {
            var parsedBuilds = new List<ItemBuild>();
            var builds = document.DocumentNode.SelectNodes("//div[@data-build-id]");
            if (builds == null)
            {
                Errors.Add("Downloading Data For " + champion + "Failed!");
                RunningTasks--;
                return null;
            }
            foreach (var node in builds)
            {
                var buildId = int.Parse(node.GetAttributeValue("data-build-id", "0"));
                try
                {
                    var parsedBuild = new ItemBuild(buildId);

                    foreach (var section in node.Descendants().Where(x => x.Name == "section"))
                    {
                        if (section.GetAttributeValue("class", "") != "starting-items" &&
                            section.GetAttributeValue("class", "") != "core-items" &&
                            section.GetAttributeValue("class", "") != "final-items") continue;
                        foreach (
                            var item in
                                section.Descendants()
                                    .Where(x => x.Name == "small" && x.GetAttributeValue("style", null) == null))
                        {

                            var itemName =
                                item.LastChild.InnerText.Replace(' ', '_')
                                    .Replace("'", "")
                                    .Replace("(", "")
                                    .Replace(")", "")
                                    .Replace(".", "")
                                    .Replace('-', '_');
                            var itemId = (ItemId) Enum.Parse(typeof(ItemId), itemName);
                            parsedBuild.Items.Add(itemId);
                        }
                    }
                    parsedBuilds.Add(parsedBuild);
                }
                catch (ArgumentException ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Could Not Parse, Ignoring: " + ex.Message);
                    Errors.Add(string.Format("Could Not Parse Build (ID: {0}, Champion: {1}). Ignoring Build. \n Error: {2}", buildId, champion, ex.Message));
                    Console.ResetColor();
                }
            }
            return parsedBuilds;
        }
Example #2
0
        public void TestBuild()
        {
            if (File.Exists(BuildConst.OutFTStreamFileName))
                File.Delete(BuildConst.OutFTStreamFileName);

            int propListCount = 15;
            E15PropertyItem[] propertyTags = new E15PropertyItem[propListCount];
            tagBegin = 0x8001;
            for (int i = 0; i < propListCount; i++)
            {
                propertyTags[i] = GetProperty();
            }

            tagBegin = 0x7990;

            List<E15PropertyItem[]> recvPropertyTagsAll = new List<E15PropertyItem[]>(2);

            int recvLength = 8;
            E15PropertyItem[] recvPropertyTags = new E15PropertyItem[recvLength];
            for (int i = 0; i < recvLength; i++)
            {
                recvPropertyTags[i] = GetProperty();
            }
            recvPropertyTagsAll.Add(recvPropertyTags);

            tagBegin = 0x7990;
            int recv2Length = 7;
            E15PropertyItem[] recv2PropertyTags = new E15PropertyItem[recv2Length];
            for (int i = 0; i < recv2Length; i++)
            {
                recv2PropertyTags[i] = GetProperty();
            }
            recvPropertyTagsAll.Add(recv2PropertyTags);

            tagBegin = 0x3000;
            int attachment1Length = 4;

            List<E15PropertyItem[]> attachmentCollectionTag = new List<E15PropertyItem[]>(1);
            E15PropertyItem attachmentNumber = new E15PropertyItem();
            attachmentNumber.nTag = 0x0E210003;
            attachmentNumber.nUsID = 0x0E21;
            attachmentNumber.PropertyType = MAPIPropertyType.Int32;
            attachmentNumber.nLength = 4;
            byte[] attachNumberBuffer = BitConverter.GetBytes((Int32)1);
            IntPtr unmanagedAttachNumberPointer = Marshal.AllocHGlobal(4);
            allNeedFreePtr.Add(unmanagedAttachNumberPointer);
            Marshal.Copy(attachNumberBuffer, 0, unmanagedAttachNumberPointer,4);
            attachmentNumber.pValue = unmanagedAttachNumberPointer;

            E15PropertyItem[] attachPropList = new E15PropertyItem[attachment1Length];
            for (int i = 0; i < attachment1Length; i++)
            {
                attachPropList[i] = GetProperty();
            }

            attachmentCollectionTag.Add(attachPropList);

            //int hResult = 0;
            using (IItemBuild build = new ItemBuild())
            {
                Assert.AreEqual(build.StartBuild(), 0);

                if (propertyTags.Length > 0)
                {
                    using (IPropListBuild propList = build.BuildPropList())
                    {
                        Assert.AreEqual(propList.StartBuild(), 0);
                        Assert.AreEqual(propList.BuildProperties(GetPropertiesPtr(propertyTags, propListCount), propListCount), 0);
                        Assert.AreEqual(propList.EndBuild(), 0);
                    }
                }

                if (recvPropertyTagsAll.Count > 0)
                {
                    using (IRecipientCollectionBuild recvCollectionBuild = build.BuildRecipientCollection())
                    {
                        Assert.AreEqual(recvCollectionBuild.StartBuild(), 0);

                        int recvIndex = 0;
                        foreach (E15PropertyItem[] recvItems in recvPropertyTagsAll)
                        {
                            using (IRecipientBuild recvBuild = recvCollectionBuild.BuildRecipient(recvIndex++))
                            {
                                Assert.AreEqual(recvBuild.StartBuild(), 0);

                                Assert.AreEqual(recvBuild.BuildProperties(GetPropertiesPtr(recvItems, recvItems.Length), recvItems.Length), 0);

                                Assert.AreEqual(recvBuild.EndBuild(), 0);
                            }
                            recvIndex++;
                        }

                        Assert.AreEqual(recvCollectionBuild.EndBuild(), 0);
                    }
                }

                if (attachmentCollectionTag.Count > 0)
                {
                    using (IAttachmentCollectionBuild attachmentCollectionBuild = build.BuildAttachmentCollection())
                    {
                        int attachIndex = 0;
                        foreach (E15PropertyItem[] attachmentItems in attachmentCollectionTag)
                        {
                            Assert.AreEqual(attachmentCollectionBuild.StartBuild(), 0);
                            using (IAttachmentBuild attachmentBuild = attachmentCollectionBuild.BuildAttachment(attachIndex))
                            {
                                Assert.AreEqual(attachmentBuild.StartBuild(), 0);

                                Assert.AreEqual(attachmentBuild.BuildAttachmentNumber(GetPropertyPtr(attachmentNumber)), 0);
                                Assert.AreEqual(attachmentBuild.BuildProperties(GetPropertiesPtr(attachmentItems, attachmentItems.Length), attachmentItems.Length), 0);

                                //todo Build Embeded;

                                Assert.AreEqual(attachmentBuild.EndBuild(), 0);
                            }
                            Assert.AreEqual(attachmentCollectionBuild.EndBuild(), 0);
                            attachIndex++;
                        }
                    }
                }

                build.EndBuild();
            }

            foreach(IntPtr ptr in allNeedFreePtr)
            {
                Marshal.FreeHGlobal(ptr);
            }
        }