public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var typedHost = (reverseHost as TaxonomyTermReverseHost);
            var item = typedHost.HostTerm;

            var def = new TaxonomyTermDefinition();

            def.Id = item.Id;

            def.Name = item.Name;
            def.Description = item.Description;


            def.IsAvailableForTagging = item.IsAvailableForTagging;

            return new TaxonomyTermModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }
예제 #2
0
        protected Term FindTermInTermSet(TermSet termSet, TaxonomyTermDefinition termModel)
        {
            Term result = null;

            if (termModel.Id.HasValue)
                result = termSet.GetTerm(termModel.Id.Value);
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                var termName = NormalizeTermName(termModel.Name);
                result = termSet.GetTerms(termName, termModel.LCID, false).FirstOrDefault();
            }

            return result;
        }
예제 #3
0
        private Term FindTermInTerm(Term term, TaxonomyTermDefinition termModel)
        {
            Term result = null;

            if (termModel.Id.HasValue)
                result = term.Terms.FirstOrDefault(t => t.Id == termModel.Id.Value);
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                var termName = NormalizeTermName(termModel.Name);
                result = term.Terms.FirstOrDefault(t => t.Name == termName);
            }

            return result;
        }
예제 #4
0
        private void DeployTermUnderTermSet(object modelHost, TermSetModelHost groupModelHost, TaxonomyTermDefinition termModel)
        {
            var termSet = groupModelHost.HostTermSet;

            var currentTerm = FindTermInTermSet(termSet, termModel);
            var termName = NormalizeTermName(termModel.Name);

            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(termName, termModel.LCID, termModel.Id.Value)
                    : termSet.CreateTerm(termName, termModel.LCID);

                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
                });
            }

            groupModelHost.HostTermStore.CommitAll();
        }
예제 #5
0
        protected void MapTermProperties(Term currentTerm, TaxonomyTermDefinition termModel)
        {
            if (!string.IsNullOrEmpty(termModel.Description))
                currentTerm.SetDescription(termModel.Description, termModel.LCID);

            if (!string.IsNullOrEmpty(termModel.CustomSortOrder))
                currentTerm.CustomSortOrder = termModel.CustomSortOrder;

            if (termModel.IsAvailableForTagging.HasValue)
                currentTerm.IsAvailableForTagging = termModel.IsAvailableForTagging.Value;

#if !NET35
            foreach (var customProp in termModel.CustomProperties.Where(p => p.Override))
            {
                currentTerm.SetCustomProperty(customProp.Name, customProp.Value);
            }
#endif

#if !NET35
            foreach (var customProp in termModel.LocalCustomProperties.Where(p => p.Override))
            {
                currentTerm.SetLocalCustomProperty(customProp.Name, customProp.Value);
            }
#endif

        }
예제 #6
0
        private void MapTermProperties(Term currentTerm, TaxonomyTermDefinition termModel)
        {
            currentTerm.SetDescription(termModel.Description, termModel.LCID);

            foreach (var customProp in termModel.CustomProperties.Where(p => p.Override))
            {
                currentTerm.SetCustomProperty(customProp.Name, customProp.Value);
            }
        }
예제 #7
0
        protected Term FindTermInTermSet(TermSet termSet, TaxonomyTermDefinition termModel)
        {
            Term result = null;

            var context = termSet.Context;

            if (termModel.Id.HasValue)
            {
                var scope = new ExceptionHandlingScope(context);
                using (scope.StartScope())
                {
                    using (scope.StartTry())
                    {
                        result = termSet.Terms.GetById(termModel.Id.Value);
                        context.Load(result);
                    }

                    using (scope.StartCatch())
                    {

                    }
                }

                context.ExecuteQueryWithTrace();
            }
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                var terms = termSet.GetTerms(new LabelMatchInformation(context)
                {
                    Lcid = termModel.LCID,
                    TermLabel = termModel.Name,
                    TrimUnavailable = false
                });

                context.Load(terms);
                context.ExecuteQueryWithTrace();

                result = terms.FirstOrDefault();
            }

            if (result != null && result.ServerObjectIsNull == false)
            {
                context.Load(result);
                context.ExecuteQueryWithTrace();

                return result;
            }

            return null;
        }
예제 #8
0
        protected Term FindTermInTerm(Term term, TaxonomyTermDefinition termModel)
        {
            Term result = null;
            IEnumerable<Term> results = null;

            var context = term.Context;
            // TODO

            if (termModel.Id.HasValue)
            {
                var id = termModel.Id.Value;

                results = context.LoadQuery(term.Terms.Where(t => t.Id == id));
                context.ExecuteQueryWithTrace();

            }
            else if (!string.IsNullOrEmpty(termModel.Name))
            {
                var name = termModel.Name;

                //var terms = term.Terms;

                //context.Load(terms);
                //context.ExecuteQueryWithTrace();

                results = context.LoadQuery(term.Terms.Where(t => t.Name == name));
                context.ExecuteQueryWithTrace();
                //result = term.Terms.FirstOrDefault(t => t.Name == termModel.Name);
            }

            result = results.FirstOrDefault();

            if (result != null)
            {
                context.Load(result);
                context.ExecuteQueryWithTrace();

                return result;
            }

            return null;
        }
예제 #9
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());

                currentTerm.SetDescription(termModel.Description, termModel.LCID);

                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");

                currentTerm.SetDescription(termModel.Description, termModel.LCID);

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

            termStore.CommitAll();
            termStore.Context.ExecuteQuery();
        }
예제 #10
0
        public void CanDeploy_TaxonomyFieldBindedToTermById()
        {
            var termSet = new TaxonomyTermSetDefinition
            {
                Name = Rnd.String(),
                Description = Rnd.String(),
            };

            var term = new TaxonomyTermDefinition
            {
                Name = Rnd.String(),
                Description = Rnd.String(),
                Id = Guid.NewGuid()
            };

            var taxField = ModelGeneratorService.GetRandomDefinition<TaxonomyFieldDefinition>(def =>
            {
                def.TermSetName = termSet.Name;
                def.TermId = term.Id.Value;
            });

            var taxonomyModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomTermStore(termStore =>
                {
                    termStore.AddRandomTermGroup(group =>
                    {
                        group.AddTaxonomyTermSet(termSet, t =>
                        {
                            t.AddTaxonomyTerm(term);
                        });
                    });
                });
            });

            var fieldModel = SPMeta2Model
                  .NewSiteModel(site =>
                  {
                      site.AddTaxonomyField(taxField);
                  });

            TestModels(new[] { taxonomyModel, fieldModel });
        }
        public void Can_Reverse_Terms()
        {
            var siteTermStore = new TaxonomyTermStoreDefinition
            {
                Id = null,
                Name = string.Empty,
                UseDefaultSiteCollectionTermStore = true
            };

            var termGroup1 = new TaxonomyTermGroupDefinition
            {
                Name = Rnd.String(),
                Id = Rnd.Guid()
            };

            var termSet1 = new TaxonomyTermSetDefinition
            {
                Name = Rnd.String(),
                Id = Rnd.Guid(),
                Contact = Rnd.String(),
                Description = Rnd.String()
            };

            var term1 = new TaxonomyTermDefinition
            {
                Name = Rnd.String(),
                Id = Rnd.Guid(),
                Description = Rnd.String()
            };

            var term2 = new TaxonomyTermDefinition
            {
                Name = Rnd.String(),
                Id = Rnd.Guid(),
                Description = Rnd.String()
            };

            var term3 = new TaxonomyTermDefinition
            {
                Name = Rnd.String(),
                Id = Rnd.Guid(),
                Description = Rnd.String()
            };

            // only witin a tes term group
            // performance boost
            var groupName = termGroup1.Name;
            var options = ReverseOptions.Default
                .AddFilterOption<TaxonomyTermGroupDefinition>(g => g.Name == groupName);

            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddTaxonomyTermStore(siteTermStore, store =>
                {
                    store.AddTaxonomyTermGroup(termGroup1, group =>
                    {
                        group.AddTaxonomyTermSet(termSet1, termSet =>
                        {
                            termSet.AddTaxonomyTerm(term1, t =>
                            {
                                t.AddTaxonomyTerm(term3);
                            });
                            termSet.AddTaxonomyTerm(term2);
                        });

                    });
                });

            });

            DeployReverseAndTestModel(model, options);
        }
        private void Internal_TaxonomyFieldBinded_ById_Within_SiteCollectionGroup(bool isTermSet, bool isTerm)
        {

            var termSetName = Rnd.String();
            var termName = Rnd.String();

            var termSet1Id = Rnd.Guid();
            var termSet2Id = Rnd.Guid();
            var termSet3Id = Rnd.Guid();

            var term1Id = Rnd.Guid();
            var term2Id = Rnd.Guid();
            var term3Id = Rnd.Guid();

            // same same names
            var termSet1 = new TaxonomyTermSetDefinition
            {
                Name = termSetName,
                Description = Rnd.String(),
            };

            var termSet2 = new TaxonomyTermSetDefinition
            {
                Name = termSetName,
                Id = termSet2Id,
                Description = Rnd.String(),
            };

            var termSet3 = new TaxonomyTermSetDefinition
            {
                Name = termSetName,
                Description = Rnd.String(),
            };

            var term1 = new TaxonomyTermDefinition
            {
                Name = termName,
                Description = Rnd.String(),
                Id = term1Id
            };

            var term2 = new TaxonomyTermDefinition
            {
                Name = termName,
                Description = Rnd.String(),
                Id = term2Id,
            };

            var term3 = new TaxonomyTermDefinition
            {
                Name = termName,
                Description = Rnd.String(),
                Id = term3Id
            };

            var termGroup1 = ModelGeneratorService.GetRandomDefinition<TaxonomyTermGroupDefinition>(def =>
            {

            });

            var termGroup2 = ModelGeneratorService.GetRandomDefinition<TaxonomyTermGroupDefinition>(def =>
            {
                def.IsSiteCollectionGroup = true;
            });

            var termGroup3 = ModelGeneratorService.GetRandomDefinition<TaxonomyTermGroupDefinition>(def =>
            {

            });

            // binding to the 2nd one
            var taxField = ModelGeneratorService.GetRandomDefinition<TaxonomyFieldDefinition>(def =>
            {
                def.IsSiteCollectionGroup = true;

                // these should be resolvbed as we are scoped to the 2nd group within site collection group

                if (isTermSet)
                    def.TermSetId = termSet2.Id;

                if (isTerm)
                    def.TermId = term2.Id;
            });

            var taxonomyModel = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomTermStore(termStore =>
                {
                    termStore.AddTaxonomyTermGroup(termGroup1, group =>
                    {
                        group.AddTaxonomyTermSet(termSet1, t =>
                        {
                            t.AddTaxonomyTerm(term1);
                        });
                    });

                    termStore.AddTaxonomyTermGroup(termGroup2, group =>
                    {
                        group.AddTaxonomyTermSet(termSet2, t =>
                        {
                            t.AddTaxonomyTerm(term2);
                        });
                    });

                    termStore.AddTaxonomyTermGroup(termGroup3, group =>
                    {
                        group.AddTaxonomyTermSet(termSet3, t =>
                        {
                            t.AddTaxonomyTerm(term3);
                        });
                    });
                });
            });

            var fieldModel = SPMeta2Model
                  .NewSiteModel(site =>
                  {
                      site.AddTaxonomyField(taxField);
                  });

            TestModels(new ModelNode[] { taxonomyModel, fieldModel });
        }
 public static ModelNode AddHostTaxonomyTerm(this ModelNode model, TaxonomyTermDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing());
 }
 public static ModelNode AddHostTaxonomyTerm(this ModelNode model, TaxonomyTermDefinition definition)
 {
     return AddHostTaxonomyTerm(model, definition, null);
 }
 public static ModelNode AddTaxonomyTerm(this ModelNode model, TaxonomyTermDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }