Merge pull request #5442 from duplicati/feature/cleanup-server-status-interface

Feature/cleanup server status interface
This commit is contained in:
Kenneth Skovhede
2024-08-14 09:09:29 +02:00
committed by GitHub
8 changed files with 4 additions and 261 deletions
@@ -1,127 +0,0 @@
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Server.Serialization;
using Duplicati.Library.RestAPI;
namespace Duplicati.Server.Serializable
{
/// <summary>
/// This class collects all reportable status properties into a single class that can be exported as JSON
/// </summary>
public class ServerStatus(LiveControls liveControls) : Duplicati.Server.Serialization.Interface.IServerStatus
{
public LiveControlState ProgramState
{
get { return EnumConverter.Convert<LiveControlState>(liveControls.State); }
}
public string UpdatedVersion
{
get
{
var u = FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion;
if (u == null)
return null;
Version v;
if (!Version.TryParse(u.Version, out v))
return null;
if (v <= System.Reflection.Assembly.GetExecutingAssembly().GetName().Version)
return null;
return u.Displayname;
}
}
public string UpdateDownloadLink => FIXMEGlobal.DataConnection.ApplicationSettings.UpdatedVersion?.GetUpdateUrls()?.FirstOrDefault();
public UpdatePollerStates UpdaterState { get { return FIXMEGlobal.UpdatePoller.ThreadState; } }
public double UpdateDownloadProgress { get { return FIXMEGlobal.UpdatePoller.DownloadProgess; } }
public Tuple<long, string> ActiveTask
{
get
{
var t = FIXMEGlobal.WorkThread.CurrentTask;
if (t == null)
return null;
else
return new Tuple<long, string>(t.TaskID, t.Backup == null ? null : t.Backup.ID);
}
}
public bool HasWarning { get { return FIXMEGlobal.DataConnection.ApplicationSettings.UnackedWarning; } }
public bool HasError { get { return FIXMEGlobal.DataConnection.ApplicationSettings.UnackedError; } }
public SuggestedStatusIcon SuggestedStatusIcon
{
get
{
if (this.ActiveTask == null)
{
if (this.ProgramState == LiveControlState.Paused)
return SuggestedStatusIcon.Paused;
if (this.HasError)
return SuggestedStatusIcon.ReadyError;
if (this.HasWarning)
return SuggestedStatusIcon.ReadyWarning;
return SuggestedStatusIcon.Ready;
}
else
{
if (this.ProgramState == LiveControlState.Running)
return SuggestedStatusIcon.Active;
else
return SuggestedStatusIcon.ActivePaused;
}
}
}
public DateTime EstimatedPauseEnd
{
get
{
return liveControls.EstimatedPauseEnd;
}
}
private long m_lastEventID = FIXMEGlobal.StatusEventNotifyer.EventNo;
public long LastEventID
{
get { return m_lastEventID; }
set { m_lastEventID = value; }
}
public long LastDataUpdateID => FIXMEGlobal.NotificationUpdateService.LastDataUpdateId;
public long LastNotificationUpdateID => FIXMEGlobal.NotificationUpdateService.LastNotificationUpdateId;
}
}
@@ -58,19 +58,11 @@ namespace Duplicati.GUI.TrayIcon
};
private record ServerStatusImpl(
Tuple<long, string> ActiveTask,
LiveControlState ProgramState,
bool HasWarning,
bool HasError,
SuggestedStatusIcon SuggestedStatusIcon,
DateTime EstimatedPauseEnd,
long LastEventID,
long LastDataUpdateID,
long LastNotificationUpdateID,
string UpdatedVersion,
string UpdateDownloadLink,
UpdatePollerStates UpdaterState,
double UpdateDownloadProgress
long LastNotificationUpdateID
) : IServerStatus;
private record NotificationImpl(
@@ -18,29 +18,16 @@
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using Duplicati.Server.Serialization;
namespace Duplicati.Server.Serialization.Interface
namespace Duplicati.GUI.TrayIcon
{
// TODO: This interface should be moved to the TrayIcon and mimic only the properties that are needed
// The source data for the interface is actually the in ServerStatusDto.cs
public interface IServerStatus
{
Tuple<long, string> ActiveTask { get; }
LiveControlState ProgramState { get; }
bool HasWarning { get; }
bool HasError { get; }
SuggestedStatusIcon SuggestedStatusIcon { get; }
DateTime EstimatedPauseEnd { get; }
long LastEventID { get; }
long LastDataUpdateID { get; }
long LastNotificationUpdateID { get; }
string UpdatedVersion { get; }
string UpdateDownloadLink { get; }
UpdatePollerStates UpdaterState { get; }
double UpdateDownloadProgress { get; }
}
}
@@ -1,43 +0,0 @@
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
namespace Duplicati.Server.Serialization.Implementations
{
internal class ServerStatus : Interface.IServerStatus
{
public Tuple<long, string> ActiveTask { get; set; }
public LiveControlState ProgramState { get; set; }
public bool HasError { get; set; }
public bool HasWarning { get; set; }
public SuggestedStatusIcon SuggestedStatusIcon { get; set; }
public DateTime EstimatedPauseEnd { get; set; }
public long LastEventID { get; set; }
public long LastDataUpdateID { get; set; }
public long LastNotificationUpdateID { get; set; }
public string UpdatedVersion { get; set; }
public string UpdateDownloadLink { get; set; }
public UpdatePollerStates UpdaterState { get; set; }
public double UpdateDownloadProgress { get; set; }
}
}
@@ -1,56 +0,0 @@
// Copyright (C) 2024, The Duplicati Team
// https://duplicati.com, hello@duplicati.com
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
namespace Duplicati.Server.Serialization.Interface
{
/// <summary>
/// Gets all server settings
/// </summary>
public interface IServerSettings
{
/// <summary>
/// The backend modules known by the server
/// </summary>
IDynamicModule[] BackendModules { get; }
/// <summary>
/// The encryption modules known by the server
/// </summary>
IDynamicModule[] EncryptionModules { get; }
/// <summary>
/// The compression modules known by the server
/// </summary>
IDynamicModule[] CompressionModules { get; }
/// <summary>
/// The generic modules known by the server
/// </summary>
IDynamicModule[] GenericModules { get; }
/// <summary>
/// The filters that are applied to all backups
/// </summary>
IFilter[] Filters { get; }
/// <summary>
/// The settings applied to all backups by default
/// </summary>
ISetting[] Settings { get; }
}
}
@@ -24,14 +24,6 @@ using Newtonsoft.Json;
namespace Duplicati.Server.Serialization
{
public class SerializableStatusCreator : CustomCreationConverter<Interface.IServerStatus>
{
public override Interface.IServerStatus Create(Type objectType)
{
return new Implementations.ServerStatus();
}
}
public class SettingsCreator : CustomCreationConverter<Interface.ISetting>
{
public override Interface.ISetting Create(Type objectType)
@@ -38,7 +38,6 @@ namespace Duplicati.Server.Serialization
{
new DayOfWeekConcerter(),
new StringEnumConverter(),
new SerializableStatusCreator(),
new SettingsCreator(),
new FilterCreator(),
new NotificationCreator(),
@@ -1,12 +1,11 @@
using Duplicati.Server.Serialization;
using Duplicati.Server.Serialization.Interface;
namespace Duplicati.WebserverCore.Dto;
/// <summary>
/// Represents the server status DTO.
/// </summary>
public sealed record ServerStatusDto : IServerStatus
public sealed record ServerStatusDto
{
/// <summary>
/// Gets or sets the active task.