private void DeployTermLabel(object modelHost, TermModelHost termModelHost, TaxonomyTermLabelDefinition labelModel)
        {
            var termStore = termModelHost.HostTermStore;
            var context = termStore.Context;

            var term = termModelHost.HostTerm;
            var currentLabel = FindLabelInTerm(term, labelModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = currentLabel,
                ObjectType = typeof(Label),
                ObjectDefinition = labelModel,
                ModelHost = modelHost
            });

            if (currentLabel == null)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new Label");

                currentLabel = term.CreateLabel(labelModel.Name, labelModel.LCID, labelModel.IsDefault);

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = currentLabel,
                    ObjectType = typeof(Label),
                    ObjectDefinition = labelModel,
                    ModelHost = modelHost
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing Term");

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = currentLabel,
                    ObjectType = typeof(Label),
                    ObjectDefinition = labelModel,
                    ModelHost = modelHost
                });
            }

            termStore.CommitAll();
            context.ExecuteQueryWithTrace();
        }
예제 #2
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost = modelHostContext.ModelHost;
            var model = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action = modelHostContext.Action;


            var definition = model.WithAssertAndCast<TaxonomyTermDefinition>("model", value => value.RequireNotNull());

            Term currentTerm = null;
            TermGroup group = null;
            TermSet termSet = null;
            TermStore termStore = null;

            TermModelHost localModelHost = new TermModelHost();

            if (modelHost is TermModelHost)
            {
                var h = (modelHost as TermModelHost);

                group = h.HostGroup;
                termSet = h.HostTermSet;
                termStore = h.HostTermStore;

                currentTerm = FindTermInTerm(h.HostTerm, definition);

                localModelHost.HostGroup = group;
                localModelHost.HostTermSet = termSet;
                localModelHost.HostTerm = currentTerm;
                localModelHost.HostTermStore = termStore;
            }
            else if (modelHost is TermSetModelHost)
            {
                var h = (modelHost as TermSetModelHost);

                termStore = h.HostTermStore;
                group = h.HostGroup;
                termSet = h.HostTermSet;

                currentTerm = FindTermInTermSet(h.HostTermSet, definition);

                localModelHost.HostGroup = group;
                localModelHost.HostTermSet = termSet;
                localModelHost.HostTerm = currentTerm;
                localModelHost.HostTermStore = termStore;
            }

            action(localModelHost);
        }
예제 #3
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action<object> action)
        {
            var definition = model.WithAssertAndCast<TaxonomyTermDefinition>("model", value => value.RequireNotNull());

            Term currentTerm = null;
            TermGroup group = null;
            TermSet termSet = null;
            TermStore termStore = null;

            TermModelHost localModelHost = new TermModelHost();

            if (modelHost is TermModelHost)
            {
                var h = (modelHost as TermModelHost);

                group = h.HostGroup;
                termSet = h.HostTermSet;
                termStore = h.HostTermStore;

                currentTerm = FindTermInTerm(h.HostTerm, definition);

                localModelHost.HostGroup = group;
                localModelHost.HostTermSet = termSet;
                localModelHost.HostTerm = currentTerm;
                localModelHost.HostTermStore = termStore;
            }
            else if (modelHost is TermSetModelHost)
            {
                var h = (modelHost as TermSetModelHost);

                termStore = h.HostTermStore;
                group = h.HostGroup;
                termSet = h.HostTermSet;

                currentTerm = FindTermInTermSet(h.HostTermSet, definition);

                localModelHost.HostGroup = group;
                localModelHost.HostTermSet = termSet;
                localModelHost.HostTerm = currentTerm;
                localModelHost.HostTermStore = termStore;
            }

            action(localModelHost);
        }
예제 #4
0
        private void DeployTermUnderTerm(object modelHost, TermModelHost groupModelHost, TaxonomyTermDefinition termModel)
        {
            var termStore = groupModelHost.HostTermStore;
            var termSet = groupModelHost.HostTerm;

            var currentTerm = FindTermInTerm(termSet, termModel);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model = null,
                EventType = ModelEventType.OnProvisioning,
                Object = currentTerm,
                ObjectType = typeof(Term),
                ObjectDefinition = termModel,
                ModelHost = modelHost
            });

            if (currentTerm == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new Term");

                currentTerm = termModel.Id.HasValue
                    ? termSet.CreateTerm(termModel.Name, termModel.LCID, termModel.Id.Value)
                    : termSet.CreateTerm(termModel.Name, termModel.LCID, Guid.NewGuid());

                MapTermProperties(currentTerm, termModel);

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = currentTerm,
                    ObjectType = typeof(Term),
                    ObjectDefinition = termModel,
                    ModelHost = modelHost
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing Term");

                MapTermProperties(currentTerm, termModel);

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioned,
                    Object = currentTerm,
                    ObjectType = typeof(Term),
                    ObjectDefinition = termModel,
                    ModelHost = modelHost
                });
            }

            termStore.CommitAll();
            termStore.Context.ExecuteQueryWithTrace();
        }