/// <summary> /// /// </summary> public CanNetworkServiceAdapter() { NetworksManager manager = NetworksManager.Instance; _ControllerChangedStatus = new EventHandler(EventHandlerControllerChangedStatus); _DeviceChangedStatus = new EventHandler(EventHandlerDeviceChangedStatus); _DevicesAmountWasChanged = new EventHandler <KeyedCollectionWasChangedEventArgs <DeviceBase> >( EventHandlerDevicesAmountWasChanged); _Devices = new List <NetworkDevice>(); // Собираем все устройства из всех сетей foreach (NetworkController network in manager.Networks) { network.ControllerChangedStatus += _ControllerChangedStatus; network.Devices.CollectionWasChanged += _DevicesAmountWasChanged; foreach (DeviceBase device in network.Devices) { device.DeviceChangedStatus += _DeviceChangedStatus; // TODO: //device.DataWasChanged += new EventHandler(device_DataWasChanged); _Devices.Add(new NetworkDevice(device)); } } }
private void ReplaceNetworksManagerControl(NetworksManager manager) { NetworksManager = manager; if (manager == null) { Text = "Neural Network"; CtlMenuStart.Enabled = false; CtlMenuReset.Enabled = false; CtlMainMenuSaveAs.Enabled = false; CtlMenuNetwork.Enabled = false; CtlNetworkContextMenu.Enabled = false; } else { Text = "Neural Network | " + Path.GetFileNameWithoutExtension(Config.Main.GetString(Const.Param.NetworksManagerName)); CtlMenuStart.Enabled = true; CtlMenuReset.Enabled = true; CtlMainMenuSaveAs.Enabled = true; CtlMenuNetwork.Enabled = true; CtlNetworkContextMenu.Enabled = true; } OnNetworkUIChanged(Notification.ParameterChanged.Structure); }
private void ReplaceNetworksManagerControl(NetworksManager manager) { if (manager == null) { CtlNetworkName.Content = "..."; CtlMenuStart.IsEnabled = false; CtlMenuReset.IsEnabled = false; CtlMainMenuSaveAs.IsEnabled = false; CtlMenuNetwork.IsEnabled = false; CtlNetworkContextMenu.IsEnabled = false; } else { CtlNetworkName.Content = Path.GetFileNameWithoutExtension(Config.Main.GetString(Const.Param.NetworksManagerName)); CtlMenuStart.IsEnabled = true; CtlMenuReset.IsEnabled = true; CtlMainMenuSaveAs.IsEnabled = true; CtlMenuNetwork.IsEnabled = true; CtlNetworkContextMenu.IsEnabled = true; CtlPlotPresenter.Clear(); CtlStatisticsPresenter.Clear(); CtlMatrixPresenter.Clear(); } OnNetworkUIChanged(Notification.ParameterChanged.Structure); }
void MakeInstance() { if (instance == null) { instance = this; } }
/// <summary> /// Конструктор /// </summary> /// <param name="networkName">Наименование данной сети</param> /// <param name="connection">Объект для физического подключения к сети</param> public NetworkController(String networkName, IDataLinkLayer connection) { NetworksManager manager = NetworksManager.Instance; // Проверяем уникальность наименование сети if (manager.Networks.Contains(networkName)) { throw new Exception( "Попытка создать сеть Modbus с наименованием, которое имеет другая сеть"); } else { _NetworkName = networkName; } _Devices = new DevicesCollection(this); _Devices.ItemsListWasChanged += new EventHandler(EventHandler_DevicesCollection_ItemsListWasChanged); _Connection = connection; if (_Connection != null) { _Connection.RequestWasRecived += new EventHandlerRequestWasRecived(EventHandler_Connection_RequestWasRecived); _Connection.ErrorOccurred += new EventHandlerErrorOccurred(EventHandler_Connection_ErrorAccured); // Переводим контроллер в состояние "стоп" Stop(); } }
private void CreateNetworksManager() { if (!StopRequest()) { return; } var network = new NetworksManager(CtlTabs, null, OnNetworkUIChanged); if (network.Config != null) { NetworksManager = network; CtlInputDataPresenter.LoadConfig(NetworksManager.Config, this); ReplaceNetworksManagerControl(NetworksManager); if (NetworksManager.IsValid()) { ApplyChangesToStandingNetworks(); } else { MessageBox.Show("Network parameter is not valid.", "Error"); } } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void EventHandler_FormNetworkControl_Load(object sender, EventArgs e) { _NetworksManager = NetworksManager.Instance; Text = "Управление сетями НГК CAN"; Icon = Properties.Resources.faviconMy; // Инициализируем системное дерево InitTreeViewSystem(); }
/// <summary> /// Конструктор /// </summary> public NetworkController() { NetworksManager manager = NetworksManager.Instance; _NetworkName = GetNewName(); //Stop(); _Devices = new DevicesCollection(this); _Devices.ItemsListWasChanged += new EventHandler(EventHandler_DevicesCollection_ItemsListWasChanged); }
public override void DataBind() { if (_bound) { return; } _bound = true; NetworksManager nMgr = new NetworksManager(); if (NetworkId != null) { this.DataItem = nMgr.GetNetwork(NetworkId.Value); } base.DataBind(); }
static void Main() { Application.CurrentCulture = new System.Globalization.CultureInfo("ru-Ru"); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.Automatic); AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(EventHandler_CurrentDomain_UnhandledException); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(EventHandler_Application_ThreadException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Создаём объект для ведения логов приложения //_Logger = LogManager.GetCurrentClassLogger(); _Logger = LogManager.GetLogger("CorrosionMonitoringSystemLogger"); _Logger.Info("Приложение запущено"); // Data base layer _NetworkManager = NetworksManager.Instance; try { _NetworkManager.LoadConfig(Application.StartupPath + @"\newtorkconfig.bin.nwc"); } catch { MessageBox.Show("Ошибка при конфигурировании системы. " + "Приложение будет закрыто", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } // Presentation layer CorrosionMonitoringSystemForm _PresentationForm = new CorrosionMonitoringSystemForm(); // Business layer BLController controller = new BLController(_NetworkManager, _PresentationForm); Application.Run(_PresentationForm); _Logger.Info("Приложение остановлено"); }
private void LoadNetworksManager(string name) { if (!StopRequest()) { return; } if (String.IsNullOrEmpty(name)) { return; } if (!File.Exists(name)) { name = "\\Networks\\" + System.IO.Path.GetFileName(name); } if (File.Exists(name)) { NetworksManager = new NetworksManager(CtlTabs, name, OnNetworkUIChanged); Config.Main.Set(Const.Param.NetworksManagerName, name); CtlInputDataPresenter.LoadConfig(NetworksManager.Config, this); ReplaceNetworksManagerControl(NetworksManager); if (NetworksManager.IsValid()) { ApplyChangesToStandingNetworks(); } else { MessageBox.Show("Network parameter is not valid.", "Error"); } } else { MessageBox.Show($"Network '{name}' is not found!", "Error", MessageBoxButton.OK); Config.Main.Set(Const.Param.NetworksManagerName, string.Empty); } }
/// <summary> /// Возвращает новое уникальное имя сети /// </summary> /// <returns></returns> private String GetNewName() { string networkName; NetworksManager manager = NetworksManager.Instance; // Устанавливаем наименование сети по умолчанию // Формат имени [Network][index] // Индекс - номер по порядку // Ищем не занятое имя и устнавливаем for (int i = 1; i < Int32.MaxValue; i++) { // Получаем новое имя networkName = "Network" + i.ToString(); // Проверяем, существует ли уже такое в списке if (!manager.Networks.Contains(networkName)) { return(networkName); } } // Не удалось найти уникальное имя. throw new Exception(); }
public override void DataBind() { if (_bound) { return; } _bound = true; _page = this.Page as lw.Base.CustomPage; this.SelectCommand = "select Top " + Top + " * from " + TableName; string cond = ""; if (Status != null) { cond = " where Status = " + (int)Status; } else { cond = " where 1=1 "; } if (!string.IsNullOrEmpty(Condition)) { cond += string.Format(" and {0}", Condition); } if (MemberId != null && String.Compare(WebContext.Profile.dbUserName, Config.GetFromWebConfig("Admin"), true) != 0 && NetworkBound) { cond += " and NetworkId in (select NetworkId from MemberNetworks where MemberId={0}"; if (onlyPreferred != null && onlyPreferred.Value) { cond += " and Prefered=1"; } cond += ")"; cond = string.Format(cond, memberId); } if (ParentId != null) { cond += " and ParentId=" + _parentId.Value.ToString(); } if (!string.IsNullOrWhiteSpace(ParentUniqueName) && (ParentId == null)) { NetworksManager nMgr = new NetworksManager(); var parentName = nMgr.GetNetwork(ParentUniqueName); int? pId = null; if (parentName != null) { pId = parentName.NetworkId; } if (pId != null) { cond += " and ParentId = " + pId; } } if (CMSMode != null && CMSMode.Value) { string q = WebContext.Request["q"]; string netDateFrom = WebContext.Request["DateFrom"]; string netDateTo = WebContext.Request["DateTo"]; if (!string.IsNullOrWhiteSpace(q)) { cond += string.Format(" and (Name like '%{0}%' or UniqueName like '%{0}%')", StringUtils.SQLEncode(q)); } if (!string.IsNullOrWhiteSpace(netDateFrom) && !string.IsNullOrWhiteSpace(netDateTo)) { cond += string.Format(" and DateCreated between '{0}' and '{1}'", DateTime.Parse(netDateFrom), DateTime.Parse(netDateTo)); } else if (!string.IsNullOrWhiteSpace(netDateFrom)) { cond += string.Format(" and DateCreated >= '{0}'", DateTime.Parse(netDateFrom)); } else if (!string.IsNullOrWhiteSpace(netDateTo)) { cond += string.Format(" and DateCreated <= '{0}'", DateTime.Parse(netDateTo)); } } if (!string.IsNullOrWhiteSpace(OrderBy)) { cond += " Order By " + OrderBy; } this.SelectCommand += cond; base.DataBind(); }
private void Init() { this.Icon = Properties.Resources.faviconMy; //this.UseWaitCursor = true; this.NetworksManager = NetworksManager.Instance; // Инициализация меню ToolStripMenuItem menuItem; ToolStripSeparator menuSeparator; menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuFile"; menuItem.Text = "&Файл"; // & для подчёркивания буквы Ф и возможность выбра меню сочетанием клавишь ALT + Ф this._MenuStripMain.Items.Add(menuItem); // Члены меню "Файл" menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuNew"; menuItem.Text = "&Создать"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); menuSeparator = new ToolStripSeparator(); menuSeparator.Name = "_MenuFileSeparator1"; ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuSeparator); menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuOpenFile"; menuItem.Text = "&Открыть файл"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuCloseFile"; menuItem.Text = "&Закрыть файл"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); menuSeparator = new ToolStripSeparator(); menuSeparator.Name = "_MenuFileSeparator2"; ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuSeparator); menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuSave"; menuItem.Text = "&Сохранить"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuSaveAs"; menuItem.Text = "Сохранить &как"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); menuSeparator = new ToolStripSeparator(); menuSeparator.Name = "_MenuFileSeparator3"; ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuSeparator); menuItem = new ToolStripMenuItem(); menuItem.Name = "_MenuExit"; menuItem.Text = "&Выход"; menuItem.Click += new EventHandler(EventHandler_MenuItem_Click); ((ToolStripMenuItem)this._MenuStripMain.Items["_MenuFile"]).DropDownItems.Add(menuItem); // Настраиваем PropertyGrid для редактирования конфигурации сетей. PropertyGrid grid = new PropertyGrid(); grid.Name = "_PropertyGridMain"; grid.Dock = DockStyle.Fill; this._SplitContainerMain.Panel2.Controls.Add(grid); grid.SelectedObject = null; // Инициализация строки статуса ToolStripLabel lableItem; lableItem = new ToolStripLabel(); lableItem.Name = "_ToolStripLabelPathToFile"; lableItem.Alignment = ToolStripItemAlignment.Left; lableItem.AutoToolTip = true; lableItem.TextAlign = ContentAlignment.MiddleLeft; lableItem.ToolTipText = "Путь к файлу конфигурации"; this._StatusStripMain.Items.Add(lableItem); // Устанавливаем путь к файлу конфигурации. this.SetPathToFile(null); return; }