private static bool UpdateInterfaceScript(Hashtable paramTable, DeviceDir directory, DeviceFileType type, bool essentialFile) { DeviceFile[] files = directory.Files.FindFiles(type); if (files == null || files.Length < 1) { if (essentialFile) { GCError.SetLastError("Cannot find script file of type: " + type.ToString()); return(false); } else { return(true); } } foreach (DeviceFile file in files) { if (!UpdateInterfaceScript(paramTable, file, type, essentialFile)) { return(false); } } return(true); }
private void RefreshDeviceInformation() { this.labelName.Text = this.labelType.Text = this.labelVersion.Text = this.labelDirection.Text = this.labelDescription.Text = ""; if (_sourceDevice == null) { return; } DeviceDir dir = _sourceDevice.Directory; if (dir == null) { MessageBox.Show(this, "Invalid device index file in : " + _sourceDevice.FolderPath, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); _sourceDevice = null; } if (dir != null) { this.labelName.Text = dir.Header.Name; this.labelVersion.Text = dir.Header.Version; this.labelType.Text = dir.Header.Type.ToString(); this.labelDirection.Text = dir.Header.Direction.ToString(); this.labelDescription.Text = dir.Header.Description; this.textBoxInterfaceName.Focus(); } }
public bool LoadConfig() { #region Garbage Load if (Program.ServiceMgt != null) { this.checkBoxEnable.Checked = Program.ServiceMgt.Config.GarbageCollection.Enable; this.numericUpDownInterval.Value = Program.ServiceMgt.Config.GarbageCollection.Interval; this.checkBoxCheckProcessFlag.Checked = Program.ServiceMgt.Config.GarbageCollection.CheckProcessFlag; this.checkBoxCheckExpireTime.Checked = Program.ServiceMgt.Config.GarbageCollection.CheckExpireTime; this.numericUpDownDay.Value = Program.ServiceMgt.Config.GarbageCollection.ExpireTime.Days; this.numericUpDownHour.Value = Program.ServiceMgt.Config.GarbageCollection.ExpireTime.Hours; this.numericUpDownMinute.Value = Program.ServiceMgt.Config.GarbageCollection.ExpireTime.Minutes; this.numericUpDownSecond.Value = Program.ServiceMgt.Config.GarbageCollection.ExpireTime.Seconds; this.radioButtonInterval.Checked = !Program.ServiceMgt.Config.GarbageCollection.StartAtParticularTime; this.radioButtonParticular.Checked = Program.ServiceMgt.Config.GarbageCollection.StartAtParticularTime; this.dateTimePickerTime.Value = Program.ServiceMgt.Config.GarbageCollection.ParticularTime.Time; LoadParticularTime(); } else { this.groupBoxGC.Enabled = this.groupBoxGCR.Enabled = false; } #endregion #region Log Config Load DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; this.enumComboBoxLevel.Text = dir.LogInfo.LogType.ToString(); this.numericUpDownFileDuration.Value = dir.LogInfo.FileDuration; #endregion return(true); }
private void AttachAdapter() { DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; if (dir == null || dir.Header == null) { return; } int adapterID = 0; try { adapterID = int.Parse(dir.Header.ID.Trim()); } catch { adapterID = -1; } amRunning = new AdapterMessage(adapterID, AdapterStatus.Running); amStopped = new AdapterMessage(adapterID, AdapterStatus.Stopped); Program.Log.Write("Messager initialized " + " (Enable=" + Enable.ToString() + ", AdapterID=" + adapterID.ToString() + ", WindowCaption=" + windowCaption + ")."); }
private void buttonDefaultBidirectional_Click(object sender, EventArgs e) { DeviceDir dir = new DeviceDir(); dir.Header.Description = "Bidirectional [device name] adapter"; dir.Header.Direction = DirectionType.BIDIRECTIONAL; dir.Header.EventTypes.Add(GWEventType.Empty); dir.Header.Version = "[device version]"; dir.Header.Type = DeviceType.UNKNOWN; dir.Header.Name = "[device name]"; dir.Header.UseCommandOnly = false; dir.Files.Add(new DeviceFile(DeviceFileType.Installer, "InstallUtil.exe")); dir.Files.Add(new DeviceFile(DeviceFileType.ServiceAssembly, "HYS.IM.Adapter.Service.exe")); dir.Files.Add(new DeviceFile(DeviceFileType.ServiceConfig, "HYS.Adapter.Service.config")); dir.Files.Add(new DeviceFile(DeviceFileType.ConfigAssembly, "HYS.IM.Adapter.Config.exe")); dir.Files.Add(new DeviceFile(DeviceFileType.ConfigConfig, "HYS.Adapter.Config.config")); dir.Files.Add(new DeviceFile(DeviceFileType.MonitorAssembly, "HYS.IM.Adapter.Monitor.exe")); dir.Files.Add(new DeviceFile(DeviceFileType.MonitorConfig, "HYS.Adapter.Monitor.config")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.IM.Adapter.Composer.exe")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.Adapter.Composer.config")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.Adapter.Base.dll")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.Common.DataAccess.dll")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.Common.Objects.dll")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "HYS.Common.Xml.dll")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "Interop.DOGMANAGERLib.dll")); dir.Files.Add(new DeviceFile(DeviceFileType.Other, "gatewaylang_SC.dll")); _dirMgt.DeviceDirInfor = dir; RefreshDevice(); }
private void RefreshInterfaceInformation() { this.labelName.Text = this.labelType.Text = this.labelDevice.Text = this.labelDirection.Text = this.labelDescription.Text = ""; if (_definedInterface == null) { return; } GCDevice device = _definedInterface.Device; DeviceDir dir = _definedInterface.Directory; if (dir == null || device == null) { MessageBox.Show(this, "Invalid device index file in interface folder : " + _definedInterface.FolderPath, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); _definedInterface = null; } this.labelName.Text = dir.Header.Name; this.labelDevice.Text = device.ToString(); this.labelType.Text = dir.Header.Type.ToString(); this.labelDirection.Text = dir.Header.Direction.ToString(); this.labelDescription.Text = dir.Header.Description; if (Program.ConfigMgt.Config.ShowConfigWhenInterfaceInstall) { ShowConfig(); } }
public bool LoadConfig() { LoadAdapterInfor(); DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; this.textBoxIName.Text = dir.Header.Name; this.textBoxIType.Text = dir.Header.Type.ToString(); this.textBoxIVersion.Text = dir.Header.Version; this.textBoxIDirection.Text = dir.Header.Direction.ToString(); this.textBoxIDescription.Text = dir.Header.Description; this.listViewFile.Items.Clear(); foreach (DeviceFile f in dir.Files) { ListViewItem item = this.listViewFile.Items.Add(f.Location); item.SubItems.Add(f.Backupable.ToString()); item.Tag = f; } this.listViewCommand.Items.Clear(); foreach (Command c in dir.Commands) { ListViewItem item = this.listViewCommand.Items.Add(c.Path); item.SubItems.Add(c.Argument); item.Tag = c; } RefreshEventType(); return(true); }
private static DeviceDir _LoadDeviceDir(string deviceFolder) { string fname = deviceFolder + "\\" + DeviceDirManager.IndexFileName; using (StreamReader sr = File.OpenText(fname)) { string xmlstr = sr.ReadToEnd(); DeviceDir dir = XObjectManager.CreateObject(xmlstr, typeof(DeviceDir)) as DeviceDir; return(dir); } }
private void RefreshDetail(GCDevice device) { this.labelName.Text = ""; this.labelType.Text = ""; this.labelVersion.Text = ""; this.labelDirection.Text = ""; this.labelDescription.Text = ""; this.listViewFile.Items.Clear(); this.listViewCommand.Items.Clear(); if (device == null) { return; } DeviceDir dir = device.Directory; if (dir == null) { MessageBox.Show(this, "Invalid device index file in : " + device.FolderPath, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } this.labelName.Text = dir.Header.Name; this.labelType.Text = dir.Header.Type.ToString(); this.labelVersion.Text = dir.Header.Version; this.labelDirection.Text = dir.Header.Direction.ToString(); this.labelDescription.Text = dir.Header.Description; int count = 1; foreach (DeviceFile f in dir.Files) { ListViewItem i = this.listViewFile.Items.Add((count++).ToString()); i.SubItems.Add(f.Location); i.SubItems.Add(f.Type.ToString()); i.SubItems.Add(f.Description); i.SubItems.Add(f.Backupable.ToString()); i.Tag = f; } count = 1; foreach (Command c in dir.Commands) { ListViewItem i = this.listViewCommand.Items.Add((count++).ToString()); i.SubItems.Add(c.Type.ToString()); i.SubItems.Add(c.Path); i.SubItems.Add(c.Argument); i.SubItems.Add(c.Description); i.Tag = c; } }
public DeviceDir GetInfor() { if (directory == null) { DeviceDirManager dirMgt = new DeviceDirManager(); dirMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (dirMgt.LoadDeviceDir()) { directory = dirMgt.DeviceDirInfor; } } return(directory); }
private void RefreshEventType() { DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; this.listViewEventTypes.Items.Clear(); foreach (GWEventType e in dir.Header.EventTypes) { ListViewItem item = this.listViewEventTypes.Items.Add(e.Code); item.SubItems.Add(e.Description); item.Tag = e; } RefreshEventTypeButton(); }
private void AttachAdapter() { DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; if (dir == null || dir.Header == null) { return; } _interfaceName = dir.Header.Name; Program.Log.Write("Garbage Colletor initialized " + " (InterfaceName=" + _interfaceName + ", Enable=" + Program.ConfigMgt.Config.GarbageCollection.Enable.ToString() + ", ParticularTime=" + Program.ConfigMgt.Config.GarbageCollection.StartAtParticularTime.ToString() + ")."); }
private void AttachAdapter() { DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; if (dir == null || dir.Header == null) { return; } _name = dir.Header.RefDeviceName; _type = dir.Header.Type; _direction = dir.Header.Direction; Program.Log.Write("License Controler initialized " + " (DeviceName=" + _name + ", DeviceType=" + _type.ToString() + ", DeviceDirection=" + _direction.ToString() + ")."); }
public static GCDevice LoadDevice(string devicePath) { if (!IsDevicePath(devicePath)) { return(null); } try { GCError.ClearLastError(); DeviceDir dir = _LoadDeviceDir(devicePath); return(new GCDevice(dir, devicePath)); } catch (Exception e) { GCError.SetLastError(e); return(null); } }
private void DeleteEventType() { if (this.listViewEventTypes.SelectedItems.Count < 1) { return; } GWEventType e = this.listViewEventTypes.SelectedItems[0].Tag as GWEventType; if (e == null) { return; } DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; dir.Header.EventTypes.Remove(e); RefreshEventType(); }
public bool SaveConfig() { #region Garbage Save if (Program.ServiceMgt != null) { Program.ServiceMgt.Config.GarbageCollection.Enable = this.checkBoxEnable.Checked; Program.ServiceMgt.Config.GarbageCollection.Interval = (int)this.numericUpDownInterval.Value; Program.ServiceMgt.Config.GarbageCollection.CheckProcessFlag = this.checkBoxCheckProcessFlag.Checked; Program.ServiceMgt.Config.GarbageCollection.CheckExpireTime = this.checkBoxCheckExpireTime.Checked; Program.ServiceMgt.Config.GarbageCollection.ExpireTime = new TimeSpan ((int)this.numericUpDownDay.Value, (int)this.numericUpDownHour.Value, (int)this.numericUpDownMinute.Value, (int)this.numericUpDownSecond.Value); Program.ServiceMgt.Config.GarbageCollection.StartAtParticularTime = this.radioButtonParticular.Checked; Program.ServiceMgt.Config.GarbageCollection.ParticularTime.Time = this.dateTimePickerTime.Value; SaveParticularTime(); if (!Program.ServiceMgt.Save()) { MessageBox.Show("Save Garbage Collection configuration failed."); } } #endregion #region Log Config Save DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; dir.LogInfo.LogType = (LogType)Enum.Parse(typeof(LogType), enumComboBoxLevel.Text); dir.LogInfo.FileDuration = (int)this.numericUpDownFileDuration.Value; if (!Program.DeviceMgt.SaveDeviceDir()) { MessageBox.Show("Save logging configuration failed."); } #endregion return(true); }
private bool outAdapter_OnDataDischarge(string[] guidList) { Program.Log.Write("-- Discharge data begin --"); bool result = false; DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; if (dir == null) { Program.Log.Write(LogType.Warning, "Cannot get adapter DeviceDir information."); goto EndSub; } if (guidList == null) { Program.Log.Write(LogType.Warning, "Receive a <null> guidList."); goto EndSub; } if (Program.ConfigMgt.Config.DumpData) { StringBuilder sb = new StringBuilder(); foreach (string id in guidList) { sb.AppendLine(id); } Program.Log.Write("GUID List (" + guidList.Length.ToString() + "):"); Program.Log.Write(sb.ToString(), false); } result = dataControler.SetProcessFlag(dir.Header.Name, guidList); EndSub: Program.Log.Write("-- Discharge data end. Return value: " + result.ToString() + " --\r\n"); return(result); }
private void AddEventType() { FormEventType frm = new FormEventType(); if (frm.ShowDialog(this) != DialogResult.OK) { return; } GWEventType e = frm.EventType; if (e == null) { return; } DeviceDir dir = Program.DeviceMgt.DeviceDirInfor; dir.Header.EventTypes.Add(e); RefreshEventType(); }
public static InterfaceRec CreateInterfaceRec(GCInterface i) { if (i == null) { return(null); } GCDevice device = i.Device; DeviceDir idir = i.Directory; InterfaceRec rec = i.InterfaceRec; rec.Folder = i.FolderPath; rec.Name = idir.Header.Name; rec.DeviceID = device.DeviceID; rec.DeviceName = device.DeviceName; rec.IndexFile = DeviceDirManager.IndexFileName; rec.Type = ((int)device.Directory.Header.Type).ToString(); rec.Description = device.Directory.Header.Description; rec.EventType = idir.Header.EventType; switch (device.Directory.Header.Direction) { case DirectionType.INBOUND: rec.Direction = "I"; break; case DirectionType.OUTBOUND: rec.Direction = "O"; break; case DirectionType.BIDIRECTIONAL: rec.Direction = "B"; break; } return(rec); }
public GCDevice(DeviceDir dir, string folder) { _directory = dir; _folderPath = folder; _deviceName = _directory.Header.Name; }
public GCInterface AddInterfaceToFolder(GCDevice gcDevice, string interfaceName, string interfacDesc) { GCError.ClearLastError(); // validation if (gcDevice == null || gcDevice.Directory == null) { GCError.SetLastError("Invalid device object."); return(null); } int progCount = 0; int fileCount = gcDevice.Directory.Files.Count; NotifyStart(fileCount + 2, 0, progCount++, "Create interface folder..."); // create interface folder string targetFolder = InterfacesFolder + "\\" + interfaceName; try { if (Directory.Exists(targetFolder)) { GCError.SetLastError("Folder " + targetFolder + " have already exist, please try another name."); NotifyComplete(false, ""); return(null); } if (Directory.CreateDirectory(targetFolder) == null) { GCError.SetLastError("Cannot create folder " + targetFolder + ", please try another name."); NotifyComplete(false, ""); return(null); } } catch (Exception e) { GCError.SetLastError("Cannot create folder " + targetFolder); GCError.SetLastError(e); NotifyComplete(false, ""); return(null); } // copy device files DeviceDir dir = gcDevice.Directory; string sourceFolder = gcDevice.FolderPath; string sourceFile = sourceFolder + "\\" + DeviceDirManager.IndexFileName; string targetFile = targetFolder + "\\" + DeviceDirManager.IndexFileName; try { NotifyGoing(progCount++, "Copying files... "); File.Copy(sourceFile, targetFile); foreach (DeviceFile f in dir.Files) { NotifyGoing(progCount++, "Copying files..."); sourceFile = sourceFolder + "\\" + f.Location; targetFile = targetFolder + "\\" + f.Location; // support sub folder in device dir string path = Path.GetDirectoryName(targetFile); if (!Directory.Exists(path)) { if (Directory.CreateDirectory(path) == null) { GCError.SetLastError("Cannot create folder " + path); NotifyComplete(false, ""); return(null); } } File.Copy(sourceFile, targetFile); } } catch (Exception e) { GCError.SetLastError("Cannot copy file from " + sourceFile + " to " + targetFile); GCError.SetLastError(e); NotifyComplete(false, ""); // roll back... FolderControl.DeleteDevice(targetFolder); return(null); } NotifyGoing(progCount++, "Updating files..."); // update DeviceDir: save interface name, which will be used by interface installation program GCDevice device = FolderControl.LoadDevice(targetFolder); device.Directory.Header.RefDeviceName = gcDevice.DeviceName; device.Directory.Header.RefDeviceID = gcDevice.DeviceID.ToString(); device.Directory.Header.Description = interfacDesc; device.Directory.Header.Name = interfaceName; if (!FolderControl.SaveDevice(device)) { GCError.SetLastError("Update device index file failed."); NotifyComplete(false, ""); // roll back... FolderControl.DeleteDevice(targetFolder); return(null); } // create interface object GCInterface i = new GCInterface(); i.Directory = device.Directory; i.InterfaceName = interfaceName; i.FolderPath = targetFolder; i.Device = gcDevice; NotifyComplete(true, ""); return(i); }
private void RefreshDetail(GCInterface gcInterface) { try { this.labelName.Text = ""; this.labelType.Text = ""; this.labelDevice.Text = ""; this.labelVersion.Text = ""; this.labelDirection.Text = ""; this.labelDescription.Text = ""; this.listViewCombination.Items.Clear(); if (gcInterface == null) { return; } DeviceDir dir = gcInterface.Directory; if (dir == null) { MessageBox.Show(this, "Invalid device index file in : " + gcInterface.FolderPath, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string deviceInfor = ""; InterfaceRec rec = gcInterface.InterfaceRec; if (rec != null) { deviceInfor = /*rec.DeviceID + " " + */ rec.DeviceName; } this.labelDevice.Text = deviceInfor; this.labelName.Text = dir.Header.Name; this.labelType.Text = dir.Header.Type.ToString(); this.labelVersion.Text = dir.Header.Version; this.labelDirection.Text = dir.Header.Direction.ToString(); //this.labelDescription.Text = dir.Header.Description; string desc = dir.Header.Description; if (desc.Length < 1) { desc = dir.Header.ConfigurationSummary; } else { desc += " (" + dir.Header.ConfigurationSummary + ")"; } this.labelDescription.Text = desc; DObjectCollection olist = combinationMgt.GetCombinedInterfaces(dir.Header.Name, dir.Header.Direction); this.listViewCombination.Items.Clear(); if (olist == null) { MessageBox.Show(this, "Access combination table failed.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int index = 1; foreach (InterfaceRec o in olist) { ListViewItem item = this.listViewCombination.Items.Add((index++).ToString()); item.SubItems.Add(o.Name); item.SubItems.Add(DataHelper.GetDirection(o.Direction).ToString()); item.SubItems.Add(DataHelper.GetType(o.Type).ToString()); item.SubItems.Add(o.Description); item.Tag = o; } } catch (Exception ex) { } }