コード例 #1
0
ファイル: FormMain.cs プロジェクト: passionalboy/TFTPServer
/*
 *      private void fastListView1_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
 *      {
 *          ColumnHeader c = fastListView1.Columns[e.ColumnIndex];
 *          if (c.Tag is string)
 *          {
 *              int minWidth;
 *
 *              if (int.TryParse((string)c.Tag, out minWidth))
 *              {
 *                  if (c.Width < minWidth)
 *                  {
 *                      c.Width = minWidth;
 *                  }
 *              }
 *          }
 *      }
 */
        private void listViewTransfers_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
        {
            e.SubItem.BackColor = e.Item.BackColor;
            e.SubItem.ForeColor = e.Item.ForeColor;

            ProgressTag tag = e.SubItem.Tag as ProgressTag;

            Action <DrawListViewSubItemEventArgs, string> drawSubItemText = (x, text) => TextRenderer.DrawText(x.Graphics, text, x.SubItem.Font, x.Bounds, x.SubItem.ForeColor, x.SubItem.BackColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right | TextFormatFlags.NoPadding | TextFormatFlags.SingleLine | TextFormatFlags.GlyphOverhangPadding);

            if (tag != null)
            {
                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.None;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                Rectangle r = e.SubItem.Bounds;
                r.Inflate(-1, -2);
                e.Graphics.DrawRectangle(Pens.LightGray, r);

                r.Offset(1, 1);
                r.Width  = r.Width - 1;
                r.Height = r.Height - 1;
                e.Graphics.FillRectangle(Brushes.LightYellow, r);

                if (tag.Mode == ProgressTag.ViewMode.Percentage)
                {
                    var rf  = RectangleF.FromLTRB(r.Left, r.Top, r.Right, r.Bottom);
                    var txt = string.Format("{0:0.0} %", 100.0 * tag.Fraction);

                    Rectangle part1 = Rectangle.FromLTRB(r.Left, r.Top, r.Left + (int)(tag.Fraction * r.Width), r.Bottom);

                    e.Graphics.SetClip(part1);
                    e.Graphics.FillRectangle(Brushes.Green, part1);
                    e.Graphics.DrawString(txt, this.Font, Brushes.White, rf, sf);

                    Rectangle part2 = Rectangle.FromLTRB(r.Left + r.Width - (int)((1.0 - tag.Fraction) * r.Width), r.Top, r.Right, r.Bottom);

                    e.Graphics.SetClip(part2);
                    e.Graphics.DrawString(txt, this.Font, Brushes.Black, rf, sf);
                }
                else if (tag.Mode == ProgressTag.ViewMode.ProgressWalker)
                {
                    int       partLocation1 = (int)(tag.Fraction * r.Width);
                    int       partLocation2 = r.Width - (int)((0.75 - tag.Fraction) * r.Width);
                    Rectangle partRectangle = Rectangle.FromLTRB(r.Left + partLocation1, r.Top, r.Left + partLocation2, r.Bottom);
                    e.Graphics.FillRectangle(Brushes.Green, partRectangle);
                }
                else if (tag.Mode == ProgressTag.ViewMode.None)
                {
                }
            }
            else
            {
                e.DrawDefault = true;
            }
        }
コード例 #2
0
        public ProgressTag CreateProgressTag(string name = "Tag 1")
        {
            using var context = new ProgressContext(ContextOptions);
            var tag = new ProgressTag(Name.Create(name).Value);

            context.ProgressTags.Add(tag);
            context.SaveChanges();
            return(tag);
        }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: passionalboy/TFTPServer
        private void OnUpdateTransfers(object sender, TFTPLogEventArgs data)
        {
            if (InvokeRequired)
            {
                Invoke(new EventHandler <TFTPLogEventArgs>(OnUpdateTransfers), sender, data);
            }
            else
            {
                try
                {
                    var lv = this.listViewTransfers;

                    int nrOfColumns = lv.Columns.Count;

                    //lv.BeginUpdate();

                    // append new items at the front
                    while (lv.Items.Count < data.Entries.Count)
                    {
                        lv.Items.Insert(0, new ListViewItem(new string[nrOfColumns]));
                    }

                    // remove items from the back
                    while (lv.Items.Count > data.Entries.Count)
                    {
                        lv.Items.RemoveAt(lv.Items.Count - 1);
                    }

                    for (int t = 0; t < lv.Items.Count; t++)
                    {
                        ListViewItem lvItem = lv.Items[t];
                        TFTPLogEntry entry  = data.Entries[t];

                        switch (entry.State)
                        {
                        case TFTPLogState.Busy:
                            lvItem.ForeColor = Color.DarkBlue;
                            break;

                        case TFTPLogState.Completed:
                            lvItem.ForeColor = Color.DarkGreen;
                            break;

                        case TFTPLogState.Stopped:
                            lvItem.ForeColor = Color.DarkRed;
                            break;
                        }

                        string[] rowAsStrings =
                            new string[]
                        {
                            entry.StartTime.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                            entry.IsUpload ? "▲" : "▼",
                            entry.Filename,
                            entry.Server,
                            string.Format("{0}", entry.Transferred),
                            string.Format("{0}", entry.FileLength < 0 ? "?" : entry.FileLength.ToString()),
                            ConvertSpeed(entry.Speed),
                            entry.State.ToString(),
                            entry.ErrorMessage,
                            ""
                        };

                        for (int c = 0; c < rowAsStrings.Length; c++)
                        {
                            ListViewItem.ListViewSubItem subItem = lvItem.SubItems[c];
                            if (subItem.Text != rowAsStrings[c])
                            {
                                subItem.Text = rowAsStrings[c];
                            }
                        }

                        var sub = lvItem.SubItems[rowAsStrings.Length - 1];

                        if (sub.Tag == null || ((ProgressTag)sub.Tag).Id != entry.Id)
                        {
                            sub.Tag = new ProgressTag()
                            {
                                Id = entry.Id, PreviousBytesTransferred = entry.Transferred
                            };
                        }

                        ProgressTag tag = (ProgressTag)sub.Tag;

                        double fraction = GetProgressFraction(entry);

                        if (fraction >= 0.0)
                        {
                            tag.Fraction = fraction;
                            tag.Mode     = ProgressTag.ViewMode.Percentage;
                        }
                        else
                        {
                            if (entry.State == TFTPLogState.Stopped)
                            {
                                tag.Mode = ProgressTag.ViewMode.None;
                            }
                            else
                            {
                                tag.Mode = ProgressTag.ViewMode.ProgressWalker;
                                if (tag.PreviousBytesTransferred != entry.Transferred)
                                {
                                    tag.Fraction = (tag.Fraction + 0.25) % 1.0;
                                    tag.PreviousBytesTransferred = entry.Transferred;
                                }
                            }
                        }
                    }
                    //lv.EndUpdate();
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e);
                }
            }
        }
コード例 #4
0
 private async Task CreateNewTag(Name name)
 {
     var tag = new ProgressTag(name);
     await _context.ProgressTags.AddAsync(tag);
 }