AddBookmark() public méthode

public AddBookmark ( string title, string url, MainWindow mw ) : void
title string
url string
mw MainWindow
Résultat void
        private void button_Click(object sender, RoutedEventArgs e)
        {
            string  readFile = System.IO.File.ReadAllText(StaticDeclarations.Bookmarkspath);
            dynamic json     = JsonConvert.DeserializeObject(readFile);

            try
            {
                foreach (dynamic item in json)
                {
                    if (Url.Text.Equals(Convert.ToString(item.Url)))
                    {
                        JArray json2 = (json as JArray);
                        json2.Remove(item);
                        _Bookmarks.ItemsCount = 0;
                        _Bookmarks.content.Children.Clear();
                        System.IO.File.WriteAllText(StaticDeclarations.Bookmarkspath, json2.ToString());
                        if (System.IO.File.Exists(StaticDeclarations.Bookmarkspath))
                        {
                            string  fileRead = System.IO.File.ReadAllText(StaticDeclarations.Bookmarkspath);
                            dynamic json1    = JsonConvert.DeserializeObject(fileRead);
                            foreach (dynamic item2 in json1)
                            {
                                _Bookmarks.AddBookmark(Convert.ToString(item2.Title), Convert.ToString(item2.Url), mainWindow);
                                foreach (var page in mainWindow.Pages)
                                {
                                    try
                                    {
                                        Task.Factory.StartNew(() => page.startPage.RefreshFavs(mainWindow));
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
            }
        }
Exemple #2
0
        public void loadFavs(MainWindow mw)
        {
            Dispatcher.BeginInvoke((Action)(() =>
            {
                bookmarks.ItemsCount = 0;
                bookmarks.RowsCount = 0;
                bookmarks.mainCanvas.Children.Clear();

                try
                {
                    TabView tabView = bookmarks.FindParent <TabView>();
                    foreach (string s in System.IO.File.ReadAllLines(TabView.Bookspath))
                    {
                        string[] split = s.Split((char)42);
                        bookmarks.AddBookmark(split[0], split[1], tabView, mw);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("LoadFavs error: " + ex.Message);
                }
            }));
        }