Exemplo n.º 1
0
        private Web EnsureWeb(ClientContext context, Web parentWeb, ShWeb configWeb)
        {
            Log.Debug("Ensuring web with url " + configWeb.Url);
            Web webToConfigure;

            if (parentWeb == null)
            {
                //We assume that the root web always exists
                webToConfigure = context.Site.RootWeb;
            }
            else
            {
                webToConfigure = GetSubWeb(context, parentWeb, configWeb.Url);

                if (webToConfigure == null)
                {
                    Log.Info("Creating web " + configWeb.Url);
                    webToConfigure = parentWeb.Webs.Add(GetWebCreationInformationFromConfig(configWeb));
                }
            }
            context.Load(webToConfigure, w => w.Url);
            context.ExecuteQuery();

            return(webToConfigure);
        }
Exemplo n.º 2
0
 private static void SetAlternateCssUrlForWeb(ClientContext context, ShWeb configWeb, Web webToConfigure)
 {
     if (!string.IsNullOrEmpty(configWeb.AlternateCssUrl))
     {
         Log.Debug("Setting AlternateCssUrl for web " + configWeb.Name);
         webToConfigure.AlternateCssUrl = ContentUploadManager.ReplaceTokensInText(configWeb.AlternateCssUrl, context);
         webToConfigure.Update();
         context.ExecuteQuery();
     }
 }
Exemplo n.º 3
0
        public void ExportData(ClientContext context, Web parentWeb, ShWeb configWeb, string outputDirectory)
        {
            var webToConfigure = GetWeb(context, parentWeb, configWeb);

            ExportListData(context, webToConfigure, configWeb.Lists, outputDirectory);

            foreach (ShWeb subWeb in configWeb.Webs)
            {
                ExportData(context, webToConfigure, subWeb, outputDirectory);
            }
        }
Exemplo n.º 4
0
        private void UploadFilesInWeb(ClientContext context, Web parentWeb, ShWeb configWeb)
        {
            Log.Info("Looking for updated files in web " + configWeb.Url);
            var webToConfigure = EnsureWeb(context, parentWeb, configWeb);

            ContentUploadManager.UploadFilesInFolder(context, webToConfigure, configWeb.ContentFolders, IncrementalUpload);

            foreach (ShWeb subWeb in configWeb.Webs)
            {
                UploadFilesInWeb(context, webToConfigure, subWeb);
            }
        }
Exemplo n.º 5
0
 private WebCreationInformation GetWebCreationInformationFromConfig(ShWeb configWeb)
 {
     return(new WebCreationInformation
     {
         Title = configWeb.Name,
         Description = configWeb.Description,
         Language = configWeb.Language,
         Url = configWeb.Url,
         UseSamePermissionsAsParentSite = true,
         WebTemplate = configWeb.Template
     });
 }
Exemplo n.º 6
0
        public void ExecuteOn(ShWeb shweb, ClientContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            var web = context.Site.RootWeb;

            web.Title = "This site has been updated by a custom task";
            web.Update();
            context.ExecuteQuery();
        }
        public void ExecuteOn(ShWeb web, ClientContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var rootWeb = context.Site.RootWeb;
            var webs    = context.LoadQuery(rootWeb.Webs.IncludeWithDefaultProperties());

            context.ExecuteQuery();

            Log.InfoFormat("Starting update process of site {0}", web.Url);

            string assemblyFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (assemblyFolder != null)
            {
                string frontPageFileName = "Forside.aspx";
                string frontPageFilePath = Path.Combine(assemblyFolder, frontPageFileName);
                var    frontPage         = System.IO.File.ReadAllBytes(Path.GetFullPath(frontPageFilePath));

                foreach (Web subweb in webs)
                {
                    Log.InfoFormat("Updating frontpage of web {0}", subweb.Title);
                    var sitePages  = subweb.Lists.GetByTitle("Områdesider");
                    var rootFolder = sitePages.RootFolder;

                    context.Load(sitePages);
                    context.Load(rootFolder, r => r.ServerRelativeUrl);
                    context.ExecuteQuery();

                    var fileLocation = Url.Combine(subweb.Url, $"SitePages/{frontPageFileName}");

                    var newFile = new FileCreationInformation
                    {
                        Content   = frontPage,
                        Url       = fileLocation,
                        Overwrite = true
                    };
                    File uploadFile = rootFolder.Files.Add(newFile);

                    context.Load(uploadFile);
                    context.Load(uploadFile.ListItemAllFields.ParentList, l => l.ForceCheckout, l => l.EnableMinorVersions, l => l.EnableModeration);
                    context.ExecuteQuery();
                }
            }
        }
Exemplo n.º 8
0
 public void ExecuteTasks(ShWeb rootWeb, ClientContext context)
 {
     foreach (var taskConfig in rootWeb.CustomTaskTypes)
     {
         TypeInfo taskTypeInfo = null;
         Tasks.TryGetValue(taskConfig.FullName, out taskTypeInfo);
         if (taskTypeInfo != null)
         {
             var instance = (ITask)Activator.CreateInstance(taskTypeInfo.AsType());
             instance.ExecuteOn(rootWeb, context);
         }
     }
     foreach (var web in rootWeb.Webs)
     {
         ExecuteTasks(web, context);
     }
 }
Exemplo n.º 9
0
        public void ExecuteTasks(ShWeb rootWeb, ClientContext context)
        {
            LoadTasks();

            foreach (var taskConfig in rootWeb.CustomTaskTypes)
            {
                TypeInfo taskTypeInfo = null;
                Tasks.TryGetValue(taskConfig.FullName, out taskTypeInfo);
                if (taskTypeInfo != null)
                {
                    var instance = (ITask)Activator.CreateInstance(taskTypeInfo.AsType());
                    instance.ExecuteOn(rootWeb, context);
                }
                else
                {
                    Log.ErrorFormat("Could not find loaded task with name {0}", taskConfig.FullName);
                }
            }
        }
Exemplo n.º 10
0
        private Web GetWeb(ClientContext context, Web parentWeb, ShWeb configWeb)
        {
            Log.Debug("Getting web with url " + configWeb.Url);
            Web webToConfigure;

            if (parentWeb == null)
            {
                //We assume that the root web always exists
                webToConfigure = context.Site.RootWeb;
            }
            else
            {
                webToConfigure = GetSubWeb(context, parentWeb, configWeb.Url);

                if (webToConfigure == null)
                {
                    throw new Exception("Web does not exist");
                }
            }
            context.Load(webToConfigure, w => w.Url);
            context.ExecuteQuery();

            return(webToConfigure);
        }
Exemplo n.º 11
0
        public void SetComposedLook(ClientContext context, ShWeb configWeb, Web web, ShComposedLook composedLook)
        {
            if (composedLook != null)
            {
                Log.Debug("Setting Composed Look for web " + configWeb.Name);
                var themeUrl      = string.Empty;
                var fontSchemeUrl = string.Empty;

                List themeList = web.GetCatalog(124);
                web.Context.Load(themeList);
                web.Context.ExecuteQuery();

                // We are assuming that the theme exists
                string camlString = @"
                <View>
                    <Query>                
                        <Where>
                            <Eq>
                                <FieldRef Name='Name' />
                                <Value Type='Text'>{0}</Value>
                            </Eq>
                        </Where>
                        </Query>
                </View>";
                camlString = string.Format(camlString, composedLook.Name);

                CamlQuery query = new CamlQuery();
                query.ViewXml = camlString;
                var themeItems = themeList.GetItems(query);
                web.Context.Load(themeItems);
                web.Context.ExecuteQuery();

                if (themeItems.Count == 0)
                {
                    if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
                    {
                        context.Load(web, w => w.ServerRelativeUrl);
                        context.ExecuteQuery();
                    }

                    var      itemInfo = new ListItemCreationInformation();
                    ListItem item     = themeList.AddItem(itemInfo);
                    item["Name"]  = composedLook.Name;
                    item["Title"] = composedLook.Title;
                    if (!string.IsNullOrEmpty(composedLook.ThemeUrl))
                    {
                        themeUrl         = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", Path.GetFileName(composedLook.ThemeUrl)));
                        item["ThemeUrl"] = themeUrl;
                    }
                    if (!string.IsNullOrEmpty(composedLook.FontSchemeUrl))
                    {
                        fontSchemeUrl         = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/theme/15/{0}", Path.GetFileName(composedLook.FontSchemeUrl)));
                        item["FontSchemeUrl"] = fontSchemeUrl;
                    }
                    if (string.IsNullOrEmpty(composedLook.MasterPageUrl))
                    {
                        item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, "/_catalogs/masterpage/seattle.master");
                    }
                    else
                    {
                        item["MasterPageUrl"] = Url.Combine(web.ServerRelativeUrl, string.Format("/_catalogs/masterpage/{0}", Path.GetFileName(composedLook.MasterPageUrl)));
                    }
                    item["DisplayOrder"] = 11;
                    item.Update();
                    context.ExecuteQuery();
                }
                else
                {
                    ListItem item = themeItems[0];
                    var      themeUrlFieldValue      = item["ThemeUrl"] as FieldUrlValue;
                    var      fontSchemeUrlFieldValue = item["FontSchemeUrl"] as FieldUrlValue;
                    if (themeUrlFieldValue != null)
                    {
                        themeUrl = UriUtilities.GetRelativeUrl(themeUrlFieldValue.Url);
                    }
                    if (fontSchemeUrlFieldValue != null)
                    {
                        fontSchemeUrl = UriUtilities.GetRelativeUrl(fontSchemeUrlFieldValue.Url);
                    }
                }

                web.ApplyTheme(themeUrl, fontSchemeUrl, null, false);
                context.ExecuteQuery();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Assumptions:
        /// 1. The order of webs and subwebs in the config file follows the structure of SharePoint sites
        /// 2. No config element is present without their parent web already being defined in the config file, except the root web
        /// </summary>
        private void EnsureAndConfigureWebAndActivateFeatures(ClientContext context, Web parentWeb, ShWeb configWeb)
        {
            var webToConfigure = EnsureWeb(context, parentWeb, configWeb);

            ListManager.CreateLists(context, webToConfigure, configWeb.Lists);
            FeatureManager.ActivateWebFeatures(context, webToConfigure, configWeb.WebFeatures);
            QuicklaunchManager.CreateQuicklaunchNodes(context, webToConfigure, configWeb.Quicklaunch);
            PropertyManager.SetProperties(context, webToConfigure, configWeb.Properties);
            ContentUploadManager.UploadFilesInFolder(context, webToConfigure, configWeb.ContentFolders, IncrementalUpload);
            ComposedLookManager.SetComposedLook(context, configWeb, webToConfigure, configWeb.ComposedLook);
            SearchNavigationManager.CreateSearchNavigationNodes(context, webToConfigure, configWeb.SearchNavigation);
            SetWelcomePageUrlIfConfigured(context, webToConfigure, configWeb);
            SetAlternateCssUrlForWeb(context, configWeb, webToConfigure);

            foreach (ShWeb subWeb in configWeb.Webs)
            {
                EnsureAndConfigureWebAndActivateFeatures(context, webToConfigure, subWeb);
            }
        }
Exemplo n.º 13
0
 private void SetWelcomePageUrlIfConfigured(ClientContext context, Web webToConfigure, ShWeb configWeb)
 {
     if (!string.IsNullOrEmpty(configWeb.WelcomePageUrl))
     {
         Log.Debug("Setting WelcomePageUrl for web " + configWeb.Name);
         var rootFolder = webToConfigure.RootFolder;
         rootFolder.WelcomePage = configWeb.WelcomePageUrl;
         rootFolder.Update();
         context.Load(webToConfigure.RootFolder);
         context.ExecuteQuery();
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Assumptions:
        /// 1. The order of webs and subwebs in the config file follows the structure of SharePoint sites
        /// 2. No config element is present without their parent web already being defined in the config file, except the root web
        /// </summary>
        private void EnsureAndConfigureWebAndActivateFeatures(ClientContext context, Web parentWeb, ShWeb configWeb)
        {
            var webToConfigure = EnsureWeb(context, parentWeb, configWeb);

            FeatureManager.ActivateWebFeatures(context, webToConfigure, configWeb.WebFeatures);
            ListManager.CreateLists(context, webToConfigure, configWeb.Lists);
            QuicklaunchManager.CreateQuicklaunchNodes(context, webToConfigure, configWeb.Quicklaunch);
            PropertyManager.SetProperties(context, webToConfigure, configWeb.Properties);
            ContentUploadManager.UploadFilesInFolder(context, webToConfigure, configWeb.ContentFolders);
            SetWelcomePageUrlIfConfigured(context, webToConfigure, configWeb);

            foreach (ShWeb subWeb in configWeb.Webs)
            {
                EnsureAndConfigureWebAndActivateFeatures(context, webToConfigure, subWeb);
            }
        }