static AppConfigManagement() { PLCNaN = ApplicationConfiguration.GetAppSetting("PLCNaN", PLCNaN); MinAvgMax_Tag_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_Tag_management", MinAvgMax_Tag_management); MinAvgMax_Group_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_Group_management", MinAvgMax_Group_management); MinAvgMax_Transaction_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_Transaction_management", MinAvgMax_Transaction_management); MinAvgMax_Group_Read_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_Group_Read_management", MinAvgMax_Group_Read_management); MinAvgMax_FrameResponse_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_FrameResponse_management", MinAvgMax_FrameResponse_management); MinAvgMax_CharacterGap_management = ApplicationConfiguration.GetAppSetting("MinAvgMax_CharacterGap_management", MinAvgMax_CharacterGap_management); WaitForReconnectServerInSec = ApplicationConfiguration.GetAppSetting("WaitForReconnectServerInSec", WaitForReconnectServerInSec); WaitForFirstGroupUpdateSendInMiliSec = ApplicationConfiguration.GetAppSetting("WaitForFirstGroupUpdateSendInMiliSec", WaitForFirstGroupUpdateSendInMiliSec); UseTimeStampToCheckForUpdate = ApplicationConfiguration.GetAppSetting("UseTimeStampToCheckForUpdate", UseTimeStampToCheckForUpdate); UseLocalTime = ApplicationConfiguration.GetAppSetting("UseLocalTime", UseLocalTime); filename = ApplicationConfiguration.GetAppSetting("configfile", ""); FileInfo fi; if (filename == null || filename.Length < 3) { fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder("\\DemoConfiguration.oses"); } else { fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename); } filename = fi.FullName; } //static AppConfigManagement
/// <summary> /// Reads the configuration. /// </summary> /// <param name="fileName">The fully qualified name of the file, or the relative file name.</param> /// <exception cref="FileNotFoundException">The exception that is thrown when an attempt to access a file /// that does not exist on disk fails. /// </exception> public void ReadConfiguration(string fileName) { FileInfo info = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(fileName); if (!info.Exists) { throw new FileNotFoundException(info.FullName); } m_Configuration.Clear(); m_Configuration.EnforceConstraints = false; m_Configuration.ReadXml(info.FullName, System.Data.XmlReadMode.IgnoreSchema); m_Configuration.EnforceConstraints = true; m_SaveFileDialog.FileName = m_OpenFileDialog.FileName = info.FullName; RaiseConfigurationChnged(); }
static AppConfigManagement() { ItemDsc_configfile = ApplicationConfiguration.GetAppSetting("ItemDsc_configfile", ""); FileInfo fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(ItemDsc_configfile); if (ItemDsc_configfile == null || ItemDsc_configfile.Length < 3) { FileInfo fiIfNull = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(@"\item_dsc.xml"); ItemDsc_configfile = fiIfNull.FullName; } else { ItemDsc_configfile = fi.FullName; } RemotingHTTPport = ApplicationConfiguration.GetAppSetting("RemotingHTTPport", RemotingHTTPport); ConsoleRemotingHTTPport = ApplicationConfiguration.GetAppSetting("ConsoleRemotingHTTPport", ConsoleRemotingHTTPport); }
/// <summary> /// reading of configuration XML file /// </summary> /// <param name="myData">target data set</param> /// <param name="filename">filename</param> public void readXMLFile(DataSet myData, string filename) { if (string.IsNullOrEmpty(filename)) { EventLogMonitor.WriteToEventLogInfo(itemdscHasNotBeenSet, 39); return; } else if (filename == "item_dsc.xml") { FileInfo fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename); string itemdscPath = fi.FullName; if (!new FileInfo(itemdscPath).Exists) { EventLogMonitor.WriteToEventLog(itemdscDoesNotExists, EventLogEntryType.Warning); return; } else { filename = itemdscPath; } } else if (!new FileInfo(filename).Exists) { EventLogMonitor.WriteToEventLog(string.Format(itemdscDoesNotExists, filename), EventLogEntryType.Warning); return; } myData.Clear(); try { myData.ReadXml(filename, XmlReadMode.IgnoreSchema); } catch (Exception) { EventLogMonitor.WriteToEventLog(itemdscCannotBeOpened, EventLogEntryType.Warning); } }
/// <summary> /// Reads the XML file. /// </summary> /// <param name="myData">My data.</param> /// <param name="filename">The filename.</param> /// <param name="open_readonly">if set to <c>true</c> file is opened as read-only.</param> public static void readXMLFile(DataSet myData, string filename, bool open_readonly) { //Processes.EventLogMonitor.WriteToEventLogInfo( "Reading: " + filename + " for CommServer configuration" ); System.IO.FileStream myFileStream; FileInfo fi = new FileInfo(filename); if (!fi.Exists) { fi = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(filename); } if (open_readonly) { myFileStream = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); } else { myFileStream = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open); } System.Xml.XmlTextReader myXmlReader; //Create an XmlTextReader with the fileStream. myXmlReader = new System.Xml.XmlTextReader(myFileStream); myData.ReadXml(myXmlReader); myXmlReader.Close(); }
static void Main() { string m_cmmdLine = Environment.CommandLine; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (m_cmmdLine.ToLower().Contains(str_debug_install_argument)) { CASApplicationInstance.InstallServer(Assembly.GetExecutingAssembly().Location); } if (m_cmmdLine.ToLower().Contains(str_debug_uninstall_argument)) { CASApplicationInstance.UnInstallServer(Assembly.GetExecutingAssembly().Location); } CASApplicationInstance application = new CASApplicationInstance(); ConfigurationEditorMain config = new ConfigurationEditorMain(); try { if (!Environment.UserInteractive) { Directory.SetCurrentDirectory(new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName); if (application.ProcessCommandLine()) { return; } application.StartAsService(new UAServer()); return; } } catch (Exception e) { Utils.Trace(e, "Unexpected error starting service."); return; } #if DEBUG MessageBox.Show("Attach debug point"); #endif if (m_cmmdLine.ToLower().Contains(str_installic_argument)) { try { LibInstaller.InstallLicense(true); } catch (Exception ex) { MessageBox.Show("License installation has failed, reason: " + ex.Message); } } UAServer server = new UAServer(); try { FileInfo configFI = RelativeFilePathsCalculator.GetAbsolutePathToFileInApplicationDataFolder(Settings.Default.ConfigurationFilePath); config.ReadConfiguration(configFI); if (config.Configuration == null) { throw new ArgumentNullException("Cannot read configuration"); } BaseDirectoryHelper.Instance.SetBaseDirectoryProvider(new BaseDirectoryProvider(configFI.DirectoryName)); ApplicationCertificate.CheckApplicationInstanceCertificate(config.Configuration, 1024, (x, y) => true, true); //TODO add logging function or user interface. ApplicationCertificate.OverrideUaTcpImplementation(config.Configuration); server.Start(config.Configuration); Application.Run(new ServerForm(server, config.Configuration, application)); } catch (Exception e) { HandleException("UA Server", e); } finally { server.Stop(); } }