コード例 #1
0
        public void TryCreateModelElement_success()
        {
            var constructor = new AnnotationConstructor();
            var context = new ModelConstructionContext { ModelSpace = Mock.Create<IModelSpace>() };
            var annotation = constructor.TryCreateModelElement(context, new NotMultipleAttribute());

            Assert.IsInstanceOf<Annotation>(annotation);
            Assert.AreEqual("@NotMultiple", annotation.Name);
            Assert.AreEqual(false, ((Annotation)annotation).AllowMultiple);
        }
コード例 #2
0
        /// <summary>
        /// Initializes the service asynchronously by loading the model space.
        /// </summary>
        /// <param name="context">An optional context for initialization.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// An awaitable task.
        /// </returns>
        public async Task InitializeAsync(IContext context = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            this.initialization.Start();

            var constructionContext = new ModelConstructionContext { RuntimeModelElementFactory = this.runtimeModelElementFactory };
            var modelSpace = this.CreateModelSpace(constructionContext);
            constructionContext.ModelSpace = modelSpace;

            try
            {
                var elementInfosCollectorTask = Task.WhenAll(this.ModelInfoProviders.Select(p => p.GetElementInfosAsync(constructionContext, cancellationToken)));
                var elementInfos = (await elementInfosCollectorTask.PreserveThreadContext()).SelectMany(e => e).ToList();

                constructionContext[nameof(IModelConstructionContext.ElementInfos)] = elementInfos;
                ((IWritableNamedElement)modelSpace).CompleteConstruction(constructionContext);

                this.modelSpace = modelSpace;

                this.initialization.Complete();
            }
            catch (Exception exception)
            {
                this.initialization.Fault(exception);
                throw;
            }
        }