Exemplo n.º 1
0
        /// <summary>
        /// Imports the new ContentTypes.
        /// </summary>
        /// <exception cref="ElementsMigrationException">If migration fails</exception>
        private void ImportNewContentTypes()
        {
            Console.WriteLine("import new ContentTypes...");
            Logger.AddMessage("import new ContentTypes...");

            ContentTypeCollection contentTypeCollectionSourceServer = this.GetAllContentTypes(SourceClientContext);
            ContentTypeCollection contentTypeCollectionTargetServer = this.GetAllContentTypes(TargetClientContext);

            HashSet <string> namesOfContentTypesOnTargetServer = contentTypeCollectionTargetServer.GetNames();

            foreach (var contentType in contentTypeCollectionSourceServer)
            {
                if (!namesOfContentTypesOnTargetServer.Contains(contentType.Name))
                {
                    Console.WriteLine("import contentType = {0}", contentType.Name);
                    Logger.AddMessage("import ContentType = '" + contentType.Name + "'");

                    this.CreateContentType(contentTypeCollectionSourceServer, contentTypeCollectionTargetServer, contentType);
                }
                else
                {
                    Console.WriteLine("don't have to migrate '{0}'", contentType.Name);
                    Logger.AddMessage("Don't have to migrate '" + contentType.Name + "'");
                }
            }

            try
            {
                TargetClientContext.ExecuteQuery();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception during importing new ContentTypes.", e);
                Logger.AddMessage("Exception during importing new ContentTypes. Error = " + e.Message);
                throw new ElementsMigrationException("Exception during importing new ContentTypes.", e);
            }
        }