Esempio n. 1
0
        // Create a CodeDOM graph.
        public CodeCompileUnit CreateClassGraph(ClassDefinationDTO classDefination)
        {
            CodeCompileUnit cu = new CodeCompileUnit();
            CodeNamespace   ns = new CodeNamespace(classDefination.NameSpace.Name);

            foreach (var directive in classDefination?.Directives)
            {
                ns.Imports.Add(new CodeNamespaceImport(directive));
            }
            AddComment(ns.Comments, classDefination.NameSpace.Comments);

            cu.Namespaces.Add(ns);

            CodeTypeDeclaration cd = new CodeTypeDeclaration(classDefination.ClassDefination.Name);

            AddComment(cd.Comments, classDefination.ClassDefination.Comments);

            ns.Types.Add(cd);

            AddMethods(cd, classDefination.Methods);

            //AddProperty(cd);

            // CodeStatement example
            CodeConstructor constructor1 = new CodeConstructor();

            constructor1.Attributes = (constructor1.Attributes & ~MemberAttributes.AccessMask) | MemberAttributes.Public;

            return(cu);
        }
        public void GenerateFacebookHelpApi()
        {
            var page = new PageHelp();

            //page.GoToPage("https://www.facebook.com/help/246750422356731/adding-friends/?helpref=hc_fnav");
            var classes  = new List <ClassDefinationDTO>();
            int attempts = 0;

            while (attempts < 4)
            {
                try
                {
                    var headerMenuItems = page.GetMainMenuItems;
                    for (var h = 1; h < headerMenuItems.Count; h++)
                    {
                        var childrenCount = page.GetMenuItemsNames(headerMenuItems[h]).Count();
                        for (var i = 0; i <= childrenCount; i++)
                        {
                            var classDTO = new ClassDefinationDTO();
                            classes.Add(classDTO);
                            classDTO.NameSpace = new Defiantion {
                                Name = headerMenuItems[h]
                            };

                            page.GetFirstItem(headerMenuItems[h]).Click();
                            var menuItem  = page.GetMenuItemsNames(headerMenuItems[h]).ToList()[i];
                            var className = menuItem.GetAttribute("aria-label");
                            var partUrl   = menuItem.GetAttribute("href");
                            page.ClickElement(menuItem);

                            var newDefination = new Defiantion();
                            newDefination.Name       = className;
                            classDTO.ClassDefination = newDefination;

                            var grandChildren = page.GetSubMenuItemsName(className);

                            if (!grandChildren.Any())
                            {
                                continue;
                            }
                            var methodDefinitions = new List <MethodDefination>();
                            for (var j = 0; j < grandChildren.Count; j++)
                            {
                                var grandChildEmement = page.GetSubMenuItemHyperlink(className, grandChildren[j])[j];

                                page.GoToPage(grandChildEmement.GetAttribute("href"));

                                string funtionNamePart = string.Empty;
                                for (var k = 0; k < page.GetFunctionNames.Count; k++)
                                {
                                    page.ClickElement(page.GetFunctionNames[k]);
                                    Thread.Sleep(10000);
                                    funtionNamePart = page.GetFunctionNames[k].Text;

                                    IEnumerable <IWebElement> functionSummaryElements = null;
                                    IList <string>            functionSummaryHeader   = null;
                                    try
                                    {
                                        functionSummaryElements = page.GetFunctionNames[k].FindElements(By.XPath($"//div[@role='main']/div//div[2]//div[@role='button']//span[text()=\"{funtionNamePart}\"]/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::h3/following-sibling::div[1]//ol"));
                                    }
                                    catch (Exception)
                                    {
                                        page.ClickElement(page.GetFunctionNames[k]);
                                        continue;
                                    }

                                    try
                                    {
                                        functionSummaryHeader = page.GetFunctionNames[k].FindElements(By.XPath($"//div[@role='main']/div//div[2]//div[@role='button']//span[text()=\"{funtionNamePart}\"]/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::div/parent::h3/following-sibling::div[1]//ol/preceding-sibling::h2")).Select(x => x.Text).ToList();
                                    }
                                    catch (Exception) { }
                                    var index = 0;
                                    foreach (var functionSummaryElement in functionSummaryElements)
                                    {
                                        var comments = new List <string>();
                                        if (functionSummaryHeader.Count() - 1 >= index)
                                        {
                                            funtionNamePart = $"{funtionNamePart}{functionSummaryHeader[index++]}";
                                        }
                                        foreach (var functionSummary in functionSummaryElement.FindElements(By.XPath("//li")))
                                        {
                                            var header = funtionNamePart;
                                            comments.Add(functionSummary.Text);
                                        }

                                        methodDefinitions.Add(new MethodDefination
                                        {
                                            Name     = $"{funtionNamePart}",
                                            Comments = comments
                                        });
                                    }

                                    Thread.Sleep(10000);
                                    page.ClickElement(page.GetFunctionNames[k]);
                                    Thread.Sleep(34000);
                                }
                            }
                            classDTO.Methods = methodDefinitions;
                            FileOperations.Serialize(@"D:\Dev\Robotize\RobotizeFacebook\Services\RobotizeAPIs\JsonClasses11", classes);
                        }
                    }
                    break;
                }
                catch (StaleElementReferenceException e)
                {
                    Debug.WriteLine(e.Message);
                }
                attempts++;
                Thread.Sleep(3000);
            }
        }
Esempio n. 3
0
        public void GenerateClassCode(ClassDefinationDTO classDefination)
        {
            var compileUnit = CreateClassGraph(classDefination);

            GenerateClassFile(compileUnit, "cs", $"{classDefination.ClassDefination.Name}.cs");
        }