Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
a.vorobiev committed Feb 16, 2021
2 parents 1428943 + 4058b67 commit a9627a8
Show file tree
Hide file tree
Showing 50 changed files with 6,398 additions and 212 deletions.
38 changes: 38 additions & 0 deletions CDP4Orm/Dao/BaseDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public abstract class BaseDao
/// </summary>
public ICommandLogger CommandLogger { get; set; }

/// <summary>
/// The <see cref="DateTime"/> of the current <see cref="NpgsqlTransaction"/>
/// </summary>
private DateTime currentTransactionDatetime;

/// <summary>
/// The <see cref="NpgsqlTransaction"/> for which <see cref="currentTransactionDatetime"/> was retrieved
/// </summary>
private NpgsqlTransaction currentTransactionDataTimeTransaction;

/// <summary>
/// Execute additional logic before each update function call.
/// </summary>
Expand Down Expand Up @@ -81,6 +91,9 @@ public abstract class BaseDao
/// </returns>
public virtual bool BeforeUpdate(NpgsqlTransaction transaction, string partition, Thing thing, Thing container, out bool isHandled, Dictionary<string, string> valueTypeDictionaryAdditions)
{
var transactionDateTime = this.GetTransactionDateTime(transaction);
thing.ModifiedOn = transactionDateTime;

isHandled = false;
return true;
}
Expand Down Expand Up @@ -187,6 +200,8 @@ public virtual bool AfterDelete(bool deleteResult, NpgsqlTransaction transaction
/// </returns>
public virtual bool BeforeWrite(NpgsqlTransaction transaction, string partition, Thing thing, Thing container, out bool isHandled, Dictionary<string, string> valueTypeDictionaryAdditions)
{
thing.ModifiedOn = this.GetTransactionDateTime(transaction);

isHandled = false;
return true;
}
Expand Down Expand Up @@ -288,6 +303,29 @@ protected void DeleteAll(NpgsqlTransaction transaction, string partition, string
}
}

/// <summary>
/// Returns the current transaction time from the server
/// </summary>
/// <param name="transaction"></param>
/// <returns></returns>
private DateTime GetTransactionDateTime(NpgsqlTransaction transaction)
{
if (transaction != null && this.currentTransactionDataTimeTransaction != transaction)
{
this.currentTransactionDataTimeTransaction = transaction;

using (var command = new NpgsqlCommand(
$"SELECT * FROM \"SiteDirectory\".\"get_transaction_time\"();",
transaction.Connection,
transaction))
{
this.currentTransactionDatetime = (DateTime)command.ExecuteScalar();
}
}

return this.currentTransactionDatetime;
}

/// <summary>
/// Instantiates a <see cref="Thing"/> from the content of a <see cref="NpgsqlDataReader"/>
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion CDP4WebServer/CDP4WebServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<OutputType>Exe</OutputType>
<Company>RHEA System S.A.</Company>
<Title>CDP4WebServer-CE</Title>
<Version>6.1.0</Version>
<Version>6.1.1</Version>
<Description>CDP4 Services Host</Description>
<Copyright>Copyright © RHEA System S.A.</Copyright>
<Authors>Sam, Merlin, Alex, Naron, Alexander</Authors>
Expand All @@ -16,6 +16,8 @@
<ItemGroup>
<PackageReference Include="Nancy.Bootstrappers.Autofac" Version="1.4.1" />
<PackageReference Include="Nancy.Owin" Version="1.4.1" />
<PackageReference Include="Hangfire" Version="1.7.19" />
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
<PackageReference Include="Owin" Version="1.0" />
<PackageReference Include="Microsoft.Owin.Diagnostics" Version="4.0.1" />
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="4.0.1" />
Expand Down
28 changes: 27 additions & 1 deletion CDP4WebServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Startup.cs" company="RHEA System S.A.">
// Copyright (c) 2016 RHEA System S.A. All rights reserverd
// Copyright (c) 2015-2021 RHEA System S.A.
//
// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft.
//
// This file is part of CDP4 Web Services Community Edition.
// The CDP4 Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C.
// This is an auto-generated class. Any manual changes to this file will be overwritten!
//
// The CDP4 Web Services Community Edition is free software; you can redistribute it and/or
// modify it under the terms of the GNU Affero General Public
// License as published by the Free Software Foundation; either
// version 3 of the License, or (at your option) any later version.
//
// The CDP4 Web Services Community Edition is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace CDP4WebServer
{
using Hangfire;
using Hangfire.MemoryStorage;

using Nancy;
using Nancy.Owin;

Expand All @@ -24,6 +46,10 @@ public class Startup
/// </param>
public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseMemoryStorage();
app.UseHangfireDashboard("/hangfire");
app.UseHangfireServer();

app.UseNancy(options => options.PassThroughWhenStatusCodesAre(HttpStatusCode.NotFound));
}
}
Expand Down
Loading

0 comments on commit a9627a8

Please sign in to comment.