Skip to content

Commit

Permalink
Fix bugs about win7 & deadline exceeded.
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoona committed Dec 17, 2019
1 parent e2a3162 commit a4add46
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ private static bool TryWriteBytes(Span<byte> destination, float value)

return true;
#else
return TryWriteBytes(destination, value);
return BitConverter.TryWriteBytes(destination, value);
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ private void DeadlineBackgroundTaskEntryPoint()
CancellationToken closingCancellationToken = this.closingCancellationTokenSource.Token;
while (!closingCancellationToken.WaitHandle.WaitOne(300))
{
DateTime now = DateTime.Now;
DateTime now = DateTime.UtcNow;
foreach (KeyValuePair<int, PlcRequestContext> entry in this.requestContextReceivingDictionary)
{
if (entry.Value.Deadline < now)
{
if (this.requestContextReceivingDictionary.TryRemove(entry.Key, out PlcRequestContext requestContext))
if (this.requestContextReceivingDictionary.TryRemove(
entry.Key,
out PlcRequestContext requestContext))
{
this.logger.LogWarning("Request {0} to {1} exceed deadline.", entry.Key, this.RemoteEndPoint);
this.logger.LogWarning(
"Request {0} to {1} exceed deadline, deadline={2:u}, now1={3:u}, now2={4:u}",
entry.Key,
this.RemoteEndPoint,
now,
DateTime.UtcNow);
requestContext.TaskCompletionSource.TrySetException(new RpcException(new Status(
StatusCode.DeadlineExceeded, string.Empty)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ private void ProcessRequest(DateTime utcNow, PlcRequestContext requestContext)
{
if (requestContext.Deadline?.ToUniversalTime() < utcNow)
{
this.logger.LogDebug(
"Request deadline exceeded, deadline={0:u}, now1={1:u}, now2={2:u}",
requestContext.Deadline,
utcNow,
DateTime.UtcNow);
requestContext.TaskCompletionSource.SetException(new RpcException(
new Status(StatusCode.DeadlineExceeded, string.Empty)));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>True</PublishSingleFile>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Extended.Wpf.Toolkit" Version="3.7.0" />
<PackageReference Condition="'$(Configuration)' != 'Release'" Include="Grpc.Core.Testing" Version="2.25.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="3.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ private async void ExecuteSwitchOnClickCommand(string fieldMask)
var updatingMask = FieldMask.FromString<Switch>(fieldMask);
var updatingSwitch = new Switch();
Switch.Descriptor.FindFieldByName(fieldMask).Accessor.SetValue(updatingSwitch, true);
DateTime now = DateTime.UtcNow;
DateTime deadline = now.AddMilliseconds(this.coreOptions.Value.DefaultWriteTimeoutMillis);
try
{
this.Switch = await this.client.UpdateSwitchAsync(
Expand All @@ -159,11 +161,23 @@ private async void ExecuteSwitchOnClickCommand(string fieldMask)
Switch = updatingSwitch,
UpdateMask = updatingMask,
},
deadline: DateTime.UtcNow.AddMilliseconds(this.coreOptions.Value.DefaultWriteTimeoutMillis));
deadline: deadline);
}
catch (RpcException e)
{
e.ShowMessageBox();
if (e.StatusCode == StatusCode.DeadlineExceeded)
{
this.logger.LogDebug(
"Request deadline exceeded, send_time={0:u}, deadline={1:u}, now={2:u}",
now,
deadline,
DateTime.UtcNow);
e.ShowMessageBox();
}
else
{
e.ShowMessageBox();
}
}
}

Expand All @@ -172,6 +186,8 @@ private async void ExecuteSwitchOffClickCommand(string fieldMask)
var updatingMask = FieldMask.FromString<Switch>(fieldMask);
var updatingSwitch = new Switch();
Switch.Descriptor.FindFieldByName(fieldMask).Accessor.SetValue(updatingSwitch, false);
DateTime now = DateTime.UtcNow;
DateTime deadline = now.AddMilliseconds(this.coreOptions.Value.DefaultWriteTimeoutMillis);
try
{
this.Switch = await this.client.UpdateSwitchAsync(
Expand All @@ -181,11 +197,23 @@ private async void ExecuteSwitchOffClickCommand(string fieldMask)
Switch = updatingSwitch,
UpdateMask = updatingMask,
},
deadline: DateTime.UtcNow.AddMilliseconds(this.coreOptions.Value.DefaultWriteTimeoutMillis));
deadline: deadline);
}
catch (RpcException e)
{
e.ShowMessageBox();
if (e.StatusCode == StatusCode.DeadlineExceeded)
{
this.logger.LogDebug(
"Request deadline exceeded, send_time={0:u}, deadline={1:u}, now={2:u}",
now,
deadline,
DateTime.UtcNow);
e.ShowMessageBox();
}
else
{
e.ShowMessageBox();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -171,15 +172,17 @@ private async void ExecuteExport()

await sw
.WriteLineAsync(
"出水温度(摄氏度),回水温度(摄氏度),加热器出水温度(摄氏度),"
"采集时间,"
+ "出水温度(摄氏度),回水温度(摄氏度),加热器出水温度(摄氏度),"
+ "环境温度(摄氏度),出水压力(米),回水压力(米),"
+ "加热器功率(千瓦),水泵流量(立方米/小时)")
.ConfigureAwait(true);
foreach (Metric m in metrics)
{
await sw
.WriteLineAsync(
$"{m.OutputWaterCelsiusDegree:F2},{m.InputWaterCelsiusDegree:F2},"
$"{m.CreateTime.ToDateTimeOffset().ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)},"
+ $"{m.OutputWaterCelsiusDegree:F2},{m.InputWaterCelsiusDegree:F2},"
+ $"{m.HeaterOutputWaterCelsiusDegree:F2},{m.EnvironmentCelsiusDegree:F2},"
+ $"{m.OutputWaterPressureMeter:F2},{m.InputWaterPressureMeter:F2},"
+ $"{m.HeaterPowerKilowatt:F2},{m.WaterPumpFlowRateCubicMeterPerHour:F2}")
Expand Down
9 changes: 0 additions & 9 deletions OneDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{9578F6A5-5
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerilogLab", "codelab\SerilogLab\SerilogLab.csproj", "{B0AF0ADB-08FE-4312-BDDE-3C3562FB7E37}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Xceed.Wpf.Toolkit", "third_party\ExtendedWPFToolkit\Xceed.Wpf.Toolkit\Xceed.Wpf.Toolkit.csproj", "{72E591D6-8F83-4D8C-8F67-9C325E623234}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -323,12 +321,6 @@ Global
{B0AF0ADB-08FE-4312-BDDE-3C3562FB7E37}.DebugNonWindows|Any CPU.Build.0 = Debug|Any CPU
{B0AF0ADB-08FE-4312-BDDE-3C3562FB7E37}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0AF0ADB-08FE-4312-BDDE-3C3562FB7E37}.Release|Any CPU.Build.0 = Release|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.DebugNonWindows|Any CPU.ActiveCfg = Debug|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.DebugNonWindows|Any CPU.Build.0 = Debug|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72E591D6-8F83-4D8C-8F67-9C325E623234}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -371,7 +363,6 @@ Global
{D724B7E1-7DCF-4BF2-AAF6-B4CDB743DB99} = {BB7EFF62-B03A-4996-9798-17DB422DD96F}
{9578F6A5-5C44-46F3-9965-DEF4D39FC5D5} = {BB7EFF62-B03A-4996-9798-17DB422DD96F}
{B0AF0ADB-08FE-4312-BDDE-3C3562FB7E37} = {9D7C39A1-EF36-4491-8CC0-2D45C3B51580}
{72E591D6-8F83-4D8C-8F67-9C325E623234} = {E307CA64-13F5-446A-BCA5-C611A235A2E4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E0F2E2F1-944D-46B4-BA89-EE1F0BBD57A1}
Expand Down
43 changes: 34 additions & 9 deletions dev-support/bin/publish.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
param(
[string] $Configuration = "Release",
[switch] $SkipGriPlc,
[switch] $SkipGriServer,
[switch] $SkipGriWpf
)

$ErrorActionPreference = "Stop"

$EnlistmentRoot = [System.IO.Path]::GetDirectoryName([System.IO.Path]::GetDirectoryName($PSScriptRoot))
Expand All @@ -9,19 +16,37 @@ if ([System.IO.Directory]::Exists($OutputRoot)) {
}
New-Item -Path $OutputRoot -ItemType Directory

dotnet.exe publish -c "Release" -f "netcoreapp3.1" -o (Join-Path $OutputRoot "GeothermalResearchInstitute/ServerConsole") (Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute ServerConsole project."
if (-not $SkipGriServer) {
dotnet.exe publish `
-c $Configuration `
-f "netcoreapp3.1" `
-o (Join-Path $OutputRoot "GeothermalResearchInstitute/ServerConsole") `
(Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.ServerConsole")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute ServerConsole project."
}
}

dotnet.exe publish -c "Release" -f "netcoreapp3.1" -o (Join-Path $OutputRoot "GeothermalResearchInstitute/FakePlcV2") (Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.FakePlcV2")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute FakePlcV2 project."
if (-not $SkipGriPlc) {
dotnet.exe publish `
-c $Configuration `
-f "netcoreapp3.1" `
-o (Join-Path $OutputRoot "GeothermalResearchInstitute/FakePlcV2") `
(Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.FakePlcV2")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute FakePlcV2 project."
}
}

dotnet.exe publish -c "Release" -f "netcoreapp3.1" -o (Join-Path $OutputRoot "GeothermalResearchInstitute/Wpf") (Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute Wpf project."
if (-not $SkipGriWpf) {
dotnet.exe publish `
-c $Configuration `
-f "netcoreapp3.1" `
-o (Join-Path $OutputRoot "GeothermalResearchInstitute/Wpf") `
(Join-Path $EnlistmentRoot "GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf")
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to publish GeothermalResearchInstitute Wpf project."
}
}

Get-ChildItem -Path (Join-Path $OutputRoot "GeothermalResearchInstitute") -Filter "*.ini" -Recurse `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ protected override void OnGotFocus(RoutedEventArgs e)
}
else
{
//Focus first Focusable Child element of ChildWindow
var focusableChild = TreeHelper.FindChild<FrameworkElement>(this.Content as DependencyObject, x => x.Focusable);
//Focus first Focusable Child element of ChildWindow
var focusableChild = TreeHelper.FindChild<FrameworkElement>(this.Content as DependencyObject, x => x.Focusable);
if (focusableChild != null)
{
_hasChildren = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,8 @@ private void MessageBox_IsVisibleChanged(object sender, DependencyPropertyChange
{
Action action = () =>
{
//Focus first Focusable Child element of MessageBox to prevent Tab outside MessageBox.
var defaultButton = this.GetDefaultButtonFromDefaultResult();
//Focus first Focusable Child element of MessageBox to prevent Tab outside MessageBox.
var defaultButton = this.GetDefaultButtonFromDefaultResult();
if (defaultButton != null)
{
defaultButton.Focus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ protected virtual void OnActiveLayoutChanged(DependencyPropertyChangedEventArgs
DispatcherPriority.Normal,
(ThreadStart)delegate ()
{
this.UpdateSwitchTemplate();
});
this.UpdateSwitchTemplate();
});
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ private void DoSwapTemplate(DataTemplate template, bool beginAnimation)
string id = SwitchTemplate.GetID(element);
if (knownLocations.ContainsKey(id))
{
// ensure that the new locations have been resolved
if (newLocations == null)
// ensure that the new locations have been resolved
if (newLocations == null)
{
newLocations = this.SwitchParent.ActiveLayout.GetNewLocationsBasedOnTargetPlacement(this, _switchRoot);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ private static void OnIDChanged(DependencyObject d, DependencyPropertyChangedEve
d.Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
(ThreadStart)delegate ()
{
parentPresenter = VisualTreeHelperEx.FindAncestorByType<SwitchPresenter>(d);
if (parentPresenter != null)
{
parentPresenter.RegisterID(e.NewValue as string, d as FrameworkElement);
}
});
parentPresenter = VisualTreeHelperEx.FindAncestorByType<SwitchPresenter>(d);
if (parentPresenter != null)
{
parentPresenter.RegisterID(e.NewValue as string, d as FrameworkElement);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ protected virtual void PerformMouseSelection()
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
{
// Select the next dateTime part
this.Select(this.GetDateTimeInfo(dateTimeInfo.StartPosition + dateTimeInfo.Length));
// Select the next dateTime part
this.Select(this.GetDateTimeInfo(dateTimeInfo.StartPosition + dateTimeInfo.Length));
}
));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ internal static Predicate<object> CreateFilter(string text, IList<PropertyItem>
if (property.DisplayName != null)
{
#if !VS2008
var displayAttribute = PropertyGridUtilities.GetAttribute<DisplayAttribute>(property.PropertyDescriptor);
var displayAttribute = PropertyGridUtilities.GetAttribute<DisplayAttribute>(property.PropertyDescriptor);
if (displayAttribute != null)
{
var canBeFiltered = displayAttribute.GetAutoGenerateFilter();
if (canBeFiltered.HasValue && !canBeFiltered.Value)
return false;
}
#endif
property.HighlightedText = property.DisplayName.ToLower().Contains(text.ToLower()) ? text : null;
property.HighlightedText = property.DisplayName.ToLower().Contains(text.ToLower()) ? text : null;
return (property.HighlightedText != null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,13 @@ private string ParseValueIntoTimeSpanInfo(TimeSpan? value, bool modifyInfo)
throw new InvalidOperationException("Wrong TimeSpan format");
}
#else
// Display days and hours or totalHours
content = (!this.ShowDays && (span.Days != 0) && (info.Format == "hh"))
? Math.Truncate(Math.Abs(span.TotalHours)).ToString()
: span.ToString(info.Format, this.CultureInfo.DateTimeFormat);
// Display days and hours or totalHours
content = (!this.ShowDays && (span.Days != 0) && (info.Format == "hh"))
? Math.Truncate(Math.Abs(span.TotalHours)).ToString()
: span.ToString(info.Format, this.CultureInfo.DateTimeFormat);
#endif

if (modifyInfo)
if (modifyInfo)
{
if (info.Format == "dd")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<UseWpf>true</UseWpf>
<OutputType>Library</OutputType>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<DebugType>Full</DebugType>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
Expand Down

0 comments on commit a4add46

Please sign in to comment.