Beispiel #1
0
        private async void LoadUser()
        {
            Application.UseWaitCursor = true;
            lStatus.Text = lDetected.Text = "";
            string act = "Подготовка строки запроса.";

            ApiPath             = lApi.Text + tUser.Text + "/";
            Program.LocalBase   = tLocal.Text;
            Program.VirtualBase = ApiPath;

            fWork fw = new fWork();

            fw.Show();
            try
            {
                act          = "Загрузка API";
                lStatus.Text = "Запрос " + ApiPath;
                Stream atomStream = await Program.Open(ApiPath);

                fw.Hide();

                act          = "Обработка Atom";
                lStatus.Text = "Получен ответ сервера. Разборка...";
                XmlReader xr = XmlReader.Create(atomStream);

                while (xr.Read())
                {
                    if (xr.NodeType == XmlNodeType.Element)
                    {
                        if (xr.Name == "app:workspace")
                        {
                            ParseWorkspace(xr);
                        }
                    }
                }

                act = "Okay";
                if (Program.LocalOnly)
                {
                    lStatus.Text = "Готово. Работа с локальной базой.";
                }
                else
                {
                    lStatus.Text = "Готово. Сетевой режим.";
                }
                atomStream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Не выполнено: " + act);
                lStatus.Text = "Ошибка.";
            }
            finally
            {
                Application.UseWaitCursor = false;
                fw.Dispose();
            }
        }
Beispiel #2
0
        //<entry></>
        private async void ParseEntry(XmlReader XR)
        {
            AlbumEntry ae = new AlbumEntry();

            while (XR.Read())
            {
                if (XR.NodeType == XmlNodeType.Element)
                {
                    if (XR.Name == "id")
                    {
                        ae.id = XR.ReadInnerXml();
                    }
                    if (XR.Name == "name")
                    {
                        ae.authorName = XR.ReadInnerXml();
                    }
                    if (XR.Name == "f:uid")
                    {
                        ae.authorFuid = XR.ReadInnerXml();
                    }
                    if (XR.Name == "title")
                    {
                        ae.title = XR.ReadInnerXml();
                    }
                    if (XR.Name == "summary")
                    {
                        ae.summary = XR.ReadInnerXml();
                    }
                    if (XR.Name == "link" && XR.GetAttribute("rel") == "self")
                    {
                        ae.self = XR.GetAttribute("href");
                    }
                    if (XR.Name == "link" && XR.GetAttribute("rel") == "photos")
                    {
                        ae.photos = XR.GetAttribute("href");
                    }
                    if (XR.Name == "link" && XR.GetAttribute("rel") == "cover")
                    {
                        ae.cover = XR.GetAttribute("href");
                    }
                    if (XR.Name == "published")
                    {
                        ae.published = XR.ReadInnerXml();
                    }
                    if (XR.Name == "app:edited")
                    {
                        ae.edited = XR.ReadInnerXml();
                    }
                    if (XR.Name == "updated")
                    {
                        ae.updated = XR.ReadInnerXml();
                    }
                    if (XR.Name == "f:protected")
                    {
                        ae.fProtected = XR.GetAttribute("value");
                    }
                    if (XR.Name == "f:image-count")
                    {
                        ae.fTmageCount = XR.GetAttribute("value");
                    }

                    if (XR.Name == "link" && XR.GetAttribute("rel") == "edit-media")
                    {
                        ae.editMedia = XR.GetAttribute("href");
                    }
                    if (XR.Name == "f:created")
                    {
                        ae.fCreated = XR.ReadInnerXml();
                    }
                    if (XR.Name == "access")
                    {
                        ae.access = XR.GetAttribute("value");
                    }
                    if (XR.Name == "xxx")
                    {
                        ae.xxx = XR.GetAttribute("value");
                    }
                    if (XR.Name == "hide_original")
                    {
                        ae.hideOriginal = XR.GetAttribute("value");
                    }
                    if (XR.Name == "disable_comments")
                    {
                        ae.disableComments = XR.GetAttribute("value");
                    }
                    if (XR.Name == "category" && XR.GetAttribute("scheme").Contains("tags"))
                    {
                        ae.tags.Add(XR.GetAttribute("term"));
                    }
                    if (XR.Name == "georss:point")
                    {
                        ae.edited = XR.ReadOuterXml();
                    }
                    if (XR.Name == "f:pod-date")
                    {
                        ae.fPodDate = XR.ReadInnerXml();
                    }
                    if (XR.Name == "f:address-binding")
                    {
                        ae.fAddressBinding = XR.ReadInnerXml();
                    }
                    if (XR.Name == "f:img" && XR.GetAttribute("size") == "orig")
                    {
                        ae.fImgOrig = XR.GetAttribute("href");
                    }
                    if (Program.SavePics && ae.fImgOrig != null)
                    {
                        fWork fw = new fWork();
                        fw.Show();
                        try { await Program.Open(ae.fImgOrig); }
                        catch { /*On Error Resume Next 'по барабану, качается же */ }
                        fw.Dispose();
                    }
                }
                if (XR.NodeType == XmlNodeType.EndElement)
                {
                    if (XR.Name == "entry")
                    {
                        break;
                    }
                }
            }
            lbItems.Items.Add(ae);
        }