internal static bool PreLoading() { #region Load DeviceDir DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (!DeviceMgt.LoadDeviceDir()) { Log.Write(LogType.Error, "Load DeviceDir failed. " + DeviceMgt.FileName); MessageBox.Show("Cannot load DeviceDir file."); return(false); } else { // initialize config ConfigMgt = new AdapterMonitorCfgMgt(); ConfigMgt.FileName = Application.StartupPath + "\\" + ConfigMgt.FileName; if (!ConfigMgt.Load()) { Log.Write(LogType.Error, "Load configuration failed. " + ConfigMgt.FileName); MessageBox.Show("Cannot load configuration file."); return(false); } else { string connStr = ConfigMgt.Config.DataDBConnection; DataAccess = new DataAccess(connStr); return(true); } } #endregion }
internal static void PreLoading() { //Load DeviceDir DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (!DeviceMgt.LoadDeviceDir()) { MessageBox.Show("Cannot load DeviceDir file."); } //Load XML file string FileName = Application.StartupPath + "\\" + SQLInAdapterConfigMgt._FileName; if (!SQLInAdapterConfigMgt.Load(FileName)) { if (SQLInAdapterConfigMgt.LastException != null) { if (MessageBox.Show("Cannot load configuration file. Do you want to create an empty configuration file?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { SQLInAdapterConfigMgt.Save(SQLInAdapterConfigMgt._FileName); } } } }
public static void PreLoading() { string FileName = Application.StartupPath + "\\" + RdetOutboundAdapterConfigMgt.FileName; Log.WriteAppStart("RdetOutboundAdapter"); //RdetOutboundAdapterConfigMgt.RdetOutAdapterConfig = RdetOutboundAdapterConfigMgt.BuildSampleConfig(); //RdetOutboundAdapterConfigMgt.Save(FileName); if (!RdetOutboundAdapterConfigMgt.Load(FileName)) { Log.Write(LogType.Error, "Load configuration failed. \r\n" + FileName + "\r\n" + RdetOutboundAdapterConfigMgt.LastException.Message); } Database = new DataBase(RdetOutboundAdapterConfigMgt.RdetOutAdapterConfig.GWDataDBConnection); DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (DeviceMgt.LoadDeviceDir()) { Log.Write("Load DeviceDir succeeded. " + DeviceMgt.FileName); } else { Log.Write(LogType.Error, "Load DeviceDir failed. " + DeviceMgt.FileName); } }
private void FormScript_Load(object sender, EventArgs e) { if (!_dirMgt.LoadDeviceDir()) { this.labelError.Visible = true; this.comboBoxType.Enabled = false; } }
private void LoadFile() { _dirMgt.FileName = this.textBoxLocation.Text; if (_dirMgt.LoadDeviceDir()) { RefreshDevice(); } else { MessageBox.Show(this, "Load DeviceDir file failed.\r\n\r\n" + _dirMgt.LastErrorInfor, "Error"); } }
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 UpdateDeviceDir() { string fileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; DeviceDirManager mgt = new DeviceDirManager(fileName); if (!mgt.LoadDeviceDir()) { MessageBox.Show(this, "Load devicedir file failed. \r\n" + fileName); return; } mgt.DeviceDirInfor.Header.Name = this.textBoxTP.Text; if (!mgt.SaveDeviceDir()) { MessageBox.Show(this, "Save devicedir file failed. \r\n" + fileName); return; } }
public void PreLoading() { // Load DeviceDir DeviceDirManager DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (DeviceMgt.LoadDeviceDir()) { _adapterName = DeviceMgt.DeviceDirInfor.Header.Name; _logTypeLevel = DeviceMgt.DeviceDirInfor.LogInfo.LogType; _fileDuration = DeviceMgt.DeviceDirInfor.LogInfo.FileDuration; } else { _adapterName = "GCGateway"; _logTypeLevel = LogType.Debug; _fileDuration = 0; //WriteLogException("Load DeviceDir failed in log module! Set adapterName as default value: \"GCGateway\""); } }
private bool UpdateDeviceDir() { DeviceDirManager deviceMgt = new DeviceDirManager(); deviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (!deviceMgt.LoadDeviceDir()) { MessageBox.Show(this, "Cannot open DeviceDir file to write. " + deviceMgt.FileName); return(false); } deviceMgt.DeviceDirInfor.Header.RefDeviceName = GWLicenseHelper.LightMWLOutDeviceName; if (!deviceMgt.SaveDeviceDir()) { MessageBox.Show(this, "Cannot save DeviceDir file. " + deviceMgt.FileName); return(false); } return(true); }
static void SetDeviceValue(string arg) { Tag t = GetTag(arg); if (t == null) { return; } DeviceDirManager dir = new DeviceDirManager(); dir.FileName = DeviceDirManager.IndexFileName; if (!dir.LoadDeviceDir()) { Log.Write(LogType.Error, "Load DeviceDir file failed. " + dir.FileName); Log.Write(dir.LastError); } try { object res = dir.DeviceDirInfor.Header.GetType().InvokeMember(t.Key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetProperty, null, dir.DeviceDirInfor.Header, new object[] { t.Value }); } catch (Exception err) { Log.Write(LogType.Error, "Set value failed."); Log.Write(err); } if (!dir.SaveDeviceDir()) { Log.Write(LogType.Error, "Save DeviceDir file failed. " + dir.FileName); Log.Write(dir.LastError); } Log.Write("Update DeviceDir file succeeded."); }
internal static void PreLoading() { Log = new Logging(Application.StartupPath + "\\MWLServer.log"); LoggingHelper.EnableApplicationLogging(Log); LoggingHelper.EnableXmlLogging(Log); Log.WriteAppStart(AppName); ConfigMgt = new MWLServerConfigMgt(); ConfigMgt.FileName = Application.StartupPath + "\\" + ConfigMgt.FileName; if (ConfigMgt.Load()) { Log.Write("Load config succeeded. " + ConfigMgt.FileName); DHelper.CharacterSetName = ConfigMgt.Config.CharacterSetName; DHelper.PersonNameEncodingRule = ConfigMgt.Config.PersonNameEncodingRule; PrivateTagHelper.PrivateTagList = ConfigMgt.Config.PrivateTagList; Log.Write("Character Set: " + DHelper.CharacterSetName); } else { Log.Write(LogType.Error, "Load config failed. " + ConfigMgt.FileName); } DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (DeviceMgt.LoadDeviceDir()) { Log.Write("Load DeviceDir succeeded. " + DeviceMgt.FileName); } else { Log.Write(LogType.Error, "Load DeviceDir failed. " + DeviceMgt.FileName); } Database = new DataBase(Program.ConfigMgt.Config.GWDataDBConnection); LoggingHelper.EnableDatabaseLogging(Database, Program.Log); }
/// <summary> /// Note: when copying passive SQL interface, this is only a shadow copy, which results in a new NT service, new tables (always empty), new GC SP and the same inbound/outbound SPs. /// </summary> /// <param name="fromInterface"></param> /// <param name="toInterfaceName"></param> /// <param name="toInterfaceDescription"></param> /// <returns></returns> public GCInterface CopyInterface(GCInterface fromInterface, string toInterfaceName, string toInterfaceDescription) { try { GCError.ClearLastError(); if (fromInterface == null || string.IsNullOrEmpty(toInterfaceName)) { return(null); } string fromFolder = ConfigHelper.GetFullPath(fromInterface.FolderPath); if (!Directory.Exists(fromFolder)) { return(null); } // copy files string toPath = Path.Combine(InterfacesFolder, toInterfaceName); string toFolder = ConfigHelper.GetFullPath(toPath); if (!Directory.Exists(toFolder)) { Directory.CreateDirectory(toFolder); } string sourceDirFile = Path.Combine(fromFolder, DeviceDirManager.IndexFileName); string targetDirFile = Path.Combine(toFolder, DeviceDirManager.IndexFileName); File.Copy(sourceDirFile, targetDirFile, true); int index = 0; NotifyStart(fromInterface.Directory.Files.Count + 2, 0, index++, "Copying files..."); foreach (DeviceFile df in fromInterface.Directory.Files) { string f = df.Location; string sourceFile = ConfigHelper.GetFullPath(fromFolder, f); string fn = ConfigHelper.GetRelativePath(fromFolder, sourceFile); string targetFile = ConfigHelper.GetFullPath(toFolder, fn); 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, true); NotifyGoing(index++, "Copying files..."); } // Update device dir GCInterface i = null; DeviceDirManager mgr = new DeviceDirManager(targetDirFile); if (mgr.LoadDeviceDir()) { mgr.DeviceDirInfor.Header.ID = "0"; mgr.DeviceDirInfor.Header.Name = toInterfaceName; mgr.DeviceDirInfor.Header.Description = toInterfaceDescription; // update interface name and description if (!mgr.SaveDeviceDir()) { GCError.SetLastError(mgr.LastError); return(null); } // copy object i = new GCInterface(); i.Directory = mgr.DeviceDirInfor; i.Device = new GCDevice(mgr.DeviceDirInfor, toPath); i.Device.DeviceID = int.Parse(mgr.DeviceDirInfor.Header.RefDeviceID); i.Device.DeviceName = mgr.DeviceDirInfor.Header.RefDeviceName; i.InterfaceName = toInterfaceName; i.FolderPath = toPath; // AddInterfaceToDatabase & update interface ID to DeviceDir file. if (!AddInterfaceToDatabase(i)) { return(null); } NotifyGoing(index++, "Registering interface..."); // update service config DeviceFile df = mgr.DeviceDirInfor.Files.FindFirstFile(DeviceFileType.ServiceConfig); string fn = ConfigHelper.GetFullPath(toFolder, df.Location); AdapterServiceCfgMgt mgt = new AdapterServiceCfgMgt(fn); if (mgt.Load()) { mgt.Config.ServiceName = toInterfaceName; if (!mgt.Save()) { GCError.SetLastError(mgt.LastError); return(null); } } else { GCError.SetLastError(mgt.LastError); return(null); } } else { GCError.SetLastError(mgr.LastError); return(null); } NotifyComplete(true, "Copy interface completed."); return(i); } catch (Exception err) { GCError.SetLastError(err); NotifyComplete(false, "Copy interface failed."); return(null); } }
static int Main(string[] args) { // initialize logging Log = new Logging(Application.StartupPath + "\\AdapterConfig.log"); LoggingHelper.EnableApplicationLogging(Log); LoggingHelper.EnableXmlLogging(Log); Log.WriteAppStart(AppName, args); // read arguments foreach (string a in args) { switch (a.ToLower()) { case AdapterConfigArgument.InIM: { InIM = true; break; } case AdapterConfigArgument.InIMWizard: { InIMWizard = true; break; } } } // check multi instance if (CheckMultiInstance(args)) { goto exit; } // load DeviceDir DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (!DeviceMgt.LoadDeviceDir()) { Log.Write(LogType.Error, "Load DeviceDir failed. " + DeviceMgt.FileName); DeviceMgt.DeviceDirInfor = new DeviceDir(); MessageBox.Show("Cannot load DeviceDir file."); } // initialize config ConfigMgt = new AdapterConfigCfgMgt(); ConfigMgt.FileName = Application.StartupPath + "\\" + ConfigMgt.FileName; if (ConfigMgt.Load()) { Log.Write("Load config succeeded. " + ConfigMgt.FileName); } else { Log.Write(LogType.Error, "Load config failed. " + ConfigMgt.FileName); goto exit; } // initialize service config ServiceMgt = new AdapterServiceCfgMgt(); ServiceMgt.FileName = Application.StartupPath + "\\" + ServiceMgt.FileName; if (ServiceMgt.Load()) { Log.Write("Load serivce config succeeded. " + ServiceMgt.FileName); } else { Log.Write(LogType.Error, "Load serivce config failed. " + ServiceMgt.FileName); ServiceMgt = null; } // log config parameters string adapterFileName = ConfigMgt.Config.AdapterFileName; DirectionType adapterDirection = ConfigMgt.Config.AdapterDirection; Log.Write("Adapter filename: " + adapterFileName, false); Log.Write("Adapter direction: " + adapterDirection, false); if (adapterFileName == null || adapterFileName.Length < 1) { goto exit; } // show window Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); try { switch (adapterDirection) { case DirectionType.INBOUND: { // initialize inbound adapter agent InAdapter = new AdapterAgent <IInboundAdapterConfig, AdapterConfigEntryAttribute>(adapterFileName, Log); InitializeAdapter(InAdapter.Instance); Application.Run(new FormConfigIn()); UninitiliazeAdapter(InAdapter.Instance); break; } case DirectionType.OUTBOUND: { // initialize outbound adapter agent OutAdapter = new AdapterAgent <IOutboundAdapterConfig, AdapterConfigEntryAttribute>(adapterFileName, Log); InitializeAdapter(OutAdapter.Instance); Application.Run(new FormConfigOut()); UninitiliazeAdapter(OutAdapter.Instance); break; } case DirectionType.BIDIRECTIONAL: { // initialize bidiretional adapter agent BiAdapter = new AdapterAgent <IBidirectionalAdapterConfig, AdapterConfigEntryAttribute>(adapterFileName, Log); InitializeAdapter(BiAdapter.Instance); Application.Run(new FormConfigBi()); UninitiliazeAdapter(BiAdapter.Instance); break; } } } catch (Exception err) { Log.Write(LogType.Error, "Error in loading main window."); Log.Write(err); } exit: // exit Log.WriteAppExit(AppName); return((int)ExitCode); }
/// <summary> /// The main entry point for the application. /// </summary> static void Main() { // initialize logging Log = new Logging(Application.StartupPath + "\\AdapterService.log"); LoggingHelper.EnableApplicationLogging(Log); LoggingHelper.EnableXmlLogging(Log); Log.WriteAppStart(AppName); // load DeviceDir DeviceMgt = new DeviceDirManager(); DeviceMgt.FileName = Application.StartupPath + "\\" + DeviceDirManager.IndexFileName; if (!DeviceMgt.LoadDeviceDir()) { Log.Write(LogType.Error, "Load DeviceDir failed. " + ConfigMgt.FileName); goto exit; } // initialize config ConfigMgt = new AdapterServiceCfgMgt(); ConfigMgt.FileName = Application.StartupPath + "\\" + ConfigMgt.FileName; if (ConfigMgt.Load()) { Log.Write("Load config succeeded. " + ConfigMgt.FileName); } else { Log.Write(LogType.Error, "Load config failed. " + ConfigMgt.FileName); goto exit; } // log config parameters string serviceName = ConfigMgt.Config.ServiceName; string adapterFileName = ConfigMgt.Config.AdapterFileName; DirectionType adapterDirection = ConfigMgt.Config.AdapterDirection; Log.Write("Service name: " + serviceName, false); Log.Write("Adapter filename: " + adapterFileName, false); Log.Write("Adapter direction: " + adapterDirection, false); //Log.Write("GWConfigDB connection: " + ConfigMgt.Config.ConfigDBConnection, false); //contains db pw //Log.Write("GWDataDB connection: " + ConfigMgt.Config.DataDBConnection, false); //contains db pw Log.Write("Dump data: " + ConfigMgt.Config.DumpData.ToString(), false); // run service switch (adapterDirection) { case DirectionType.INBOUND: { // initialize inbound adapter agent InAdapter = new AdapterAgent <IInboundAdapterService, AdapterServiceEntryAttribute>(adapterFileName, Log); ServiceBase[] ServicesToRun = new ServiceBase[] { new InboundService() }; ServiceBase.Run(ServicesToRun); break; } case DirectionType.OUTBOUND: { // initialize outbound adapter agent OutAdapter = new AdapterAgent <IOutboundAdapterService, AdapterServiceEntryAttribute>(adapterFileName, Log); ServiceBase[] ServicesToRun = new ServiceBase[] { new OutboundService() }; ServiceBase.Run(ServicesToRun); break; } case DirectionType.BIDIRECTIONAL: { // initialize bidiretional adapter agent BiAdapter = new AdapterAgent <IBidirectionalAdapterService, AdapterServiceEntryAttribute>(adapterFileName, Log); ServiceBase[] ServicesToRun = new ServiceBase[] { new BidirectionalService() }; ServiceBase.Run(ServicesToRun); break; } } exit: // exit Log.WriteAppExit(AppName); }
public static void Load() { //#region Save Config //using (StreamWriter sw = File.CreateText(FileName)) //{ // Config = new OutboundDBInstallConfig(); // string str = Config.ToXMLString(); // sw.Write(str); //} //#endregion #region Load Config using (StreamReader sr = File.OpenText(FileName)) { try { string str = sr.ReadToEnd(); if (str.Equals("")) { Config = new OutboundConfig(); } else { Config = XObjectManager.CreateObject(str, typeof(OutboundConfig)) as OutboundConfig; } } catch { if (Config == null) { Config = new OutboundConfig(); } } finally { if (Config == null) { Config = new OutboundConfig(); } } } #endregion #region Load DeviceDir DeviceDir.LoadDeviceDir(); int iDevice_ID; if (!int.TryParse(DeviceDir.DeviceDirInfor.Header.ID, out iDevice_ID)) { Program.log.Write(LogType.Error, "Device_ID invalid"); Config.Device_ID = -1; } else { Config.Device_ID = iDevice_ID; } Config.INameOutbound = DeviceDir.DeviceDirInfor.Header.Name; #endregion #region GWDBInfo.Init AdapterConfigCfgMgt mgt = new AdapterConfigCfgMgt(); if (mgt.Load()) { GWDBInfo.Init(mgt.Config.ConfigDBConnection); } else { Program.log.Write(mgt.LastError); } #endregion }