• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Tenant类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Tenant的典型用法代码示例。如果您正苦于以下问题:C# Tenant类的具体用法?C# Tenant怎么用?C# Tenant使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Tenant类属于命名空间,在下文中一共展示了Tenant类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CreateSiteCollectionFromTemplate

        private static void CreateSiteCollectionFromTemplate(ClientContext cc, string tenantUrl, string newSiteUrl, string userName)
        {
            Tenant tenant = new Tenant(cc);
            SiteCreationProperties newsiteProp = new SiteCreationProperties();
            newsiteProp.Lcid = 1033;
            newsiteProp.Owner = userName;
            newsiteProp.Title = "New Site";
            newsiteProp.Url = newSiteUrl;
            newsiteProp.StorageMaximumLevel = 100; //MB
            newsiteProp.UserCodeMaximumLevel = 10;

            SpoOperation spoO = tenant.CreateSite(newsiteProp);
            cc.Load(spoO, i => i.IsComplete);
            cc.ExecuteQuery();

            while (!spoO.IsComplete)
            {
                //Wait for 30 seconds and then try again
                System.Threading.Thread.Sleep(10000);
                spoO.RefreshLoad();
                cc.ExecuteQuery();
                Console.WriteLine("Site creation status: " + (spoO.IsComplete ? "completed" : "waiting"));
            }

            Console.WriteLine("SiteCollection Created.");
        }
开发者ID:NicolajLarsen,项目名称:PnP,代码行数:26,代码来源:Program.cs


示例2: Get

 public OperationResult Get()
 {
     var siteUrl = Request.GetQueryNameValuePairs().FirstOrDefault(p => p.Key == "siteUrl").Value;
     var ret = new OperationResult()
     {
         IsSuccess = true
     };
     UsingTenantContext(context => {                
         try
         {
             var tenant = new Tenant(context);
             tenant.SetSiteLockState(siteUrl, SiteLockState.Unlock, wait: true);
         }
         catch (Exception e)
         {
             ret.IsSuccess = false;
             ret.Message = e.Message;
             return;
         }
     });
     if (ret.IsSuccess)
     {
         DbRepository.UsingContext(dbContext => {
             var site = dbContext.GetSite(siteUrl);
             if (site != null)
                 site.ComplianceState.IsLocked = false;
             dbContext.SaveChanges();
         });
     }
     return ret;
 }
开发者ID:nishantpunetha,项目名称:PnP,代码行数:31,代码来源:UnlockController.cs


示例3: CreateDeleteCreateSiteCollectionTest

        public void CreateDeleteCreateSiteCollectionTest()
        {
            using (var tenantContext = TestCommon.CreateTenantClientContext())
            {
                var tenant = new Tenant(tenantContext);

                //Create site collection test
                string siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
                var siteExists = tenant.SiteExists(siteToCreateUrl);
                Assert.IsTrue(siteExists, "Site collection creation failed");

                //Delete site collection test: move to recycle bin
                tenant.DeleteSiteCollection(siteToCreateUrl, true);
                bool recycled = tenant.CheckIfSiteExists(siteToCreateUrl, "Recycled");
                Assert.IsTrue(recycled, "Site collection recycling failed");

                //Remove from recycle bin
                tenant.DeleteSiteCollectionFromRecycleBin(siteToCreateUrl, true);
                var siteExists2 = tenant.SiteExists(siteToCreateUrl);
                Assert.IsFalse(siteExists2, "Site collection deletion from recycle bin failed");

                //Create a site collection using the same url as the previously deleted site collection
                siteToCreateUrl = CreateTestSiteCollection(tenant, sitecollectionName);
                siteExists = tenant.SiteExists(siteToCreateUrl);
                Assert.IsTrue(siteExists, "Second site collection creation failed");
            }
        }
开发者ID:rroman81,项目名称:PnP-Sites-Core,代码行数:27,代码来源:TenantExtensionsTests.cs


示例4: AddAdministratorsTenant

        public static void AddAdministratorsTenant(this Web web, IEnumerable<UserEntity> adminLogins, Uri siteUrl, bool addToOwnersGroup = false)
        {
            Tenant tenant = new Tenant(web.Context);

            tenant.AddAdministrators(adminLogins, siteUrl, addToOwnersGroup);

        }
开发者ID:AaronSaikovski,项目名称:PnP,代码行数:7,代码来源:SecurityExtensions.deprecated.cs


示例5: btnUpdateSiteCollectionStatus_Click

        protected void btnUpdateSiteCollectionStatus_Click(object sender, EventArgs e)
        {
            string siteUrl = sitecollections.SelectedValue;
            using (var ctx = GetAdminContext())
            {
                // get site collections.
                Tenant tenant = new Tenant(ctx);
                SiteProperties siteProp = tenant.GetSitePropertiesByUrl(siteUrl, true);
                ctx.Load(siteProp);
                ctx.ExecuteQuery();

                switch (rblSharingOptions.SelectedValue)
                {
                    case "Disabled":
                        siteProp.SharingCapability = SharingCapabilities.Disabled;
                        lblStatus.Text = "External sharing is for authenticated and guest users.";
                        break;
                    case "ExternalUserAndGuestSharing":
                        siteProp.SharingCapability = SharingCapabilities.ExternalUserAndGuestSharing;
                        lblStatus.Text = "External sharing is for authenticated and guest users.";
                        break;
                    case "ExternalUserSharingOnly":
                        siteProp.SharingCapability = SharingCapabilities.ExternalUserSharingOnly;
                        lblStatus.Text = "External sharing is for authenticated and guest users.";
                        break;
                }
                // Update based on applied setting
                siteProp.Update();
                ctx.ExecuteQuery();
                lblStatus.Text = string.Format("Sharing status updated for site collection at URL: {0}", siteUrl);
            }
        }
开发者ID:tandis,项目名称:PnP,代码行数:32,代码来源:ExternalSettingsAtSiteCollectionLevel.aspx.cs


示例6: ProcessSiteCreationRequest

        public string ProcessSiteCreationRequest(ClientContext ctx, SiteCollectionRequest siteRequest)
        {
            // Resolve full URL 
            var webFullUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", siteRequest.TenantName, siteRequest.ManagedPath, siteRequest.Url);

            // Resolve the actual SP template to use
            string siteTemplate = SolveActualTemplate(siteRequest);

            Tenant tenant = new Tenant(ctx);
            if (tenant.SiteExists(webFullUrl))
            {
                // Abort... can't proceed, URL taken.
                throw new InvalidDataException(string.Format("site already existed with same URL as {0}. Process aborted.", webFullUrl));
            }
            else
            {
                // Create new site collection with storage limits and settings from the form
                tenant.CreateSiteCollection(webFullUrl,
                                            siteRequest.Title,
                                            siteRequest.Owner,
                                            siteTemplate,
                                            (int)siteRequest.StorageMaximumLevel,
                                            (int)(siteRequest.StorageMaximumLevel * 0.75),
                                            siteRequest.TimeZoneId,
                                            0,
                                            0,
                                            siteRequest.Lcid);

                return webFullUrl;
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:31,代码来源:SiteManager.cs


示例7: btnCheckUrl_Click

        protected void btnCheckUrl_Click(object sender, EventArgs e)
        {
            User currUser = ResolveCurrentUser();

            //get the base tenant admin urls
            var tenantStr = Page.Request["SPHostUrl"].ToLower().Replace("-my", "").Substring(8);
            tenantStr = tenantStr.Substring(0, tenantStr.IndexOf("."));
            var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

            // Let's resolve the admin URL and wanted new site URL
            var webUrl = String.Format("https://{0}.sharepoint.com/{1}/{2}", tenantStr, "sites", txtUrl.Text);
            var tenantAdminUri = new Uri(String.Format("https://{0}-admin.sharepoint.com", tenantStr));

            // Creating new app only context for the operation
            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal,
                tenantAdminUri.Authority,
                TokenHelper.GetRealmFromTargetUrl(tenantAdminUri)).AccessToken;

            using (var ctx = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), accessToken))
            {
                Tenant tenant = new Tenant(ctx);

                if (tenant.SiteExists(webUrl))
                {
                    lblStatus1.Text = string.Format("Site already existed. Used URL - {0}", webUrl);
                }
                else
                {
                    lblStatus1.Text = string.Format("Site with given URL does not exist. Used URL - {0}", webUrl);
                }
            }

        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:34,代码来源:Scenario2.aspx.cs


示例8: Execute

 public List<SiteProperties> Execute(ClientContext tenantAdminCtx) {
     Logger.Verbose($"About to execute {nameof(GetTenantSiteCollections)}");
     var tenant = new Tenant(tenantAdminCtx);
     tenantAdminCtx.Load(tenant);
     tenantAdminCtx.ExecuteQuery();
     return GetTenantSiteCollectionsRecursive(tenant, new List<SiteProperties>(), 0);
 }
开发者ID:ronnieholm,项目名称:Bugfree.Spo.Cqrs,代码行数:7,代码来源:GetTenantSiteCollections.cs


示例9: Main

        static void Main(string[] args)
        {
            //gather settings from the host process config file
            string tenantName = ConfigurationManager.AppSettings["TenantName"];
            string tenantUpnDomain = ConfigurationManager.AppSettings["TenantUpnDomain"];
            Uri tenantAdminUri = new Uri(string.Format("https://{0}-admin.sharepoint.com", tenantName));
            
            //get the ream and app-only access token
            string adminRealm = TokenHelper.GetRealmFromTargetUrl(tenantAdminUri);
            var adminToken = TokenHelper.GetAppOnlyAccessToken
                (TokenHelper.SharePointPrincipal, tenantAdminUri.Authority, adminRealm).AccessToken;
                
            //we use the app-only access token to authenticate without the interaction of the user
            using (ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), adminToken))
            {
                //load the tenant object
                var tenant = new Tenant(clientContext);
                clientContext.Load(tenant);
                clientContext.ExecuteQuery();

                //call the extension method to get all site collections
                IList<SiteEntity> siteCollections = tenant.GetSiteCollections();

                //at this stage you could build aby report, like an Excel file with OpenXML
                //in this demo we generate a simple email
                EmailProperties emailProperties = GenerateEmailReport(siteCollections);
                
                //use the OffideDev PnP utilities to send out the email
                Utility.SendEmail(clientContext, emailProperties);
                clientContext.ExecuteQuery();
            }
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:32,代码来源:Program.cs


示例10: Button1_Click

        protected void Button1_Click(object sender, EventArgs e)
        {
            Uri tenantAdministrationUrl = new Uri("https://dotnetrocks-admin.sharepoint.com/");

            string accessToken = TokenHelper.GetAppOnlyAccessToken(
                TokenHelper.SharePointPrincipal,
                tenantAdministrationUrl.Authority,
                TokenHelper.GetRealmFromTargetUrl(tenantAdministrationUrl)).AccessToken;

            var newSite = new SiteCreationProperties()
            {
                Url = "https://dotnetrocks.sharepoint.com/sites/" + SiteName.Text,
                Owner = SiteOwner.Text,
                Template = "STS#0", // Team Site
                Title = "App Provisioned Site - " + SiteName.Text,
                StorageMaximumLevel = 1000,
                StorageWarningLevel = 500,
                TimeZoneId = 7,
                UserCodeMaximumLevel = 7,
                UserCodeWarningLevel = 1
            };

            using (var clientContext = TokenHelper.GetClientContextWithAccessToken(tenantAdministrationUrl.ToString(), accessToken))
            {
                var tenant = new Tenant(clientContext);
                var spoOperation = tenant.CreateSite(newSite);

                clientContext.Load(spoOperation);
                clientContext.ExecuteQuery();
            }
        }
开发者ID:Souratendu,项目名称:SharePoint-Power-Hour-Code-Samples,代码行数:31,代码来源:Default.aspx.cs


示例11: RunGetsSurveyAnswersForIdFromStore

        public void RunGetsSurveyAnswersForIdFromStore()
        {
            var mockSurveyStore = new Mock<ISurveyStore>();
            var mockSurveyAnswerStore = new Mock<ISurveyAnswerStore>();
            var mockTenantStore = new Mock<ITenantStore>();
            var mockSurveySqlStore = new Mock<ISurveySqlStore>();
            var command = new TransferSurveysToSqlAzureCommand(mockSurveyAnswerStore.Object, mockSurveyStore.Object, mockTenantStore.Object, mockSurveySqlStore.Object);
            var message = new SurveyTransferMessage { Tenant = "tenant", SlugName = "slugName" };
            var survey = new Survey("slugName")
                             {
                                 Tenant = "tenant",
                             };
            survey.Questions.Add(new Question
                                     {
                                         Text = "What is your favorite food?",
                                         PossibleAnswers = "Coffee\nPizza\nSalad",
                                         Type = QuestionType.MultipleChoice
                                     });
            mockSurveyStore.Setup(r => r.GetSurveyByTenantAndSlugName("tenant", "slugName", true)).Returns(survey);
            mockSurveyStore.Setup(r => r.GetSurveysByTenant("tenant")).Returns(new List<Survey> { survey });
            mockSurveyAnswerStore.Setup(r => r.GetSurveyAnswerIds("tenant", "slugName")).Returns(new List<string> { "id" });
            mockSurveyAnswerStore.Setup(r => r.GetSurveyAnswer("tenant", "slugName", "id")).Returns(new SurveyAnswer());
            var tenant = new Tenant { SqlAzureConnectionString = "connectionString" };
            mockTenantStore.Setup(r => r.GetTenant("tenant")).Returns(tenant);

            command.Run(message);

            mockSurveyAnswerStore.Verify(r => r.GetSurveyAnswer(message.Tenant, "slugName", "id"));
        }
开发者ID:hanzzhang,项目名称:developguide,代码行数:29,代码来源:TransferSurveysToSqlAzureCommandFixture.cs


示例12: CreateTestSiteCollection

        internal static string CreateTestSiteCollection(Tenant tenant, string sitecollectionName)
        {
            try
            {
                string devSiteUrl = ConfigurationManager.AppSettings["SPODevSiteUrl"];
                string siteToCreateUrl = GetTestSiteCollectionName(devSiteUrl, sitecollectionName);

                string siteOwnerLogin = ConfigurationManager.AppSettings["SPOUserName"];
                if (TestCommon.AppOnlyTesting())
                {
                    using (var clientContext = TestCommon.CreateClientContext())
                    {
                        List<UserEntity> admins = clientContext.Web.GetAdministrators();
                        siteOwnerLogin = admins[0].LoginName.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries)[2];
                    }
                }

                SiteEntity siteToCreate = new SiteEntity()
                {
                    Url = siteToCreateUrl,
                    Template = "STS#0",
                    Title = "Test",
                    Description = "Test site collection",
                    SiteOwnerLogin = siteOwnerLogin,
                };

                tenant.CreateSiteCollection(siteToCreate, false, true);
                return siteToCreateUrl;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
开发者ID:stijnbrouwers,项目名称:PnP-Sites-Core,代码行数:35,代码来源:FeatureExtensionsTests.cs


示例13: Main

        static void Main(string[] args)
        {

            string SHAREPOINT_PID = "00000003-0000-0ff1-ce00-000000000000";  //This is hard-coded for SharePoint Online (ie - all tenants)
            //The app must have tenant-level permissions and can be installed on any site in the tenancy. You must use the tenant
            //admin site url to get client context.
            var sharePointUrl = new Uri("https://<Office 365 domain>-admin.sharepoint.com");
            string sharePointRealm = TokenHelper.GetRealmFromTargetUrl(sharePointUrl);
            var token = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, sharePointUrl.Authority, sharePointRealm).AccessToken;


            //read the Sites.xml file and then release the file so we can save over it later
            string path = @"C:\<path>\Sites.xml";

            XDocument doc;
            using (var fileStream = System.IO.File.OpenRead(path))
            {
                doc = XDocument.Load(fileStream);
            }

            //get all the requested sites from the Sites.xml file and loop through each for processing
            var sites = doc.Root.Elements("site");
            foreach (var site in sites)
            {
                using (var clientContext = TokenHelper.GetClientContextWithAccessToken(sharePointUrl.ToString(), token))
                {

                    clientContext.Load(clientContext.Web.Lists);
                    clientContext.ExecuteQuery();
                    var siteUrl = site.Attribute("url").Value;
                    var tenant = new Tenant(clientContext);
                    var newSite = new SiteCreationProperties()
                    {
                        Url = siteUrl,
                        Owner = "<admin user>@<Office 365 domain>.onmicrosoft.com",
                        Template = "STS#0",
                        Title = "Batch provisioning test site",
                        //StorageMaximumLevel = 100,
                        //StorageWarningLevel = 300,
                        TimeZoneId = 7,
                        UserCodeMaximumLevel = 7,
                        UserCodeWarningLevel = 1,
                    };

                    var spoOperation = tenant.CreateSite(newSite);
                    clientContext.Load(spoOperation);
                    clientContext.ExecuteQuery();

                    while (!spoOperation.IsComplete)
                    {
                        System.Threading.Thread.Sleep(2000);
                        clientContext.Load(spoOperation);
                        clientContext.ExecuteQuery();

                    }

                }
            }

        }
开发者ID:CherifSy,项目名称:PnP,代码行数:60,代码来源:Program.cs


示例14: GetNextSiteCollectionUrlTenant

        /// <summary>
        /// Returns the next site collection number
        /// </summary>
        /// <param name="siteDirectoryUrl">Url to the site directory site</param>
        /// <returns>The next site collection Url</returns>
        public string GetNextSiteCollectionUrlTenant(ClientContext cc, Web web, ClientContext ccSiteDirectory, Web webSiteDirectory, string siteDirectoryUrl, string siteDirectoryListName, string baseSiteUrl)
        {
            int lastNumber = GetLastSiteCollectionNumber(ccSiteDirectory, webSiteDirectory, siteDirectoryUrl, siteDirectoryListName);

            lastNumber++;

            string nextSiteName = DateTime.Now.ToString("yyyy") + String.Format("{0:0000}", lastNumber);
            string nextUrl = String.Format("{0}{1}", baseSiteUrl, nextSiteName);

            bool validUrl = false;

            Tenant tenant = new Tenant(web.Context);
            while (!validUrl)
            {
                if (!tenant.SiteExists(nextUrl))
                {
                    validUrl = true;
                }
                else
                {
                    lastNumber++;
                    nextSiteName = DateTime.Now.ToString("yyyy") + String.Format("{0:0000}", lastNumber);
                    nextUrl = String.Format("{0}{1}", baseSiteUrl, nextSiteName);
                }
            }

            return nextUrl;
        }
开发者ID:Calisto1980,项目名称:PnP,代码行数:33,代码来源:SiteDirectoryManager.cs


示例15: CreateTenant

        public async Task CreateTenant(CreateTenantInput input)
        {
            //Create tenant
            var tenant = new Tenant(input.TenancyName, input.Name);
            var defaultEdition = await _editionManager.FindByNameAsync(EditionManager.DefaultEditionName);
            if (defaultEdition != null)
            {
                tenant.EditionId = defaultEdition.Id;
            }

            CheckErrors(await TenantManager.CreateAsync(tenant));
            await CurrentUnitOfWork.SaveChangesAsync(); //To get new tenant's id.

            //We are working entities of new tenant, so changing tenant filter
            using (CurrentUnitOfWork.SetFilterParameter(AbpDataFilters.MayHaveTenant, AbpDataFilters.Parameters.TenantId, tenant.Id))
            {
                //Create static roles for new tenant
                CheckErrors(await _roleManager.CreateStaticRoles(tenant.Id));

                await CurrentUnitOfWork.SaveChangesAsync(); //To get static role ids

                //grant all permissions to admin role
                var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);
                await _roleManager.GrantAllPermissionsAsync(adminRole);

                //Create admin user for the tenant
                var adminUser = User.CreateTenantAdminUser(tenant.Id, input.AdminEmailAddress, User.DefaultPassword);
                CheckErrors(await UserManager.CreateAsync(adminUser));
                await CurrentUnitOfWork.SaveChangesAsync(); //To get admin user's id

                //Assign admin user to role!
                CheckErrors(await UserManager.AddToRoleAsync(adminUser.Id, adminRole.Name));
                await CurrentUnitOfWork.SaveChangesAsync();
            }
        }
开发者ID:wddpct,项目名称:SimpleTask,代码行数:35,代码来源:TenantAppService.cs


示例16: CreateSiteCollectionTenant

 public static Guid CreateSiteCollectionTenant(this Web web, string url, string title, string siteOwnerLogin,
                                                 string template, int storageMaximumLevel, int storageWarningLevel,
                                                 int timeZoneId, int userCodeMaximumLevel, int userCodeWarningLevel,
                                                 uint lcid, bool removeFromRecycleBin = false, bool wait = true)
 {
     Tenant tenant = new Tenant(web.Context);
     return tenant.AddSiteCollection(url, title, siteOwnerLogin, template, storageMaximumLevel, storageWarningLevel, timeZoneId, userCodeMaximumLevel, userCodeWarningLevel, lcid, removeFromRecycleBin, wait);
 }
开发者ID:JohnKozell,项目名称:PnP,代码行数:8,代码来源:WebExtensions.cs


示例17: SetNoAccessRedirectUrl

 public static void SetNoAccessRedirectUrl(string host)
 {
      UsingTenantContext(context => {                
         var tenant = new Tenant(context);
         tenant.NoAccessRedirectUrl = string.Format("{0}/{1}", host, "App/index.html#/unlock/");
         context.ExecuteQuery();
     });            
 }
开发者ID:nishantpunetha,项目名称:PnP,代码行数:8,代码来源:UnlockController.cs


示例18: BuildForInternalAsync

        private async Task BuildForInternalAsync(Tenant tenant)
        {
            //Create Organization Units

            var organizationUnits = new List<OrganizationUnit>();

            var producing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Producing");

            var researchAndDevelopment = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Research & Development", producing);

            var ivrProducts = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "IVR Related Products", researchAndDevelopment);
            var voiceTech = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Voice Technologies", researchAndDevelopment);
            var inhouseProjects = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Inhouse Projects", researchAndDevelopment);

            var qualityManagement = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Quality Management", producing);
            var testing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Testing", producing);

            var selling = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Selling");

            var marketing = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Marketing", selling);
            var sales = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Sales", selling);
            var custRelations = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Customer Relations", selling);

            var supporting = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Supporting");

            var buying = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Buying", supporting);
            var humanResources = await CreateAndSaveOrganizationUnit(organizationUnits, tenant, "Human Resources", supporting);

            //Create users

            var users = _randomUserGenerator.GetRandomUsers(RandomHelper.GetRandom(12, 26), tenant.Id);
            foreach (var user in users)
            {
                //Create the user
                await _userManager.CreateAsync(user);
                await CurrentUnitOfWork.SaveChangesAsync();

                //Add to roles
                _userManager.AddToRole(user.Id, StaticRoleNames.Tenants.User);

                //Add to OUs
                var randomOus = RandomHelper.GenerateRandomizedList(organizationUnits).Take(RandomHelper.GetRandom(0, 3));
                foreach (var ou in randomOus)
                {
                    await _userManager.AddToOrganizationUnitAsync(user, ou);
                }

                //Set profile picture
                if (RandomHelper.GetRandom(100) < 70) //A user will have a profile picture in 70% probability.
                {
                    await SetRandomProfilePictureAsync(user);
                }
            }

            //Set a picture to admin!
            var admin = _userManager.FindByName(User.AdminUserName);
            await SetRandomProfilePictureAsync(admin);
        }
开发者ID:Zbun,项目名称:Gld.Activity.Project,代码行数:58,代码来源:TenantDemoDataBuilder.cs


示例19: HandleDefaultGroups

        /// <summary>
        /// With on-premises builds default groups are not created during site provisioning 
        /// so we have to create them.
        /// </summary>
        /// <param name="properties"></param>
        public virtual void HandleDefaultGroups(SiteInformation properties)
        {            
            string _ownerGroupDisplayName =string.Format(PCResources.Site_Web_OwnerGroup_Title, properties.Title);
            string _memberGroupDisplayName = string.Format(PCResources.Site_Web_MemberGroup_Title, properties.Title);
            string _vistorGroupDisplayName = string.Format(PCResources.Site_Web_VisitorGroup_Title, properties.Title);

            UsingContext(ctx =>
            {
                Tenant tenant = new Tenant(ctx);
                var site = tenant.GetSiteByUrl(properties.Url);
                var web = site.RootWeb;

                ctx.Load(web.AssociatedOwnerGroup);
                ctx.Load(web.AssociatedMemberGroup);
                ctx.Load(web.AssociatedVisitorGroup);
                ctx.ExecuteQuery();

                Group _ownerGroup;
                Group _memberGroup;
                Group _visitorGroup;
                if (web.AssociatedOwnerGroup.ServerObjectIsNull == true) {
                    _ownerGroup = web.AddGroup(_ownerGroupDisplayName, PCResources.Site_Web_OwnerGroup_Description, true, false);
                }
                else {
                    _ownerGroup = web.AssociatedOwnerGroup;
                }
                if (web.AssociatedMemberGroup.ServerObjectIsNull == true) {
                    _memberGroup = web.AddGroup(_memberGroupDisplayName, PCResources.Site_Web_MemberGroup_Description, false, false);
                }
                else {
                    _memberGroup = web.AssociatedMemberGroup;
                }
                if (web.AssociatedVisitorGroup.ServerObjectIsNull == true) {
                        _visitorGroup = web.AddGroup(_vistorGroupDisplayName, PCResources.Site_Web_VisitorGroup_Description, false, false );
                }
                else {
                    _visitorGroup = web.AssociatedVisitorGroup;
                }

                web.AssociateDefaultGroups(_ownerGroup, _memberGroup, _visitorGroup);
                ctx.ExecuteQuery();
               Log.Info("Provisioning.Common.OnPremSiteProvisioningService.HandleDefaultGroups", PCResources.Site_Web_DefaultGroups_Created, properties.Url);

                using (var newSiteCtx = ctx.Clone(properties.Url))
                {
                    newSiteCtx.Web.AddPermissionLevelToGroup(_ownerGroupDisplayName, RoleType.Administrator);
                    newSiteCtx.Web.AddPermissionLevelToGroup(_memberGroupDisplayName, RoleType.Editor);
                    newSiteCtx.Web.AddPermissionLevelToGroup(_vistorGroupDisplayName, RoleType.Reader);
                    newSiteCtx.ExecuteQuery();
                   Log.Info("Provisioning.Common.OnPremSiteProvisioningService.HandleDefaultGroups", PCResources.Site_Web_Groups_Security_Permissions_Set, 
                        _ownerGroupDisplayName, 
                        _memberGroupDisplayName, 
                        _vistorGroupDisplayName);
                }
            });

        }
开发者ID:nats31,项目名称:PnP,代码行数:62,代码来源:OnPremSiteProvisioningService.cs


示例20: CreateSiteCollection

        public override void CreateSiteCollection(SiteInformation siteRequest, Template template)
        {
            Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Starting, siteRequest.Url);
 
            UsingContext(ctx =>
            {
                try
                {
                    Stopwatch _timespan = Stopwatch.StartNew();

                    Tenant _tenant = new Tenant(ctx);
                    var _newsite = new SiteCreationProperties();
                    _newsite.Title = siteRequest.Title;
                    _newsite.Url = siteRequest.Url;
                    _newsite.Owner = siteRequest.SiteOwner.Name;
                    _newsite.Template = template.RootTemplate;
                    _newsite.Lcid = siteRequest.Lcid;
                    _newsite.TimeZoneId = siteRequest.TimeZoneId;
                    _newsite.StorageMaximumLevel = template.StorageMaximumLevel;
                    _newsite.StorageWarningLevel = template.StorageWarningLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeMaximumLevel;
                    _newsite.UserCodeMaximumLevel = template.UserCodeWarningLevel;

                    SpoOperation op = _tenant.CreateSite(_newsite);
                    ctx.Load(_tenant);
                    ctx.Load(op, i => i.IsComplete);
                    ctx.ExecuteQuery();

                    while (!op.IsComplete)
                    {
                        //wait 30seconds and try again
                        System.Threading.Thread.Sleep(30000);
                        op.RefreshLoad();
                        ctx.ExecuteQuery();
                    }
                    
                    var _site = _tenant.GetSiteByUrl(siteRequest.Url);
                    var _web = _site.RootWeb;
                    _web.Description = siteRequest.Description;
                    _web.Update();
                    ctx.Load(_web);
                    ctx.ExecuteQuery();

                    _timespan.Stop();
                    Log.TraceApi("SharePoint", "Office365SiteProvisioningService.CreateSiteCollection", _timespan.Elapsed, "SiteUrl={0}", siteRequest.Url);
                }
            
                catch (Exception ex)
                {
                    Log.Error("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection",
                        PCResources.SiteCreation_Creation_Failure, 
                        siteRequest.Url, ex.Message, ex);
                    throw;
                }
               Log.Info("Provisioning.Common.Office365SiteProvisioningService.CreateSiteCollection", PCResources.SiteCreation_Creation_Successful, siteRequest.Url);
            });
        }
开发者ID:sndkr,项目名称:PnP,代码行数:57,代码来源:Office365SiteProvisioningService.cs



注:本文中的Tenant类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Term类代码示例发布时间:2022-05-24
下一篇:
C# TemporaryVariableReference类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap