1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Timers;
using ISSAPIConnection;
namespace Dumper.Autoscope
{
public enum AutoscopeAskerStatus {Creating,StandBy,Asking,Malfunction,Error};
public class AutoscopeAsker
{
protected Timer _timer;
protected ClISSUserInterface _ui;
protected string _ip;
protected BackgroundWorker _asking_thread;
protected AutoscopeAskerStatus _status;
public string Data;
/// <summary>
/// Конструктор. Входные параметры адрес автоскопа и интервал обпроса.
/// Объект самостоятельно создает поток снятия данных и вслучае успеха
/// инициирует событие "Получены новые данные". Данные с автоскопа
/// передаются в аргументах события.
/// </summary>
/// <param name="sAutoscopeIP">Строка, IP адрес автоскопа</param>
/// <param name="iPollingInterval">
/// Целое, Интервал опроса автоскопа
/// </param>
public AutoscopeAsker(ClISSUserInterface AutoscopeUI,string AutoscopeIP, int iPollingInterval)
{
//TODO: Конструктор аскера
_status = AutoscopeAskerStatus.Creating;
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - Creating object", DateTime.Now.ToString(), _ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - Create Object", DateTime.Now.ToString(), _ip));
#endif
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - Init timer, UI & BW", DateTime.Now.ToString(), this._ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - Init timer, UI & BW", DateTime.Now.ToString(), _ip));
#endif
//Инициализация таймера
_timer = new Timer();
_timer.AutoReset = true;
_timer.Interval = iPollingInterval*1000;
_timer.Elapsed +=new ElapsedEventHandler(TimerElapsed);
_ui = AutoscopeUI;
_ip = AutoscopeIP;
_asking_thread = new BackgroundWorker();
_asking_thread.DoWork+=new System.ComponentModel.DoWorkEventHandler(_asking_thread_DoWork);
_asking_thread.RunWorkerCompleted+=new System.ComponentModel.RunWorkerCompletedEventHandler(_asking_thread_RunWorkerCompleted);
_timer.Start();
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - timer started...", DateTime.Now.ToString(), _ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - timer started...", DateTime.Now.ToString(), _ip));
#endif
_status = AutoscopeAskerStatus.StandBy;
}
public AutoscopeAsker(string CommunicationServerIP, string AutoscopeIP, int iPollingInterval)
{
_status = AutoscopeAskerStatus.Creating;
//TODO: Конструктор аскера
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - Creating object", DateTime.Now.ToString(), _ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - Create Object", DateTime.Now.ToString(), _ip));
#endif
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - Init timer, UI & BW", DateTime.Now.ToString(), this._ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - Init timer, UI & BW", DateTime.Now.ToString(), _ip));
#endif
//Инициализация таймера
_timer = new Timer();
_timer.AutoReset = true;
_timer.Interval = iPollingInterval * 1000;
_timer.Elapsed += new ElapsedEventHandler(TimerElapsed);
_ui = new ClISSUserInterface(CommunicationServerIP);
_ip = AutoscopeIP;
_asking_thread = new BackgroundWorker();
_asking_thread.DoWork += new System.ComponentModel.DoWorkEventHandler(_asking_thread_DoWork);
_asking_thread.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(_asking_thread_RunWorkerCompleted);
//_timer.Start();
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - timer started...", DateTime.Now.ToString(), _ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - timer started...", DateTime.Now.ToString(), _ip));
#endif
_status = AutoscopeAskerStatus.StandBy;
}
public void Start()
{
_timer.Start();
}
//Timer
protected void TimerElapsed(object sender, EventArgs e)
{
if (_status == AutoscopeAskerStatus.StandBy)
{
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - Tick...", DateTime.Now.ToString(), _ip);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - Tick...", DateTime.Now.ToString(), _ip));
#endif
_asking_thread.RunWorkerAsync();
}
}
//BackgroundWorker
public void _asking_thread_DoWork(object sender, DoWorkEventArgs e)
{
_status = AutoscopeAskerStatus.Asking;
BackgroundWorker worker = sender as BackgroundWorker;
e.Result =_ui.ReadPollingData(_ip);
}
public void _asking_thread_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Data = (string)e.Result;
#if DEBUG
Console.WriteLine("{0}: AutoscopeAsker {1} - new data {2}", DateTime.Now.ToString(), _ip, Data);
System.Diagnostics.Debug.WriteLine(String.Format("{0}: AutoscopeAsker {1} - new data {2}", DateTime.Now.ToString(), _ip, Data));
#endif
_status = AutoscopeAskerStatus.StandBy;
}
}
}