Files
duplicati/Duplicati/Server/Serializable/ServerStatus.cs
T

149 lines
5.6 KiB
C#
Raw Normal View History

2024-02-28 15:45:30 +01:00
// 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:
2013-05-05 17:54:59 +02:00
//
2024-02-28 15:45:30 +01:00
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
2013-05-05 17:54:59 +02:00
//
2024-02-28 15:45:30 +01:00
// 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.
2013-05-05 17:54:59 +02:00
using System;
using System.Linq;
using System.Collections.Generic;
using Duplicati.Server.Serialization;
namespace Duplicati.Server.Serializable
{
/// <summary>
/// This class collects all reportable status properties into a single class that can be exported as JSON
/// </summary>
2013-11-23 14:26:36 +01:00
public class ServerStatus : Duplicati.Server.Serialization.Interface.IServerStatus
2013-05-05 17:54:59 +02:00
{
public LiveControlState ProgramState
{
get { return EnumConverter.Convert<LiveControlState>(Program.LiveControl.State); }
}
public string UpdatedVersion
{
get
{
var u = Program.DataConnection.ApplicationSettings.UpdatedVersion;
if (u == null)
return null;
2014-07-08 02:14:08 +02:00
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 UpdatePollerStates UpdaterState { get { return Program.UpdatePoller.ThreadState; } }
public bool UpdateReady { get { return Duplicati.Library.AutoUpdater.UpdaterManager.HasUpdateInstalled; } }
public double UpdateDownloadProgress { get { return Program.UpdatePoller.DownloadProgess; } }
public Tuple<long, string> ActiveTask
2013-05-05 17:54:59 +02:00
{
get
{
2013-11-23 14:26:36 +01:00
var t = Program.WorkThread.CurrentTask;
if (t == null)
return null;
2013-05-05 17:54:59 +02:00
else
return new Tuple<long, string>(t.TaskID, t.Backup == null ? null : t.Backup.ID);
2013-05-05 17:54:59 +02:00
}
}
public IList<Tuple<long, string>> SchedulerQueueIds
2013-05-05 17:54:59 +02:00
{
get { return (from n in Program.Scheduler.WorkerQueue where n.Backup != null select new Tuple<long, string>(n.TaskID, n.Backup.ID)).ToList(); }
2013-05-05 17:54:59 +02:00
}
public IList<Tuple<string, DateTime>> ProposedSchedule
{
get
{
return (
from n in Program.Scheduler.Schedule
let backupid = (from t in n.Value.Tags
where t != null && t.StartsWith("ID=", StringComparison.Ordinal)
select t.Substring("ID=".Length)).FirstOrDefault()
where !string.IsNullOrWhiteSpace(backupid)
select new Tuple<string, DateTime>(backupid, n.Key)
).ToList();
}
}
2013-05-05 17:54:59 +02:00
2014-07-31 22:08:54 +02:00
public bool HasWarning { get { return Program.DataConnection.ApplicationSettings.UnackedWarning; } }
public bool HasError { get { return Program.DataConnection.ApplicationSettings.UnackedError; } }
2013-05-05 17:54:59 +02:00
public SuggestedStatusIcon SuggestedStatusIcon
{
get
{
2014-03-20 15:09:28 +01:00
if (this.ActiveTask == null)
2013-05-05 17:54:59 +02:00
{
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 Program.LiveControl.EstimatedPauseEnd;
}
}
private long m_lastEventID = Program.StatusEventNotifyer.EventNo;
public long LastEventID
{
get { return m_lastEventID; }
set { m_lastEventID = value; }
}
public long LastDataUpdateID { get { return Program.LastDataUpdateID; } }
2014-08-04 01:06:29 +02:00
public long LastNotificationUpdateID { get { return Program.LastNotificationUpdateID; } }
2013-05-05 17:54:59 +02:00
}
}