Inheritance: ISPDGListItemInfo
Exemple #1
0
        public void CreateItemsAndDocuments()
        {
            int totalProgress = 0;
            if( workingDefinition.MaxNumberofItemsToGenerate > 0
                || workingDefinition.MaxNumberofDocumentLibraryItemsToGenerate > 0
                || workingDefinition.MaxNumberofItemsBigListToGenerate >0)
            {
                totalProgress = CalculateTotalItemsForProgressReporting();
            }
            else
            {
                return;
            }

            updateProgressOverall("Creating Items and Documents", totalProgress);

            foreach (SiteCollInfo siteCollInfo in workingSiteCollections)
            {
                using (var siteColl = ObjectsFactory.GetSite(siteCollInfo.URL))
                {
                    foreach (SiteInfo siteInfo in siteCollInfo.Sites)
                    {
                        using (var web = siteColl.OpenWeb(siteInfo.ID))
                        {
                            var available = siteInfo.Lists;
                            //shuffle because of big lists
                            available.Shuffle();
                            foreach (ListInfo listInfo in available)
                            {
                                titleUsage.Clear();
                                if (!listInfo.isLib)
                                {
                                    var list = web.GetList(listInfo.Name);

                                    if( listInfo.TemplateType == SPDGListTemplateType.Tasks )
                                    {
                                        updateProgressDetail("Start adding items to tasks list: " + listInfo.Name + " in site: " + web.Url,0);
                                    }
                                    else if (listInfo.TemplateType == SPDGListTemplateType.Events)
                                    {
                                        updateProgressDetail("Start adding events to calendar: " + listInfo.Name + " in site: " + web.Url,0);
                                    }
                                    else
                                    {
                                        updateProgressDetail("Start adding items to list: " + listInfo.Name + " in site: " + web.Url,0);
                                    }

                                    List<ISPDGListItemInfo> batch=new List<ISPDGListItemInfo>();
                                    int itemCount = listInfo.isBigList ? workingDefinition.MaxNumberofItemsBigListToGenerate : workingDefinition.MaxNumberofItemsToGenerate;
                                    itemCount = SampleData.GetRandomNumber(itemCount*3/4, itemCount);
                                    for (int i = 0; i < itemCount; i++ )
                                    {
                                        var itemInfo=new SPDGListItemInfo();
                                        if (listInfo.TemplateType == SPDGListTemplateType.Tasks)
                                        {
                                            populateTask(itemInfo);
                                        }
                                        else if (listInfo.TemplateType == SPDGListTemplateType.Events)
                                        {
                                            populateEvent(itemInfo);
                                        }
                                        else
                                        {

                                            populateItemInfo(list, itemInfo, false);
                                        }
                                        batch.Add(itemInfo);

                                        if (batch.Count > 400)
                                        {
                                            list.AddItems(batch);
                                            updateProgressDetail(string.Format("Created {0}/{1} items for list {2}: ", i + 1, itemCount, list.RootFolder.Url), batch.Count);
                                            batch.Clear();
                                        }
                                    }
                                    if (batch.Count > 0)
                                    {
                                        list.AddItems(batch);
                                        updateProgressDetail(string.Format("Created {0} items for list {1}: ", itemCount, list.RootFolder.Url), batch.Count);
                                        batch.Clear();
                                    }
                                    listInfo.ItemCount = itemCount;
                                }
                                else
                                {
                                    docsAdded = 0;
                                    var list = web.GetList(listInfo.Name);
                                    updateProgressDetail("Start adding documents to library: " + listInfo.Name + " in site: " + web.Url,0);

                                    while (docsAdded < workingDefinition.MaxNumberofDocumentLibraryItemsToGenerate)
                                    {
                                        addDocumentToFolder(list,list.RootFolder);
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }
        public override void Execute()
        {
            foreach (SiteCollInfo siteCollInfo in Owner.WorkingSiteCollections)
            {
                using (var siteColl = Owner.ObjectsFactory.GetSite(siteCollInfo.URL))
                {
                    foreach (SiteInfo siteInfo in siteCollInfo.Sites)
                    {
                        using (var web = siteColl.OpenWeb(siteInfo.ID))
                        {
                            var available = siteInfo.Lists;
                            //shuffle because of big lists
                            available.Shuffle();
                            foreach (ListInfo listInfo in available)
                            {
                                _titleUsage.Clear();
                                if (!listInfo.isLib)
                                {
                                    var list = web.GetList(listInfo.Name);

                                    if( listInfo.TemplateType == SPDGListTemplateType.Tasks )
                                    {
                                        Owner.IncrementCurrentTaskProgress("Start adding items to tasks list: " + listInfo.Name + " in site: " + web.Url,0);
                                    }
                                    else if (listInfo.TemplateType == SPDGListTemplateType.Events)
                                    {
                                        Owner.IncrementCurrentTaskProgress("Start adding events to calendar: " + listInfo.Name + " in site: " + web.Url,0);
                                    }
                                    else
                                    {
                                        Owner.IncrementCurrentTaskProgress("Start adding items to list: " + listInfo.Name + " in site: " + web.Url,0);
                                    }

                                    List<ISPDGListItemInfo> batch=new List<ISPDGListItemInfo>();
                                    int itemCount = listInfo.isBigList ? WorkingDefinition.MaxNumberofItemsBigListToGenerate : WorkingDefinition.MaxNumberofItemsToGenerate;
                                    itemCount = SampleData.GetRandomNumber(itemCount*3/4, itemCount);
                                    for (int i = 0; i < itemCount; i++ )
                                    {
                                        var itemInfo=new SPDGListItemInfo();
                                        if (listInfo.TemplateType == SPDGListTemplateType.Tasks)
                                        {
                                            populateTask(itemInfo);
                                        }
                                        else if (listInfo.TemplateType == SPDGListTemplateType.Events)
                                        {
                                            populateEvent(itemInfo);
                                        }
                                        else
                                        {

                                            populateItemInfo(list, itemInfo, false);
                                        }
                                        batch.Add(itemInfo);

                                        if (batch.Count > 400)
                                        {
                                            list.AddItems(batch);
                                            Owner.IncrementCurrentTaskProgress(string.Format("Created {0}/{1} items for list {2}: ", i + 1, itemCount, list.RootFolder.Url), batch.Count);
                                            batch.Clear();
                                        }
                                    }
                                    if (batch.Count > 0)
                                    {
                                        list.AddItems(batch);
                                        Owner.IncrementCurrentTaskProgress(string.Format("Created {0} items for list {1}: ", itemCount, list.RootFolder.Url), batch.Count);
                                        batch.Clear();
                                    }
                                    listInfo.ItemCount = itemCount;
                                }
                                else
                                {
                                    _docsAdded = 0;
                                    var list = web.GetList(listInfo.Name);
                                    Owner.IncrementCurrentTaskProgress("Start adding documents to library: " + listInfo.Name + " in site: " + web.Url,0);

                                    while (_docsAdded < WorkingDefinition.MaxNumberofDocumentLibraryItemsToGenerate)
                                    {
                                        addDocumentToFolder(list,list.RootFolder);
                                    }

                                }
                            }
                        }
                    }
                }
            }
        }