Example #1
0
 public ImportedContentType(ContentTypeImporter importer, ContentType type, ContentTypeId parentId)
 {
     this.Importer = importer;
     this.Id       = type.Id;
     this.Name     = type.Name;
     this.Type     = type;
     this.Fields   = new Dictionary <string, ImportedContentTypeField>();
     if (parentId.StringValue == this.Id.StringValue)
     {
         parentId = null;
     }
     this.ParentId = parentId;
 }
Example #2
0
 protected FSObjectImporter(string label, ImportContext importContext, ContentTypeImporter contentTypeImporter, PermissionsImporter permissionsImporter) : base(label, importContext)
 {
     this.ContentTypeImporter = contentTypeImporter;
     this.PermissionsImporter = permissionsImporter;
     this.UserGroupImporter   = permissionsImporter?.UserGroupImporter;
 }
Example #3
0
 protected FSObjectImporter(string label, ContentTypeImporter contentTypeImporter, PermissionsImporter permissionsImporter) : this(label, contentTypeImporter?.ImportContext ?? permissionsImporter.ImportContext, contentTypeImporter, permissionsImporter)
 {
 }
Example #4
0
        public static int MainLoop(string[] args)
        {
            ILog   log     = null;
            string baseDir = Directory.GetCurrentDirectory();
            // Initialize log4j
            Configuration options = new Configuration(baseDir, args);

            if (options.help)
            {
                Console.Error.WriteLine(options.GetUsage());
                return(1);
            }
            List <string> errors = options.ValidateConfiguration();

            if (errors.Count > 0)
            {
                Console.Error.WriteLine(string.Format("{0} Configuration Errors detected:", errors.Count));
                foreach (string e in errors)
                {
                    Console.Error.WriteLine(string.Format("\t* {0}", e));
                }
                return(2);
            }

            System.IO.Directory.CreateDirectory(options.caches);

            string logDir = string.Format("{0}\\logs", baseDir);

            System.IO.Directory.CreateDirectory(logDir);

            Environment.SetEnvironmentVariable("CMF_LOGDATE", string.Format("{0:yyyyMMdd-HHmmss}", DateTime.Now));
            Environment.SetEnvironmentVariable("CMF_LOGDIR", logDir);

            XmlConfigurator.Configure(new FileInfo(string.Format("{0}\\log4net.xml", baseDir)));
            LOG = log = LogManager.GetLogger(typeof(Launcher));
            log.Info("Initializing Application");

            if (options.indexOnly)
            {
                ImportContext  importContext  = new ImportContext(null, options.content, options.metadata, options.caches);
                FormatResolver formatResolver = new FormatResolver(importContext);
                new DocumentImporter(new FolderImporter(importContext), formatResolver, options.locationMode, options.fixExtensions).StoreLocationIndex();
                return(0);
            }

            ServicePointManager.MaxServicePointIdleTime = (int)SharePointSession.TIME_OUT.TotalMilliseconds;
            ServicePointManager.SetTcpKeepAlive(true, (int)SharePointSession.TIME_OUT.TotalMilliseconds, 60000);
            ServicePointManager.DefaultConnectionLimit = options.threads * 10;

            using (DirectoryEntry ldapDirectory = BindToLDAP(options))
            {
                log.Info(string.Format("Using SharePoint at [{0}]", options.siteUrl));

                string userString = options.user;
                if (!string.IsNullOrWhiteSpace(options.domain))
                {
                    userString = string.Format("{0}@{1}", userString, options.domain);
                }

                SecureString userPassword = null;
                if (!string.IsNullOrWhiteSpace(options.user))
                {
                    if (options.password == null)
                    {
                        Console.Write(string.Format("Enter The Sharepoint Password for [{0}]: ", userString));
                        userPassword = Tools.ReadPassword();
                    }
                    else
                    {
                        String pass = CRYPT.Decrypt(options.password);
                        pass = CRYPT.Encrypt(pass);
                        log.Info(string.Format("Using stored credentials for [{0}] = [{1}]", userString, pass));
                        userPassword = new SecureString();
                        foreach (char c in CRYPT.Decrypt(pass))
                        {
                            userPassword.AppendChar(c);
                        }
                    }
                }

                using (SharePointSessionFactory sessionFactory = new SharePointSessionFactory(new SharePointSessionInfo(options.siteUrl, options.user, userPassword, options.domain, options.applicationId, options.certificateKey, options.certificatePass, options.library, options.reuseCount)))
                {
                    ImportContext importContext = new ImportContext(sessionFactory, options.content, options.metadata, options.caches);
                    using (ObjectPool <SharePointSession> .Ref sessionRef = sessionFactory.GetSession())
                    {
                        SharePointSession session       = sessionRef.Target;
                        ClientContext     clientContext = session.ClientContext;
                        List documentLibrary            = sessionRef.Target.DocumentLibrary;
                        // We configure the document library as required
                        documentLibrary.EnableVersioning    = true;
                        documentLibrary.EnableMinorVersions = true;
                        documentLibrary.ForceCheckout       = false;
                        documentLibrary.ContentTypesEnabled = true;
                        // documentLibrary.MajorVersionLimit = 50000;
                        // documentLibrary.MajorWithMinorVersionsLimit = 50000;
                        documentLibrary.Update();
                        session.ExecuteQuery();
                    }

                    FormatResolver formatResolver = new FormatResolver(importContext);

                    ContentTypeImporter contentTypeImporter = null;
                    for (int i = 0; i <= options.retries; i++)
                    {
                        try
                        {
                            contentTypeImporter = new ContentTypeImporter(importContext, options.library, options.cleanTypes);
                            break;
                        }
                        catch (Exception e)
                        {
                            contentTypeImporter = null;
                            log.Warn("WARNING: ContentTypeImporter failed to initialize due to an exception", e);
                        }
                    }
                    if (contentTypeImporter == null)
                    {
                        log.Error(string.Format("ContentTypeImporter failed to initialize after {0} attempts", options.retries + 1));
                        return(3);
                    }

                    UserGroupImporter userGroupImporter = null;
                    for (int i = 0; i <= options.retries; i++)
                    {
                        try
                        {
                            userGroupImporter = new UserGroupImporter(importContext, ldapDirectory, options.ldapSyncDomain, options.fallbackUser, options.internalUser, options.fallbackGroup, options.internalGroup);
                            break;
                        }
                        catch (Exception e)
                        {
                            userGroupImporter = null;
                            log.Warn("WARNING: UserGroupImporter failed to initialize due to an exception", e);
                        }
                    }
                    if (userGroupImporter == null)
                    {
                        log.Error(string.Format("UserGroupImporter failed to initialize after {0} attempts", options.retries + 1));
                        return(4);
                    }

                    PermissionsImporter permissionsImporter = new PermissionsImporter(userGroupImporter);
                    FolderImporter      folderImporter      = new FolderImporter(contentTypeImporter, permissionsImporter);
                    DocumentImporter    documentImporter    = new DocumentImporter(folderImporter, formatResolver, options.locationMode, options.fixExtensions);
                    bool aborted = false;

                    Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
                    {
                        if (aborted)
                        {
                            return;
                        }
                        aborted  = true;
                        e.Cancel = true;
                        documentImporter.Abort = true;
                        folderImporter.Abort   = true;
                        string msg = "Program Interrupted (hit Ctrl-C again to terminate immediately)";
                        if (log == null)
                        {
                            Console.WriteLine(msg);
                        }
                        else
                        {
                            log.Warn(msg);
                        }
                    };

                    try
                    {
                        documentImporter.StoreDocuments(options.threads, options.simulationMode, options.locationMode, options.autoPublish, options.retries);
                        folderImporter.FinalizeFolders(options.threads, options.retries);
                        documentImporter.StoreLocationIndex();
                    }
                    finally
                    {
                        log.Info(documentImporter.ProcessingReport);
                        log.Info(folderImporter.ProcessingReport);
                    }
                    return(aborted ? 1 : 0);
                }
            }
        }
Example #5
0
        private FolderImporter(ImportContext importContext, ContentTypeImporter contentTypeImporter, PermissionsImporter permissionsImporter) : base("folders", importContext, contentTypeImporter, permissionsImporter)
        {
            Dictionary <string, FolderInfo> folderDictionary = new Dictionary <string, FolderInfo>();

            using (XmlReader folders = this.ImportContext.LoadIndex("folders"))
            {
                int currentDepth = 0;
                Dictionary <string, List <FolderInfo> > accumulated = new Dictionary <string, List <FolderInfo> >();
                int accumulatedCount = 0;

                using (ObjectPool <SharePointSession> .Ref sessionRef = this.ImportContext.SessionFactory?.GetSession())
                {
                    SharePointSession session = sessionRef?.Target;
                    outer : while (folders.ReadToFollowing("folder"))
                    {
                        string location = null;
                        string path     = null;
                        using (XmlReader folder = folders.ReadSubtree())
                        {
                            // We're only interested in the <location> and <path> elements, so if they're not there
                            // we simply move on to the next folder
                            if (!folder.ReadToFollowing("path"))
                            {
                                goto outer;
                            }
                            path = "/" + folder.ReadElementContentAsString();
                            if (!folder.ReadToFollowing("location"))
                            {
                                goto outer;
                            }
                            location = folder.ReadElementContentAsString();
                        }

                        int thisDepth = (path == "/" ? 0 : thisDepth = Tools.CountChars(path, '/'));

                        // If we've changed depths, we process what we've accumulated so far
                        if (thisDepth > currentDepth)
                        {
                            if (session != null)
                            {
                                Log.Info(string.Format("Creating {0} folders in the target environment, depth {1}", accumulatedCount, thisDepth));
                                try
                                {
                                    ProcessAccumulatedFolders(session, accumulated);
                                }
                                catch (Exception e)
                                {
                                    Log.Error("Failed to process the current accumulated folder batch");
                                    throw e;
                                }
                            }
                            accumulated.Clear();
                            accumulatedCount = 0;
                            currentDepth     = thisDepth;
                        }

                        // A new folder to handle...
                        FolderInfo f = new FolderInfo(this.ImportContext.FormatMetadataLocation(location));

                        List <FolderInfo> l = null;
                        if (!accumulated.ContainsKey(f.SafePath))
                        {
                            l = new List <FolderInfo>();
                            accumulated[f.SafePath] = l;
                        }
                        else
                        {
                            l = accumulated[f.SafePath];
                        }

                        /*
                         * if (thisDepth == 0)
                         * {
                         *  // Check to see if this is a cabinet we want to avoid
                         *  if (XmlConvert.ToBoolean(XmlTools.GetAttributeValue(xml, "dctm:is_private")))
                         *  {
                         *      Log.Info(string.Format("Skipping private cabinet [{0}]", f.FullPath));
                         *      continue;
                         *  }
                         * }
                         */
                        l.Add(f);
                        accumulatedCount++;
                        folderDictionary[f.FullPath] = f;
                    }
                    if ((session != null) && accumulatedCount > 0)
                    {
                        Log.Info(string.Format("Creating {0} folders in the target environment, depth {1}", accumulated.Count, currentDepth + 1));
                        try
                        {
                            ProcessAccumulatedFolders(session, accumulated);
                        }
                        catch (Exception e)
                        {
                            Log.Error("Failed to process the last accumulated folder batch");
                            throw e;
                        }
                    }
                }
            }

            this.Folders = folderDictionary;
        }
Example #6
0
 public FolderImporter(ContentTypeImporter contentTypeImporter, PermissionsImporter permissionsImporter) : this(contentTypeImporter?.ImportContext ?? permissionsImporter.ImportContext, contentTypeImporter, permissionsImporter)
 {
 }
Example #7
0
 public ImportedContentType(ContentTypeImporter importer, ContentType type) : this(importer, type, type.Parent.Id)
 {
 }