示例#1
0
        private void UpdateAdapterServiceCfg()
        {
            AdapterServiceCfgMgt mgt = new AdapterServiceCfgMgt();

            mgt.FileName = Application.StartupPath + "\\" + mgt.FileName;
            if (mgt.Load())
            {
                ReplacementRuleItem itemComments = new ReplacementRuleItem(GWDataDBField.r_COMMENTS);
                itemComments.RegularExpression.Expression  = @"[\n]";
                itemComments.RegularExpression.Replacement = "\r\n";

                ReplacementRuleItem itemDiagnosis = new ReplacementRuleItem(GWDataDBField.r_DIAGNOSE);
                itemDiagnosis.RegularExpression.Expression  = @"[\n]";
                itemDiagnosis.RegularExpression.Replacement = "\r\n";

                mgt.Config.Replacement.Enable = true;
                mgt.Config.Replacement.Fields.Add(itemComments);
                mgt.Config.Replacement.Fields.Add(itemDiagnosis);

                mgt.Config.DataDBConnection = this.textBoxRISDBCnn.Text.Trim();
                if (!mgt.Save())
                {
                    MessageBox.Show(this, "Save Adapter Service configuration failed.", "Warning");
                }
            }
            else
            {
                MessageBox.Show(this, "Load Adapter Service configuration failed.", "Warning");
            }
        }
示例#2
0
        private static bool UpdateInterfaceService(Hashtable paramTable)
        {
            string path = paramTable[IMParameter.InterfaceDirectory] as string;

            // update Adapter Service config
            AdapterServiceCfgMgt serviceMgt = new AdapterServiceCfgMgt();

            serviceMgt.FileName = path + "\\" + serviceMgt.FileName;
            if (serviceMgt.Load())
            {
                serviceMgt.Config.NotifyStatusToIM   = true;
                serviceMgt.Config.IMWindowCaption    = paramTable[IMParameter.IMCaption] as string;
                serviceMgt.Config.ConfigDBConnection = paramTable[IMParameter.ConfigDBConnection] as string;
                serviceMgt.Config.DataDBConnection   = paramTable[IMParameter.DataDBConnection] as string;
                serviceMgt.Config.ServiceName        = paramTable[IMParameter.ServiceName] as string;
                //US29442
                #region
                serviceMgt.Config.GarbageCollection.MaxRecordCountLimitation = 500;
                #endregion
                if (!serviceMgt.Save())
                {
                    GCError.SetLastError("Save config file failed. " + serviceMgt.FileName);
                    GCError.SetLastError(serviceMgt.LastError);
                    return(false);
                }
            }
            else
            {
                GCError.SetLastError("Load config file failed. " + serviceMgt.FileName);
                GCError.SetLastError(serviceMgt.LastError);
                return(false);
            }

            return(true);
        }
示例#3
0
        public FormService()
        {
            InitializeComponent();

            string filename = ConfigHelper.GetFullPath(Program.ConfigMgt.Config.ServiceConfigFileName);

            configMgt = new AdapterServiceCfgMgt(filename);
            this.textBoxLocation.Text = filename;
        }
示例#4
0
        private void LoadAdapterServiceCfg()
        {
            AdapterServiceCfgMgt mgt = new AdapterServiceCfgMgt();

            mgt.FileName = Application.StartupPath + "\\" + mgt.FileName;
            if (mgt.Load())
            {
                this.textBoxRISDBCnn.Text = mgt.Config.DataDBConnection;
            }
            else
            {
                MessageBox.Show(this, "Load Adapter Service configuration failed.", "Warning");
            }
        }
示例#5
0
        private bool LoadSetting()
        {
            _cfgMgt          = new AdapterServiceCfgMgt();
            _cfgMgt.FileName = Application.StartupPath + "\\" + _cfgMgt.FileName;

            if (_cfgMgt.Load())
            {
                this.textBoxDBCnn.Text = _cfgMgt.Config.DataDBConnection;
                return(true);
            }
            else
            {
                MessageBox.Show(this, "Cannot open configuration file: \r\n" + _cfgMgt.FileName +
                                "\r\n\r\nError Message:\r\n" + ((_cfgMgt.LastError == null) ? "" : _cfgMgt.LastError.Message),
                                this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
        }
示例#6
0
        public string GetServiceName2()
        {
            AdapterServiceCfgMgt configMgt = new AdapterServiceCfgMgt();

            configMgt.FileName = Application.StartupPath + "\\" + configMgt.FileName;

            if (configMgt.Load())
            {
                Console.WriteLine("Load config file succeeded. " + configMgt.FileName);
                string serviceName = configMgt.Config.ServiceName;
                Console.WriteLine("Service name: " + serviceName);
                return(serviceName);
            }
            else
            {
                Console.WriteLine("Load config file failed. " + configMgt.FileName);
                Console.WriteLine(configMgt.LastErrorInfor);
                return("[NULL]");
            }
        }
示例#7
0
        private void CreateTableScript()
        {
            string dbName         = this.textBoxRISDBName.Text.Trim();
            string interfaceName  = this.textBoxTP.Text.Trim();
            string fnameInstall   = Application.StartupPath + "\\" + RuleScript.InstallTable.FileName;
            string fnameUninstall = Application.StartupPath + "\\" + RuleScript.UninstallTable.FileName;

            GarbageRule          gcRule         = null;
            string               serviceCfgFile = Application.StartupPath + "\\" + ConfigHelper.ServiceDefaultFileName;
            AdapterServiceCfgMgt mgt            = new AdapterServiceCfgMgt(serviceCfgFile);

            if (mgt.Load())
            {
                gcRule = mgt.Config.GarbageCollection;
                //US29442
                #region
                //gcRule.MaxRecordCountLimitation = 500;
                #endregion
            }
            else
            {
                MessageBox.Show(this, "Cannot open file : " + serviceCfgFile + "\r\n" + mgt.LastErrorInfor,
                                this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            using (StreamWriter sw = File.CreateText(fnameInstall))
            {
                string strSql = RuleControl.GetCreateTableSQL(interfaceName, gcRule);
                strSql = strSql.Replace("USE GWDataDB", "USE " + dbName);
                sw.Write(strSql);
            }
            using (StreamWriter sw = File.CreateText(fnameUninstall))
            {
                string strSql = RuleControl.GetDropTableSQL(interfaceName);
                strSql = strSql.Replace("USE GWDataDB", "USE " + dbName);
                sw.Write(strSql);
            }
        }
示例#8
0
        /// <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);
            }
        }
示例#9
0
        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);
        }
示例#10
0
        /// <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);
        }
示例#11
0
        public static bool UpdateDBConnection(string interfacesPath, string dataDB, string configDB)
        {
            string[] pathList = Directory.GetDirectories(ConfigHelper.GetFullPath(interfacesPath));
            if (pathList == null)
            {
                return(false);
            }

            foreach (string path in pathList)
            {
                AdapterServiceCfgMgt mgtSerivce = new AdapterServiceCfgMgt();
                mgtSerivce.FileName = path + "\\" + mgtSerivce.FileName;
                if (mgtSerivce.Load())
                {
                    mgtSerivce.Config.DataDBConnection   = dataDB;
                    mgtSerivce.Config.ConfigDBConnection = configDB;
                    if (!mgtSerivce.Save())
                    {
                        GCError.SetLastError(mgtSerivce.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtSerivce.LastError);
                    return(false);
                }

                AdapterConfigCfgMgt mgtConfig = new AdapterConfigCfgMgt();
                mgtConfig.FileName = path + "\\" + mgtConfig.FileName;
                if (mgtConfig.Load())
                {
                    mgtConfig.Config.DataDBConnection   = dataDB;
                    mgtConfig.Config.ConfigDBConnection = configDB;
                    if (!mgtConfig.Save())
                    {
                        GCError.SetLastError(mgtConfig.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtConfig.LastError);
                    return(false);
                }

                AdapterMonitorCfgMgt mgtMonitor = new AdapterMonitorCfgMgt();
                mgtMonitor.FileName = path + "\\" + mgtMonitor.FileName;
                if (mgtMonitor.Load())
                {
                    mgtMonitor.Config.DataDBConnection   = dataDB;
                    mgtMonitor.Config.ConfigDBConnection = configDB;
                    if (!mgtMonitor.Save())
                    {
                        GCError.SetLastError(mgtMonitor.LastError);
                        return(false);
                    }
                }
                else
                {
                    GCError.SetLastError(mgtMonitor.LastError);
                    return(false);
                }
            }

            return(true);
        }
示例#12
0
        public void ImportConfig()
        {
            GCInterface gcInterface = _interfaceView.GetSelectedInterface();

            if (gcInterface == null)
            {
                return;
            }

            if (!gcInterface.Directory.Files.HasBackupableFile())
            {
                MessageBox.Show(frmMain, "There is no configuration file in this interface (" + gcInterface.FolderPath + ")",
                                "Import Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            base.SetStatus("Importing interface configuration.");

            FolderBrowserDialog dlg = new FolderBrowserDialog();

            dlg.ShowNewFolderButton = false;
            dlg.Description         = "Please select a folder which contains interface configuration to be imported.";
            if (dlg.ShowDialog(frmMain) != DialogResult.OK)
            {
                goto _ImportExit;
            }

            frmMain.Cursor = Cursors.WaitCursor;
            string folderName = dlg.SelectedPath;

            string[] filelist = _interfaceManager.DetectConfig(gcInterface, folderName);
            frmMain.Cursor = Cursors.Default;

            if (filelist == null)
            {
                Program.Log.Write(LogType.Warning, "{Interface} Import interface configuration failed : " + GCError.LastErrorInfor);
                if (GCError.LastError != null)
                {
                    Program.Log.Write(LogType.Error, GCError.LastError.ToString());
                }

                MessageBox.Show(frmMain, "Import interface configuration failed.\r\n\r\n" + GCError.LastErrorInfor,
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                goto _ImportExit;
            }

            if (filelist.Length < 1)
            {
                MessageBox.Show(frmMain, "Cannot find any configuration file in " + folderName,
                                "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                goto _ImportExit;
            }

            FormFiles frm = new FormFiles(FileOperator.Import, gcInterface, filelist, gcInterface.FolderPath);

            if (frm.ShowDialog(frmMain) == DialogResult.OK)
            {
                //update AdapterService configuration (ServiceName, DataDBConnection, ConfigDBConnection, etc.)
                foreach (string fileName in filelist)
                {
                    string fName = Path.GetFileName(fileName);
                    if (fName == ConfigHelper.ServiceDefaultFileName)
                    {
                        fName = gcInterface.FolderPath + "\\" + fName;
                        AdapterServiceCfgMgt mgt = new AdapterServiceCfgMgt(fName);
                        if (mgt.Load())
                        {
                            mgt.Config.ServiceName        = gcInterface.InterfaceName;
                            mgt.Config.DataDBConnection   = Program.ConfigMgt.Config.DataDBConnection;
                            mgt.Config.ConfigDBConnection = Program.ConfigMgt.Config.ConfigDBConnection;
                            if (mgt.Save())
                            {
                                Program.Log.Write(LogType.Info, "AdapterService configuration updated.");
                            }
                        }
                    }
                }

                //update SQL scripts (SP)
                if (Program.ConfigMgt.Config.ShowConfigAfterImportConfig)
                {
                    CallAdapterConfigProcess(gcInterface, AdapterConfigArgument.InIMWizard);
                }
            }

_ImportExit:
            base.ClearStatus();
        }