Skip to content

Commit

Permalink
⚡ refactor: Global using organization and use UtcNow (#363)
Browse files Browse the repository at this point in the history
* feat: Support PostgreSQL

* ⚡ refactor: Global using organization and use UtcNow
  • Loading branch information
wzh425 authored Dec 10, 2024
1 parent 47b5552 commit 014dcec
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 86 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<MasaFrameworkPackageVersion>1.2.0-preview.5</MasaFrameworkPackageVersion>
<MasaStackSdksPackageVersion>1.2.1-preview.8</MasaStackSdksPackageVersion>
<MasaStackSdksPackageVersion>1.2.1-preview.9</MasaStackSdksPackageVersion>
<MicrosoftPackageVersion>6.0.8</MicrosoftPackageVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

namespace Masa.Alert.Application.Contracts.AlarmRules.Dtos;

public enum AlarmRuleSearchTimeTypes
{
ModificationTime = 1,
CreationTime,
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,4 @@ public GetAlarmRuleInputDto(string filter, AlarmRuleTypes type, AlarmRuleSearchT
AppIdentity = appIdentity;
MetricId = metricId;
}
}

public enum AlarmRuleSearchTimeTypes
{
ModificationTime = 1,
CreationTime,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task QueryRulesAsync(CheckAlarmRuleCommand command)
public async Task QueryAggregationAsync(CheckAlarmRuleCommand command)
{
var alarmRule = command.AlarmRule;
var checkTime = command.ExcuteTime ?? DateTimeOffset.Now;
var checkTime = command.ExcuteTime ?? DateTimeOffset.UtcNow;
var latest = await _domainService.GetLatest(alarmRule.Id);
var startTime = alarmRule.GetStartCheckTime(checkTime, latest);

Expand Down Expand Up @@ -77,11 +77,11 @@ public async Task ExecuteRulesAsync(CheckAlarmRuleCommand command)
{
if (command.IsStop)
{
await _domainService.AddAggregateResult(command.AlarmRule.Id, command.ExcuteTime ?? DateTimeOffset.Now, command.AggregateResult, false, 0, new List<RuleResultItem>());
await _domainService.AddAggregateResult(command.AlarmRule.Id, command.ExcuteTime ?? DateTimeOffset.UtcNow, command.AggregateResult, false, 0, new List<RuleResultItem>());
return;
}

await _domainService.CheckRuleAsync(command.ExcuteTime ?? DateTimeOffset.Now, command.AlarmRule, command.AggregateResult);
await _domainService.CheckRuleAsync(command.ExcuteTime ?? DateTimeOffset.UtcNow, command.AlarmRule, command.AggregateResult);
}

private async Task<ConcurrentDictionary<string, long>> QueryLogAggregationAsync(AlarmRule alarmRule, DateTime startTime, DateTime endTime, CheckAlarmRuleCommand command)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void AddAggregateVariables(Dictionary<string, object> variables, Concurr

private async Task AddLogVariablesAsync(AlarmRule alarmRule, Dictionary<string, object> variables)
{
var checkTime = DateTimeOffset.Now;
var checkTime = DateTimeOffset.UtcNow;
var latest = await _domainService.GetLatest(alarmRule.Id);
var startTime = alarmRule.GetStartCheckTime(checkTime, latest);
if (startTime == null)
Expand Down
3 changes: 1 addition & 2 deletions src/Domain/Masa.Alert.Domain.Shared/_Imports.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

global using System.Runtime.CompilerServices;
global using Masa.BuildingBlocks.Data.Contracts;
global using System.Runtime.CompilerServices;
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AlarmHandleStatusCommit : ValueObject
public AlarmHandleStatusCommit(AlarmHistoryHandleStatuses status, Guid userId, string remarks)
{
Status = status;
CreationTime = DateTimeOffset.Now;
CreationTime = DateTimeOffset.UtcNow;
UserId = userId;
Remarks = remarks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public AlarmHistory(Guid alarmRuleId, AlertSeverity alertSeverity, bool isNotifi
IsNotification = isNotification;
RuleResultItems = ruleResultItems;
AlarmCount = 1;
FirstAlarmTime = DateTimeOffset.Now;
LastAlarmTime = DateTimeOffset.Now;
FirstAlarmTime = DateTimeOffset.UtcNow;
LastAlarmTime = DateTimeOffset.UtcNow;

Handle = new();
_handleStatusCommits.Add(new AlarmHandleStatusCommit(AlarmHistoryHandleStatuses.Pending, default, string.Empty));
}

public void Recovery(bool isAuto)
{
RecoveryTime = DateTimeOffset.Now;
RecoveryTime = DateTimeOffset.UtcNow;
Duration = (long)(RecoveryTime - FirstAlarmTime).Value.TotalSeconds;

if (isAuto)
Expand All @@ -67,7 +67,7 @@ public void Update(AlertSeverity alertSeverity, bool isNotification, List<RuleRe
IsNotification = isNotification;
RuleResultItems = ruleResultItems;
AlarmCount++;
LastAlarmTime = DateTimeOffset.Now;
LastAlarmTime = DateTimeOffset.UtcNow;
}

public void AddAlarmRuleRecord(DateTimeOffset excuteTime, ConcurrentDictionary<string, long> aggregateResult, bool isTrigger, int consecutiveCount, List<RuleResultItem> ruleResultItems)
Expand All @@ -82,7 +82,7 @@ public void AddAlarmRuleRecord(DateTimeOffset excuteTime, ConcurrentDictionary<s

public void Notification()
{
LastNotificationTime = DateTimeOffset.Now;
LastNotificationTime = DateTimeOffset.UtcNow;
}

public void SetIsNotification(bool isNotification, bool isSilence, ConcurrentDictionary<string, long> aggregateResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public bool CheckIsSilence(DateTimeOffset? lastNotificationTime)

var silenceEndTime = GetSilenceEndTime(lastNotificationTime.Value);

if (!silenceEndTime.HasValue || DateTimeOffset.Now > silenceEndTime)
if (!silenceEndTime.HasValue || DateTimeOffset.UtcNow > silenceEndTime)
{
return false;
}
Expand Down
55 changes: 27 additions & 28 deletions src/Domain/Masa.Alert.Domain/_Imports.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

global using Masa.BuildingBlocks.Ddd.Domain.Entities.Full;
global using Masa.BuildingBlocks.Ddd.Domain.Entities;
global using Masa.Alert.Domain.Shared.AlarmRules;
// System Namespaces
global using System.Collections.Concurrent;
global using System.Collections.ObjectModel;

// MASA Building Blocks and Contrib Packages
global using Masa.BuildingBlocks.Caching;
global using Masa.BuildingBlocks.Data;
global using Masa.BuildingBlocks.Data.Contracts;
global using Masa.BuildingBlocks.Ddd.Domain.Entities.Full;
global using Masa.BuildingBlocks.Ddd.Domain.Events;
global using Masa.BuildingBlocks.Ddd.Domain.Repositories;
global using Masa.Alert.Domain.Shared.Enums;
global using Masa.BuildingBlocks.Ddd.Domain.Services;
global using Masa.BuildingBlocks.Ddd.Domain.Values;
global using Masa.Contrib.Ddd.Domain;
global using Masa.BuildingBlocks.Ddd.Domain.Events;
global using Masa.BuildingBlocks.RulesEngine;
global using Masa.Contrib.RulesEngine.MicrosoftRulesEngine;
global using System.Collections.Concurrent;
global using Masa.BuildingBlocks.Dispatcher.Events;
global using Masa.Alert.Domain.AlarmRules.Aggregates;
global using Masa.BuildingBlocks.Data;
global using Masa.Alert.Domain.AlarmRules.Repositories;
global using FluentValidation.Results;
global using Masa.Contrib.Dispatcher.Events;
global using Microsoft.Extensions.Logging;

// MASA Alert Domain Shared
global using Masa.Alert.Domain.Shared.AlarmRules;
global using Masa.Alert.Domain.Shared.AlarmHistory;
global using Masa.Alert.Domain.AlarmHistories;
global using Masa.Alert.Domain.AlarmHistories.Events;
global using Masa.Alert.Domain.Shared;
global using Masa.Alert.Domain.Shared.Consts;

// MASA Alert Domain Aggregates
global using Masa.Alert.Domain.AlarmRules.Aggregates;
global using Masa.Alert.Domain.AlarmHistories.Aggregates;
global using Masa.Alert.Domain.AlarmHistories.Repositories;
global using Masa.BuildingBlocks.ReadWriteSplitting.Cqrs.Commands;
global using Masa.Alert.Infrastructure.Common.Utils;
global using System.Threading.Channels;
global using Masa.Alert.Domain.AlarmRules.Events;
global using Masa.Alert.Domain.WebHooks.Aggregates;

// MASA Alert Domain Events
global using Masa.Alert.Domain.AlarmRules.Events;
global using Masa.Alert.Domain.AlarmHistories.Events;
global using Masa.Alert.Domain.WebHooks.Events;
global using System.Text.Json.Serialization;
global using Masa.BuildingBlocks.Data.Contracts;
global using Masa.BuildingBlocks.Data.UoW;
global using Masa.BuildingBlocks.Ddd.Domain.Services;
global using Masa.BuildingBlocks.Caching;
global using Masa.Alert.Domain.Shared.Consts;

// MASA Alert Domain Repositories
global using Masa.Alert.Domain.AlarmRules.Repositories;

// MASA Alert Infrastructure
global using Masa.Alert.Infrastructure.Common.Utils;
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Design;
global using Microsoft.Extensions.Configuration;
global using Masa.Alert.EntityFrameworkCore;
global using Microsoft.Extensions.Configuration;
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
global using Masa.BuildingBlocks.Data.Contracts;
global using Microsoft.EntityFrameworkCore.Design;
global using Microsoft.Extensions.Configuration;
3 changes: 0 additions & 3 deletions src/Infrastructure/Masa.Alert.EntityFrameworkCore/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@
global using Masa.Alert.Domain.WebHooks.Aggregates;
global using Masa.Alert.Domain.WebHooks.Repositories;
global using Masa.Alert.Infrastructure.EntityFrameworkCore.EntityFrameworkCore.ValueConverters;
global using Masa.BuildingBlocks.Data;
global using Masa.BuildingBlocks.Data.UoW;
global using Masa.BuildingBlocks.Data.Contracts;
global using Masa.Contrib.Ddd.Domain.Repository.EFCore;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Metadata.Builders;
global using Microsoft.Extensions.Logging;
global using Microsoft.EntityFrameworkCore.Design;
global using Microsoft.Extensions.Configuration;
global using System.Reflection;
46 changes: 24 additions & 22 deletions src/Web/Masa.Alert.Web.Admin.Server/_Imports.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the Apache License. See LICENSE.txt in the project root for license information.

global using Mapster;
global using Microsoft.AspNetCore.ResponseCompression;
global using BlazorDownloadFile;
global using Masa.Stack.Components;
// System Namespaces
global using System.Security.Cryptography.X509Certificates;

// Microsoft Namespaces
global using Microsoft.AspNetCore.Authentication;
global using Microsoft.AspNetCore.Authentication.Cookies;
global using Microsoft.AspNetCore.Authentication.OpenIdConnect;
global using Microsoft.AspNetCore.Hosting.StaticWebAssets;
global using Microsoft.AspNetCore.Mvc;
global using Microsoft.AspNetCore.Mvc.RazorPages;
global using Microsoft.AspNetCore.Hosting.StaticWebAssets;
global using System.Net.NetworkInformation;
global using Microsoft.AspNetCore.Authentication.Cookies;
global using Masa.BuildingBlocks.Configuration;
global using Masa.Alert.Infrastructure.Common.Extensions;
global using Masa.Stack.Components.Models;
global using System.Security.Cryptography.X509Certificates;
global using Masa.Alert.ApiGateways.Caller.Extensions;
global using Masa.Contrib.Configuration.ConfigurationApi.Dcc;
global using Masa.Stack.Components.Extensions.OpenIdConnect;
global using Masa.Contrib.StackSdks.Tsc;
global using Masa.BuildingBlocks.StackSdks.Config;
global using Masa.Contrib.Configuration.ConfigurationApi.Dcc.Options;
global using Masa.Contrib.StackSdks.Config;
global using Microsoft.AspNetCore.ResponseCompression;
global using Microsoft.IdentityModel.Logging;
global using Masa.Contrib.StackSdks.Caller;
global using Microsoft.AspNetCore.Authentication.OpenIdConnect;
global using Microsoft.IdentityModel.Protocols.OpenIdConnect;

// Third-party Libraries
global using BlazorDownloadFile;
global using FluentValidation;
global using FluentValidation.Resources;
global using Microsoft.IdentityModel.Protocols.OpenIdConnect;
global using System.Reflection;
global using Mapster;

// MASA Building Blocks and Contrib Packages
global using Masa.Contrib.StackSdks.Caller;
global using Masa.Contrib.StackSdks.Config;
global using Masa.Contrib.Configuration.ConfigurationApi.Dcc;
global using Masa.Stack.Components;
global using Masa.Stack.Components.Extensions.OpenIdConnect;

// MASA Alert Infrastructure and Extensions
global using Masa.Alert.Infrastructure.Common.Extensions;
global using Masa.Alert.ApiGateways.Caller.Extensions;
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
private List<long> GetTimeListByFixedInterval(int count = 10)
{
var timeList = new List<long>();
var time = _startTime ?? DateTimeOffset.Now;
var time = _startTime ?? DateTimeOffset.UtcNow;

var i = 0;
while (CheckIsAddTime(time, i))
Expand Down Expand Up @@ -195,7 +195,7 @@

if (timezone != null)
cronExpression.TimeZone = timezone;
var time = _startTime ?? DateTimeOffset.Now;
var time = _startTime ?? DateTimeOffset.UtcNow;
var i = 0;
while (CheckIsAddTime(time, i))
{
Expand Down
7 changes: 4 additions & 3 deletions src/Web/Masa.Alert.Web.Admin/Masa.Alert.Web.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="Masa.BuildingBlocks.Authentication.Identity" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.SearchEngine.AutoComplete.ElasticSearch" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Stack.Components" Version="0.0.488" />
<PackageReference Include="Masa.Stack.Components" Version="0.0.491" />
<PackageReference Include="Masa.Utils.Data.Elasticsearch" Version="$(MasaFrameworkPackageVersion)" />
<PackageReference Include="Masa.Contrib.StackSdks.Tsc" Version="$(MasaStackSdksPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.3" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.0-preview.4.22251.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\ApiGateways\Caller\Masa.Alert.ApiGateways.Caller\Masa.Alert.ApiGateways.Caller.csproj" />
<ProjectReference Include="..\..\Contracts\Masa.Alert.Contracts.Admin\Masa.Alert.Contracts.Admin.csproj" />
<ProjectReference Include="..\..\Infrastructure\Masa.Alert.Infrastructure.Common\Masa.Alert.Infrastructure.Common.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void GetNextRunTime(int showCount = 5)

var sb = new StringBuilder();

var startTime = DateTimeOffset.Now;
var startTime = DateTimeOffset.UtcNow;

var cronExpression = new CronExpression(_model.CheckFrequency.CronExpression);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private void GetNextRunTime(int showCount = 5)

var sb = new StringBuilder();

var startTime = DateTimeOffset.Now;
var startTime = DateTimeOffset.UtcNow;

var cronExpression = new CronExpression(_model.CheckFrequency.CronExpression);

Expand Down
1 change: 0 additions & 1 deletion src/Web/Masa.Alert.Web.Admin/_Imports.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
@using Microsoft.JSInterop
@using static Masa.Stack.Components.JsInitVariables
@using Masa.Alert.Web.Admin.Components.GenericColumnRender
@using Masa.Contrib.StackSdks.Mc.Infrastructure.Extensions
@using Masa.Alert.Web.Admin.Pages.AlarmRules.Modules
@using Masa.Alert.Domain.Shared.AlarmRules
@using Masa.Alert.Web.Admin.Components.Modules.Alarm
Expand Down

0 comments on commit 014dcec

Please sign in to comment.