Ejemplo n.º 1
0
        public async Task <bool> LoadSearchFromDB(string search = "")
        {
            if (search != "")
            {
                try
                {
                    try
                    {
                        await prepareData();
                    }
                    catch { };

                    var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Data/places.db");
                    SQLiteAsyncConnection conn = new SQLiteAsyncConnection(dbPath);

                    var tourist = new RssDataGroup("TouristSearch",
                                                   "Результаты поиска " + search.Trim(), "Достопримечательности", "", "");
                    tourist.Order = 554;

                    try
                    {
                        //OR Content LIKE '%" + search + "%'
                        string query = "SELECT * FROM MapItem WHERE (Title LIKE '%" + search + "%') OR (Description LIKE '%" + search + "%') OR (Content LIKE '%" + search + "%') ORDER BY Object_rate DESC LIMIT 0,200";
                        query = "SELECT * FROM MapItem ORDER BY Object_rate";
                        var SomeItems = await conn.QueryAsync <MapItem>(query);

                        var i = 0;
                        foreach (var item in SomeItems)
                        {
                            if ((item.Title != null && item.Title.Contains(search) ||
                                 (item.Content != null && item.Content.Contains(search))) && (i < 100))
                            {
                                i++;
                                item.Group = tourist;
                                tourist.Items.Add(item);
                            }
                            ;
                        }
                        ;

                        if (i > 0)
                        {
                            try
                            {
                                this._allGroups.Remove(this._allGroups.FirstOrDefault(c => c.UniqueId == "TouristSearch"));
                                tourist.ImagePath = tourist.Items.First().ImagePath;
                            }
                            catch { };
                            this._allGroups.Add(tourist);
                            RaisePropertyChanged("AllGroups");
                        }
                        ;
                    }
                    catch { };
                }
                catch { };
            }
            ;
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> AddGroupForFeedAsync(StorageFile sf)
        {
            string clearedContent = String.Empty;

            if (GetGroup(sf.DisplayName) != null)
            {
                return(false);
            }

            var feed = new SyndicationFeed();

            feed.LoadFromXml(await XmlDocument.LoadFromFileAsync(sf));

            var feedGroup = new RssDataGroup(
                uniqueId: sf.DisplayName.ToString().Replace(".rss", ""),
                title: "Новости", //feed.Title != null ? feed.Title.Text : null,
                subtitle: feed.Subtitle != null ? feed.Subtitle.Text : null,
                imagePath: feed.ImageUri != null ? feed.ImageUri.ToString() : null,
                description: null);

            foreach (var i in feed.Items)
            {
                string imagePath = GetImageFromPostContents(i);

                if (i.Summary != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Summary.Text);
                }
                else
                if (i.Content != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Content.Text);
                }

                if (imagePath != null && feedGroup.Image == null)
                {
                    feedGroup.SetImage(imagePath);
                }

                if (imagePath == null)
                {
                    imagePath = "ms-appx:///Assets/DarkGray.png";
                }

                feedGroup.Items.Add(new RssDataItem(
                                        uniqueId: i.Id, title: i.Title.Text, subtitle: null, imagePath: imagePath,
                                        description: null, content: clearedContent, @group: feedGroup));
            }

            _allGroups.Add(feedGroup);
            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> LoadBestFromDB()
        {
            try
            {
                await prepareData();
            }
            catch { };

            var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Data/places.db");
            SQLiteAsyncConnection conn = new SQLiteAsyncConnection(dbPath);

            var tourist = new RssDataGroup("touristBestItems",
                                           "Лучшие по рейтингу", "Достопримечательности", "", "");

            tourist.Order = 15;

            try
            {
                var SomeItems = await conn.QueryAsync <MapItem>("SELECT * FROM MapItem ORDER BY Object_rate DESC LIMIT 0,200");

                foreach (var item in SomeItems)
                {
                    item.Group = tourist;
                    tourist.Items.Add(item);
                }
                ;
                try
                {
                    this._allGroups.Remove(this._allGroups.FirstOrDefault(c => c.UniqueId == "TouristBest"));
                    tourist.ImagePath = tourist.Items.First().ImagePath;
                }
                catch { };
                this._allGroups.Add(tourist);
                RaisePropertyChanged("AllGroups");
            }
            catch { };
            return(true);
        }
Ejemplo n.º 4
0
        public async Task <bool> AddGroupForFeedAsync(string feedUrl, string ID = "1", string titleRss = "")
        {
            string clearedContent = String.Empty;

            if (GetGroup(feedUrl) != null)
            {
                return(false);
            }

            var feed = await new SyndicationClient().RetrieveFeedAsync(new Uri(feedUrl));

            var localFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync
                                  ("Data", CreationCollisionOption.OpenIfExists);

            //получаем/перезаписываем файл с именем "ID".rss
            var fileToSave = await localFolder.CreateFileAsync(ID + ".rss", CreationCollisionOption.ReplaceExisting);

            //сохраняем фид в этот файл
            await feed.GetXmlDocument(SyndicationFormat.Rss20).SaveToFileAsync(fileToSave);

            var feedGroup = new RssDataGroup(
                uniqueId: ID,
                title: titleRss,
                subtitle: feed.Subtitle != null ? feed.Subtitle.Text : null,
                imagePath: feed.ImageUri != null ? feed.ImageUri.ToString() : null,
                description: null);

            foreach (var i in feed.Items)
            {
                string imagePath = null;
                try
                {
                    imagePath = GetImageFromPostContents(i);;
                }
                catch { };

                if (i.Summary != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Summary.Text);
                }
                else
                if (i.Content != null)
                {
                    clearedContent = Windows.Data.Html.HtmlUtilities.ConvertToText(i.Content.Text);
                }

                if (imagePath != null && feedGroup.Image == null)
                {
                    feedGroup.SetImage(imagePath);
                }

                if (imagePath == null)
                {
                    imagePath = "ms-appx:///Assets/DarkGray.png";
                }

                try
                {
                    feedGroup.Items.Add(new RssDataItem(
                                            uniqueId: i.Id, title: i.Title.Text, subtitle: null, imagePath: imagePath,
                                            description: null, content: clearedContent, @group: feedGroup));
                }
                catch { };
            }

            _allGroups.Remove(_allGroups.FirstOrDefault(c => c.UniqueId == feedGroup.UniqueId));
            _allGroups.Add(feedGroup);
            //AllGroups = SortItems();
            return(true);
        }