/// <summary> /// Gibt das FavIcon für einen Link zurück /// </summary> /// <param name="link"></param> /// <returns></returns> public Image GetFavIconForLink(Link link) { var client = new WebClient(); var downloadPath = Directory.GetCurrentDirectory() + "\\temp\\"; var filename = link.Guid + ".png"; if (!Directory.Exists(downloadPath)) Directory.CreateDirectory(downloadPath); var downloadDirFiles = Directory.GetFiles(downloadPath).Select(fi => new FileInfo(fi)); if (downloadDirFiles.Any(fi => fi.Name.Equals(filename))) { return GetImage(downloadPath + filename); } try { if (!_connectionTester.IsClientConnected()) return null; client.DownloadFile(GoogleFavIconGetter + link.Uri, downloadPath + filename); Log.Debug("FavIcon download for Link '" +link.Name +"' successful. Path: " +downloadPath + filename); return GetImage(downloadPath + filename); } catch (Exception e) { Log.Debug("Could not download FavIcon for Link '" +link.Name +"' Reason: " +e.Message); return null; } }
/// <summary> /// Löscht einen Link /// </summary> /// <param name="link"></param> public static void DeleteLink(Link link) { var result = MessageBox.Show(CommonText.LinkDeleteQuestion, CommonText.LinkDeleteTitle,MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) DataStore.Instance.OnLinksDeleted(link.WrapInList()); }
/// <summary> /// Erstellt den ToolTip für einen Link /// </summary> /// <param name="link"></param> /// <returns></returns> public string BuildLinkToolTip(Link link) { return CommonText.Link + ": " + link.Uri + Environment.NewLine + Environment.NewLine + CommonText.Created + ": " + link.Created.ToString("g") + Environment.NewLine + CommonText.Calls + ": " + link.InvokeCount; }
/// <summary> /// Dialog zum Bearbeiten eines bestehenden Links /// </summary> /// <param name="link"></param> public LinkDialog(Link link) { InitWindow(); Title = LinkDialogRes.EditLinkTitle; _changedLink = link; NameTextBox.Text = link.Name; UriTextBox.Text = link.Uri; CategoryComboBox.SelectedValue = link.Category.Name; UpdateButtonState(); }
/// <summary> /// Erstellt das Kontextmenü für Links /// </summary> /// <param name="link"></param> /// <returns></returns> public ContextMenu BuildLinkContextMenu(Link link) { var cm = new ContextMenu(); cm.HasDropShadow = true; var open = new MenuItem(); open.Header = CommonText.Open; open.Click += (o, e) => CommandStore.OpenLinkInDefaultBrowser(link); cm.Items.Add(open); var edit = new MenuItem(); edit.Header = CommonText.Edit; edit.Click += (o, e) => CommandStore.OpenEditLinkDialog(link); cm.Items.Add(edit); var delete = new MenuItem(); delete.Header = CommonText.Delete; delete.Click += (o,e) => CommandStore.DeleteLink(link); cm.Items.Add(delete); return cm; }
/// <summary> /// Fügt einen Link hinzu /// </summary> /// <param name="link"></param> public static void EditLink(Link link) { if (DataStore.Instance.Links.Any(li => li.Guid.Equals(link.Guid))) DataStore.Instance.OnLinksChanged(link.WrapInList()); }
/// <summary> /// Fügt einen Link hinzu /// </summary> /// <param name="link"></param> public static void AddLink(Link link) { if(!DataStore.Instance.Links.Any(li => li.Uri.Equals(link.Uri))) DataStore.Instance.OnLinksAdded(link.WrapInList()); }
/// <summary> /// Öffnet den Link im Browser /// </summary> /// <param name="link"></param> public static void OpenLinkInDefaultBrowser(Link link) { try { System.Diagnostics.Process.Start(link.Uri); link.InvokeCount++; DataStore.Instance.OnLinksChanged(link.WrapInList()); } catch (Exception e) { MessageBox.Show(e.Message, CommonText.Error, MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Öffnet den Dialog zum Bearbeiten eines Links /// </summary> /// <param name="link"></param> public static void OpenEditLinkDialog(Link link) { var dialog = new LinkDialog(link); dialog.ShowDialog(); }
/// <summary> /// Speichert die Änderungen an dem bestehenden Link oder legt einen neuen Link an /// </summary> private void Save() { if (_changedLink == null) { var link = new Link(); link.Uri = UriTextBox.Text; link.Name = NameTextBox.Text; link.Category = DataStore.Instance.Categories.First(cat => cat.Name.Equals(CategoryComboBox.SelectedValue.ToString())); CommandStore.AddLink(link); } else { _changedLink.Name = NameTextBox.Text; _changedLink.Uri = UriTextBox.Text; _changedLink.Category = DataStore.Instance.Categories.First(cat => cat.Name.Equals(CategoryComboBox.SelectedValue.ToString())); CommandStore.EditLink(_changedLink); } }