Пример #1
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);
        }
Пример #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);
        }
Пример #3
0
        private string get_site_info(SSite s)
        {
            string r = s.id + "," + s.name + "," + s.image_url + "," + s.description;

            return(r);
        }