/// <summary>
 /// Provide a DB context object for client code to execute database operations
 /// </summary>
 /// <param name="action">The ad-hoc database operation which takes a GovernanceDbContext instance</param>
 public void UsingContext(Action <GovernanceDbContext> action)
 {
     using (var context = new GovernanceDbContext(ConnectionString))
     {
         action(context);
     }
 }
示例#2
0
 /// <summary>
 /// Provide a DB context object for client code to execute database operations
 /// </summary>
 /// <param name="action">The ad-hoc database operation which takes a GovernanceDbContext instance</param>
 public void UsingContext(Action<GovernanceDbContext> action)
 {
     using (var context = new GovernanceDbContext(ConnectionString))
     {
         action(context);
     }
 }
 public void DropCreateDbTest()
 {
     Database.SetInitializer<GovernanceDbContext>(new DropCreateDatabaseIfModelChanges<GovernanceDbContext>());
     var connectionString = ConfigurationManager.ConnectionStrings["default"].ConnectionString;
     var context = new GovernanceDbContext(connectionString);
     var site = context.Sites.FirstOrDefault();
     Debug.WriteLine(connectionString);
     Assert.Inconclusive(
         site != null ? "No changed in data model!" : "DB is empty now!");
 }
示例#4
0
  /// <summary>
  /// Go thru each site collection records from DB
  /// </summary>
  /// <param name="dbContext">The database context</param>
  /// <param name="siteList">The site collection record list</param>
 protected override void ResolveSitesFromDb(GovernanceDbContext dbContext, List<string> siteList)
 {
     int maxPage;
     int page = 1;
     do
     {
         var sites = dbContext.GetAllSites(page, PageSize, out maxPage);
         foreach (var site in sites)
         {
             siteList.Add(site.Url);
         }
     }
     while (page++ < maxPage);
 }
 /// <summary>
 /// Query DB for all root web or sub web records that matches the PreprocessPredictor criteria of the the attached site policy
 /// </summary>
 /// <param name="dbContext">The db context object</param>
 /// <param name="webList">The web records list</param>
 protected override void ResolveSitesFromDb(GovernanceDbContext dbContext, List<string> webList)
 {
     int maxPage;
     int page = 1;
     do
     {
         var webs = dbContext.GetAllWebs(
             page, PageSize, out maxPage, new[] { Policy.PreprocessPredictor });
         foreach (var web in webs)
         {
             webList.Add(web.Url);
         }
     }
     while (page++ < maxPage);
 }
示例#6
0
 /// <summary>
 /// Query database by union each policy's noncompliance predictor criteria
 /// </summary>
 /// <param name="dbContext">The database context object</param>
 /// <param name="siteList">The site collection record list</param>
 protected override void ResolveSitesFromDb(GovernanceDbContext dbContext, List<string> siteList)
 {
     int maxPage;
     int page = 1;
     do
     {
         var expressions = from policy in PolicyManager.GetAllGovernancePolicy()
                           select policy.NoncompliancePredictor;
         var sites = dbContext.GetAllSites(
             page, PageSize, out maxPage, Includes, expressions.ToArray());
         foreach (var site in sites)
         {
             siteList.Add(site.Url);
         }
     }
     while (page++ < maxPage);
 }
 public void AddOrUpdateSiteTest()
 {
     string connetionString = ConfigurationManager.ConnectionStrings["default"].ConnectionString;
     var context = new GovernanceDbContext(connetionString);
     string url = "https://microsoftspoppe.sharepoint.com/teams/TestSite";
     var existed = context.GetSite(url);
     int existedId = existed == null ? 0 : existed.Id;
     var site = new SiteInformation()
     {
         Administrators = new List<SiteUser>() {
             new SiteUser()
             {
                 Email = "*****@*****.**",
                 LoginName = "*****@*****.**",
             }
         },
         AudienceScope = "Enterprise",
         BusinessImpact = "MBI",
         CreatedBy = "*****@*****.**",
         CreatedDate = DateTime.UtcNow,
         ComplianceState = new ComplianceState(),
         Description = "Test Save Site",
         Guid = Guid.NewGuid(),
         Lcid = 1099,
         LastBusinessImpact = "LBI",
         ModifiedBy = "*****@*****.**",
         ModifiedDate = DateTime.UtcNow,
         SharingStatus = 0,
         SiteMetadata = new SiteMetadata[] {
             new SiteMetadata()
             {
                 MetadataKey = "TargetedAudience",
                 MetadataValue = "PM",
             }
         },
         StorageMaximumLevel = 500,
         StorageWarningLevel = 400,
         Template = "STS#0",
         TimeZoneId = 13,
         Title = "Test Save Site",
         Url = url,
     };
     context.SaveSite(site);
     Assert.AreEqual(existedId+1, site.Id);
 }
示例#8
0
 /// <summary>
 /// Query site collection records as the sites to process for the timer job 
 /// </summary>
 /// <param name="dbContext">The database context</param>
 /// <param name="siteList">The site collection record list</param>
 protected abstract void ResolveSitesFromDb(GovernanceDbContext dbContext, List<string> siteList);