Skip to content

Commit 1fa5d43

Browse files
committed
Minor changes related to custom FBA SharePoint authentication
1 parent e903d77 commit 1fa5d43

File tree

9 files changed

+99
-28
lines changed

9 files changed

+99
-28
lines changed

src/SPCoder.RunnerApp/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<appender-ref ref="RollingLogFileAppender" />
1010
</logger>
1111
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
12-
<file value="Log\spcoder-runner.log" />
12+
<file type="log4net.Util.PatternString" value="Log\spcoder-runner-[%processid]-%property{RunnerId}.log" />
1313
<appendToFile value="true" />
1414
<rollingStyle value="Composite" />
1515
<datePattern value="yyyyMMdd" />
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
//here you can write your code
2-
Console.WriteLine("code");
2+
Console.WriteLine("code");
3+
4+
//This shows how you can access the Arguments array from the scripts
5+
//LogInfo("code");
6+
//if (Arguments != null && Arguments.Length > 0)
7+
//{
8+
// LogInfo(Arguments[0]);
9+
// Console.WriteLine(Arguments[0]);
10+
//}

src/SPCoder.RunnerApp/Program.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,22 @@ class Program
1313
{
1414
static void Main(string[] args)
1515
{
16+
if (args != null && args.Length > 0)
17+
{
18+
log4net.GlobalContext.Properties["RunnerId"] = args[0];
19+
}
1620
XmlConfigurator.Configure();
17-
21+
SPCoderLogging.Logger.Info("Start");
1822
RoslynExecutor re = new RoslynExecutor();
23+
re.Arguments = args;
1924
re.Execute();
25+
SPCoderLogging.Logger.Info("Finish");
2026
}
2127
}
2228

2329
public class RoslynExecutor
2430
{
31+
public string[] Arguments = null;
2532
public List<string> FilesRegisteredForExecution = new List<string>();
2633
public static ScriptState<object> ScriptStateCSharp = null;
2734
public void Execute()
@@ -44,7 +51,10 @@ public void Execute()
4451
}
4552
catch (Exception ex)
4653
{
47-
SPCoderLogging.Logger.Error("Error during execution of FilesRegisteredForExecution: " + script + "; " + ex.Message);
54+
SPCoderLogging.Logger.Error("Error during execution of FilesRegisteredForExecution: " + script + "; " + ex.Message + "; " + ex.StackTrace);
55+
Console.Error.WriteLine("Error during execution of FilesRegisteredForExecution: " + script + "; " + ex.Message + "; " + ex.StackTrace);
56+
//Environment.ExitCode = 500;
57+
//Environment.Exit(500);
4858
}
4959
}
5060
}
@@ -91,14 +101,24 @@ public object ExecuteScriptCSharp(string script, int timesCalled = 0)
91101
}
92102
}
93103

94-
public void LogError(string err)
104+
public static void LogError(string err)
95105
{
96106
SPCoderLogging.Logger.Error(err);
97107
}
98108

99-
public void LogInfo(string err)
109+
public static void LogError(object err, Exception exc)
110+
{
111+
SPCoderLogging.Logger.Error(err, exc);
112+
}
113+
114+
public static void LogInfo(string err)
100115
{
101116
SPCoderLogging.Logger.Info(err);
102117
}
118+
119+
public static void LogWarning(string text)
120+
{
121+
SPCoderLogging.Logger.Warn(text);
122+
}
103123
}
104124
}

src/SPCoder.RunnerApp/SPCoder.RunnerApp.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
77
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
88
<ProjectGuid>{F30ABA79-A45A-428C-ADB2-3FC538F3E255}</ProjectGuid>
9-
<OutputType>Exe</OutputType>
9+
<OutputType>WinExe</OutputType>
1010
<RootNamespace>SPCoder.RunnerApp</RootNamespace>
1111
<AssemblyName>SPCoder.RunnerApp</AssemblyName>
1212
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
@@ -25,6 +25,7 @@
2525
<DefineConstants>DEBUG;TRACE</DefineConstants>
2626
<ErrorReport>prompt</ErrorReport>
2727
<WarningLevel>4</WarningLevel>
28+
<Prefer32Bit>false</Prefer32Bit>
2829
</PropertyGroup>
2930
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3031
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,6 +36,9 @@
3536
<ErrorReport>prompt</ErrorReport>
3637
<WarningLevel>4</WarningLevel>
3738
</PropertyGroup>
39+
<PropertyGroup>
40+
<StartupObject />
41+
</PropertyGroup>
3842
<ItemGroup>
3943
<Reference Include="log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
4044
<HintPath>..\packages\log4net.2.0.8\lib\net45-full\log4net.dll</HintPath>
@@ -127,7 +131,9 @@
127131
<None Include="Code\code.csx">
128132
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
129133
</None>
130-
<None Include="packages.config" />
134+
<None Include="packages.config">
135+
<SubType>Designer</SubType>
136+
</None>
131137
</ItemGroup>
132138
<ItemGroup>
133139
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Net;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace SPCoder.SharePoint.Client.ListsWebService
9+
{
10+
public partial class Lists : System.Web.Services.Protocols.SoapHttpClientProtocol
11+
{
12+
protected override WebRequest GetWebRequest(Uri uri)
13+
{
14+
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);
15+
// here you can set the custom headers if it is necessary for FBA
16+
//request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
17+
return request;
18+
}
19+
}
20+
}

src/SPCoder.SharePoint.Client/SPCoder.SharePoint.Client.csproj

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
<WarningLevel>4</WarningLevel>
3232
</PropertyGroup>
3333
<ItemGroup>
34+
<Reference Include="AngleSharp, Version=0.9.9.0, Culture=neutral, PublicKeyToken=e83494dcdc6d31ea, processorArchitecture=MSIL">
35+
<HintPath>..\packages\AngleSharp.0.9.9\lib\net45\AngleSharp.dll</HintPath>
36+
</Reference>
3437
<Reference Include="Camlex.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=831792d54d5285b7, processorArchitecture=MSIL">
3538
<HintPath>..\packages\Camlex.Client.dll.4.0.0\lib\net45\Camlex.Client.dll</HintPath>
3639
</Reference>
@@ -85,58 +88,58 @@
8588
<HintPath>..\packages\Microsoft.IdentityModel.Tokens.5.2.4\lib\net45\Microsoft.IdentityModel.Tokens.dll</HintPath>
8689
</Reference>
8790
<Reference Include="Microsoft.Office.Client.Policy, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
88-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.Office.Client.Policy.dll</HintPath>
91+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.Office.Client.Policy.dll</HintPath>
8992
</Reference>
9093
<Reference Include="Microsoft.Office.Client.TranslationServices, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
91-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.Office.Client.TranslationServices.dll</HintPath>
94+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.Office.Client.TranslationServices.dll</HintPath>
9295
</Reference>
9396
<Reference Include="Microsoft.Office.SharePoint.Tools, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
94-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.Office.SharePoint.Tools.dll</HintPath>
97+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.Office.SharePoint.Tools.dll</HintPath>
9598
</Reference>
9699
<Reference Include="Microsoft.Online.SharePoint.Client.Tenant, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
97-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.Online.SharePoint.Client.Tenant.dll</HintPath>
100+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.Online.SharePoint.Client.Tenant.dll</HintPath>
98101
</Reference>
99102
<Reference Include="Microsoft.ProjectServer.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
100-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.ProjectServer.Client.dll</HintPath>
103+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.ProjectServer.Client.dll</HintPath>
101104
</Reference>
102105
<Reference Include="Microsoft.SharePoint.Client, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
103-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.dll</HintPath>
106+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.dll</HintPath>
104107
</Reference>
105108
<Reference Include="Microsoft.SharePoint.Client.DocumentManagement, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
106-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.DocumentManagement.dll</HintPath>
109+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.DocumentManagement.dll</HintPath>
107110
</Reference>
108111
<Reference Include="Microsoft.SharePoint.Client.Publishing, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
109-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Publishing.dll</HintPath>
112+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Publishing.dll</HintPath>
110113
</Reference>
111114
<Reference Include="Microsoft.SharePoint.Client.Runtime, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
112-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Runtime.dll</HintPath>
115+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Runtime.dll</HintPath>
113116
</Reference>
114117
<Reference Include="Microsoft.SharePoint.Client.Runtime.Windows, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
115-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Runtime.Windows.dll</HintPath>
118+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Runtime.Windows.dll</HintPath>
116119
</Reference>
117120
<Reference Include="Microsoft.SharePoint.Client.Search, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
118-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Search.dll</HintPath>
121+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Search.dll</HintPath>
119122
</Reference>
120123
<Reference Include="Microsoft.SharePoint.Client.Search.Applications, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
121-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Search.Applications.dll</HintPath>
124+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Search.Applications.dll</HintPath>
122125
</Reference>
123126
<Reference Include="Microsoft.SharePoint.Client.Taxonomy, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
124-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.Taxonomy.dll</HintPath>
127+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.Taxonomy.dll</HintPath>
125128
</Reference>
126129
<Reference Include="Microsoft.SharePoint.Client.UserProfiles, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
127-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.UserProfiles.dll</HintPath>
130+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.UserProfiles.dll</HintPath>
128131
</Reference>
129132
<Reference Include="Microsoft.SharePoint.Client.WorkflowServices, Version=16.1.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
130-
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20017.12000\lib\net45\Microsoft.SharePoint.Client.WorkflowServices.dll</HintPath>
133+
<HintPath>..\packages\Microsoft.SharePointOnline.CSOM.16.1.20211.12000\lib\net45\Microsoft.SharePoint.Client.WorkflowServices.dll</HintPath>
131134
</Reference>
132135
<Reference Include="Microsoft.WindowsAzure.Storage, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
133136
<HintPath>..\packages\WindowsAzure.Storage.7.0.0\lib\net40\Microsoft.WindowsAzure.Storage.dll</HintPath>
134137
</Reference>
135138
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
136139
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
137140
</Reference>
138-
<Reference Include="OfficeDevPnP.Core, Version=3.16.1912.0, Culture=neutral, PublicKeyToken=5e633289e95c321a, processorArchitecture=MSIL">
139-
<HintPath>..\packages\SharePointPnPCoreOnline.3.16.1912\lib\net45\OfficeDevPnP.Core.dll</HintPath>
141+
<Reference Include="OfficeDevPnP.Core, Version=3.23.2007.0, Culture=neutral, PublicKeyToken=5e633289e95c321a, processorArchitecture=MSIL">
142+
<HintPath>..\packages\SharePointPnPCoreOnline.3.23.2007\lib\net461\OfficeDevPnP.Core.dll</HintPath>
140143
</Reference>
141144
<Reference Include="PresentationCore" />
142145
<Reference Include="SharePointPnP.IdentityModel.Extensions, Version=1.2.4.0, Culture=neutral, PublicKeyToken=5e633289e95c321a, processorArchitecture=MSIL">
@@ -195,6 +198,7 @@
195198
<Compile Include="HelperWindows\LoginWindow.Designer.cs">
196199
<DependentUpon>LoginWindow.cs</DependentUpon>
197200
</Compile>
201+
<Compile Include="ListsWebService\Lists.cs" />
198202
<Compile Include="Properties\AssemblyInfo.cs" />
199203
<Compile Include="Properties\Settings.Designer.cs">
200204
<AutoGen>True</AutoGen>

src/SPCoder.SharePoint.Client/Utils/CSOMConnector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.SharePoint.Client;
55
using SPCoder.Core.Utils;
66
using SPCoder.HelperWindows;
7+
using SPCoder.SharePoint.Client.ListsWebService;
78
using SPCoder.SharePoint.Client.Utils;
89
using SPCoder.Utils.Nodes;
910
using System;
@@ -130,6 +131,12 @@ public override BaseNode ExpandNode(BaseNode node, bool doIfLoaded = false)
130131
return node;
131132
}
132133

134+
static void clientContext_ExecutingWebRequest_Auth(object sender, Microsoft.SharePoint.Client.WebRequestEventArgs e)
135+
{
136+
//in case your custom FBA requires custom headers, you can set those here
137+
//e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
138+
}
139+
133140
public override BaseNode GetSPStructure(string siteUrl)
134141
{
135142
this.Endpoint = siteUrl;
@@ -196,6 +203,11 @@ public override BaseNode GetSPStructure(string siteUrl)
196203
Context.Credentials = new NetworkCredential(Username, Password);
197204
}
198205

206+
//in case your custom FBA requires custom headers you could set the event handler here
207+
//if (/* custom logic */)
208+
//{
209+
// Context.ExecutingWebRequest += new EventHandler<Microsoft.SharePoint.Client.WebRequestEventArgs>(clientContext_ExecutingWebRequest_Auth);
210+
//}
199211
var rootNode = this.GenerateRootNode();
200212
return rootNode;
201213
}

src/SPCoder.SharePoint.Client/packages.config

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3+
<package id="AngleSharp" version="0.9.9" targetFramework="net47" />
34
<package id="AppForSharePointOnlineWebToolkit" version="3.1.5" targetFramework="net45" />
45
<package id="Camlex.Client.dll" version="4.0.0" targetFramework="net47" />
56
<package id="EPPlus" version="4.5.3.2" targetFramework="net47" />
@@ -20,10 +21,10 @@
2021
<package id="Microsoft.IdentityModel.Logging" version="5.2.4" targetFramework="net45" requireReinstallation="true" />
2122
<package id="Microsoft.IdentityModel.Tokens" version="5.2.4" targetFramework="net45" requireReinstallation="true" />
2223
<package id="Microsoft.Office.Client.Policy" version="15.0.0" targetFramework="net45" />
23-
<package id="Microsoft.SharePointOnline.CSOM" version="16.1.20017.12000" targetFramework="net47" />
24+
<package id="Microsoft.SharePointOnline.CSOM" version="16.1.20211.12000" targetFramework="net47" />
2425
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net47" />
2526
<package id="SharePointPnP.IdentityModel.Extensions" version="1.2.4" targetFramework="net47" />
26-
<package id="SharePointPnPCoreOnline" version="3.16.1912" targetFramework="net47" />
27+
<package id="SharePointPnPCoreOnline" version="3.23.2007" targetFramework="net47" />
2728
<package id="System.IdentityModel.Tokens.Jwt" version="5.2.4" targetFramework="net45" requireReinstallation="true" />
2829
<package id="System.IO" version="4.3.0" targetFramework="net45" requireReinstallation="true" />
2930
<package id="System.Net.Http" version="4.3.1" targetFramework="net45" requireReinstallation="true" />

src/SPCoder.WinApp/Windows/ExplorerView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ private void tvSp_Expanded(object sender, TreeViewAdvEventArgs e)
547547
var newNode = node.RootNode.NodeConnector.ExpandNode(node);
548548
//SPCoderForm.MainForm.AppendToLog("Data retrieved " + node.Url);
549549

550-
CreateTreeViewNode2((Node)e.Node.Tag, newNode, newNode.RootNode.OMType);
550+
CreateTreeViewNode2((Node)e.Node.Tag, newNode, node.RootNode.OMType);
551551

552552
node.LoadedData = true;
553553
((Node)e.Node.Tag).Image = oldImage;

0 commit comments

Comments
 (0)