/// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            output = string.Empty;



            bool   compressFile         = !Params["nofilecompression"].UserTypedIn;
            string filename             = Params["filename"].Value;
            bool   quiet                = Params["quiet"].UserTypedIn;
            bool   haltOnWarning        = Params["haltonwarning"].UserTypedIn;
            bool   haltOnFatalError     = Params["haltonfatalerror"].UserTypedIn;
            bool   includeusersecurity  = Params["includeusersecurity"].UserTypedIn;
            bool   logFile              = !Params["nologfile"].UserTypedIn;
            bool   retainObjectIdentity = Params["retainobjectidentity"].UserTypedIn;
            bool   copySecurity         = Params["copysecuritysettings"].UserTypedIn;
            bool   suppressAfterEvents  = Params["suppressafterevents"].UserTypedIn;

            bool   retargetLinks = Params["retargetlinks"].UserTypedIn;
            string sourceUrl     = Params["sourceurl"].Value;
            string targetUrl     = Params["url"].Value;

            Common.Lists.ImportList importList = new Common.Lists.ImportList(sourceUrl, targetUrl, retargetLinks);

            SPUpdateVersions updateVersions = SPUpdateVersions.Append;

            if (Params["updateversions"].UserTypedIn)
            {
                updateVersions = (SPUpdateVersions)Enum.Parse(typeof(SPUpdateVersions), Params["updateversions"].Value);
            }

            importList.PerformImport(compressFile, filename, quiet, haltOnWarning, haltOnFatalError, includeusersecurity, logFile, retainObjectIdentity, copySecurity, suppressAfterEvents, updateVersions);
            return((int)ErrorCodes.NoError);
        }
        protected override void InternalProcessRecord()
        {
            using (SPWeb targetWeb = TargetWeb.Read())
            {
                SPList sourceList = SourceList.Read();
                try
                {
                    bool   compressFile        = !NoFileCompression.IsPresent;
                    bool   quiet               = !Verbose;
                    bool   haltOnWarning       = HaltOnWarning.IsPresent;
                    bool   haltOnFatalError    = HaltOnError.IsPresent;
                    bool   includeusersecurity = IncludeUserSecurity.IsPresent;
                    bool   excludeDependencies = !IncludeDependencies.IsPresent;
                    bool   copySecurity        = includeusersecurity;
                    bool   logFile             = !NoLogFile.IsPresent;
                    bool   deleteSource        = DeleteSource.IsPresent;
                    string directory           = null;
                    if (!string.IsNullOrEmpty(Path))
                    {
                        directory = Path;
                    }
                    bool suppressAfterEvents = SuppressAfterEvents.IsPresent;
                    bool retargetLinks       = RetargetLinks.IsPresent;

                    SPIncludeVersions versions = SPIncludeVersions.All;
                    if (IncludeVersions.HasValue)
                    {
                        versions = IncludeVersions.Value;
                    }

                    SPUpdateVersions updateVersions = SPUpdateVersions.Append;
                    if (UpdateVersions.HasValue)
                    {
                        updateVersions = UpdateVersions.Value;
                    }

                    SPIncludeDescendants includeDescendents = SPIncludeDescendants.All;
                    if (IncludeDescendants.HasValue)
                    {
                        includeDescendents = IncludeDescendants.Value;
                    }

                    bool useSqlSnapshot  = UseSqlSnapshot.IsPresent;
                    bool excludeChildren = ExcludeChildren.IsPresent;
                    Common.Lists.ImportList importList = new Common.Lists.ImportList(sourceList, targetWeb, retargetLinks);

                    importList.Copy(directory, compressFile, CompressionSize, includeusersecurity, excludeDependencies, haltOnFatalError, haltOnWarning, versions, updateVersions, suppressAfterEvents, copySecurity, deleteSource, logFile, quiet, includeDescendents, useSqlSnapshot, excludeChildren, RetainObjectIdentity);
                }
                finally
                {
                    targetWeb.Site.Dispose();
                    sourceList.ParentWeb.Dispose();
                    sourceList.ParentWeb.Site.Dispose();
                }
            }
        }
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string sourceUrl           = Params["sourceurl"].Value;
            string targetUrl           = Params["targeturl"].Value;
            bool   compressFile        = !Params["nofilecompression"].UserTypedIn;
            bool   quiet               = Params["quiet"].UserTypedIn;
            bool   haltOnWarning       = Params["haltonwarning"].UserTypedIn;
            bool   haltOnFatalError    = Params["haltonfatalerror"].UserTypedIn;
            bool   includeusersecurity = Params["includeusersecurity"].UserTypedIn;
            bool   excludeDependencies = Params["excludedependencies"].UserTypedIn;
            bool   copySecurity        = includeusersecurity;
            bool   logFile             = !Params["nologfile"].UserTypedIn;
            bool   deleteSource        = Params["deletesource"].UserTypedIn;
            string directory           = null;

            if (Params["temppath"].UserTypedIn)
            {
                directory = Params["temppath"].Value;
            }
            bool suppressAfterEvents   = Params["suppressafterevents"].UserTypedIn;
            bool retargetLinks         = Params["retargetlinks"].UserTypedIn;
            SPIncludeVersions versions = SPIncludeVersions.All;

            if (Params["versions"].UserTypedIn)
            {
                versions = (SPIncludeVersions)Enum.Parse(typeof(SPIncludeVersions), Params["versions"].Value);
            }
            SPUpdateVersions updateVersions = SPUpdateVersions.Append;

            if (Params["updateversions"].UserTypedIn)
            {
                updateVersions = (SPUpdateVersions)Enum.Parse(typeof(SPUpdateVersions), Params["updateversions"].Value);
            }
            SPIncludeDescendants includeDescendents = (SPIncludeDescendants)Enum.Parse(typeof(SPIncludeDescendants), Params["includedescendants"].Value, true);
            bool useSqlSnapshot  = Params["usesqlsnapshot"].UserTypedIn;
            bool excludeChildren = Params["excludechildren"].UserTypedIn;
            int  cabSize         = 0;

            if (Params["cabsize"].UserTypedIn)
            {
                cabSize = int.Parse(Params["cabsize"].Value);
            }

            Common.Lists.ImportList importList = new Common.Lists.ImportList(sourceUrl, targetUrl, retargetLinks);

            importList.Copy(directory, compressFile, cabSize, includeusersecurity, excludeDependencies, haltOnFatalError, haltOnWarning, versions, updateVersions, suppressAfterEvents, copySecurity, deleteSource, logFile, quiet, includeDescendents, useSqlSnapshot, excludeChildren, false);

            return((int)ErrorCodes.NoError);
        }
        /// <summary>
        /// Sets up the import object.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="filename">The filename.</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        internal static void SetupImportObject(SPImportSettings settings, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, bool logFile, bool quiet, SPUpdateVersions updateVersions, bool retainObjectIdentity, bool suppressAfterEvents)
        {
            settings.CommandLineVerbose  = !quiet;
            settings.HaltOnNonfatalError = haltOnFatalError;
            settings.HaltOnWarning       = haltOnWarning;
            settings.FileCompression     = compressFile;
            settings.SuppressAfterEvents = suppressAfterEvents;

            if (!compressFile)
            {
                if (string.IsNullOrEmpty(filename) || !Directory.Exists(filename))
                {
                    throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { filename }));
                }
            }
            else if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { filename }));
            }

            if (!compressFile)
            {
                settings.FileLocation = filename;
            }
            else
            {
                string path;
                Utilities.SplitPathFile(filename, out path, out filename);
                settings.FileLocation = path;
                settings.BaseFileName = filename;
            }

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "import.log");
                }
                else
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".import.log");
                }
            }


            if (includeusersecurity)
            {
                settings.IncludeSecurity  = SPIncludeSecurity.All;
                settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
            }
            settings.UpdateVersions       = updateVersions;
            settings.RetainObjectIdentity = retainObjectIdentity;
        }
        /// <summary>
        /// Imports the site providing the option to retain the source objects ID values.  The source object
        /// must no longer exist in the target content database.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="targeturl">The targeturl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        public void ImportSite(string filename, string targeturl, bool haltOnWarning, bool haltOnFatalError, bool noFileCompression, bool includeUserSecurity, bool quiet, bool logFile, bool retainObjectIdentity, SPUpdateVersions updateVersions, bool suppressAfterEvents)
        {
            //if (!retainObjectIdentity)
            //{
            //    // Use the built in "import" command.
            //    ImportSite(filename, targeturl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity,
            //               quiet, logFile, updateVersions);
            //    return;
            //}

            SPImportSettings settings = new SPImportSettings();
            SPImport         import   = new SPImport(settings);

            SetupImportObject(settings, !noFileCompression, filename, haltOnFatalError, haltOnWarning, includeUserSecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            using (SPSite site = new SPSite(targeturl))
            {
                settings.SiteUrl = site.Url;
                Common.Lists.ExportList.ValidateUser(site);

                string dirName;
                Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(targeturl), site.ServerRelativeUrl), out dirName, out m_webName);
                m_webParentUrl = site.ServerRelativeUrl;
                if (!string.IsNullOrEmpty(dirName))
                {
                    if (!m_webParentUrl.EndsWith("/"))
                    {
                        m_webParentUrl = m_webParentUrl + "/";
                    }
                    m_webParentUrl = m_webParentUrl + dirName;
                }
                if (m_webName == null)
                {
                    m_webName = string.Empty;
                }
            }

            EventHandler <SPDeploymentEventArgs> handler = new EventHandler <SPDeploymentEventArgs>(OnSiteImportStarted);

            import.Started += handler;

            try
            {
                import.Run();
            }
            catch (SPException ex)
            {
                if (retainObjectIdentity && ex.Message.StartsWith("The Web site address ") && ex.Message.EndsWith(" is already in use."))
                {
                    throw new SPException(
                              "You cannot import the web because the source web still exists.  Either specify the \"-deletesource\" parameter or manually delete the source web and use the exported file.", ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Log file generated: ");
                Console.WriteLine("\t{0}", settings.LogFilePath);
                Console.WriteLine();
            }
        }
        /// <summary>
        /// Imports the site providing the option to retain the source objects ID values.  The source object
        /// must no longer exist in the target content database.
        /// </summary>
        /// <param name="filename">The filename.</param>
        /// <param name="targeturl">The targeturl.</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="noFileCompression">if set to <c>true</c> [no file compression].</param>
        /// <param name="includeUserSecurity">if set to <c>true</c> [include user security].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        public void ImportSite(string filename, string targeturl, bool haltOnWarning, bool haltOnFatalError, bool noFileCompression, bool includeUserSecurity, bool quiet, bool logFile, bool retainObjectIdentity, SPUpdateVersions updateVersions, bool suppressAfterEvents)
        {
            //if (!retainObjectIdentity)
            //{
            //    // Use the built in "import" command.
            //    ImportSite(filename, targeturl, haltOnWarning, haltOnFatalError, noFileCompression, includeUserSecurity,
            //               quiet, logFile, updateVersions);
            //    return;
            //}

            SPImportSettings settings = new SPImportSettings();
            SPImport import = new SPImport(settings);

            SetupImportObject(settings, !noFileCompression, filename, haltOnFatalError, haltOnWarning, includeUserSecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            using (SPSite site = new SPSite(targeturl))
            {
                settings.SiteUrl = site.Url;
                Common.Lists.ExportList.ValidateUser(site);

                string dirName;
                Utilities.SplitUrl(Utilities.ConvertToServiceRelUrl(Utilities.GetServerRelUrlFromFullUrl(targeturl), site.ServerRelativeUrl), out dirName, out m_webName);
                m_webParentUrl = site.ServerRelativeUrl;
                if (!string.IsNullOrEmpty(dirName))
                {
                    if (!m_webParentUrl.EndsWith("/"))
                    {
                        m_webParentUrl = m_webParentUrl + "/";
                    }
                    m_webParentUrl = m_webParentUrl + dirName;
                }
                if (m_webName == null)
                {
                    m_webName = string.Empty;
                }
            }

            EventHandler<SPDeploymentEventArgs> handler = new EventHandler<SPDeploymentEventArgs>(OnSiteImportStarted);
            import.Started += handler;

            try
            {
                import.Run();
            }
            catch (SPException ex)
            {
                if (retainObjectIdentity && ex.Message.StartsWith("The Web site address ") && ex.Message.EndsWith(" is already in use."))
                {
                    throw new SPException(
                        "You cannot import the web because the source web still exists.  Either specify the \"-deletesource\" parameter or manually delete the source web and use the exported file.", ex);

                }
                else
                    throw;
            }
            finally
            {
                Console.WriteLine();
                Console.WriteLine("Log file generated: ");
                Console.WriteLine("\t{0}", settings.LogFilePath);
                Console.WriteLine();
            }
        }
        /// <summary>
        /// Sets up the import object.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="filename">The filename.</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="retainObjectIdentity">if set to <c>true</c> [retain object identity].</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        internal static void SetupImportObject(SPImportSettings settings, bool compressFile, string filename, bool haltOnFatalError, bool haltOnWarning, bool includeusersecurity, bool logFile, bool quiet, SPUpdateVersions updateVersions, bool retainObjectIdentity, bool suppressAfterEvents)
        {
            settings.CommandLineVerbose = !quiet;
            settings.HaltOnNonfatalError = haltOnFatalError;
            settings.HaltOnWarning = haltOnWarning;
            settings.FileCompression = compressFile;
            settings.SuppressAfterEvents = suppressAfterEvents;

            if (!compressFile)
            {
                if (string.IsNullOrEmpty(filename) || !Directory.Exists(filename))
                {
                    throw new SPException(SPResource.GetString("DirectoryNotFoundExceptionMessage", new object[] { filename }));
                }
            }
            else if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                throw new SPException(SPResource.GetString("FileNotFoundExceptionMessage", new object[] { filename }));
            }

            if (!compressFile)
            {
                settings.FileLocation = filename;
            }
            else
            {
                string path;
                Utilities.SplitPathFile(filename, out path, out filename);
                settings.FileLocation = path;
                settings.BaseFileName = filename;
            }

            if (logFile)
            {
                if (!compressFile)
                {
                    settings.LogFilePath = Path.Combine(settings.FileLocation, "import.log");
                }
                else
                    settings.LogFilePath = Path.Combine(settings.FileLocation, filename + ".import.log");
            }

            if (includeusersecurity)
            {
                settings.IncludeSecurity = SPIncludeSecurity.All;
                settings.UserInfoDateTime = SPImportUserInfoDateTimeOption.ImportAll;
            }
            settings.UpdateVersions = updateVersions;
            settings.RetainObjectIdentity = retainObjectIdentity;
        }
        /// <summary>
        /// Copies the specified source list to the target URL.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        /// <param name="copySecurity">if set to <c>true</c> [copy security].</param>
        /// <param name="deleteSource">if set to <c>true</c> [delete source].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        internal void Copy(string directory, bool compressFile, int cabSize, bool includeusersecurity, bool excludeDependencies, bool haltOnFatalError, bool haltOnWarning, SPIncludeVersions versions, SPUpdateVersions updateVersions, bool suppressAfterEvents, bool copySecurity, bool deleteSource, bool logFile, bool quiet, SPIncludeDescendants includeDescendents, bool useSqlSnapshot, bool excludeChildren, bool retainObjectIdentity)
        {
            if (string.IsNullOrEmpty(directory))
                directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            string filename = directory;
            if (compressFile)
                filename = Path.Combine(directory, "temp.cmp");

            SPExportObject exportObject = new SPExportObject();
            SPExportSettings exportSettings = new SPExportSettings();
            exportSettings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(exportSettings);

            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(exportSettings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, true, quiet, versions);

            ExportList.PerformExport(export, exportObject, exportSettings, logFile, quiet, m_sourceUrl, useSqlSnapshot);

            SPImportSettings importSettings = new SPImportSettings();
            SPImport import = new SPImport(importSettings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(importSettings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, importSettings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (!logFile && !deleteSource)
                {
                    Directory.Delete(directory, true);
                }
                else if (logFile && !deleteSource)
                {
                    foreach (string s in Directory.GetFiles(directory))
                    {
                        FileInfo file = new FileInfo(s);
                        if (file.Extension == ".log")
                            continue;
                        file.Delete();
                    }
                }

                if (deleteSource || copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                        if (sourceList != null)
                        {
                            // If the user has chosen to include security then assume they mean for all the settings to match
                            // the source - copy those settings using the CopyListSecurity operation.
                            if (copySecurity)
                            {
                                Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                            }

                            // If the user wants the source deleted (move operation) then delete using the DeleteList operation.
                            if (deleteSource)
                            {
                                DeleteList.Delete(sourceList, true);
                                Console.WriteLine("Source list deleted.  You can find the exported list here: " +
                                                  directory);
                            }
                        }
                    }
                }
            }
            finally
            {
                if (m_targetSite != null)
                    m_targetSite.Dispose();
                if (m_targetWeb != null)
                    m_targetWeb.Dispose();
            }
        }
        public void PerformImport(bool compressFile, string filename, bool quiet, bool haltOnWarning, bool haltOnFatalError, bool includeusersecurity, bool logFile, bool retainObjectIdentity, bool copySecurity, bool suppressAfterEvents, SPUpdateVersions updateVersions)
        {
            SPImportSettings settings = new SPImportSettings();
            SPImport import = new SPImport(settings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(settings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, settings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (includeusersecurity && !string.IsNullOrEmpty(m_sourceUrl) && copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                    using (SPWeb sourceWeb = sourceSite.OpenWeb())
                    {
                        SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                        if (sourceList != null)
                        {
                            if (m_targetList != null)
                                Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                        }
                    }
                }
            }
            finally
            {
                if (m_targetSite != null)
                    m_targetSite.Dispose();
                if (m_targetWeb != null)
                    m_targetWeb.Dispose();
            }
        }
Example #10
0
        public void PerformImport(bool compressFile, string filename, bool quiet, bool haltOnWarning, bool haltOnFatalError, bool includeusersecurity, bool logFile, bool retainObjectIdentity, bool copySecurity, bool suppressAfterEvents, SPUpdateVersions updateVersions)
        {
            SPImportSettings settings = new SPImportSettings();
            SPImport         import   = new SPImport(settings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(settings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb  = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, settings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (includeusersecurity && !string.IsNullOrEmpty(m_sourceUrl) && copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                        using (SPWeb sourceWeb = sourceSite.OpenWeb())
                        {
                            SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                            if (sourceList != null)
                            {
                                if (m_targetList != null)
                                {
                                    Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                                }
                            }
                        }
                }
            }
            finally
            {
                if (m_targetSite != null)
                {
                    m_targetSite.Dispose();
                }
                if (m_targetWeb != null)
                {
                    m_targetWeb.Dispose();
                }
            }
        }
Example #11
0
        /// <summary>
        /// Copies the specified source list to the target URL.
        /// </summary>
        /// <param name="directory">The directory.</param>
        /// <param name="compressFile">if set to <c>true</c> [compress file].</param>
        /// <param name="includeusersecurity">if set to <c>true</c> [includeusersecurity].</param>
        /// <param name="excludeDependencies">if set to <c>true</c> [exclude dependencies].</param>
        /// <param name="haltOnFatalError">if set to <c>true</c> [halt on fatal error].</param>
        /// <param name="haltOnWarning">if set to <c>true</c> [halt on warning].</param>
        /// <param name="versions">The versions.</param>
        /// <param name="updateVersions">The update versions.</param>
        /// <param name="suppressAfterEvents">if set to <c>true</c> [suppress after events].</param>
        /// <param name="copySecurity">if set to <c>true</c> [copy security].</param>
        /// <param name="deleteSource">if set to <c>true</c> [delete source].</param>
        /// <param name="logFile">if set to <c>true</c> [log file].</param>
        /// <param name="quiet">if set to <c>true</c> [quiet].</param>
        internal void Copy(string directory, bool compressFile, int cabSize, bool includeusersecurity, bool excludeDependencies, bool haltOnFatalError, bool haltOnWarning, SPIncludeVersions versions, SPUpdateVersions updateVersions, bool suppressAfterEvents, bool copySecurity, bool deleteSource, bool logFile, bool quiet, SPIncludeDescendants includeDescendents, bool useSqlSnapshot, bool excludeChildren, bool retainObjectIdentity)
        {
            if (string.IsNullOrEmpty(directory))
            {
                directory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            }
            string filename = directory;

            if (compressFile)
            {
                filename = Path.Combine(directory, "temp.cmp");
            }

            SPExportObject   exportObject   = new SPExportObject();
            SPExportSettings exportSettings = new SPExportSettings();

            exportSettings.ExcludeDependencies = excludeDependencies;
            SPExport export = new SPExport(exportSettings);

            exportObject.Type = SPDeploymentObjectType.List;
            exportObject.IncludeDescendants = includeDescendents;
            exportObject.ExcludeChildren    = excludeChildren;
            StsAdm.OperationHelpers.ExportHelper.SetupExportObjects(exportSettings, cabSize, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, true, quiet, versions);

            ExportList.PerformExport(export, exportObject, exportSettings, logFile, quiet, m_sourceUrl, useSqlSnapshot);

            SPImportSettings importSettings = new SPImportSettings();
            SPImport         import         = new SPImport(importSettings);

            StsAdm.OperationHelpers.ImportHelper.SetupImportObject(importSettings, compressFile, filename, haltOnFatalError, haltOnWarning, includeusersecurity, logFile, quiet, updateVersions, retainObjectIdentity, suppressAfterEvents);

            try
            {
                m_targetSite = new SPSite(m_targetUrl);
                m_targetWeb  = m_targetSite.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_targetUrl)];

                PerformImport(import, importSettings, logFile, m_targetUrl);

                // If the list is a discussion list then attempt to resolve flattened threads.
                //if (m_targetList != null)
                //    SiteCollectionSettings.RepairSiteCollectionImportedFromSubSite.RepairDiscussionList(m_targetSite, m_targetList);

                if (!logFile && !deleteSource)
                {
                    Directory.Delete(directory, true);
                }
                else if (logFile && !deleteSource)
                {
                    foreach (string s in Directory.GetFiles(directory))
                    {
                        FileInfo file = new FileInfo(s);
                        if (file.Extension == ".log")
                        {
                            continue;
                        }
                        file.Delete();
                    }
                }

                if (deleteSource || copySecurity)
                {
                    using (SPSite sourceSite = new SPSite(m_sourceUrl))
                        using (SPWeb sourceWeb = sourceSite.OpenWeb())
                        {
                            SPList sourceList = Utilities.GetListFromViewUrl(sourceWeb, m_sourceUrl);

                            if (sourceList != null)
                            {
                                // If the user has chosen to include security then assume they mean for all the settings to match
                                // the source - copy those settings using the CopyListSecurity operation.
                                if (copySecurity)
                                {
                                    Common.Lists.CopyListSecurity.CopySecurity(sourceList, m_targetList, m_targetWeb, true, quiet);
                                }

                                // If the user wants the source deleted (move operation) then delete using the DeleteList operation.
                                if (deleteSource)
                                {
                                    DeleteList.Delete(sourceList, true);
                                    Console.WriteLine("Source list deleted.  You can find the exported list here: " +
                                                      directory);
                                }
                            }
                        }
                }
            }
            finally
            {
                if (m_targetSite != null)
                {
                    m_targetSite.Dispose();
                }
                if (m_targetWeb != null)
                {
                    m_targetWeb.Dispose();
                }
            }
        }