/// <summary>
        /// Returns the web urls of selected items in a TreeNodeCollection.
        /// </summary>
        /// <param name="selection">the TreeNodeCollection to check</param>
        /// <returns>selected web urls as string</returns>
        internal static HashSet <string> GetSelectedWebUrls(this TreeNodeCollection selection)
        {
            HashSet <string> webUrlList = new HashSet <string>();

            foreach (TreeNode item in selection)
            {
                IMigratable migratable = (IMigratable)item;
                if (migratable.GetType() == typeof(SSiteCollection))
                {
                    SSiteCollection siteCollection = (SSiteCollection)migratable;
                    if (siteCollection.Checked)
                    {
                        //// is sitecollection is checked, add every page
                        foreach (SSite site in siteCollection.Sites)
                        {
                            XmlAttribute attr = site.XmlData.Attributes["Url"];
                            string       url  = attr.Value;
                            if (url != null)
                            {
                                webUrlList.Add(url);
                            }
                        }
                    }
                    else
                    {
                        foreach (SSite site in siteCollection.Sites)
                        {
                            if (site.Checked)
                            {
                                XmlAttribute attr = site.XmlData.Attributes["Url"];
                                string       url  = attr.Value;
                                if (url != null)
                                {
                                    webUrlList.Add(url);
                                }
                            }
                        }
                    }
                }
                else
                {
                    //// other items are either site and could be in set already or they are list, which is not important for this query.
                }
            }

            return(webUrlList);
        }
Example #2
0
        /// <summary>
        /// Loads the site collection of a Sharepoint server
        /// </summary>
        /// <param name="srcWebs">webs web service</param>
        /// <param name="srcLists">lists web service</param>
        /// <param name="loadListData">load data items or not</param>
        /// <returns>A Sharepoint site collection tree</returns>
        private SSiteCollection LoadSharepointTree(WebsWS.Webs srcWebs, ListsWS.Lists srcLists, bool loadListData)
        {
            SSiteCollection siteCollection = new SSiteCollection();

            // get all webs names (first is the site collection)
            XmlNode allSrcWebs = srcWebs.GetAllSubWebCollection();

            // result<List>: <Web Title="F*****g site collection" Url="http://ss13-css-009:31920" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
            Dictionary <string, string> webs = new Dictionary <string, string>();

            foreach (XmlNode web in allSrcWebs)
            {
                webs.Add(web.Attributes["Url"].InnerText, web.Attributes["Title"].InnerText);
            }

            bool   firstRun          = true;
            string srcListsUrlBuffer = srcLists.Url;
            var    allSrcWebsXml     = new List <XmlNode>();

            foreach (KeyValuePair <string, string> web in webs)
            {
                // load details on each web
                XmlNode w = srcWebs.GetWeb(web.Key);
                allSrcWebsXml.Add(w);
                SSite site = new SSite();
                site.ParentObject = siteCollection;
                site.XmlData      = w;

                string url = w.Attributes["Url"].InnerText + WebService.UrlLists;

                // only do this, if destination site is being loaded
                if (!loadListData)
                {
                    this.destinationSiteUrls.Add(w.Attributes["Url"].InnerText);
                }

                // get all lists
                srcLists.Url = url;
                XmlNode lc = srcLists.GetListCollection();

                // lists to migrate: Hidden="False"
                foreach (XmlNode list in lc.ChildNodes)
                {
                    // if BaseType==1 --> its a document library
                    if (list.Attributes["Hidden"].InnerText.ToUpper().Equals("FALSE") && !list.Attributes["BaseType"].InnerText.Equals("1"))
                    {
                        // load list details with all fields
                        XmlNode listDetails = srcLists.GetList(list.Attributes["Title"].InnerText);
                        Console.WriteLine(list.Attributes["Title"].InnerText + ", BaseType=" + listDetails.Attributes["BaseType"].InnerText);
                        SList shareList = new SList();
                        shareList.ParentObject = site;
                        shareList.XmlList      = listDetails;

                        // load list data
                        if (loadListData)
                        {
                            // attention: GetListItems only returns the elements of the default view, if you do not specify the viewfields you want
                            XmlDocument xmlDoc     = new System.Xml.XmlDocument();
                            XmlElement  viewFields = xmlDoc.CreateElement("ViewFields");

                            XmlElement field;
                            foreach (XmlElement f in shareList.XmlList["Fields"])
                            {
                                field = xmlDoc.CreateElement("FieldRef");
                                field.SetAttribute("Name", f.Attributes["Name"].InnerText);
                                viewFields.AppendChild(field);
                            }

                            XmlNode listItems = srcLists.GetListItems(list.Attributes["Title"].InnerText, null, null, viewFields, null, null, null);
                            shareList.XmlListData = listItems;
                        }

                        site.AddList(shareList, false);
                        Console.WriteLine("\t\t" + list.Attributes["Title"].InnerText);
                    }
                }

                if (firstRun)
                {
                    site.IsSiteCollectionSite = true;
                    firstRun = false;
                }
                else
                {
                    site.IsSiteCollectionSite = false;
                }

                siteCollection.AddSite(site, false);
            }

            srcLists.Url           = srcListsUrlBuffer;
            siteCollection.XmlData = allSrcWebsXml;

            return(siteCollection);
        }
Example #3
0
        /// <summary>
        /// Migrate a site
        /// </summary>
        /// <param name="src">source site to migrate</param>
        /// <param name="dstSC">destination site collection</param>
        /// <returns>If successful or not</returns>
        public async Task <bool> MigrateSiteAsync(SSite src, SSiteCollection dstSC)
        {
            // mirate the site f:
            //   - if it is not the site collection site (its a conventional subsite)
            //   - if it is the site collection site and the site collection is not migrated (then the contents are migrated to a conventional site)
            if (!src.IsSiteCollectionSite || (src.IsSiteCollectionSite && !this.SourceSiteCollection.Migrate))
            {
                this.log.AddMessage("Migrating site \"" + src.Name + "\" started");

                string url = Regex.Replace(src.XmlData.Attributes["Title"].InnerText, @"[^A-Za-z0-9_\.~]+", "-");

                // find a fitting url
                int    i      = 1;
                string newUrl = url;
                while (this.destinationSiteUrls.FindAll(delegate(string s) { return(s.EndsWith(newUrl)); }).Count > 0)
                {
                    newUrl = url + i.ToString();
                    i++;
                }

                url = newUrl;

                string title             = src.XmlData.Attributes["Title"].InnerText;
                string description       = src.XmlData.Attributes["Description"].InnerText;
                string templateName      = this.GetSiteTemplate(src.XmlData.Attributes["Url"].InnerText);
                uint   language          = this.GetLanguage(this.SourceSiteCollection);
                bool   languageSpecified = true;
                uint   locale            = await this.GetLocale();

                bool localeSpecified            = true;
                uint collationLocale            = locale;
                bool collationLocaleSpecified   = true;
                bool uniquePermissions          = true;
                bool uniquePermissionsSpecified = true;
                bool anonymous          = true;
                bool anonymousSpecified = true;
                bool presence           = true;
                bool presenceSpecified  = true;

                Task <bool> createWeb = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        this.ws.DstSites.CreateWeb(url, title, description, templateName, language, languageSpecified, locale, localeSpecified, collationLocale, collationLocaleSpecified, uniquePermissions, uniquePermissionsSpecified, anonymous, anonymousSpecified, presence, presenceSpecified);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        // there is always an error... no matter what you do (XML error, altough I couldn't have made one here)
                        // has to be ignored! return true! always
                        Debug.WriteLine(e.Message);
                        return(true);
                    }
                });

                if (await createWeb)
                {
                    Task <XmlNode> getWebs = Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            return(this.ws.DstWebs.GetWebCollection());
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.Message);
                            return((new XmlDocument()).CreateElement("null"));
                        }
                    });

                    XmlNode webs = await getWebs;
                    foreach (XmlNode web in webs)
                    {
                        if (web.Attributes["Url"].InnerText.EndsWith(url))
                        {
                            url = web.Attributes["Url"].InnerText;
                        }
                    }

                    // set the new migrate to
                    foreach (var l in src.Lists)
                    {
                        l.MigrateToUrl = url;
                    }

                    await this.MigrateSiteColumnsAsync(src.XmlData.Attributes["Url"].InnerText, url);
                }

                return(true);
            }

            return(true);
        }
Example #4
0
 /// <summary>
 /// Extracts the language number
 /// </summary>
 /// <param name="sc">the site collection to look for</param>
 /// <returns>the language code</returns>
 private uint GetLanguage(SSiteCollection sc)
 {
     return(Convert.ToUInt32(sc.XmlData.ElementAt(0).Attributes["Language"].InnerText));
 }
Example #5
0
 /// <summary>
 /// Loads the destination site collection and stores it
 /// </summary>
 /// <returns>the source site collection</returns>
 public SSiteCollection LoadDestinationSiteCollection()
 {
     this.DestinationSiteCollection = this.LoadSharepointTree(this.ws.DstWebs, this.ws.DstLists, false);
     return(this.DestinationSiteCollection);
 }
Example #6
0
        private async void ButtonTestMigrationClicked(object o, EventArgs e)
        {
            this.FileMigrationTabLoaded();
            if (this.settings.SiteCollectionMigration)
            {
                MessageBox.Show("As the destination web application is empty, migration will be started now.", "Info");
                this.EnableTab(this.tabPageMigrationProgress, true);
                this.tabControMain.SelectedTab = this.tabPageMigrationProgress;
                this.waitForm.Show();
                this.waitForm.SpecialText = "migrating elements";
                await this.MigrateAll();

                this.waitForm.Hide();
            }
            else
            {
                this.EnableTab(this.tabPageContentSelection, false);
                this.EnableTab(this.tabPageMigrationPreparation, true);

                /*
                 * 1. Site Collection will be migrated
                 *      a. --> nothing to choose, skip to migration
                 * 2. Sites and lists will be migrated
                 *      a. --> all lists beneath a site will stay there
                 *      b. --> all lists where the site is not migrated must have a combobox to choose the destination site (or the newly created ones)
                 * 3. Only lists are migrated
                 *      a. same as 2.b
                 */
                this.waitForm.Show();
                this.waitForm.SpecialText = "loading migration elements";
                this.log.AddMessage("Loading migration elements");

                // Generate the ListView with the source elements to configure
                // 1. site collection
                if (this.sourceSiteCollection.Migrate)
                {
                    listViewMigrationContent.Items.Add(new SListViewItem(this.sourceSiteCollection));
                }

                List <SList> listsWithoutSite = new List <SList>();

                // 2. sites
                foreach (SSite site in this.sourceSiteCollection.Sites)
                {
                    if (site.Migrate)
                    {
                        listViewMigrationContent.Items.Add(new SListViewItem(site));
                    }

                    foreach (SList li in site.Lists)
                    {
                        if (li.Migrate && site.Migrate)
                        {
                            listViewMigrationContent.Items.Add(new SListViewItem(li));
                        }

                        if (li.Migrate && !site.Migrate)
                        {
                            listsWithoutSite.Add(li);
                        }
                    }
                }

                if (listsWithoutSite.Count > 0)
                {
                    this.listViewMigrationContent.Items.Add("---Lists without Sites---");
                    foreach (SList li in listsWithoutSite)
                    {
                        this.listViewMigrationContent.Items.Add(new SListViewItem(li));
                    }
                }

                Task <string> loadDestinationTree = Task.Factory.StartNew(() =>
                {
                    try
                    {
                        this.destinationSiteCollection = this.contentLoader.LoadDestinationSiteCollection();
                        return(string.Empty);
                    }
                    catch (Exception ex)
                    {
                        return(ex.Message);
                    }
                });

                string error = await loadDestinationTree;
                if (!error.Equals(string.Empty))
                {
                    MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.waitForm.Hide();
                this.tabControMain.SelectedTab = this.tabPageMigrationPreparation;
            }
        }
Example #7
0
        /// <summary>
        /// Tries to connect to the server and loads the migration tree.
        /// </summary>
        /// <returns>Task with bool as return value.</returns>
        private async Task <bool> ApplyConfigurationAndLoadSourceTreeAsync()
        {
            try
            {
                string txt = "Trying to connect to source";
                this.waitForm.SpecialText = txt;
                this.log.AddMessage(txt);
                await this.ConnectToSource();
            }
            catch (Exception ex)
            {
                this.waitForm.SpecialText = string.Empty;
                Debug.WriteLine(ex.ToString());
                throw new LoginFailedException("Could not connect to source SharePoint. Please check your login Data");
            }
            finally
            {
                this.waitForm.SpecialText = string.Empty;
            }

            try
            {
                // as there is no site collection at the destination it makes no sense to connect to it
                if (!this.settings.SiteCollectionMigration)
                {
                    string txt2 = "Trying to connect to destination";
                    this.waitForm.SpecialText = txt2;
                    this.log.AddMessage(txt2);
                    await this.ConnectToDestination();
                }
                else
                {
                    Connector     connector     = new Connector();
                    ProxySettings proxySettings = null;
                    if (this.checkBoxProxyActivate.Checked)
                    {
                        proxySettings = new ProxySettings(this.textBoxProxyUrl.Text.Trim(), this.textBoxProxyUsername.Text.Trim(), this.textBoxProxyPassword.Text.Trim());
                    }
                    this.migrationData.TargetClientContext = connector.ConnectToClientContext(this.settings.ToHost, this.settings.ToUserName, this.settings.ToPassword, this.settings.ToDomain, proxySettings);
                    this.migrationData.SourceClientContext = connector.ConnectToClientContext(this.settings.FromHost, this.settings.FromUserName, this.settings.FromPassword, this.settings.FromDomain, proxySettings);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                throw new LoginFailedException("Could not connect to destination SharePoint. Please check your login Data");
            }
            finally
            {
                this.waitForm.SpecialText = string.Empty;
            }

            string txt3 = "Generating migration tree";

            this.waitForm.SpecialText = txt3;
            this.log.AddMessage(txt3);
            Task <SSiteCollection> t = Task.Factory.StartNew(() =>
            {
                return(this.contentLoader.LoadSourceSiteCollection());
            });

            this.sourceSiteCollection = await t;

            // make sure, the site collection is checked, if it will be migrated
            if (this.settings.SiteCollectionMigration)
            {
                this.sourceSiteCollection.Checked = true;
                this.sourceSiteCollection.Migrate = true;
                foreach (SSite s in this.sourceSiteCollection.Sites)
                {
                    if (s.IsSiteCollectionSite)
                    {
                        s.Migrate = true;
                        s.Checked = true;
                    }
                }
            }

            return(true);
        }