private static void CheckPasswordValue(this AddMultipleItemsOptions option) { if (string.IsNullOrEmpty(option.Password)) { logger.Info("please input user password :"); option.Password = Console.ReadLine(); } }
//private static void CheckUrlValue(this AddMultipleItemsOptions option) //{ // if (string.IsNullOrEmpty(option.Url)) // { // logger.Info("please input site url:"); // option.Url = Console.ReadLine(); // } //} private static void CheckUserNameValue(this AddMultipleItemsOptions option) { if (string.IsNullOrEmpty(option.UserName)) { logger.Info("please input user name:"); option.UserName = Console.ReadLine(); } }
private static void CheckCountValue(this AddMultipleItemsOptions option) { if (option.Count == 0) { logger.Info("please input create item count:"); option.Count = int.Parse(Console.ReadLine()); } }
public static void CheckArguement(this AddMultipleItemsOptions option) { option.CheckCountValue(); option.CheckPasswordValue(); //option.CheckUrlValue(); option.CheckUserNameValue(); //option.CheckTitleValue(); }
private static List <string> FilterSiteCollections(AddMultipleItemsOptions option) { logger.Info($"Start searh site collections with {option.KeyWord}"); var siteUrls = new List <string>(); var tenantContext = tokenHelper.GetClientContextForServiceAccount(option.AdminUrl, option.UserName, option.Password); tenantContext.RequestTimeout = 6000 * 1000; Tenant tenant = new Tenant(tenantContext); SPOSitePropertiesEnumerableFilter filter = new SPOSitePropertiesEnumerableFilter { //IncludeDetail = true, IncludePersonalSite = PersonalSiteFilter.Exclude, Template = "STS", Filter = $"Url -like '{option.KeyWord}'", }; string tempIndex = null; do { filter.StartIndex = tempIndex; var sitePropertyEnum = tenant.GetSitePropertiesFromSharePointByFilters(filter); tenantContext.Load(sitePropertyEnum); tenantContext.ExecuteQuery(); foreach (SiteProperties siteProperty in sitePropertyEnum) { siteUrls.Add(siteProperty.Url.TrimEnd('/')); } tempIndex = sitePropertyEnum.NextStartIndexFromSharePoint; if (option.LimiteCount > 0 && siteUrls.Count >= option.LimiteCount) { logger.Info($"stop search site collections with {option.KeyWord}, beacuse site collection count exceed {option.LimiteCount}"); break; } }while (tempIndex != null); logger.Info($"Finish searh site collections with {option.KeyWord}, site collection count: {siteUrls.Count}, limite count: {option.LimiteCount}"); return(option.LimiteCount > 0 ? siteUrls.Take(option.LimiteCount).ToList() : siteUrls); }
public static void Run(AddMultipleItemsOptions option) { var siteUrls = FilterSiteCollections(option); int index = 0; foreach (var siteUrl in siteUrls) { try { logger.Info($"Start add files to {siteUrl}"); var context = tokenHelper.GetClientContextForServiceAccount(siteUrl, option.UserName, option.Password); context.RequestTimeout = 6000 * 1000; var list = context.Web.Lists.GetByTitle("Documents"); context.Load(list, l => l.BaseType, l => l.ItemCount); context.ExecuteQuery(); if (list.BaseType == BaseType.DocumentLibrary) { if (list.ItemCount < option.Count) { AddFilesToLibrary(list, context, option.Count - list.ItemCount); } } else { if (list.ItemCount < option.Count) { AddListItemsToList(list, context, option.Count - list.ItemCount); } } } catch (Exception e) { logger.Error($"An error while add item to {siteUrl}, error: {e.ToString()}"); } index++; logger.Info($"Add items to {siteUrl} finished, finished site count: {index}, total site collection count: {siteUrls.Count}"); } }