コード例 #1
0
        public void ConstructorTestMethod()
        {
            ModelDesignExport   _exporter = new ModelDesignExport();
            List <TraceMessage> _log      = new List <TraceMessage>();
            string        _filePath       = "ConstructorTestMethodPtah.xml";
            IModelFactory _factory        = _exporter.GetFactory(_filePath, x => _log.Add(x));

            _factory.CreateNamespace("NameSpace1", String.Empty, String.Empty);
            _factory.CreateNamespace("NameSpace2", String.Empty, String.Empty);
            _exporter.ExportToXMLFile();
            FileInfo _outputFile = new FileInfo(_filePath);

            Assert.IsTrue(_outputFile.Exists);
            Assert.AreEqual <long>(1, _log.Count);
            Assert.IsTrue(720 < _outputFile.Length);
        }
コード例 #2
0
        /// <summary>
        /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>.
        /// </summary>
        /// <param name="nodesCollection">The items <see cref="IEnumerable{IUANodeBase}" /> imported to the Address Space <see cref="IAddressSpaceContext" />.</param>
        /// <param name="exportModelFactory">The model export factory.</param>
        /// <param name="addressSpaceContext">The Address Space context.</param>
        /// <param name="traceEvent">The trace event method encapsulation.</param>
        internal static void ValidateExportModel(IEnumerable <IUANodeBase> nodesCollection, IModelFactory exportModelFactory, IAddressSpaceValidationContext addressSpaceContext, Action <TraceMessage> traceEvent)
        {
            traceEvent(TraceMessage.DiagnosticTraceMessage(string.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <IUANodeBase>())));
            List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model;

            foreach (IModelTableEntry _ns in addressSpaceContext.ExportNamespaceTable)
            {
                string _publicationDate = _ns.PublicationDate.HasValue ? _ns.PublicationDate.Value.ToShortDateString() : DateTime.UtcNow.ToShortDateString();
                string _version         = _ns.Version;
                exportModelFactory.CreateNamespace(_ns.ModelUri, _publicationDate, _version);
            }
            string _msg = null;
            int    _nc  = 0;

            foreach (IUANodeBase _item in nodesCollection)
            {
                try
                {
                    ValidateExportNode(_item, exportModelFactory, null, y =>
                    {
                        if (y.TraceLevel != TraceEventType.Verbose)
                        {
                            _errors.Add(y.BuildError);
                        }
                        traceEvent(y);
                    });
                    _nc++;
                }
                catch (Exception _ex)
                {
                    _msg = string.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace);
                    traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg));
                }
            }
            if (_errors.Count == 0)
            {
                _msg = string.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nc);
            }
            else
            {
                _msg = string.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes and {1} errors.", _nc, _errors.Count);
            }
            traceEvent(TraceMessage.DiagnosticTraceMessage(_msg));
        }
コード例 #3
0
        /// <summary>
        /// Validates the selected nodes <paramref name="nodesCollection"/> and export it using <paramref name="exportModelFactory"/>.
        /// </summary>
        /// <param name="nodesCollection">The items <see cref="UANodeContext" /> imported to the Address Space <see cref="IAddressSpaceContext" />.</param>
        /// <param name="exportModelFactory">The model export factory.</param>
        /// <param name="addressSpaceContext">The Address Space context.</param>
        /// <param name="traceEvent">The trace event method encapsulation.</param>
        internal static void ValidateExportModel
            (IEnumerable <UANodeContext> nodesCollection, IModelFactory exportModelFactory, AddressSpaceContext addressSpaceContext, Action <TraceMessage> traceEvent)
        {
            traceEvent(TraceMessage.DiagnosticTraceMessage(String.Format("Entering Validator.ValidateExportModel - starting creation of the ModelDesign for {0} nodes.", nodesCollection.Count <UANodeContext>())));
            List <BuildError> _errors = new List <BuildError>(); //TODO should be added to the model;

            foreach (string _ns in addressSpaceContext.ExportNamespaceTable())
            {
                exportModelFactory.CreateNamespace(_ns);
            }
            string _msg = null;
            int    _nc  = 0;

            foreach (UANodeContext _item in nodesCollection)
            {
                try
                {
                    ValidateExportNode(_item, exportModelFactory, null, y =>
                    {
                        if (y.TraceLevel != TraceEventType.Verbose)
                        {
                            _errors.Add(y.BuildError);
                        }
                        traceEvent(y);
                    });
                    _nc++;
                }
                catch (Exception _ex)
                {
                    _msg = String.Format("Error caught while processing the node {0}. The message: {1} at {2}.", _item.UANode.NodeId, _ex.Message, _ex.StackTrace);
                    traceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, _msg));
                }
            }
            if (_errors.Count == 0)
            {
                _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nc);
            }
            else
            {
                _msg = String.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes and {1} errors.", _nc, _errors.Count);
            }
            traceEvent(TraceMessage.DiagnosticTraceMessage(_msg));
        }