コード例 #1
0
        private static SortedList <int, Entities.Bookmark> ReadBookmarks(XmlElement startNode)
        {
            SortedList <int, Entities.Bookmark> bookmarkList = new SortedList <int, Entities.Bookmark>();
            XmlNode boomarksNode = startNode.SelectSingleNode("bookmarks");

            if (boomarksNode != null)
            {
                XmlNodeList bookmarkNodeList = boomarksNode.ChildNodes; // all "bookmark" nodes
                foreach (XmlNode node in bookmarkNodeList)
                {
                    string text = null;
                    string posX = null;
                    string posY = null;
                    string line = null;
                    foreach (XmlAttribute attr in node.Attributes)
                    {
                        if (attr.Name.Equals("line"))
                        {
                            line = attr.InnerText;
                        }
                    }
                    foreach (XmlNode subNode in node.ChildNodes)
                    {
                        if (subNode.Name.Equals("text"))
                        {
                            text = subNode.InnerText;
                        }
                        else if (subNode.Name.Equals("posX"))
                        {
                            posX = subNode.InnerText;
                        }
                        else if (subNode.Name.Equals("posY"))
                        {
                            posY = subNode.InnerText;
                        }
                    }
                    if (line == null || posX == null || posY == null)
                    {
                        _logger.Error("Invalid XML format for bookmark: {0}", node.InnerText);
                        continue;
                    }
                    int lineNum = int.Parse(line);
                    Entities.Bookmark bookmark = new Entities.Bookmark(lineNum);
                    bookmark.OverlayOffset = new Size(int.Parse(posX), int.Parse(posY));
                    if (text != null)
                    {
                        bookmark.Text = text;
                    }
                    bookmarkList.Add(lineNum, bookmark);
                }
            }
            return(bookmarkList);
        }
コード例 #2
0
        public static void ImportBookmarkList(string logfileName, string fileName,
                                              SortedList <int, Entities.Bookmark> bookmarkList)
        {
            using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read))
            {
                using (StreamReader reader = new StreamReader(fs))
                {
                    if (!reader.EndOfStream)
                    {
                        reader.ReadLine(); // skip "Log file name;Line number;Comment"
                    }

                    while (!reader.EndOfStream)
                    {
                        try
                        {
                            string line = reader.ReadLine();
                            line = line.Replace(replacementForNewLine, "\r\n").Replace("\\\r\n", replacementForNewLine);

                            // Line is formatted: logfileName ";" bookmark.LineNum ";" bookmark.Text;
                            int firstSeparator  = line.IndexOf(';');
                            int secondSeparator = line.IndexOf(';', firstSeparator + 1);

                            string fileStr = line.Substring(0, firstSeparator);
                            string lineStr = line.Substring(firstSeparator + 1, secondSeparator - firstSeparator - 1);
                            string comment = line.Substring(secondSeparator + 1);

                            int lineNum;
                            if (int.TryParse(lineStr, out lineNum))
                            {
                                Entities.Bookmark bookmark = new Entities.Bookmark(lineNum, comment);
                                bookmarkList.Add(lineNum, bookmark);
                            }
                            else
                            {
                                //!!!log error: skipping a line entry
                            }
                        }
                        catch
                        {
                            //!!!
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void CellPainting(ILogPaintContext logPaintCtx, DataGridView gridView, int rowIndex,
                                        DataGridViewCellPaintingEventArgs e)
        {
            if (rowIndex < 0 || e.ColumnIndex < 0)
            {
                e.Handled = false;
                return;
            }
            ILogLine line = logPaintCtx.GetLogLine(rowIndex);

            if (line != null)
            {
                HilightEntry entry = logPaintCtx.FindHighlightEntry(line, true);
                e.Graphics.SetClip(e.CellBounds);
                if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected)
                {
                    Color backColor = e.CellStyle.SelectionBackColor;
                    Brush brush;
                    if (gridView.Focused)
                    {
                        brush = new SolidBrush(e.CellStyle.SelectionBackColor);
                    }
                    else
                    {
                        Color color = Color.FromArgb(255, 170, 170, 170);
                        brush = new SolidBrush(color);
                    }
                    e.Graphics.FillRectangle(brush, e.CellBounds);
                    brush.Dispose();
                }
                else
                {
                    Color bgColor = Color.White;
                    if (!DebugOptions.disableWordHighlight)
                    {
                        if (entry != null)
                        {
                            bgColor = entry.BackgroundColor;
                        }
                    }
                    else
                    {
                        if (entry != null)
                        {
                            bgColor = entry.BackgroundColor;
                        }
                    }
                    e.CellStyle.BackColor = bgColor;
                    e.PaintBackground(e.ClipBounds, false);
                }

                if (DebugOptions.disableWordHighlight)
                {
                    e.PaintContent(e.CellBounds);
                }
                else
                {
                    PaintCell(logPaintCtx, e, gridView, false, entry);
                }

                if (e.ColumnIndex == 0)
                {
                    Entities.Bookmark bookmark = logPaintCtx.GetBookmarkForLine(rowIndex);
                    if (bookmark != null)
                    {
                        Rectangle r; // = new Rectangle(e.CellBounds.Left + 2, e.CellBounds.Top + 2, 6, 6);
                        r = e.CellBounds;
                        r.Inflate(-2, -2);
                        Brush brush = new SolidBrush(logPaintCtx.BookmarkColor);
                        e.Graphics.FillRectangle(brush, r);
                        brush.Dispose();
                        if (bookmark.Text.Length > 0)
                        {
                            StringFormat format = new StringFormat();
                            format.LineAlignment = StringAlignment.Center;
                            format.Alignment     = StringAlignment.Center;
                            Brush brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0));
                            Font  font   = logPaintCtx.MonospacedFont;
                            e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height),
                                                  format);
                            brush2.Dispose();
                        }
                    }
                }

                e.Paint(e.CellBounds, DataGridViewPaintParts.Border);
                e.Handled = true;
            }
        }
コード例 #4
0
ファイル: BookmarkView.cs プロジェクト: jsuppe/LogExpert
 public void BookmarkTextChanged(Entities.Bookmark bookmark)
 {
     throw new NotImplementedException();
 }
コード例 #5
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            List <ImportBookmarkModel> importedBookmarks;

            try
            {
                importedBookmarks = JsonSerializer.Deserialize <List <ImportBookmarkModel> >(Json);
            }
            catch
            {
                ModelState.AddModelError("Json", "Error reading JSON.");
                return(Page());
            }

            foreach (var bookmark in importedBookmarks)
            {
                var entity = new Entities.Bookmark();

                var resource = await _context.GetResourceByLocationAsync(bookmark.Location);

                if (resource == null)
                {
                    ModelState.AddModelError("Location", $"Resource does not exist for {bookmark.Location}. Resource must be added first.");
                    return(Page());
                }
                entity.ResourceId = resource.Id;

                var user = await _context.GetUserByUsernameAsync(bookmark.Username);

                if (user == null)
                {
                    ModelState.AddModelError("Username", $"User does not exist for {bookmark.Username}. User must be added first.");
                    return(Page());
                }
                entity.UserId = user.Id;

                entity.Title       = bookmark.Title ?? "";
                entity.Description = bookmark.Description ?? "";
                entity.IsPublic    = bookmark.Public;
                entity.Favorited   = bookmark.Favorite;
                entity.Tags        = BookmarkTagHelper.StringToList(bookmark.Tags);
                entity.CreateDate  = DateTime.UtcNow;

                _context.AddBookmark(entity);
            }

            try
            {
                await _context.SaveChangesAsync();

                TempData["Message"] = $"{importedBookmarks.Count} bookmark(s) were successfully imported.";
                return(RedirectToPage("./Index"));
            }
            catch
            {
                ModelState.AddModelError("Json", "Error saving bookmarks to database.");
            }

            return(Page());
        }
コード例 #6
0
 internal void AddBookmark(Entities.Bookmark bookmark)
 {
     BookmarkList.Add(bookmark.LineNum, bookmark);
     OnBookmarkAdded();
 }