Ejemplo n.º 1
0
        private int FindCreateArtifactType(ArtifactType artifactType)
        {
            using (RuntimeEntityModel context = RuntimeEntityModel.CreateInstance())
            {
                if (string.IsNullOrEmpty(artifactType.ReferenceName))
                {
                    throw new ArgumentException(string.Format(MigrationToolkitResources.MissingArtifactTypeRefName));
                }


                if (string.IsNullOrEmpty(artifactType.FriendlyName))
                {
                    throw new ArgumentException(string.Format(MigrationToolkitResources.MissingArtifactTypeDispName));
                }

                var artifactTypeQuery = from t in context.RTArtifactTypeSet
                                        where t.ReferenceName.Equals(artifactType.ReferenceName) &&
                                        t.DisplayName.Equals(artifactType.FriendlyName) &&
                                        t.ArtifactContentType.Equals(artifactType.ContentTypeReferenceName)
                                        select t;

                if (artifactTypeQuery.Count() > 0)
                {
                    return(artifactTypeQuery.First().Id);
                }

                var newType = RTArtifactType.CreateRTArtifactType(0, artifactType.ReferenceName, artifactType.FriendlyName,
                                                                  artifactType.ContentTypeReferenceName);
                context.AddToRTArtifactTypeSet(newType);
                context.TrySaveChanges();
                return(newType.Id);
            }
        }