Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Coscine
backend
apis
Project
Commits
31336850
Commit
31336850
authored
Jul 11, 2019
by
Benedikt Heinrichs
Browse files
New: FireEvents on ProjectCreation
parent
60707448
Changes
5
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/Project.Tests/DefaultControllerTests.cs
View file @
31336850
...
...
@@ -10,6 +10,7 @@ using System;
using
System.Collections.Generic
;
using
System.IO
;
using
System.Linq
;
using
System.Management
;
namespace
Coscine.Api.Project.Tests
{
...
...
@@ -116,10 +117,42 @@ namespace Coscine.Api.Project.Tests
{
"UserId"
,
user
.
Id
.
ToString
()
}
};
var
additionalProtocol
=
Program
.
Configuration
.
GetStringAndWait
(
"coscine/local/sharepoint/additional/protocol"
);
var
additionalPort
=
Program
.
Configuration
.
GetStringAndWait
(
"coscine/local/sharepoint/additional/port"
);
var
additionalSite
=
Program
.
Configuration
.
GetStringAndWait
(
"coscine/local/sharepoint/additional/site"
);
var
sharePointSite
=
"https://"
;
if
(
additionalProtocol
!=
null
)
{
sharePointSite
=
additionalProtocol
+
"://"
;
}
//initialize the select query with command text
ManagementObjectSearcher
searcher
=
new
ManagementObjectSearcher
(
"root\\CIMV2"
,
"SELECT Name FROM Win32_ComputerSystem"
);
//execute the query
foreach
(
ManagementObject
process
in
searcher
.
Get
())
{
//print system info
process
.
Get
();
sharePointSite
=
sharePointSite
+
process
[
"Name"
]
+
"."
+
process
[
"Domain"
];
}
if
(
additionalPort
!=
null
)
{
sharePointSite
+=
":"
+
additionalPort
;
}
if
(
additionalSite
!=
null
)
{
sharePointSite
+=
"/"
+
additionalSite
;
}
request
.
SetupGet
(
x
=>
x
.
Headers
).
Returns
(
new
HeaderDictionary
{
{
"X-Requested-With"
,
"XMLHttpRequest"
},
{
"Authorization"
,
"Bearer "
+
jwtHandler
.
GenerateJwtToken
(
values
)}
{
"Authorization"
,
"Bearer "
+
jwtHandler
.
GenerateJwtToken
(
values
)},
{
"Referer"
,
sharePointSite
}
}
);
...
...
src/Project.Tests/Project.Tests.csproj
View file @
31336850
...
...
@@ -27,6 +27,7 @@
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
<PlatformTarget>
x64
</PlatformTarget>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
...
...
@@ -205,6 +206,7 @@
<HintPath>
..\packages\System.Diagnostics.DiagnosticSource.4.5.1\lib\net46\System.Diagnostics.DiagnosticSource.dll
</HintPath>
</Reference>
<Reference
Include=
"System.Drawing"
/>
<Reference
Include=
"System.Management"
/>
<Reference
Include=
"System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"
>
<HintPath>
..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll
</HintPath>
</Reference>
...
...
src/Project/Controllers/ProjectController.cs
View file @
31336850
using
Coscine.Api.Project.Exceptions
;
using
Coscine.Action
;
using
Coscine.Action.EventArgs
;
using
Coscine.Action.Implementations.Project
;
using
Coscine.Api.Project.Exceptions
;
using
Coscine.Api.Project.Factories
;
using
Coscine.Api.Project.Models
;
using
Coscine.Api.Project.ReturnObjects
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.SharePoint
;
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Management
;
namespace
Coscine.Api.Project.Controllers
{
public
class
ProjectController
:
Controller
{
private
readonly
Authenticator
_authenticator
;
private
readonly
List
<
IProjectAction
>
projectActions
;
public
ProjectController
()
{
_authenticator
=
new
Authenticator
(
this
);
projectActions
=
new
List
<
IProjectAction
>()
{
new
PIDAction
(),
new
SharePointSiteAction
()
};
}
[
Route
(
"[controller]"
)]
...
...
@@ -68,13 +80,39 @@ namespace Coscine.Api.Project.Controllers
[
HttpPost
(
"[controller]"
)]
public
IActionResult
Store
()
{
return
Ok
(
_authenticator
.
ValidateAndExecute
((
user
)
=>
return
base
.
Ok
(
_authenticator
.
ValidateAndExecute
((
user
)
=>
{
ProjectObject
projectObject
=
ObjectFactory
<
ProjectObject
>.
DeserializeFromStream
(
Request
.
Body
);
ProjectModel
projectModel
=
new
ProjectModel
();
var
project
=
projectModel
.
StoreFromObject
(
projectObject
,
user
);
FireEvents
((
projectAction
,
projectEventArgs
)
=>
projectAction
.
OnProjectCreate
(
project
,
projectEventArgs
));
return
new
ProjectObject
(
project
.
Id
,
project
.
Description
,
project
.
DisplayName
,
project
.
Organization
,
project
.
StartDate
,
project
.
EndDate
,
project
.
Keywords
);
}));
}
private
void
FireEvents
(
Action
<
IProjectAction
,
ProjectEventArgs
>
eventAction
)
{
var
sharePointSite
=
Request
.
Headers
[
"Referer"
];
SPUserToken
systemAccount
=
SPUserToken
.
SystemAccount
;
using
(
SPSite
site
=
new
SPSite
(
sharePointSite
,
systemAccount
))
{
using
(
SPWeb
web
=
site
.
OpenWeb
())
{
SPContext
context
=
SPContext
.
GetContext
(
web
);
object
[]
args
=
new
object
[]
{
context
};
ProjectEventArgs
projectEventArgs
=
new
ProjectEventArgs
(
Program
.
Configuration
,
args
);
foreach
(
var
projectAction
in
projectActions
)
{
eventAction
(
projectAction
,
projectEventArgs
);
}
}
}
}
}
}
src/Project/Project.csproj
View file @
31336850
...
...
@@ -23,7 +23,7 @@
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<PlatformTarget>
x64
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
...
...
@@ -45,12 +45,18 @@
<Reference
Include=
"Consul, Version=0.7.2.6, Culture=neutral, PublicKeyToken=20a6ad9a81df1d95, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Consul.0.7.2.6\lib\net45\Consul.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Action, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Action.1.0.0\lib\net461\Coscine.Action.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Configuration, Version=1.4.0.0, Culture=neutral, PublicKeyToken=ce3d7a32d7dc1e5a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Configuration.1.4.0\lib\net461\Coscine.Configuration.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.Database, Version=1.3.0.0, Culture=neutral, PublicKeyToken=767d77427707b70a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.Database.1.3.0\lib\net461\Coscine.Database.dll
</HintPath>
</Reference>
<Reference
Include=
"Coscine.ProxyApi, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Coscine.ProxyApi.1.1.0\lib\net461\Coscine.ProxyApi.dll
</HintPath>
</Reference>
<Reference
Include=
"EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
>
<HintPath>
..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll
</HintPath>
</Reference>
...
...
@@ -341,6 +347,7 @@
<Reference
Include=
"Microsoft.Net.Http.Headers, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Microsoft.Net.Http.Headers.2.2.0\lib\netstandard2.0\Microsoft.Net.Http.Headers.dll
</HintPath>
</Reference>
<Reference
Include=
"Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL"
/>
<Reference
Include=
"Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
>
<HintPath>
..\packages\Microsoft.Win32.Registry.4.5.0\lib\net461\Microsoft.Win32.Registry.dll
</HintPath>
</Reference>
...
...
@@ -427,6 +434,7 @@
<Private>
True
</Private>
<Private>
True
</Private>
</Reference>
<Reference
Include=
"System.Management"
/>
<Reference
Include=
"System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"
>
<HintPath>
..\packages\System.Memory.4.5.2\lib\netstandard2.0\System.Memory.dll
</HintPath>
<Private>
True
</Private>
...
...
@@ -523,6 +531,7 @@
<Reference
Include=
"System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"
>
<HintPath>
..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll
</HintPath>
</Reference>
<Reference
Include=
"System.Web"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
...
...
src/Project/packages.config
View file @
31336850
...
...
@@ -3,8 +3,10 @@
<
package
id
=
"AutoMapper"
version
=
"8.0.0"
targetFramework
=
"net472"
/>
<
package
id
=
"AutoMapper.Extensions.Microsoft.DependencyInjection"
version
=
"6.0.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Consul"
version
=
"0.7.2.6"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Action"
version
=
"1.0.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Configuration"
version
=
"1.4.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.Database"
version
=
"1.3.0"
targetFramework
=
"net472"
/>
<
package
id
=
"Coscine.ProxyApi"
version
=
"1.1.0"
targetFramework
=
"net472"
/>
<
package
id
=
"EntityFramework"
version
=
"6.2.0"
targetFramework
=
"net472"
/>
<
package
id
=
"linq2db"
version
=
"2.6.4"
targetFramework
=
"net472"
/>
<
package
id
=
"linq2db.SqlServer"
version
=
"2.6.4"
targetFramework
=
"net472"
/>
...
...
Ghost User
@ghost
mentioned in commit
bd1ed418
·
Jul 22, 2019
mentioned in commit
bd1ed418
mentioned in commit bd1ed418d4e4bc2448f76df133601d6cbf31b6c7
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment