Al momento le wp non funzionano
This commit is contained in:
Kalarumeth
2022-08-02 09:53:18 +02:00
parent 0cc1b8f0ee
commit a4f46cb24a
8 changed files with 1597 additions and 711 deletions
+128 -32
View File
@@ -1,18 +1,16 @@
using Microsoft.SharePoint;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet;
using Microsoft.Online.SharePoint.TenantAdministration;
using Microsoft.PowerPlatform.Dataverse.Client;
using System;
using Microsoft.SharePoint.Client.WebParts;
using OfficeDevPnP.Core.Pages;
using System.Collections.Concurrent;
using System.Net;
using System.Net.Http;
using System.Security;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using SP = Microsoft.SharePoint.Client;
using spc = SharePointOnlineUtils.SharePointCustomOperation;
namespace SharePointOnlineUtils
{
@@ -41,6 +39,7 @@ namespace SharePointOnlineUtils
public class Program
{
public static async Task Main()
{
#region SPO Credential
@@ -88,7 +87,7 @@ namespace SharePointOnlineUtils
string year = DateTime.Now.Year.ToString();
string projectsYear = $"Commesse{year}";
string listTitle = $"Lista Commesse {year}";
string ssProjectTitle = "CT0011";
string ssProjectTitle = "CT0001";
Uri site = new Uri($"{siteCollection}/sites/{projectsYear}");
Uri subSite = new Uri($"{siteCollection}/sites/{projectsYear}/{ssProjectTitle}");
@@ -97,20 +96,22 @@ namespace SharePointOnlineUtils
var ctx = authMgr.GetContext(site, user, psw);
var sCtx = authMgr.GetContext(subSite, user, psw);
if (SharePointCustomOperation.SiteExist(ctx) == true && SharePointCustomOperation.SiteExist(sCtx) == false)
{
#region Site Context
SharePointCustomOperation.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
SharePointCustomOperation.OnenoteSPFeature(ctx, year, ssProjectTitle);
SharePointCustomOperation.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
#endregion
//if (SharePointCustomOperation.SiteExist(ctx) == true && SharePointCustomOperation.SiteExist(sCtx) == false)
//{
// #region Site Context
// SharePointCustomOperation.ProjectSubSite(ssProjectTitle, projectsYear, ctx);
// SharePointCustomOperation.OnenoteSPFeature(ctx, year, ssProjectTitle);
// SharePointCustomOperation.ProjectListEntry(ssProjectTitle, listTitle, projectsYear, ctx);
// #endregion
#region SubSite Context
SharePointCustomOperation.ProjectDocLib(ssProjectTitle, sCtx);
SharePointCustomOperation.ProjectSubProjList(ssProjectTitle, sCtx);
SharePointCustomOperation.ProjectQuickMenu(ssProjectTitle, subSite.ToString(), sCtx);
#endregion
}
// #region SubSite Context
// SharePointCustomOperation.ProjectDocLib(ssProjectTitle, sCtx);
// SharePointCustomOperation.ProjectSubProjList(ssProjectTitle, sCtx);
// SharePointCustomOperation.ProjectQuickMenu(ssProjectTitle, subSite.ToString(), sCtx);
// #endregion
//}
spc.WebPartPage(sCtx);
}
@@ -794,6 +795,7 @@ namespace SharePointOnlineUtils
#region Rights
public static async Task DomainGroupRights(ClientContext ctx, string docLibName)
{
#region Groups & Privileges
Dictionary<string, string> itsADGruopRole = new Dictionary<string, string>()
{
{ "ITS-SPO-PROJ-OWNER", "Full Control" },
@@ -809,13 +811,15 @@ namespace SharePointOnlineUtils
{ "ITS-SPO-PROJ-SALES-MODIFY", "Edit" },
{ "ITS-SPO-PROJ-SALES-READ", "Read" }
};
#endregion
Console.WriteLine("> Inizializzata la fase di assegnazione dei ruoli.");
if (string.IsNullOrEmpty(docLibName))
try
{
try
if (string.IsNullOrEmpty(docLibName))
{
#region Site Permission
Web web = ctx.Web;
foreach (KeyValuePair<string, string> role in itsADGruopRole)
@@ -833,13 +837,11 @@ namespace SharePointOnlineUtils
ctx.ExecuteQuery();
Console.WriteLine("> Completata la fase di assegnazione dei ruoli.");
#endregion
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )"); return; }
}
else
{
try
else
{
#region DocLib Permission
Web web = ctx.Web;
List list = web.Lists.GetByTitle(docLibName);
ctx.Load(list);
@@ -862,9 +864,102 @@ namespace SharePointOnlineUtils
}
ctx.ExecuteQuery();
Console.WriteLine($"> Completata la fase di assegnazione dei ruoli in {docLibName}.");
#endregion
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} {ex.StackTrace} )"); return; }
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} {ex.StackTrace} )"); return; }
}
#endregion
#region WebParts
protected void ReplaceWebPartsWithAppParts(ClientContext ctx)
{
Web web = ctx.Web;
// Get properties from the Web.
ctx.Load(web,
w => w.ServerRelativeUrl,
w => w.AllProperties);
ctx.ExecuteQuery();
// Read the Pages library name from the Web properties.
var pagesListName = web.AllProperties["__pageslistname"] as string;
var list = web.Lists.GetByTitle(pagesListName);
var items = list.GetItems(CamlQuery.CreateAllItemsQuery());
// Get the file associated with each list item.
ctx.Load(items, i => i.Include(item => item.File));
ctx.ExecuteQuery();
// Iterate through all pages in the Pages list.
foreach (var item in items)
{
FindWebPartToReplace(item, ctx, web);
}
}
private static void FindWebPartToReplace(ListItem item, ClientContext clientContext, Web web)
{
SP.File page = item.File;
// Requires Full Control permissions on the Web.
string oldWebPartTitle = "";
LimitedWebPartManager webPartManager = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
clientContext.Load(webPartManager,
wpm => wpm.WebParts,
wpm => wpm.WebParts.Include(
wp => wp.WebPart.Title));
clientContext.ExecuteQuery();
foreach (var oldWebPartDefinition in webPartManager.WebParts)
{
var oldWebPart = oldWebPartDefinition.WebPart;
// Modify the web part if we find an old web part with the same title.
if (oldWebPart.Title != oldWebPartTitle) continue;
ReplaceWebPart(web, item, webPartManager, oldWebPartDefinition, clientContext, page);
}
}
private static void ReplaceWebPart(Web web, ListItem item, LimitedWebPartManager webPartManager, WebPartDefinition oldWebPartDefinition, ClientContext clientContext, SP.File page)
{
string appPartXml = "";
// Create a web part definition using the XML string.
var definition = webPartManager.ImportWebPart(appPartXml);
webPartManager.AddWebPart(definition.WebPart, "RightColumn", 0);
// Delete the old web part from the page.
oldWebPartDefinition.DeleteWebPart();
clientContext.Load(page,
p => p.CheckOutType,
p => p.Level);
clientContext.ExecuteQuery();
}
public static void WebPartPage(ClientContext ctx)
{
try
{
ClientSidePage pageWebParts = ctx.Web.AddClientSidePage("PageWithSections.aspx", true);
pageWebParts.AddSection(CanvasSectionTemplate.OneColumnFullWidth, 5);
pageWebParts.Save();
var components = pageWebParts.AvailableClientSideComponents();
var webPartToAdd = components.Where(wp => wp.ComponentType == 1 && wp.Name == "MYWEBPARTNAME").FirstOrDefault();
if (webPartToAdd != null)
{
ClientSideWebPart clientWp = new ClientSideWebPart(webPartToAdd) { Order = 1 };
pageWebParts.AddControl(clientWp, pageWebParts.Sections[0].Columns[2]);
}
pageWebParts.Save();
ctx.ExecuteQuery();
}
catch (Exception ex) { Console.WriteLine($"!> Qualcosa è andato storto... ( {ex.Message} )\n[\n{ex.StackTrace}\n]"); return; }
}
#endregion
}
@@ -877,12 +972,13 @@ namespace SharePointOnlineUtils
private const string defaultAADAppId = "46e6296e-176f-4ebb-a14b-bdd5678c16e6";
// Token cache handling
private static readonly SemaphoreSlim semaphoreSlimTokens = new SemaphoreSlim(1);
private AutoResetEvent tokenResetEvent = null;
private readonly ConcurrentDictionary<string, string> tokenCache = new ConcurrentDictionary<string, string>();
private bool disposedValue;
#region CSOM
internal class TokenWaitInfo
{
public RegisteredWaitHandle Handle = null;
@@ -965,7 +1061,7 @@ namespace SharePointOnlineUtils
else
{
//Console.WriteLine($"Returning token from cache for resource {resourceUri.DnsSafeHost} and user {userPrincipalName}");
Console.WriteLine("OK - Execution Querry");
Console.WriteLine("OK - Execution Query");
return accessTokenFromCache;
}
}
@@ -1056,6 +1152,6 @@ namespace SharePointOnlineUtils
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
#endregion
}
}
File diff suppressed because it is too large Load Diff
@@ -8,9 +8,14 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.7" />
<PackageReference Include="Microsoft.PowerPlatform.Dataverse.Client" Version="1.0.9" />
<PackageReference Include="Microsoft.SharePoint.Client" Version="14.0.4762.1000" />
<PackageReference Include="Microsoft.SharePointOnline.CSOM" Version="16.1.22615.12000" />
<PackageReference Include="PnP.Core" Version="1.7.0" />
<PackageReference Include="PnP.Core.Admin" Version="1.7.0" />
<PackageReference Include="PnP.Core.Auth" Version="1.7.0" />
<PackageReference Include="SharePointPnP.IdentityModel.Extensions" Version="1.2.4" />
<PackageReference Include="SharePointPnPCoreOnline" Version="3.28.2012" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.21.0" />
</ItemGroup>
@@ -92,9 +92,7 @@ C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Ide
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\System.Text.Json.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Caching.Abstractions.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Caching.Memory.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Configuration.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Configuration.Abstractions.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Configuration.Binder.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.DependencyInjection.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.Extensions.Http.dll
@@ -135,10 +133,24 @@ C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\ru\System.Pri
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\tr\System.Private.ServiceModel.resources.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\zh-Hans\System.Private.ServiceModel.resources.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\zh-Hant\System.Private.ServiceModel.resources.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netcoreapp3.0\Microsoft.Win32.SystemEvents.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\unix\lib\netcoreapp3.0\System.Drawing.Common.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netcoreapp3.0\System.Drawing.Common.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netstandard2.0\System.Runtime.Caching.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netcoreapp3.0\System.Security.Cryptography.Pkcs.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netstandard2.0\System.Security.Cryptography.ProtectedData.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\netcoreapp3.0\System.Windows.Extensions.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.ApplicationInsights.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Authorization.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Components.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Components.Authorization.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Components.Forms.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Components.Web.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Components.WebAssembly.Authentication.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.AspNetCore.Metadata.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\Microsoft.JSInterop.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\PnP.Core.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\PnP.Core.Admin.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\PnP.Core.Auth.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\System.IO.Pipelines.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\TimeZoneConverter.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\net6.0\Microsoft.Win32.SystemEvents.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\unix\lib\net6.0\System.Drawing.Common.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\net6.0\System.Drawing.Common.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\net6.0\System.Security.Cryptography.ProtectedData.dll
C:\Sources\VS\console_spo_utils\console_spo_utils\bin\Debug\net6.0\runtimes\win\lib\net6.0\System.Windows.Extensions.dll
@@ -14,13 +14,11 @@
"outputPath": "C:\\Sources\\VS\\console_spo_utils\\console_spo_utils\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\Offline Packages",
"C:\\Program Files\\DevExpress 22.1\\Components\\Offline Packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\cbo\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 21.2.config",
"C:\\Program Files (x86)\\NuGet\\Config\\DevExpress 22.1.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
@@ -29,7 +27,6 @@
"net6.0"
],
"sources": {
"C:\\Program Files (x86)\\DevExpress 21.2\\Components\\System\\Components\\Packages": {},
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"C:\\Program Files\\DevExpress 22.1\\Components\\System\\Components\\Packages": {},
"https://api.nuget.org/v3/index.json": {}
@@ -50,6 +47,10 @@
"net6.0": {
"targetAlias": "net6.0",
"dependencies": {
"Microsoft.AspNetCore.Components.WebAssembly.Authentication": {
"target": "Package",
"version": "[6.0.7, )"
},
"Microsoft.PowerPlatform.Dataverse.Client": {
"target": "Package",
"version": "[1.0.9, )"
@@ -62,6 +63,22 @@
"target": "Package",
"version": "[16.1.22615.12000, )"
},
"PnP.Core": {
"target": "Package",
"version": "[1.7.0, )"
},
"PnP.Core.Admin": {
"target": "Package",
"version": "[1.7.0, )"
},
"PnP.Core.Auth": {
"target": "Package",
"version": "[1.7.0, )"
},
"SharePointPnP.IdentityModel.Extensions": {
"target": "Package",
"version": "[1.2.4, )"
},
"SharePointPnPCoreOnline": {
"target": "Package",
"version": "[3.28.2012, )"
@@ -5,14 +5,16 @@
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\cbo\.nuget\packages\;C:\Program Files (x86)\DevExpress 21.2\Components\Offline Packages;C:\Program Files\DevExpress 22.1\Components\Offline Packages;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\cbo\.nuget\packages\;C:\Program Files\DevExpress 22.1\Components\Offline Packages;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.2.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\cbo\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\DevExpress 21.2\Components\Offline Packages\" />
<SourceRoot Include="C:\Program Files\DevExpress 22.1\Components\Offline Packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.components.webassembly.authentication\6.0.7\buildTransitive\Microsoft.AspNetCore.Components.WebAssembly.Authentication.props" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.components.webassembly.authentication\6.0.7\buildTransitive\Microsoft.AspNetCore.Components.WebAssembly.Authentication.props')" />
</ImportGroup>
</Project>
@@ -2,5 +2,6 @@
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<Import Project="$(NuGetPackageRoot)system.text.json\6.0.2\build\System.Text.Json.targets" Condition="Exists('$(NuGetPackageRoot)system.text.json\6.0.2\build\System.Text.Json.targets')" />
<Import Project="$(NuGetPackageRoot)microsoft.aspnetcore.components.analyzers\6.0.7\buildTransitive\netstandard2.0\Microsoft.AspNetCore.Components.Analyzers.targets" Condition="Exists('$(NuGetPackageRoot)microsoft.aspnetcore.components.analyzers\6.0.7\buildTransitive\netstandard2.0\Microsoft.AspNetCore.Components.Analyzers.targets')" />
</ImportGroup>
</Project>
File diff suppressed because it is too large Load Diff