Beispiel #1
0
        internal static IEnumerable <string> GetAllUrls(APage Page)
        {
            if (Page.HasThrewError || Page.IsEmpty)
            {
                yield break;
            }

            for (int i = 0; i < Page.Length; i++)
            {
                if (Page.Content[i] == '"')
                {
                    var Url = new StringBuilder();

                    while (Page.Content[++i] != '"')
                    {
                        if (i + 1 >= Page.Content.Length)
                        {
                            break;
                        }

                        Url.Append(Page.Content[i]);
                    }

                    var Uri = Url.ToString();

                    if (Uri.EndsWith(".html") || Uri.EndsWith(".css") || Uri.EndsWith(".js") || Uri.EndsWith(".jpg") || Uri.EndsWith(".jpeg") || Uri.EndsWith(".png"))
                    {
                        yield return(Url.ToString());
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Loads the specified page asynchronously and executes the callback.
        /// </summary>
        /// <param name="PageUrl">The page URL.</param>
        /// <param name="Callback">The callback.</param>
        internal async Task LoadAsync(Uri PageUrl, Action <APage> Callback)
        {
            var Page = new APage(PageUrl);

            try
            {
                var Content = await this.WebClient.DownloadStringTaskAsync(PageUrl.AbsoluteUri);

                if (!string.IsNullOrEmpty(Content))
                {
                    Page.SetContent(Content);
                }
            }
            catch (Exception Exception)
            {
                Page.SetError(Exception);
            }

            if (Callback != null)
            {
                try
                {
                    Callback(Page);
                }
                catch (Exception)
                {
                    // ..
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Loads the specified page asynchronously.
        /// </summary>
        /// <param name="PageUrl">The page URL.</param>
        internal async Task <APage> LoadAsync(string PageUrl)
        {
            var RequestedUrl = Path.Combine(this.Uri.AbsoluteUri, PageUrl);
            var RequestedUri = new Uri(RequestedUrl);
            var Page         = new APage(RequestedUri);

            try
            {
                var Content = await this.WebClient.DownloadStringTaskAsync(RequestedUri.AbsoluteUri);

                if (!string.IsNullOrEmpty(Content))
                {
                    Page.SetContent(Content);
                }
            }
            catch (Exception Exception)
            {
                Page.SetError(Exception);
            }

            if (this.OnPageCrawled != null)
            {
                try
                {
                    this.OnPageCrawled.Invoke(this, Page);
                }
                catch (Exception)
                {
                    // ..
                }
            }

            return(Page);
        }
Beispiel #4
0
        public void UpdateListPageEl(UIBaseEl new_el = null)
        {
            // Загружает информацию напрямую из сохранённой страницы
            //

            if (list_page_name.SelectedIndex == -1)
            {
                return;
            }

            APage editPage = pageList[list_page_name.SelectedIndex];

            elementsPageStackPanel.Children.Clear();

            if (new_el != null)
            {
                editPage.Elements.Add(new_el.CompileElement());
            }

            UIControlList.Clear();

            foreach (var el in editPage.Elements)
            {
                AbstrUIBase UIel = PageElCenter.TryGenUiControl(el);

                if (UIel != null)
                {
                    AppendNewUIel(UIel);
                }
            }

            curPage = editPage;

            SoftUpdate();
        }
Beispiel #5
0
        //
        // Events
        //

        private void button_Save_Click(object sender, RoutedEventArgs e)
        {
            List <AbstrPageEl> new_elements = new List <AbstrPageEl>();

            foreach (var UIel in UIControlList)
            {
                new_elements.Add(UIel.CompileElement());
            }

            if (new_elements.Count >= 1)
            {
                curPage = new APage(curPage.Name, curPage.ID, new_elements);

                if (list_page_name.SelectedIndex != -1)
                {
                    pageList[list_page_name.SelectedIndex] = curPage;
                }

                Writer.WritePageListToXML(pageList, pathToXML);
                UpdateListPageEl();

                ShowPopup(String.Format(
                              "Сохранено: {0} эл.", new_elements.Count.ToString()));
            }
            else
            {
                ShowPopup("Ничего не сохранено :(");
            }
        }
Beispiel #6
0
        public void UpdateListPageEl(UIBaseEl new_el = null)
        {
            // Загружает информацию напрямую из сохранённой страницы
            //

            if (list_page_name.SelectedIndex == -1)
            {
                return;
            }

            APage editPage = pageList[list_page_name.SelectedIndex];

            elementsPageStackPanel.Children.Clear();

            if (new_el != null)
            {
                editPage.Elements.Add(new_el.CompileElement());
            }

            UIControlList.Clear();
            //var el in editPage.Elements
            for (int i = 0; i < editPage.Elements.Count; i++)
            {
                var el = editPage.Elements[i];
                el.SetID(i);
                CreateNewUIel(el);
            }

            curPage = editPage;

            SoftUpdate();
        }
Beispiel #7
0
    private void ActivatePanel(APage panel)
    {
        if (_currentPageInstance.Page != null)
        {
            _currentPageInstance.Page.DeactivatePanel();
        }

        _currentPageInstance.Page = panel;
        _currentPageInstance.Page.ActivatePanel();
        if (panel is GUI_Game guiGame)
        {
            GameManager.Instance.SetGame(guiGame);
        }
    }
Beispiel #8
0
        internal static string GetUriFromIndex(APage Page)
        {
            if (Page.HasThrewError || Page.IsEmpty)
            {
                return(string.Empty);
            }

            var RedString = "location.href=";
            var RedIndex  = Page.Content.IndexOf(RedString, StringComparison.Ordinal);

            if (RedIndex == -1)
            {
                return(string.Empty);
            }

            RedIndex += RedString.Length;

            if (Page.Content[RedIndex] != '"')
            {
                return(string.Empty);
            }

            var CurrentChar = ++RedIndex;
            var HostName    = new StringBuilder();

            while (Page.Content[CurrentChar] != '"')
            {
                HostName.Append(Page.Content[CurrentChar]);

                if (CurrentChar++ >= Page.Content.Length)
                {
                    break;
                }
            }

            if (HostName[HostName.Length - 1] == '?')
            {
                HostName.Remove(HostName.Length - 1, 1);
            }

            return("http://" + Page.Uri.Host + HostName);
        }
        static public List <APage> LoadPageListFromXML(string fileName)
        {
            XmlDocument  xdd      = new XmlDocument();
            List <APage> pageList = new List <APage>();

            try
            {
                xdd.Load(fileName);

                XmlNode root = xdd.DocumentElement;

                if (root.HasChildNodes)
                {
                    foreach (XmlNode nd_page in root)
                    {
                        // Просмотр записанных страниц
                        // Чтение имени и ID страницы
                        XmlNode ndName = nd_page.Attributes.GetNamedItem(XMLDefines.XMLPageAttr.Name);
                        XmlNode ndID   = nd_page.Attributes.GetNamedItem(XMLDefines.XMLPageAttr.ID);

                        List <AbstrPageEl> page_elements = new List <AbstrPageEl>();
                        foreach (XmlNode nd_el in nd_page)
                        {
                            if (nd_el.Name == XMLDefines.XMLTag.PageEl)
                            {
                                // Собираем элемент страницы по шаблону
                                //

                                int type_ep = int.Parse(
                                    nd_el.Attributes.GetNamedItem(
                                        XMLDefines.XMLBaseElAttr.TypeEl
                                        ).Value);

                                PageEl pl = (PageEl)PageElCenter.TryLoadFromXml(type_ep, nd_el);

                                if (pl != null)
                                {
                                    page_elements.Add(pl);
                                }
                            }
                        }

                        APage page = new APage(
                            ndName.Value,
                            int.Parse(ndID.Value),
                            page_elements
                            );
                        pageList.Add(page);
                    }
                }
            }
            catch (System.IO.FileNotFoundException ex)
            {
                MessageBox.Show("В директории не неайден существующий файл с настройками, поэтому будет создан новый.");
                var ls = new List <APage>();
                ls.Add(new APage());
                Writer.WritePageListToXML(ls, fileName);
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
            return(pageList);
        }