프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter_AutoModeling / Utill / Log.cs @ 1430f5a6

이력 | 보기 | 이력해설 | 다운로드 (3.96 KB)

1
using System;
2
using System.Windows.Forms;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Drawing;
7
using System.Threading;
8
using System.Threading.Tasks;
9
using System.IO;
10

    
11
namespace SPPID.Utill
12
{
13
    public static class Log
14
    {
15
        public static string logPath = "";
16

    
17
        public static void WriteLine(Exception ex)
18
        {
19
            using (StreamWriter sw = new StreamWriter(logPath, true))
20
            {
21
                sw.WriteLine(ex.Message);
22
                sw.WriteLine(ex.StackTrace);
23
            }
24
        }
25

    
26
        public static void WriteLine(string text)
27
        {
28
            using (StreamWriter sw = new StreamWriter(logPath, true))
29
            {
30
                sw.WriteLine(text);
31
            }
32
        }
33

    
34
        delegate void SetListBoxItemDelegete(ListBoxItem listboxItem, ListBox listBoxLog);
35
        public static void WriteLine(ListBoxItem item, ListBox listBoxLog)
36
        {
37
            if (listBoxLog != null)
38
            {
39
                if (listBoxLog.InvokeRequired)
40
                {
41
                    listBoxLog.Invoke(new SetListBoxItemDelegete(WriteLine), new object[] { item, listBoxLog });
42
                }
43
                else
44
                {
45
                    bool selectLast = false;
46
                    if (listBoxLog.SelectedIndex == listBoxLog.Items.Count - 1)
47
                        selectLast = true;
48
                    listBoxLog.Items.Add(item.Message);
49
                    if (selectLast)
50
                        listBoxLog.SelectedIndex = listBoxLog.Items.Count - 1;
51

    
52
                    WriteLine(item.Message);
53
                }
54
            }
55
        }
56

    
57
        delegate void SetProgressBarMaximumValueDelegete(int value, ToolStripProgressBar listboxItem);
58
        public static void SetProgressMaximumValue(int value, ToolStripProgressBar progressBar)
59
        {
60
            if (progressBar != null)
61
            {
62
                ToolStrip toolStrip = progressBar.GetCurrentParent();
63
                if (toolStrip.InvokeRequired)
64
                {
65
                    toolStrip.Invoke(new SetProgressBarMaximumValueDelegete(SetProgressMaximumValue), new object[] {value, progressBar });
66
                }
67
                else
68
                {
69
                    progressBar.Maximum = value;
70
                }
71
            }
72
        }
73

    
74
        delegate void ProgressBarIncrementDelegate(ToolStripProgressBar listboxItem);
75
        public static void ProgressBarIncrement(ToolStripProgressBar progressBar)
76
        {
77
            if (progressBar != null)
78
            {
79
                ToolStrip toolStrip = progressBar.GetCurrentParent();
80
                if (toolStrip.InvokeRequired)
81
                {
82
                    toolStrip.Invoke(new ProgressBarIncrementDelegate(ProgressBarIncrement), new object[] { progressBar });
83
                }
84
                else
85
                {
86
                    progressBar.Value = (progressBar.Value + progressBar.Step);
87
                }
88
            }
89
        }
90

    
91
        delegate void SetProgressBarValueDelegate(int value, ToolStripProgressBar listboxItem);
92
        public static void SetProgressBarValue(int value, ToolStripProgressBar progressBar)
93
        {
94
            if (progressBar != null)
95
            {
96
                ToolStrip toolStrip = progressBar.GetCurrentParent();
97
                if (toolStrip.InvokeRequired)
98
                {
99
                    toolStrip.Invoke(new SetProgressBarValueDelegate(SetProgressBarValue), new object[] { value, progressBar });
100
                }
101
                else
102
                {
103
                    if (progressBar.Value <= progressBar.Maximum)
104
                    {
105
                        progressBar.Value = value;
106
                    }
107
                }
108
            }
109
        }
110
    }
111

    
112
    public class ListBoxItem
113
    {
114
        public ListBoxItem(string message, Color color)
115
        {
116
            Message = message;
117
            Color = color;
118
        }
119

    
120
        public string Message { get; set; }
121
        public Color Color { get; set; }
122
    }
123
}
클립보드 이미지 추가 (최대 크기: 500 MB)