public static BookmarkInfo LoadBookmark(string bookmarkFileName) { if (string.IsNullOrEmpty(bookmarkFileName)) return null; if (!System.IO.File.Exists(bookmarkFileName)) return null; try { XmlDocument dom = new XmlDocument(); dom.Load(bookmarkFileName); BookmarkInfo info = new BookmarkInfo(); info.Name = dom.DocumentElement.Name; info.IsFolder = true; info.Childs = new List<BookmarkInfo>(); LoadNode(dom.DocumentElement, info); return info; } catch (Exception ex) { ExceptionProcess.ProcessWithResume(ex); System.IO.File.Delete(bookmarkFileName); return null; } }
public BookmarkPropertyForm(BookmarkInfo bookmarkInfo) : this() { txtName.Text = bookmarkInfo.Name; txtAddress.Text = bookmarkInfo.Address; m_bookmarkInfo = bookmarkInfo; }
public BizBookmarkInfo(BookmarkInfo dataInfo) { BookmarkInfoID = dataInfo.BookmarkInfoID; UserWebFolderID = dataInfo.UserWebFolderID; UserInfoID = dataInfo.UserInfoID; Href = dataInfo.Href; HTML = dataInfo.HTML; Host = dataInfo.Host; CreateTime = dataInfo.CreateTime; IElementJSON = dataInfo.IElementJSON; BookmarkName = dataInfo.BookmarkName; Grate = dataInfo.Grate; HashCode = dataInfo.HashCode; IsShowWithiframe = dataInfo.IsShowWithiframe; }
public static void SaveBookmark(BookmarkInfo info, string bookmarkFileName) { XmlDocument dom = new XmlDocument(); // Write down the XML declaration XmlDeclaration xmlDeclaration = dom.CreateXmlDeclaration("1.0", "utf-8", null); // Create the root element XmlElement rootNode = dom.CreateElement("RootBookmark"); dom.InsertBefore(xmlDeclaration, dom.DocumentElement); dom.AppendChild(rootNode); SaveNode(rootNode, info); dom.Save(bookmarkFileName); }
/// <summary> /// Manages DragDrop operations /// </summary> private void treeViewBookMark_DragDrop(object sender, DragEventArgs e) { // Unlock updates DragHelper.ImageList_DragLeave(this.treeViewBookMark.Handle); // Get drop node TreeNode dropNode = this.treeViewBookMark.GetNodeAt(this.treeViewBookMark.PointToClient(new Point(e.X, e.Y))); // If drop node isn't equal to drag node, add drag node as child of drop node if (this.dragNode != dropNode) { BookmarkInfo dropInfo = dropNode.Tag as BookmarkInfo; BookmarkInfo dragInfo = dragNode.Tag as BookmarkInfo; // Remove drag node from parent if (this.dragNode.Parent == null) { m_rootBookmarkInfo.Childs.Remove(dragInfo); this.treeViewBookMark.Nodes.Remove(this.dragNode); } else { (this.dragNode.Parent.Tag as BookmarkInfo).Childs.Remove(dragInfo); this.dragNode.Parent.Nodes.Remove(this.dragNode); } if (dropInfo.IsFolder) { // Add drag node to drop node dropInfo.Childs.Add(dragInfo); dropNode.Nodes.Add(this.dragNode); } else { // Add drag node to drop node (dropNode.Parent.Tag as BookmarkInfo).Childs.Insert(dropNode.Index, dragInfo); dropNode.Parent.Nodes.Insert(dropNode.Index, this.dragNode); } dropNode.ExpandAll(); // Set drag node to null this.dragNode = null; // Disable scroll timer this.timer.Enabled = false; } }
/// <summary> /// 把DataRow转换成Model /// </summary> public BookmarkInfo ToModel(MySqlDataReader dr) { BookmarkInfo bookmarkInfo = new BookmarkInfo(); bookmarkInfo.BookmarkInfoID = (long)ToModelValue(dr, "BookmarkInfoID"); bookmarkInfo.UserWebFolderID = (long)ToModelValue(dr, "UserWebFolderID"); bookmarkInfo.UserInfoID = (long)ToModelValue(dr, "UserInfoID"); bookmarkInfo.Href = (string)ToModelValue(dr, "Href"); bookmarkInfo.HTML = (string)ToModelValue(dr, "HTML"); bookmarkInfo.Host = (string)ToModelValue(dr, "Host"); bookmarkInfo.CreateTime = (DateTime)ToModelValue(dr, "CreateTime"); bookmarkInfo.IElementJSON = (string)ToModelValue(dr, "IElementJSON"); bookmarkInfo.BookmarkName = (string)ToModelValue(dr, "BookmarkName"); bookmarkInfo.Grate = (int)ToModelValue(dr, "Grate"); bookmarkInfo.HashCode = (int)ToModelValue(dr, "HashCode"); bookmarkInfo.IsShowWithiframe = (int)ToModelValue(dr, "IsShowWithiframe"); return(bookmarkInfo); }
private void UpdateNode(TreeNode node) { if (node == null) { return; } BookmarkInfo info = node.Tag as BookmarkInfo; if (!string.IsNullOrEmpty(textBoxName.Text)) { info.Name = textBoxName.Text.Trim(); } info.Description = textBoxDesc.Text.Trim(); info.Address = textBoxHref.Text.Trim(); treeViewBookMark.SelectedNode = selected_node; treeViewBookMark.SelectedNode.Text = textBoxName.Text.Trim(); }
public static async Task UpdateHistoryListAsync(BookmarkInfo bookmark) { if (RecentList == null) { await LoadHistoryDataAsync(); } //var existed = RecentList.FirstOrDefault(item => item.Position.SeriesId == bookmark.Position.SeriesId); //// No Changes //if (bookmark.Position.VolumeNo == existed.Position.VolumeNo && bookmark.Position.ChapterNo == existed.Position.ChapterNo && bookmark.Position.LineNo == existed.Position.LineNo) // return; RecentList.RemoveAll(item => item.Position.SeriesId == bookmark.Position.SeriesId); RecentList.Add(bookmark); IsHistoryListChanged = true; await SaveHistoryDataAsync(); NotifyRecentsChanged(); }
/// <summary> /// Creates treeView /// References : /// ms-help://MS.MSDNQTR.v90.en/enu_kbnetframeworkkb/netframeworkkb/317597.htm /// http://support.microsoft.com/kb/317597 /// </summary> private void AddNode(BookmarkInfo parentInfo, TreeNode parentNode) { try { // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (parentInfo.IsFolder) { foreach (BookmarkInfo subInfo in parentInfo.Childs) { TreeNode subNode; subNode = new TreeNode(subInfo.Name); subNode.Name = subInfo.Name + Guid.NewGuid().ToString(); subNode.Tag = subInfo; if (subInfo.IsFolder) { subNode.ImageIndex = 0; subNode.SelectedImageIndex = 0; } else { subNode.ImageIndex = 1; subNode.SelectedImageIndex = 1; } parentNode.Nodes.Add(subNode); AddNode(subInfo, subNode); } } } catch (Exception) { treeViewBookMark.Nodes.Clear(); this.treeViewBookMark.Enabled = false; //StackFrame file_info = new StackFrame(true); //error(ref file_info, ex.Message); return; } }
private void CreateNew(TreeNode node, string text, bool isFolder) { BookmarkInfo newInfo = new BookmarkInfo(); newInfo.Name = text; newInfo.Childs = new List <BookmarkInfo>(); newInfo.IsFolder = isFolder; BookmarkInfo nowInfo = GetBookmarkInfo(node); nowInfo.Childs.Add(newInfo); TreeNode newNode = new TreeNode(newInfo.Name, isFolder ? 0 : 1, isFolder ? 0 : 1); newNode.Tag = newInfo; this.selected_node.Nodes.Add(newNode); this.selected_node.Expand(); this.treeViewBookMark.SelectedNode = this.selected_node = newNode; }
public static void Add(BookmarkInfo info) { XmlNode objNode = ConfigDoc.SelectSingleNode("/TXTReaderConfig/bookmark"); XmlElement objElement = ConfigDoc.CreateElement("item"); objElement.SetAttribute("id", Guid.NewGuid().ToString()); objElement.SetAttribute("classid", info.ClassID.ToString()); objElement.SetAttribute("bookname", info.BookName); objElement.SetAttribute("markedindex", info.MarkedIndex.ToString()); objElement.SetAttribute("filepath", info.FilePath); //objElement.InnerText = info.BookName; objNode.AppendChild(objElement); ConfigDoc.Save(ConfigfilePath); //List<Natsuhime.XmlAttribInfo> arribs = new List<Natsuhime.XmlAttribInfo>(); //arribs.Add(new XmlAttribInfo("classid ", info.ClassID.ToString() )); //arribs.Add(new XmlAttribInfo("markedindex ", info.MarkedIndex.ToString() )); //arribs.Add(new XmlAttribInfo("filepath ", info.FilePath )); //XmlHelper.XmlInsertElement(ConfigfilePath, "/TXTReaderConfig/bookmark", "item", arribs, info.BookName); }
public BookmarkInfo CreateBookmarkFromCurrentPage() { var bookmark = new BookmarkInfo { ViewDate = DateTime.Now, Position = new NovelPositionIdentifier { ChapterId = ChapterId, ChapterNo = ChapterNo, VolumeId = ParentVolumeId, VolumeNo = App.CurrentVolume.VolumeNo, SeriesId = App.CurrentSeries.Id, LineNo = CurrentLineNo, }, ContentDescription = (from line in Lines where !line.IsImage && line.Id >= CurrentLineNo select line.Content) .FirstOrDefault(), DescriptionImageUri = App.CurrentVolume.CoverImageUri, ChapterTitle = Title, VolumeTitle = App.CurrentVolume.Title, SeriesTitle = App.CurrentSeries.Title, Progress = ProgressPercentage, }; if (bookmark.ContentDescription == null) { bookmark.ContentDescription = (from line in Lines where !line.IsImage && line.Id < CurrentLineNo select line.Content) .LastOrDefault(); } if (bookmark.ContentDescription == null) { bookmark.ContentDescription = Title; } //bookmark.DescriptionImageUri = (from line in Lines where line.IsImage && line.Id < CurrentLineNo select line.Content).FirstOrDefault(), //if (bookmark.DescriptionImageUri == null) // bookmark.; return(bookmark); }
private void BookmarkManagerForm_Load(object sender, EventArgs e) { m_rootBookmarkInfo = LoadBookmark(m_bookmarkFile); if (m_rootBookmarkInfo == null) { return; } treeViewBookMark.Nodes.Clear(); treeViewBookMark.Nodes.Add(new TreeNode(rootNodeName)); TreeNode tNode = treeViewBookMark.Nodes[0]; tNode.Tag = m_rootBookmarkInfo; // SECTION 3. Populate the TreeView with the DOM nodes. AddNode(m_rootBookmarkInfo, tNode); treeViewBookMark.SelectedNode = treeViewBookMark.Nodes[0]; selected_node = treeViewBookMark.Nodes[0]; treeViewBookMark.SelectedNode.Expand(); }
public static List <BookmarkInfo> GetBookmarkList() { List <BookmarkInfo> bookmarklist = new List <BookmarkInfo>(); XmlNode objNode = ConfigDoc.SelectSingleNode("/TXTReaderConfig/bookmark"); foreach (XmlNode n in objNode.ChildNodes) { BookmarkInfo info = new BookmarkInfo(); info.id = n.Attributes["id"].Value; info.ClassID = Convert.ToInt32(n.Attributes["classid"].Value); info.BookName = n.Attributes["bookname"].Value; info.MarkedIndex = Convert.ToInt32(n.Attributes["markedindex"].Value); info.FilePath = n.Attributes["filepath"].Value; bookmarklist.Add(info); //foreach (XmlAttribute a in n.Attributes) //{ // //a. //} } return(bookmarklist); }
private static void LoadNode(XmlNode inXmlNode, BookmarkInfo parentInfo) { // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { parentInfo.IsFolder = true; XmlNodeList nodeList = inXmlNode.ChildNodes; for (int i = 0; i <= nodeList.Count - 1; i++) { XmlNode xNode = nodeList[i]; BookmarkInfo subInfo = new BookmarkInfo(); if (xNode.Attributes["Name"] != null) { subInfo.Name = xNode.Attributes["Name"].Value; subInfo.Address = xNode.Attributes["Address"].Value; subInfo.Description = xNode.Attributes["Description"].Value; subInfo.IsFolder = Convert.ToBoolean(xNode.Attributes["IsFolder"].Value); subInfo.Childs = new List <BookmarkInfo>(); parentInfo.Childs.Add(subInfo); LoadNode(xNode, subInfo); } } } else { XmlNode xNode = inXmlNode; parentInfo.IsFolder = false; //BookmarkInfo newInfo = new BookmarkInfo(); if (xNode.Attributes["Name"] != null) { parentInfo.Name = xNode.Attributes["Name"].Value; parentInfo.Address = xNode.Attributes["Address"].Value; parentInfo.Description = xNode.Attributes["Description"].Value; parentInfo.IsFolder = Convert.ToBoolean(xNode.Attributes["IsFolder"].Value); } } }
public void Create(object input = null) { try { // 1. Add new bookmark to database string trimmedName = Name.Trim(); bool duplicate_check = (new BookmarkRepo()).AddBookmark(trimmedName, Global, User); // 1.1 Track change BookmarkInfo info = new BookmarkInfo(trimmedName, User); new Tracker(User).TrackCreate <BookmarkInfo>(info); // 2. Refresh Bookmarks collection BookmarkBoxes.Clear(); PopulateBookmarks(); Name = ""; // 3. Hide detailed view //Win.Height = _initialHeight; CreateVisibility = Visibility.Collapsed; NewBookmarkVisibility = Visibility.Visible; // 4. Check bookmark boxes CheckBookmarkBoxes(); Global = 0; if (!duplicate_check) { _dialogService.OpenDialog(new DialogOkViewModel("This bookmark already exists.", "Warning", DialogType.Warning)); } } catch (Exception e) { new BugTracker().Track("Bookmark Manager", "Create Bookmark", e.Message, e.StackTrace); _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error)); } }
/// <summary> /// 根据传入Model更新数据并返回更新后的Model /// </summary> public int Update(BookmarkInfo bookmarkInfo) { string sql = "UPDATE tblBookmarkInfo " + "SET " + " UserWebFolderID = @UserWebFolderID" + ", UserInfoID = @UserInfoID" + ", Href = @Href" + ", HTML = @HTML" + ", Host = @Host" + ", CreateTime = @CreateTime" + ", IElementJSON = @IElementJSON" + ", BookmarkName = @BookmarkName" + ", Grate = @Grate" + ", HashCode = @HashCode" + ", IsShowWithiframe = @IsShowWithiframe" + " WHERE BookmarkInfoID = @BookmarkInfoID"; MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@BookmarkInfoID", bookmarkInfo.BookmarkInfoID) , new MySqlParameter("@UserWebFolderID", ToDBValue(bookmarkInfo.UserWebFolderID)) , new MySqlParameter("@UserInfoID", ToDBValue(bookmarkInfo.UserInfoID)) , new MySqlParameter("@Href", ToDBValue(bookmarkInfo.Href)) , new MySqlParameter("@HTML", ToDBValue(bookmarkInfo.HTML)) , new MySqlParameter("@Host", ToDBValue(bookmarkInfo.Host)) , new MySqlParameter("@CreateTime", ToDBValue(bookmarkInfo.CreateTime)) , new MySqlParameter("@IElementJSON", ToDBValue(bookmarkInfo.IElementJSON)) , new MySqlParameter("@BookmarkName", ToDBValue(bookmarkInfo.BookmarkName)) , new MySqlParameter("@Grate", ToDBValue(bookmarkInfo.Grate)) , new MySqlParameter("@HashCode", ToDBValue(bookmarkInfo.HashCode)) , new MySqlParameter("@IsShowWithiframe", ToDBValue(bookmarkInfo.IsShowWithiframe)) }; return(MyDBHelper.ExecuteNonQuery(sql, para)); }
//添加书签 private void tsmiAddBookmark_Click(object sender, EventArgs e) { if (currentfilepath != null && currentfilepath != string.Empty) { int markedindex = rtbxMain.GetCharIndexFromPosition(new Point(0, 0)); //int xx2 = rtbxMain.GetFirstCharIndexFromLine(1); List <BookmarkInfo> bmlist = bookmarklist.FindAll( delegate(BookmarkInfo info) { return(info.FilePath == currentfilepath); } ); if (bmlist.Count > 0) { bmlist[0].MarkedIndex = markedindex; Bookmark.Update(bmlist[0]); MessageBox.Show("更新书签成功."); } else { BookmarkInfo info; info = new BookmarkInfo(); info.BookName = this.tsmiCurrentFilename.Text; info.ClassID = 0; info.MarkedIndex = markedindex; info.FilePath = currentfilepath; Bookmark.Add(info); MessageBox.Show("添加书签成功."); } InitBookmarkMenu(); } else { MessageBox.Show("还没有打开任何文件,无法加入书签."); } }
public void Sync() { // 1. Sync information _logs.ForEach((log) => { User user = new UserRepo().GetUserByName(log.Username); switch (log.Type) { case "Create": // Create article if (log.Info.InfoType == "ArticleInfo") { ArticleInfo local_info = log.Info as ArticleInfo; Article article = new Article(local_info); ArticleRepo repo = new ArticleRepo(); // Edge case: Article already exists if (repo.GetArticleWithTitle(article.Title) != null) { string mismatch = $"Article '{local_info.Title}' already exists."; _mismatches.Add(mismatch); return; } // 1. Add article to database repo.SaveArticle(article, user); // 2. Copy file string fileName = repo.GetFileWithTitle(local_info.Title); File.Copy( Path.Combine(_filesPath, local_info.FileName + ".pdf"), Path.Combine(Path.Combine(Environment.CurrentDirectory, "Files"), fileName + ".pdf")); Article dbArticle = repo.GetArticleWithTitle(local_info.Title); // 3. Add references and bookmarks BookmarkRepo bookmarkRepo = new BookmarkRepo(); ReferenceRepo referenceRepo = new ReferenceRepo(); // Bookmarks local_info.Bookmarks.ForEach((bookmark) => { Bookmark dbBookmark = bookmarkRepo.GetBookmark(bookmark.Name, user); bookmarkRepo.AddArticleToBookmark(dbBookmark, dbArticle); }); // References local_info.References.ForEach((reference) => { Reference dbReference = referenceRepo.GetReference(reference.Name); referenceRepo.AddArticleToReference(dbReference, dbArticle); }); } // Create bookmark else if (log.Info.InfoType == "BookmarkInfo") { BookmarkInfo local_info = log.Info as BookmarkInfo; BookmarkRepo repo = new BookmarkRepo(); // Edge case: Bookmark already exists if (repo.GetBookmark(local_info.Name, user) != null) { string mismatch = $"Bookmark '{local_info.Name}' already exists."; _mismatches.Add(mismatch); return; } repo.AddBookmark(local_info.Name, local_info.Global, user); } // Create reference else if (log.Info.InfoType == "ReferenceInfo") { ReferenceInfo local_info = log.Info as ReferenceInfo; ReferenceRepo repo = new ReferenceRepo(); // Edge case: Reference already exists if (repo.GetReference(local_info.Name) != null) { string mismatch = $"Reference '{local_info.Name}' already exists."; _mismatches.Add(mismatch); return; } new ReferenceRepo().AddReference(local_info.Name); } break; case "Update": // Update article if (log.Info.InfoType == "ArticleInfo") { ArticleInfo local_info = (ArticleInfo)log.Info; ArticleRepo repo = new ArticleRepo(); Article existingArticle = repo.GetFullArticleWithTitle(user, log.Changed); // Edge case: Article I am trying to update doesn't exist if (existingArticle == null) { string mismatch = $"Article '{log.Changed}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Article newArticle = new Article(local_info); newArticle.ID = existingArticle.ID; repo.UpdateArticle(newArticle, user); } // Update bookmark else if (log.Info.InfoType == "BookmarkInfo") { BookmarkInfo local_info = (BookmarkInfo)log.Info; BookmarkRepo repo = new BookmarkRepo(); Bookmark existingBookmark = repo.GetBookmark(log.Changed, user); // Edge case: Bookmark I am trying to update doesn't exist if (existingBookmark == null) { string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Bookmark newBookmark = new Bookmark(local_info); newBookmark.ID = existingBookmark.ID; repo.UpdateBookmark(newBookmark); } // Update reference else if (log.Info.InfoType == "ReferenceInfo") { ReferenceInfo local_info = (ReferenceInfo)log.Info; ReferenceRepo repo = new ReferenceRepo(); Reference existingReference = repo.GetReference(log.Changed); // Edge case: Reference I am trying to update doesn't exist if (existingReference == null) { string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated."; _mismatches.Add(mismatch); return; } Reference newReference = new Reference(local_info); newReference.ID = existingReference.ID; if (local_info.Title != null) { newReference.ArticleID = (int)new ArticleRepo().GetArticleWithTitle(local_info.Title).ID; } repo.UpdateReference(newReference); } break; case "Coupling": Couple info = (Couple)log.Info; // Couple bookmark if (info.CollectionType == "Bookmark") { BookmarkRepo bookmarkRepo = new BookmarkRepo(); ArticleRepo articleRepo = new ArticleRepo(); Bookmark bookmark = bookmarkRepo.GetBookmark(info.Name, user); Article article = articleRepo.GetArticleWithTitle(info.Title); // Edge case: Article or bookmark doesn't exist or Article is already in bookmark if (bookmark == null) { string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because bookmark doesn't exist"; _mismatches.Add(mismatch); return; } else if (article == null) { string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because article doesn't exist"; _mismatches.Add(mismatch); return; } // Add if (info.ActionType == "Add") { // Edge case: Article is already in bookmark if (bookmarkRepo.CheckArticleInBookmark(bookmark, article)) { string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'"; _mismatches.Add(mismatch); return; } bookmarkRepo.AddArticleToBookmark(bookmark, article); } // Remove else if (info.ActionType == "Remove") { // Edge case: Article is not in bookmark if (!bookmarkRepo.CheckArticleInBookmark(bookmark, article)) { string mismatch = $"Article - '{info.Title}' can not be removed from bookmark '{info.Name}' (Its not there)"; _mismatches.Add(mismatch); return; } bookmarkRepo.RemoveArticleFromBookmark(bookmark, article); } } // Couple reference else if (info.CollectionType == "Reference") { ReferenceRepo referenceRepo = new ReferenceRepo(); ArticleRepo articleRepo = new ArticleRepo(); Reference reference = referenceRepo.GetReference(info.Name); Article article = articleRepo.GetArticleWithTitle(info.Title); // Edge case: Article or bookmark doesn't exist if (reference == null) { string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because reference doesn't exist"; _mismatches.Add(mismatch); return; } else if (article == null) { string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because article doesn't exist"; _mismatches.Add(mismatch); return; } // Add if (info.ActionType == "Add") { if (referenceRepo.CheckArticleInReference(reference, article)) { string mismatch = $"Article - '{info.Title}' is already in reference '{info.Name}'"; _mismatches.Add(mismatch); return; } referenceRepo.AddArticleToReference(reference, article); } // Remove else if (info.ActionType == "Remove") { if (!referenceRepo.CheckArticleInReference(reference, article)) { string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'"; _mismatches.Add(mismatch); return; } referenceRepo.RemoveArticleFromReference(reference, article); } } break; case "Delete": DeleteInfo local_info1 = (DeleteInfo)log.Info; // Delete article if (local_info1.ObjectType == "Article") { ArticleRepo repo = new ArticleRepo(); Article article = repo.GetArticleWithTitle(local_info1.Name); // Edge case: Article I am trying to delete doesn't exist if (article == null) { string mismatch = $"Can't delete article '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } string file = repo.GetFileWithTitle(local_info1.Name); repo.DeleteArticle(article); File.Delete(Path.Combine(Environment.CurrentDirectory, "Files", file + ".pdf")); } // Delete bookmark else if (local_info1.ObjectType == "Bookmark") { BookmarkRepo repo = new BookmarkRepo(); Bookmark bookmark = repo.GetBookmark(local_info1.Name, user); // Edge case: Bookmark I am trying to delete doesn't exist if (bookmark == null) { string mismatch = $"Can't delete bookmark '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } repo.DeleteBookmark(bookmark); } // Delete reference else if (local_info1.ObjectType == "Reference") { ReferenceRepo repo = new ReferenceRepo(); Reference reference = repo.GetReference(local_info1.Name); // Edge case: Reference I am trying to delete doesn't exist if (reference == null) { string mismatch = $"Can't delete reference '{local_info1.Name}' because it doesn't exist"; _mismatches.Add(mismatch); return; } repo.DeleteReference(reference); } break; case "Personal": PersonalInfo local_info2 = (PersonalInfo)log.Info; ArticleRepo repo1 = new ArticleRepo(); Article article3 = repo1.GetArticleWithTitle(local_info2.Title); // Edge case: Article I am trying to add personal doesn't exist if (article3 == null) { string mismatch = $"Can't add personal to article '{local_info2.Title}' because it doesn't exist"; _mismatches.Add(mismatch); return; } article3.PersonalComment = local_info2.PersonalComment; article3.SIC = local_info2.SIC; repo1.UpdatePersonal(article3, user); break; case "Pending": PendingInfo l_info = (PendingInfo)log.Info; // 1. Remove pending section status from db new GlobalRepo().RemovePending(l_info.Section); // 2. Remove section from json string path = Path.Combine(Environment.CurrentDirectory, "sections.json"); string textInfo = File.ReadAllText(path); List <string> sections = JsonConvert.DeserializeObject <List <string> >(textInfo); sections.Remove(l_info.Section); textInfo = JsonConvert.SerializeObject(sections); File.WriteAllText(path, textInfo); break; default: break; } }); // 2. Write mismatches WriteMismatches(); }
private static void SaveNode(XmlNode inXmlNode, BookmarkInfo parentInfo) { if (parentInfo == null) return; foreach (BookmarkInfo subInfo in parentInfo.Childs) { /*invalid XML Character Replaced With "<" "<" ">" ">" "\"" """ "\'" "'" "&" "&" */ // 不需要Escape。System.Security.SecurityElement.Escape(subInfo.Name) // Create a new <Category> element and add it to the root node XmlElement parentNode = inXmlNode.OwnerDocument.CreateElement("Bookmark" + System.Guid.NewGuid().ToString()); // Set attribute name and value! parentNode.SetAttribute("Name", subInfo.Name); parentNode.SetAttribute("Address", subInfo.Address); parentNode.SetAttribute("Description", subInfo.Description); parentNode.SetAttribute("IsFolder", subInfo.IsFolder.ToString()); inXmlNode.AppendChild(parentNode); SaveNode(parentNode, subInfo); } }
private void LoadBookmarkMenuItems() { while(tsmBookmark.DropDownItems.Count > 4) tsmBookmark.DropDownItems.RemoveAt(4); string fileName = SystemDirectory.UserDataDirectory + "\\bookmark.xml"; if (!System.IO.File.Exists(fileName)) return; m_rootBookmarkInfo = BookmarkManagerForm.LoadBookmark(fileName); if (m_rootBookmarkInfo != null) { AddBookmarkMenuItems(m_rootBookmarkInfo, tsmBookmark); } //AMS.Profile.IProfile profile = SystemProfileFile.DefaultUserProfile; //string history = profile.GetValue("MainWindow", "Bookmark", string.Empty); //if (!string.IsNullOrEmpty(history)) //{ // string[] ss = history.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); // foreach (string s in ss) // { // //Dictionary<string, string> bm = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(s); // BookmarkInfo bookmarkInfo = null; // try // { // bookmarkInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<BookmarkInfo>(s); // } // catch (Exception) // { // } // if (bookmarkInfo == null) // continue; // ToolStripMenuItem menuItem = new ToolStripMenuItem(); // menuItem.MouseDown += new MouseEventHandler(BookmarkMenuItem_MouseDown); // menuItem.Text = bookmarkInfo.Name; // menuItem.Click += new EventHandler(BookmarkMenuItem_Click); // //if (!string.IsNullOrEmpty(info.ImageName)) // //{ // // menuItem.Image = Feng.Windows.ImageResource.Get("Icons." + info.ImageName + ".png").Reference; // //} // //if (menuItem.Image == null) // //{ // // menuItem.Image = GetDefaultImage(info); // //} // //menuItem.Visible = Authority.AuthorizeByRule(info.Visible); // string address = bookmarkInfo.Address; // menuItem.ToolTipText = address; // menuItem.Tag = bookmarkInfo; // tsmBookmark.DropDownItems.Add(menuItem); // } //} }
public Bookmark(BookmarkInfo info) { this.ID = info.ID; this.Name = info.Name; this.Global = info.Global; }
private void DeleteBookmarkInfo(BookmarkInfo toDeleteInfo, BookmarkInfo parentInfo) { if (parentInfo.IsFolder) { for (int i = 0; i < parentInfo.Childs.Count; ++i) { if (parentInfo.Childs[i] == toDeleteInfo) { parentInfo.Childs.RemoveAt(i); return; } DeleteBookmarkInfo(toDeleteInfo, parentInfo.Childs[i]); } } }
/// <summary>${controls_BookMark_method_addBookMark_D}</summary> /// <param name="name">${controls_BookMark_method_addBookMark_param_name}</param> /// <param name="viewbounds">${controls_BookMark_method_addBookMark_param_viewBounds}</param> public void AddBookmark(string name, Rectangle2D viewbounds) { name = name.Trim(); if (string.IsNullOrEmpty(name)) { name = DateTime.Now.ToString(CultureInfo.InvariantCulture); } BookmarkInfo bookmarkInfo = new BookmarkInfo { Name = name, ViewBounds = viewbounds }; Bookmarks.Add(bookmarkInfo); isLoaded = true; if (bookmarkList != null && bookmarkList.Columns.Count > 0) { bookmarkList.ScrollIntoView(bookmarkInfo, bookmarkList.Columns[0]); } SaveBookmarks(); }
private void AddBookmarkMenuItems(BookmarkInfo parentInfo, ToolStripMenuItem parentItem) { foreach (BookmarkInfo subInfo in parentInfo.Childs) { ToolStripMenuItem menuItem = new ToolStripMenuItem(); menuItem.MouseDown += new MouseEventHandler(BookmarkMenuItem_MouseDown); menuItem.Image = subInfo.IsFolder ? Feng.Windows.ImageResource.Get("Feng", "Icons.iconFolder.png").Reference : Feng.Windows.ImageResource.Get("Feng", "Icons.iconBookmark.png").Reference; menuItem.Text = subInfo.Name; menuItem.Click += new EventHandler(BookmarkMenuItem_Click); //menuItem.Visible = Authority.AuthorizeByRule(info.Visible); string address = subInfo.Address; //menuItem.ToolTipText = address; menuItem.Tag = subInfo; parentItem.DropDownItems.Add(menuItem); AddBookmarkMenuItems(subInfo, menuItem); } }
private void tsmAddToBookmark_Click(object sender, EventArgs e) { string address = GetAddress(); if (!string.IsNullOrEmpty(address)) { BookmarkInfo bookmarkInfo = new BookmarkInfo(); bookmarkInfo.Name = this.ActiveChildMdiForm.Text; bookmarkInfo.Address = address; bookmarkInfo.Childs = new List<BookmarkInfo>(); m_rootBookmarkInfo.Childs.Add(bookmarkInfo); ToolStripMenuItem menuItem = new ToolStripMenuItem(); menuItem.MouseDown += new MouseEventHandler(BookmarkMenuItem_MouseDown); menuItem.Text = bookmarkInfo.Name; menuItem.Click += new EventHandler(BookmarkMenuItem_Click); //if (!string.IsNullOrEmpty(info.ImageName)) //{ // menuItem.Image = Feng.Windows.ImageResource.Get("Icons." + info.ImageName + ".png").Reference; //} //if (menuItem.Image == null) //{ // menuItem.Image = GetDefaultImage(info); //} //menuItem.Visible = Authority.AuthorizeByRule(info.Visible); menuItem.ToolTipText = address; menuItem.Tag = bookmarkInfo; tsmBookmark.DropDownItems.Add(menuItem); SaveBookmarkMenuItems(); } else { MessageForm.ShowWarning("��ǰҳ��"); } }
public bool BufferReceive(OperationContext operationContext, ReceiveContext receiveContext, string bookmarkName, BufferedReceiveState state, bool retry) { bool flag = false; BufferedReceiveMessageProperty property = null; if (BufferedReceiveMessageProperty.TryGet(operationContext.IncomingMessageProperties, out property)) { CorrelationMessageProperty property = null; if (!CorrelationMessageProperty.TryGet(operationContext.IncomingMessageProperties, out property)) { return(flag); } EventHandler handler = null; InstanceKey instanceKey = property.CorrelationKey; int channelKey = operationContext.Channel.GetHashCode(); if (!this.throttle.Acquire(channelKey)) { return(flag); } try { if (!this.UpdateProperty(property, receiveContext, channelKey, bookmarkName, state)) { return(flag); } if (handler == null) { handler = delegate(object sender, EventArgs e) { lock (this.thisLock) { if (this.bufferedProperties.ContainsKey(instanceKey) && this.bufferedProperties[instanceKey].Remove(property)) { try { property.RequestContext.DelayClose(false); property.RequestContext.Abort(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } } this.throttle.Release(channelKey); } } }; } receiveContext.Faulted += handler; lock (this.thisLock) { if (receiveContext.State != ReceiveContextState.Received) { return(flag); } bool flag2 = false; if (retry) { property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); property.ReplayRequest(); property.Notification.NotifyInvokeReceived(property.RequestContext.InnerRequestContext); flag2 = true; } else { ReadOnlyCollection <BookmarkInfo> bookmarksForInstance = this.host.DurableInstanceManager.PersistenceProviderDirectory.GetBookmarksForInstance(instanceKey); if (bookmarksForInstance != null) { for (int i = 0; i < bookmarksForInstance.Count; i++) { BookmarkInfo info = bookmarksForInstance[i]; if (info.BookmarkName == bookmarkName) { property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); property.ReplayRequest(); property.Notification.NotifyInvokeReceived(property.RequestContext.InnerRequestContext); flag2 = true; break; } } } } if (!flag2) { List <BufferedReceiveMessageProperty> list; if (!this.bufferedProperties.TryGetValue(instanceKey, out list)) { list = new List <BufferedReceiveMessageProperty>(); this.bufferedProperties.Add(instanceKey, list); } property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); list.Add(property); } else { this.throttle.Release(channelKey); } return(true); } } finally { if (!flag) { this.throttle.Release(channelKey); } } } return(flag); }
/// <summary> /// Adds a bookmark. If the bookmark already exists, null is returned. /// </summary> /// <param name="bookmark">Bookmark info</param> /// <returns></returns> public Bookmark?Add(BookmarkInfo bookmark) => Add(new[] { bookmark }).FirstOrDefault();
public int Update(BookmarkInfo bookmarkInfo) { return(new BookmarkInfoDAL().Update(bookmarkInfo)); }
public BookmarkInfo CreateBookmarkFromCurrentPage() { var bookmark = new BookmarkInfo { ViewDate = DateTime.Now, Position = new NovelPositionIdentifier { ChapterId = ChapterId, ChapterNo = ChapterNo, VolumeId = ParentVolumeId, VolumeNo = App.CurrentVolume.VolumeNo, SeriesId = App.CurrentSeries.Id, LineNo = CurrentLineNo, }, ContentDescription = (from line in Lines where !line.IsImage && line.Id >= CurrentLineNo select line.Content) .FirstOrDefault(), DescriptionImageUri = App.CurrentVolume.CoverImageUri, ChapterTitle = Title, VolumeTitle = App.CurrentVolume.Title, SeriesTitle = App.CurrentSeries.Title, Progress = ProgressPercentage, }; if (bookmark.ContentDescription == null) { bookmark.ContentDescription = (from line in Lines where !line.IsImage && line.Id < CurrentLineNo select line.Content) .LastOrDefault(); } if (bookmark.ContentDescription == null) bookmark.ContentDescription = Title; //bookmark.DescriptionImageUri = (from line in Lines where line.IsImage && line.Id < CurrentLineNo select line.Content).FirstOrDefault(), //if (bookmark.DescriptionImageUri == null) // bookmark.; return bookmark; }
public bool BufferReceive(OperationContext operationContext, ReceiveContext receiveContext, string bookmarkName, BufferedReceiveState state, bool retry) { Fx.Assert(receiveContext != null, "ReceiveContext must be present in order to perform buffering"); bool success = false; BufferedReceiveMessageProperty property = null; if (BufferedReceiveMessageProperty.TryGet(operationContext.IncomingMessageProperties, out property)) { CorrelationMessageProperty correlation = null; if (CorrelationMessageProperty.TryGet(operationContext.IncomingMessageProperties, out correlation)) { InstanceKey instanceKey = correlation.CorrelationKey; int channelKey = operationContext.Channel.GetHashCode(); if (this.throttle.Acquire(channelKey)) { try { // Tag the property with identifying data to be used during later processing if (UpdateProperty(property, receiveContext, channelKey, bookmarkName, state)) { // Cleanup if we are notified the ReceiveContext faulted underneath us receiveContext.Faulted += delegate(object sender, EventArgs e) { lock (this.thisLock) { if (this.bufferedProperties.ContainsKey(instanceKey)) { if (this.bufferedProperties[instanceKey].Remove(property)) { try { property.RequestContext.DelayClose(false); property.RequestContext.Abort(); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } // ---- these exceptions as we are already on the error path } this.throttle.Release(channelKey); } } } }; // Actual Buffering lock (this.thisLock) { // Optimistic state check in case we just raced with the receiveContext // faulting. If the receiveContext still faults after the state check, the above // cleanup routine will handle things correctly. In both cases, a double-release // of the throttle is protected. if (receiveContext.State == ReceiveContextState.Received) { bool found = false; // if the exception indicates retry-able (such as RetryException), // we will simply retry. This happens when racing with abort and // WF informing the client to retry (BufferedReceiveManager is a // client in this case). if (retry) { property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); property.ReplayRequest(); property.Notification.NotifyInvokeReceived(property.RequestContext.InnerRequestContext); found = true; } else { ReadOnlyCollection <BookmarkInfo> bookmarks = this.host.DurableInstanceManager.PersistenceProviderDirectory.GetBookmarksForInstance(instanceKey); // Retry in case match the existing bookmark if (bookmarks != null) { for (int i = 0; i < bookmarks.Count; ++i) { BookmarkInfo bookmark = bookmarks[i]; if (bookmark.BookmarkName == bookmarkName) { // Found it so retry... property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); property.ReplayRequest(); property.Notification.NotifyInvokeReceived(property.RequestContext.InnerRequestContext); found = true; break; } } } } if (!found) { List <BufferedReceiveMessageProperty> properties; if (!this.bufferedProperties.TryGetValue(instanceKey, out properties)) { properties = new List <BufferedReceiveMessageProperty>(); this.bufferedProperties.Add(instanceKey, properties); } property.RequestContext.DelayClose(true); property.RegisterForReplay(operationContext); properties.Add(property); } else { this.throttle.Release(channelKey); } success = true; } } } } finally { if (!success) { this.throttle.Release(channelKey); } } } } } return(success); }
private void BookmarkManagerForm_Load(object sender, EventArgs e) { m_rootBookmarkInfo = LoadBookmark(m_bookmarkFile); if (m_rootBookmarkInfo == null) return; treeViewBookMark.Nodes.Clear(); treeViewBookMark.Nodes.Add(new TreeNode(rootNodeName)); TreeNode tNode = treeViewBookMark.Nodes[0]; tNode.Tag = m_rootBookmarkInfo; // SECTION 3. Populate the TreeView with the DOM nodes. AddNode(m_rootBookmarkInfo, tNode); treeViewBookMark.SelectedNode = treeViewBookMark.Nodes[0]; selected_node = treeViewBookMark.Nodes[0]; treeViewBookMark.SelectedNode.Expand(); }
private void SaveBookmarkMenuItems(BookmarkInfo parentInfo, ToolStripItem parentItem) { ToolStripMenuItem parentMenuItem = parentItem as ToolStripMenuItem; if (parentMenuItem == null) return; parentInfo.Childs.Clear(); foreach (ToolStripItem subItem in parentMenuItem.DropDownItems) { BookmarkInfo subInfo = subItem.Tag as BookmarkInfo; parentInfo.Childs.Add(subInfo); SaveBookmarkMenuItems(subInfo, subItem); } }
private void CreateNew(TreeNode node, string text, bool isFolder) { BookmarkInfo newInfo = new BookmarkInfo(); newInfo.Name = text; newInfo.Childs = new List<BookmarkInfo>(); newInfo.IsFolder = isFolder; BookmarkInfo nowInfo = GetBookmarkInfo(node); nowInfo.Childs.Add(newInfo); TreeNode newNode = new TreeNode(newInfo.Name, isFolder ? 0 : 1, isFolder ? 0 : 1); newNode.Tag = newInfo; this.selected_node.Nodes.Add(newNode); this.selected_node.Expand(); this.treeViewBookMark.SelectedNode = this.selected_node = newNode; }
private void SaveBookmarkMenuItems() { //StringBuilder sb = new StringBuilder(); //foreach (ToolStripItem i in tsmBookmark.DropDownItems) //{ // if (i == tsmAddToBookmark || i == tsmBookmarkManage || i == tsmBookmarkSeparator) // continue; // BookmarkInfo bookmarkInfo = i.Tag as BookmarkInfo; // sb.Append(Newtonsoft.Json.JsonConvert.SerializeObject(bookmarkInfo)); // sb.Append(Environment.NewLine); //} //if (sb.Length > 0) //{ // SystemProfileFile.DefaultUserProfile.SetValue("MainWindow", "Bookmark", sb.ToString()); //} m_rootBookmarkInfo = new BookmarkInfo(); m_rootBookmarkInfo.Name = "��ǩ"; m_rootBookmarkInfo.Childs = new List<BookmarkInfo>(); foreach (ToolStripItem i in tsmBookmark.DropDownItems) { if (i == tsmAddToBookmark || i == tsmBookmarkManage || i == tsmBookmarkSeparator) continue; BookmarkInfo bookmarkInfo = i.Tag as BookmarkInfo; m_rootBookmarkInfo.Childs.Add(bookmarkInfo); SaveBookmarkMenuItems(bookmarkInfo, i); } string fileName = SystemDirectory.UserDataDirectory + "\\bookmark.xml"; BookmarkManagerForm.SaveBookmark(m_rootBookmarkInfo, fileName); }
public bool BookmarkInfoAdd(BookmarkInfo bookmarkInfo) { return(new BookmarkInfoDAL().Add(bookmarkInfo)); }
private void BookmarkList_SelectionChanged(object sender, SelectionChangedEventArgs e) { bookmark = bookmarkList.SelectedItem as BookmarkInfo; ZoomToViewBounds(); }
private static void LoadNode(XmlNode inXmlNode, BookmarkInfo parentInfo) { // Loop through the XML nodes until the leaf is reached. // Add the nodes to the TreeView during the looping process. if (inXmlNode.HasChildNodes) { parentInfo.IsFolder = true; XmlNodeList nodeList = inXmlNode.ChildNodes; for (int i = 0; i <= nodeList.Count - 1; i++) { XmlNode xNode = nodeList[i]; BookmarkInfo subInfo = new BookmarkInfo(); if (xNode.Attributes["Name"] != null) { subInfo.Name = xNode.Attributes["Name"].Value; subInfo.Address = xNode.Attributes["Address"].Value; subInfo.Description = xNode.Attributes["Description"].Value; subInfo.IsFolder = Convert.ToBoolean(xNode.Attributes["IsFolder"].Value); subInfo.Childs = new List<BookmarkInfo>(); parentInfo.Childs.Add(subInfo); LoadNode(xNode, subInfo); } } } else { XmlNode xNode = inXmlNode; parentInfo.IsFolder = false; //BookmarkInfo newInfo = new BookmarkInfo(); if (xNode.Attributes["Name"] != null) { parentInfo.Name = xNode.Attributes["Name"].Value; parentInfo.Address = xNode.Attributes["Address"].Value; parentInfo.Description = xNode.Attributes["Description"].Value; parentInfo.IsFolder = Convert.ToBoolean(xNode.Attributes["IsFolder"].Value); } } }
public void AddRecent(BookmarkInfo bookmark) { }