当前位置: 首页>>代码示例>>C#>>正文


C# Tenant类代码示例

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


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


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