Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 09be720

Browse files
committed
Merge pull request #158 from OfficeDev/dev
December 2016 master merge
2 parents ee4cdff + dbd0488 commit 09be720

File tree

194 files changed

+512
-13948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+512
-13948
lines changed

CONTRIBUTING.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ c:\[YOUR REPO FOLDER]\PnP-PowerShell
4242
The reason for this is that the PnP-PowerShell library will have references to the release and debug builds of the PnP-Sites-Core library.
4343

4444
A few notes:
45-
###Every new cmdlet should provide help and examples###
45+
###Every new cmdlet should provide help and examples
4646
As documentation is autogenerated by building the solution, make sure that you include both help and examples, alike
4747

4848
```csharp
@@ -55,17 +55,19 @@ As documentation is autogenerated by building the solution, make sure that you i
5555
{
5656
}
5757
```
58-
###Most cmdlets will extend SPOWebCmdlet which provides a few helper objects for you to use, like SelectedWeb and ClientContext###
58+
###Most cmdlets will extend SPOWebCmdlet which provides a few helper objects for you to use, like SelectedWeb and ClientContext
5959
As most cmdlets are 'web sensitive' (e.g. you can specify a -Web parameter to point to a different subweb), make sure that you use the correct ClientContext. When a user specifies the -Web parameter
6060
in a cmdlet that extens SPOWebCmdlet, the cmdlet will switch it's internal context to that web, reusing credentials. It is important to use the right context, and the easiest way to do that is to use
6161

6262
```csharp
6363
var context = SelectedWeb.Context;
6464
```
65-
###Cmdlets will have to work both on-premises and in the cloud###
65+
###Cmdlets will have to work both on-premises and in the cloud
6666
You can use preprocessor variables ("CLIENTSDKV15" and "CLIENTSDKV16") to build different cmdlets for the different targets. In cases where it is not possible to provide functionality for either the
6767
cloud or on-premises, make sure to remove the full cmdlet from the compiled solution by having #IF(!CLIENTSDKV15) or #IF(CLIENTSDKV15) as the _first line of the cmdlet, before using statements.
68-
Make the last line, after all code * The verb of a cmdlet (get-, add-, etc.) should follow acceptable cmdlet standards and should be part of one of the built in verbs classes (VerbsCommon, VerbsData, etc.):
68+
69+
See the following example
70+
6971

7072
```csharp
7173
#if !CLIENTSDKV15
@@ -80,6 +82,10 @@ public class MyCmdlet : SPOWebCmdlet
8082

8183
If only parts of a cmdlet require different behaviour based upon the different version of the SDK, you are recommended to use the #CLIENTSDKV15 preprocessor variable throughout your code to exclude or include certain code.
8284

85+
###Cmdlets will have to use common verbs
86+
87+
The verb of a cmdlet (get-, add-, etc.) should follow acceptable cmdlet standards and should be part of one of the built in verbs classes (VerbsCommon, VerbsData, etc.):
88+
8389
##Documentation contributions
8490
If you want to contribute to cmdlet documentation, please do not make a pull request to modify the actual files in the Documentation folder itself. Those files
8591
are automatically generated based upon comments in the actual classes. So if you want to modify documentation and or add an example of a cmdlet, navigate to the

Chocolatey/OfficeDevPnPCmdlets15/OfficeDevPnPPowerShellCommands15.nuspec

-12
This file was deleted.
Binary file not shown.

Chocolatey/OfficeDevPnPCmdlets15/tools/chocolateyInstall.ps1

-3
This file was deleted.

Chocolatey/OfficeDevPnPCmdlets15/tools/chocolateyUninstall.ps1

-2
This file was deleted.
Binary file not shown.

Chocolatey/OfficeDevPnPCmdlets16/officedevpnppowershellcommands16.nuspec

-12
This file was deleted.

Chocolatey/OfficeDevPnPCmdlets16/tools/chocolateyInstall.ps1

-3
This file was deleted.

Chocolatey/OfficeDevPnPCmdlets16/tools/chocolateyUninstall.ps1

-2
This file was deleted.

CmdletHelpGenerator/Program.cs

+12-19
Original file line numberDiff line numberDiff line change
@@ -354,22 +354,20 @@ static void Main(string[] args)
354354
{
355355
string mdFilePath = string.Format("{0}\\Documentation\\{1}{2}.md", solutionDir, cmdletInfo.Verb, cmdletInfo.Noun);
356356
toc.Add(cmdletInfo);
357-
//var existingHashCode = string.Empty;
357+
358358
if (System.IO.File.Exists(mdFilePath))
359359
{
360360
originalMd = System.IO.File.ReadAllText(mdFilePath);
361-
362-
}
363-
var docHeaderBuilder = new StringBuilder();
364361

362+
}
363+
var docBuilder = new StringBuilder();
364+
365+
// Header
365366

366-
// Separate header from body to calculate the hashcode later
367-
docHeaderBuilder.AppendFormat("#{0}{1}", cmdletInfo.FullCommand, Environment.NewLine);
368-
docHeaderBuilder.AppendFormat("*Topic automatically generated on: {0}*{1}", DateTime.Now.ToString("yyyy'-'MM'-'dd"), Environment.NewLine);
369-
docHeaderBuilder.Append(Environment.NewLine);
367+
docBuilder.AppendFormat("#{0}{1}", cmdletInfo.FullCommand, Environment.NewLine);
370368

371369
// Body
372-
var docBuilder = new StringBuilder();
370+
373371
docBuilder.AppendFormat("{0}{1}", cmdletInfo.Description, Environment.NewLine);
374372
docBuilder.AppendFormat("##Syntax{0}", Environment.NewLine);
375373
foreach (var cmdletSyntax in cmdletInfo.Syntaxes.OrderBy(s => s.ParameterSetName))
@@ -433,12 +431,10 @@ static void Main(string[] args)
433431

434432
foreach (var result in diffResults)
435433
{
436-
if (!result.text.Contains("*Topic automatically generated on"))
434+
if (result.operation != DiffMatchPatch.Operation.EQUAL)
437435
{
438-
if (result.operation != DiffMatchPatch.Operation.EQUAL)
439-
{
440-
System.IO.File.WriteAllText(mdFilePath, docHeaderBuilder.Append(docBuilder).ToString());
441-
}
436+
System.IO.File.WriteAllText(mdFilePath, docBuilder.ToString());
437+
break;
442438
}
443439
}
444440
}
@@ -489,12 +485,9 @@ static void Main(string[] args)
489485

490486
foreach (var result in diffResults)
491487
{
492-
if (!result.text.Contains("*Topic automatically generated on"))
488+
if (result.operation != DiffMatchPatch.Operation.EQUAL)
493489
{
494-
if (result.operation != DiffMatchPatch.Operation.EQUAL)
495-
{
496-
System.IO.File.WriteAllText(readmePath, docBuilder.ToString());
497-
}
490+
System.IO.File.WriteAllText(readmePath, docBuilder.ToString());
498491
}
499492
}
500493
}

Commands/Base/SPOCmdlet.cs

-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,5 @@ protected override void ProcessRecord()
8585
}
8686
}
8787

88-
8988
}
9089
}

Commands/Base/SPOnlineConnection.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Microsoft.SharePoint.Client;
2+
using OfficeDevPnP.Core.Diagnostics;
23
using OfficeDevPnP.PowerShell.Commands.Enums;
34
using System;
45
using System.Collections.Generic;

Commands/Branding/GetTheme.cs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Management.Automation;
2+
using Microsoft.SharePoint.Client;
3+
using OfficeDevPnP.PowerShell.CmdletHelpAttributes;
4+
using Newtonsoft.Json;
5+
using OfficeDevPnP.Core.Framework.Provisioning.Model;
6+
7+
namespace OfficeDevPnP.PowerShell.Commands
8+
{
9+
[Cmdlet(VerbsCommon.Get, "SPOTheme")]
10+
[CmdletHelp("Returns the current theme/composed look of the current web.",
11+
Category = CmdletHelpCategory.Branding)]
12+
[CmdletExample(
13+
Code = @"PS:> Get-SPOTheme",
14+
Remarks = "Returns the current composed look of the current web.",
15+
SortOrder = 1)]
16+
[CmdletExample(
17+
Code = @"PS:> Get-SPOTheme -DetectCurrentComposedLook",
18+
Remarks = "Returns the current composed look of the current web, and will try to detect the currently applied composed look based upon the actual site. Without this switch the cmdlet will first check for the presence of a property bag variable called _PnP_ProvisioningTemplateComposedLookInfo that contains composed look information when applied through the provisioning engine or the Set-SPOTheme cmdlet.",
19+
SortOrder = 2)]
20+
public class GetTheme : SPOWebCmdlet
21+
{
22+
private const string PROPBAGKEY = "_PnP_ProvisioningTemplateComposedLookInfo";
23+
24+
[Parameter(Mandatory = false, HelpMessage = "Specify this switch to not use the PnP Provisioning engine based composed look information but try to detect the current composed look as is.")]
25+
public SwitchParameter DetectCurrentComposedLook;
26+
27+
protected override void ExecuteCmdlet()
28+
{
29+
if (SelectedWeb.PropertyBagContainsKey("_PnP_ProvisioningTemplateComposedLookInfo") && !DetectCurrentComposedLook)
30+
{
31+
try
32+
{
33+
WriteWarning("The information presented here is based upon the fact that the theme has been set using either the PnP Provisioning Engine or using the Set-SPOTheme cmdlet. This information is retrieved from a propertybag value and may differ from the actual site.");
34+
var composedLook = JsonConvert.DeserializeObject<ComposedLook>(SelectedWeb.GetPropertyBagValueString("_PnP_ProvisioningTemplateComposedLookInfo", ""));
35+
WriteObject(composedLook);
36+
}
37+
catch
38+
{
39+
var themeEntity = SelectedWeb.GetCurrentComposedLook();
40+
WriteObject(themeEntity);
41+
}
42+
43+
}
44+
else
45+
{
46+
var themeEntity = SelectedWeb.GetCurrentComposedLook();
47+
WriteObject(themeEntity);
48+
}
49+
}
50+
}
51+
}

Commands/Branding/SetMasterPage.cs

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,64 @@
11
using System.Management.Automation;
22
using Microsoft.SharePoint.Client;
33
using OfficeDevPnP.PowerShell.CmdletHelpAttributes;
4+
using System;
45

56
namespace OfficeDevPnP.PowerShell.Commands
67
{
78
[Cmdlet(VerbsCommon.Set, "SPOMasterPage")]
89
[CmdletHelp("Sets the default master page of the current web.",
910
Category = CmdletHelpCategory.Branding)]
1011
[CmdletExample(
11-
Code = @"
12-
PS:> Set-SPOMasterPage -MasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master
13-
", SortOrder = 1)]
12+
Code = @"PS:> Set-SPOMasterPage -MasterPageServerRelativeUrl /sites/projects/_catalogs/masterpage/oslo.master",
13+
Remarks = "Sets the master page based on a server relative URL",
14+
SortOrder = 1)]
15+
[CmdletExample(
16+
Code = @"PS:> Set-SPOMasterPage -MasterPageSiteRelativeUrl _catalogs/masterpage/oslo.master",
17+
Remarks = "Sets the master page based on a site relative URL",
18+
SortOrder = 2)]
1419
public class SetMasterPage : SPOWebCmdlet
1520
{
16-
[Parameter(Mandatory = false)]
21+
[Parameter(Mandatory = false, ParameterSetName = "SERVER")]
1722
[Alias("MasterPageUrl")]
1823
public string MasterPageServerRelativeUrl = null;
1924

20-
[Parameter(Mandatory = false)]
25+
[Parameter(Mandatory = false, ParameterSetName = "SERVER")]
2126
[Alias("CustomMasterPageUrl")]
2227
public string CustomMasterPageServerRelativeUrl = null;
2328

29+
[Parameter(Mandatory = false, ParameterSetName = "SITE")]
30+
public string MasterPageSiteRelativeUrl = null;
31+
32+
[Parameter(Mandatory = false, ParameterSetName = "SITE")]
33+
public string CustomMasterPageSiteRelativeUrl = null;
34+
2435
protected override void ExecuteCmdlet()
2536
{
26-
if (!string.IsNullOrEmpty(MasterPageServerRelativeUrl))
27-
SelectedWeb.SetMasterPageByUrl(MasterPageServerRelativeUrl);
37+
if (ParameterSetName == "SERVER")
38+
{
39+
if (!string.IsNullOrEmpty(MasterPageServerRelativeUrl))
40+
SelectedWeb.SetMasterPageByUrl(MasterPageServerRelativeUrl);
2841

29-
if (!string.IsNullOrEmpty(CustomMasterPageServerRelativeUrl))
30-
SelectedWeb.SetCustomMasterPageByUrl(CustomMasterPageServerRelativeUrl);
42+
if (!string.IsNullOrEmpty(CustomMasterPageServerRelativeUrl))
43+
SelectedWeb.SetCustomMasterPageByUrl(CustomMasterPageServerRelativeUrl);
44+
}
45+
else
46+
{
47+
if (!string.IsNullOrEmpty(MasterPageSiteRelativeUrl))
48+
{
49+
SelectedWeb.SetMasterPageByUrl(GetServerRelativeUrl(MasterPageSiteRelativeUrl));
50+
}
51+
if (!string.IsNullOrEmpty(CustomMasterPageSiteRelativeUrl))
52+
{
53+
SelectedWeb.SetCustomMasterPageByUrl(GetServerRelativeUrl(CustomMasterPageSiteRelativeUrl));
54+
}
55+
}
56+
}
3157

58+
private string GetServerRelativeUrl(string url)
59+
{
60+
var serverRelativeUrl = SelectedWeb.EnsureProperty(w => w.ServerRelativeUrl);
61+
return UrlUtility.Combine(serverRelativeUrl, url);
3262
}
3363
}
3464
}

Commands/Branding/SetTheme.cs

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
using System.Management.Automation;
22
using Microsoft.SharePoint.Client;
33
using OfficeDevPnP.PowerShell.CmdletHelpAttributes;
4+
using Newtonsoft.Json;
5+
using OfficeDevPnP.Core.Framework.Provisioning.Model;
46

57
namespace OfficeDevPnP.PowerShell.Commands
68
{
79
[Cmdlet(VerbsCommon.Set, "SPOTheme")]
8-
[CmdletHelp("Sets the theme of the current web.",
10+
[CmdletHelp("Sets the theme of the current web.",
911
Category = CmdletHelpCategory.Branding)]
1012
[CmdletExample(
1113
Code = @"PS:> Set-SPOTheme -ColorPaletteUrl /_catalogs/theme/15/company.spcolor",
1214
SortOrder = 1)]
1315
public class SetTheme : SPOWebCmdlet
1416
{
17+
private const string PROPBAGKEY = "_PnP_ProvisioningTemplateComposedLookInfo";
18+
1519
[Parameter(Mandatory = false)]
1620
public string ColorPaletteUrl = null;
1721

@@ -26,8 +30,39 @@ public class SetTheme : SPOWebCmdlet
2630

2731
protected override void ExecuteCmdlet()
2832
{
33+
2934
SelectedWeb.ApplyTheme(ColorPaletteUrl, FontSchemeUrl, BackgroundImageUrl, ShareGenerated);
35+
3036
ClientContext.ExecuteQueryRetry();
37+
38+
var composedLook = new ComposedLook();
39+
// Set the corresponding property bag value which is used by the provisioning engine
40+
if (SelectedWeb.PropertyBagContainsKey(PROPBAGKEY))
41+
{
42+
composedLook = JsonConvert.DeserializeObject<ComposedLook>(SelectedWeb.GetPropertyBagValueString(PROPBAGKEY, ""));
43+
44+
}
45+
else
46+
{
47+
composedLook = new ComposedLook();
48+
composedLook.BackgroundFile = "";
49+
SelectedWeb.EnsureProperty(w => w.AlternateCssUrl);
50+
composedLook.AlternateCSS = SelectedWeb.AlternateCssUrl;
51+
composedLook.ColorFile = "";
52+
SelectedWeb.EnsureProperty(w => w.MasterUrl);
53+
composedLook.MasterPage = SelectedWeb.MasterUrl;
54+
composedLook.FontFile = "";
55+
SelectedWeb.EnsureProperty(w => w.SiteLogoUrl);
56+
composedLook.SiteLogo = SelectedWeb.SiteLogoUrl;
57+
}
58+
59+
composedLook.Name = composedLook.Name ?? "Custom by PnP PowerShell";
60+
composedLook.ColorFile = ColorPaletteUrl ?? composedLook.ColorFile;
61+
composedLook.FontFile = FontSchemeUrl ?? composedLook.FontFile;
62+
composedLook.BackgroundFile = BackgroundImageUrl ?? composedLook.BackgroundFile;
63+
var composedLookJson = JsonConvert.SerializeObject(composedLook);
64+
65+
SelectedWeb.SetPropertyBagValue(PROPBAGKEY, composedLookJson);
3166
}
3267
}
3368
}
Binary file not shown.
Binary file not shown.

Commands/OfficeDevPnP.PowerShell.Commands.csproj

+1-8
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@
125125
<SpecificVersion>False</SpecificVersion>
126126
<HintPath>..\..\PnP-Sites-Core\Assemblies\16\Microsoft.SharePoint.Client.WorkflowServices.dll</HintPath>
127127
</Reference>
128-
<Reference Include="Microsoft.Office.Client.Education, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
129-
<SpecificVersion>False</SpecificVersion>
130-
<HintPath>..\ReferenceAssemblies\16\Microsoft.Office.Client.Education.dll</HintPath>
131-
</Reference>
132128
</ItemGroup>
133129
</When>
134130
<Otherwise>
@@ -181,10 +177,6 @@
181177
<SpecificVersion>False</SpecificVersion>
182178
<HintPath>..\..\PnP-Sites-Core\Assemblies\15\Microsoft.SharePoint.Client.WorkflowServices.dll</HintPath>
183179
</Reference>
184-
<Reference Include="Microsoft.Office.Client.Education, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
185-
<SpecificVersion>False</SpecificVersion>
186-
<HintPath>..\ReferenceAssemblies\15\Microsoft.Office.Client.Education.dll</HintPath>
187-
</Reference>
188180
</ItemGroup>
189181
</Otherwise>
190182
</Choose>
@@ -278,6 +270,7 @@
278270
<Compile Include="Branding\ApplyProvisioningTemplate.cs" />
279271
<Compile Include="Branding\GetProvisioningTemplate.cs" />
280272
<Compile Include="Branding\NewProvisioningTemplateFromFolder.cs" />
273+
<Compile Include="Branding\GetTheme.cs" />
281274
<Compile Include="ContentTypes\RemoveContentTypeFromList.cs" />
282275
<Compile Include="ContentTypes\SetDefaultContentTypeToList.cs" />
283276
<Compile Include="ContentTypes\AddContentTypeToList.cs" />

Commands/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@
3939
// You can specify all the values or you can default the Build and Revision Numbers
4040
// by using the '*' as shown below:
4141
// [assembly: AssemblyVersion("1.0.*")]
42-
[assembly: AssemblyVersion("1.8.1115.0")]
43-
[assembly: AssemblyFileVersion("1.8.1115.0")]
42+
[assembly: AssemblyVersion("1.9.1215.0")]
43+
[assembly: AssemblyFileVersion("1.9.1215.0")]

0 commit comments

Comments
 (0)