private static void Do(Options options) { PrintLogo(options); BuildErrorsHandling.Log.TraceEventAction += z => Console.WriteLine(z.ToString()); IAddressSpaceContext _as = AddressSpaceFactory.AddressSpace; //Creates Address Space infrastructure exposed to the API clients using default messages handler. ModelDesignExport _exporter = new ModelDesignExport(); //creates new instance of the ModelDesignExport class that captures functionality supporting export functionality of the OPC UA Information Model represented //by an xml file compliant with UAModelDesign schema. bool _exportModel = false; if (!string.IsNullOrEmpty(options.ModelDesignFileName)) { _as.InformationModelFactory = _exporter.GetFactory(options.ModelDesignFileName, BuildErrorsHandling.Log.TraceEvent); //Sets the information model factory, which can be used to export a part of the OPC UA Address Space. _exportModel = true; } if (options.Filenames == null) { throw new ArgumentOutOfRangeException($"{nameof(options.Filenames)}", "List of input files to convert i incorrect. At least one file UANodeSet must be entered."); } foreach (string _path in options.Filenames) { FileInfo _fileToRead = new FileInfo(_path); if (!_fileToRead.Exists) { throw new FileNotFoundException(string.Format($"FileNotFoundException - the file {_path} doesn't exist.", _fileToRead.FullName)); } _as.ImportUANodeSet(_fileToRead); //Imports a part of the OPC UA Address Space contained in the file compliant with the `UANodeSet` schema. } if (string.IsNullOrEmpty(options.IMNamespace)) { _as.ValidateAndExportModel(); } else { _as.ValidateAndExportModel(options.IMNamespace); //Validates and exports the selected model. } if (_exportModel) { _exporter.ExportToXMLFile(options.Stylesheet); //Serializes the already generated model and writes the XML document to a file. } }
private static void Do(Options options) { PrintLogo(options); Action <TraceMessage> _tracingMethod = z => Console.WriteLine(z.ToString()); IAddressSpaceContext _as = new AddressSpaceContext(_tracingMethod); ModelDesignExport _exporter = new ModelDesignExport(); bool _exportModel = false; if (!string.IsNullOrEmpty(options.ModelDesignFileName)) { _as.InformationModelFactory = _exporter.GetFactory(options.ModelDesignFileName, _tracingMethod); _exportModel = true; } if (options.Filenames == null) { throw new ArgumentOutOfRangeException($"{nameof(options.Filenames)}", "List of input files to convert i incorrect. At least one file UANodeSet must be entered."); } foreach (string _path in options.Filenames) { FileInfo _fileToRead = new FileInfo(_path); if (!_fileToRead.Exists) { throw new FileNotFoundException(string.Format($"FileNotFoundException - the file {_path} doesn't exist.", _fileToRead.FullName)); } _as.ImportUANodeSet(_fileToRead); } if (string.IsNullOrEmpty(options.IMNamespace)) { _as.ValidateAndExportModel(); } else { _as.ValidateAndExportModel(options.IMNamespace); } if (_exportModel) { _exporter.ExportToXMLFile(options.Stylesheet); } }