code optimization
This commit is contained in:
@@ -1,45 +1,39 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention;
|
||||
|
||||
public class FilesRetentionClient : ClientBase
|
||||
{
|
||||
public class FilesRetentionClient : ClientBase
|
||||
public FilesRetentionClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
public FilesRetentionClient(NextcloudClient client) : base(client)
|
||||
}
|
||||
|
||||
public bool CreateRetentionRule(RetentionRuleInfo rule)
|
||||
{
|
||||
var entry = rule.ToOcsData();
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().CreateRetentionRule(entry);
|
||||
}
|
||||
|
||||
public bool DeleteRetentionRule(int ruleID)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().DeleteRetentionRule(ruleID);
|
||||
}
|
||||
|
||||
public RetentionRule[]? GetRetentionRules()
|
||||
{
|
||||
var api = Client.Ocs.GetApi<OcsApiFilesRetention>();
|
||||
var response = api.GetRetentionRules();
|
||||
|
||||
if (response?.Data is not null)
|
||||
{
|
||||
var rules = new List<RetentionRule>();
|
||||
|
||||
foreach (var entry in response.Data)
|
||||
rules.Add(new RetentionRule(entry));
|
||||
|
||||
return rules.ToArray();
|
||||
}
|
||||
|
||||
public bool CreateRetentionRule(RetentionRuleInfo rule)
|
||||
{
|
||||
var entry = rule.ToOcsData();
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().CreateRetentionRule(entry);
|
||||
}
|
||||
|
||||
public bool DeleteRetentionRule(int ruleID)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiFilesRetention>().DeleteRetentionRule(ruleID);
|
||||
}
|
||||
|
||||
public RetentionRule[]? GetRetentionRules()
|
||||
{
|
||||
var api = Client.Ocs.GetApi<OcsApiFilesRetention>();
|
||||
var response = api.GetRetentionRules();
|
||||
|
||||
if (response?.Data is not null)
|
||||
{
|
||||
var rules = new List<RetentionRule>();
|
||||
|
||||
foreach (var entry in response.Data)
|
||||
rules.Add(new RetentionRule(entry));
|
||||
|
||||
return rules.ToArray();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
|
||||
|
||||
public class RetentionRule : RetentionRuleInfo
|
||||
{
|
||||
public class RetentionRule : RetentionRuleInfo
|
||||
/// <summary>
|
||||
/// The ID for the retention rule.
|
||||
/// </summary>
|
||||
public int ID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines if a background job has been generated
|
||||
/// </summary>
|
||||
public bool HasJob { get; init; }
|
||||
|
||||
public RetentionRule()
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID for the retention rule.
|
||||
/// </summary>
|
||||
public int ID { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Defines if a background job has been generated
|
||||
/// </summary>
|
||||
public bool HasJob { get; init; }
|
||||
|
||||
public RetentionRule()
|
||||
{
|
||||
}
|
||||
|
||||
public RetentionRule(OcsResponseDataEntryRetention data)
|
||||
{
|
||||
ID = data.ID ?? -1;
|
||||
TagID = data.TagID ?? -1;
|
||||
TimeUnit = (RetentionTimeUnit)(data.TimeUnit ?? 0);
|
||||
TimeAmount = data.TimeAmount ?? -1;
|
||||
TimeAfter = (RetentionTimeAfter)(data.TimeAfter ?? 0);
|
||||
HasJob = data.HasJob ?? false;
|
||||
}
|
||||
public RetentionRule(OcsResponseDataEntryRetention data)
|
||||
{
|
||||
ID = data.ID ?? -1;
|
||||
TagID = data.TagID ?? -1;
|
||||
TimeUnit = (RetentionTimeUnit)(data.TimeUnit ?? 0);
|
||||
TimeAmount = data.TimeAmount ?? -1;
|
||||
TimeAfter = (RetentionTimeAfter)(data.TimeAfter ?? 0);
|
||||
HasJob = data.HasJob ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,43 +1,37 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
|
||||
|
||||
public class RetentionRuleInfo
|
||||
{
|
||||
public class RetentionRuleInfo
|
||||
/// <summary>
|
||||
/// The ID for the tag that is used for this rule.
|
||||
/// </summary>
|
||||
public int TagID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The unit used for the time.
|
||||
/// </summary>
|
||||
public RetentionTimeUnit TimeUnit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Represents numer of days/weeks/months/years.
|
||||
/// </summary>
|
||||
public int TimeAmount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The time used for the rule.
|
||||
/// </summary>
|
||||
public RetentionTimeAfter TimeAfter { get; init; }
|
||||
|
||||
public OcsDataRetentionRule ToOcsData()
|
||||
{
|
||||
/// <summary>
|
||||
/// The ID for the tag that is used for this rule.
|
||||
/// </summary>
|
||||
public int TagID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The unit used for the time.
|
||||
/// </summary>
|
||||
public RetentionTimeUnit TimeUnit { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Represents numer of days/weeks/months/years.
|
||||
/// </summary>
|
||||
public int TimeAmount { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The time used for the rule.
|
||||
/// </summary>
|
||||
public RetentionTimeAfter TimeAfter { get; init; }
|
||||
|
||||
public OcsDataRetentionRule ToOcsData()
|
||||
return new OcsDataRetentionRule
|
||||
{
|
||||
return new OcsDataRetentionRule
|
||||
{
|
||||
TagID = TagID,
|
||||
TimeUnit = (int)TimeUnit,
|
||||
TimeAmount = TimeAmount,
|
||||
TimeAfter = (int)TimeAfter
|
||||
};
|
||||
}
|
||||
TagID = TagID,
|
||||
TimeUnit = (int)TimeUnit,
|
||||
TimeAmount = TimeAmount,
|
||||
TimeAfter = (int)TimeAfter
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
|
||||
public enum RetentionTimeAfter
|
||||
{
|
||||
public enum RetentionTimeAfter
|
||||
{
|
||||
CreationDate,
|
||||
LastAccess
|
||||
}
|
||||
CreationDate,
|
||||
LastAccess
|
||||
}
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Model
|
||||
public enum RetentionTimeUnit
|
||||
{
|
||||
public enum RetentionTimeUnit
|
||||
{
|
||||
Day,
|
||||
Week,
|
||||
Month,
|
||||
Year
|
||||
}
|
||||
Day,
|
||||
Week,
|
||||
Month,
|
||||
Year
|
||||
}
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
|
||||
public class OcsDataRetentionRule : OcsData
|
||||
{
|
||||
public class OcsDataRetentionRule : OcsData
|
||||
{
|
||||
|
||||
[JsonProperty("tagid")]
|
||||
public int? TagID { get; set; }
|
||||
[JsonProperty("tagid")]
|
||||
public int? TagID { get; set; }
|
||||
|
||||
[JsonProperty("timeunit")]
|
||||
public int? TimeUnit { get; set; }
|
||||
[JsonProperty("timeunit")]
|
||||
public int? TimeUnit { get; set; }
|
||||
|
||||
[JsonProperty("timeamount")]
|
||||
public int? TimeAmount { get; set; }
|
||||
[JsonProperty("timeamount")]
|
||||
public int? TimeAmount { get; set; }
|
||||
|
||||
[JsonProperty("timeafter")]
|
||||
public int? TimeAfter { get; set; }
|
||||
}
|
||||
[JsonProperty("timeafter")]
|
||||
public int? TimeAfter { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,31 +1,25 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
|
||||
public class OcsResponseDataEntryRetention : OcsResponseDataEntry
|
||||
{
|
||||
public class OcsResponseDataEntryRetention : OcsResponseDataEntry
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int? ID { get; set; }
|
||||
[JsonProperty("id")]
|
||||
public int? ID { get; set; }
|
||||
|
||||
[JsonProperty("tagid")]
|
||||
public int? TagID { get; set; }
|
||||
[JsonProperty("tagid")]
|
||||
public int? TagID { get; set; }
|
||||
|
||||
[JsonProperty("timeunit")]
|
||||
public int? TimeUnit { get; set; }
|
||||
[JsonProperty("timeunit")]
|
||||
public int? TimeUnit { get; set; }
|
||||
|
||||
[JsonProperty("timeamount")]
|
||||
public int? TimeAmount { get; set; }
|
||||
[JsonProperty("timeamount")]
|
||||
public int? TimeAmount { get; set; }
|
||||
|
||||
[JsonProperty("timeafter")]
|
||||
public int? TimeAfter { get; set; }
|
||||
[JsonProperty("timeafter")]
|
||||
public int? TimeAfter { get; set; }
|
||||
|
||||
[JsonProperty("hasJob")]
|
||||
public bool? HasJob { get; set; }
|
||||
}
|
||||
[JsonProperty("hasJob")]
|
||||
public bool? HasJob { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
|
||||
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
|
||||
{
|
||||
public class OcsResponseRetention : OcsResponse<OcsResponseDataArray<OcsResponseDataEntryRetention>>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,38 +1,31 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention.Ocs;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.FileRetention;
|
||||
|
||||
public class OcsApiFilesRetention : OcsApiBase
|
||||
{
|
||||
public class OcsApiFilesRetention : OcsApiBase
|
||||
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULES = new("/ocs/v2.php/apps/files_retention/api/v1/retentions");
|
||||
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULE = new("/ocs/v2.php/apps/files_retention/api/v1/retentions/{0}");
|
||||
|
||||
public OcsApiFilesRetention(OcsApi manager) : base(manager)
|
||||
{
|
||||
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULES = new("/ocs/v2.php/apps/files_retention/api/v1/retentions");
|
||||
public static readonly OcsApiUrlPath OCS_FILE_RETENTION_RULE = new("/ocs/v2.php/apps/files_retention/api/v1/retentions/{0}");
|
||||
}
|
||||
|
||||
public OcsApiFilesRetention(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
public bool CreateRetentionRule(OcsDataRetentionRule rule)
|
||||
{
|
||||
var response = Manager.MakeRequest(HttpMethod.Post, OCS_FILE_RETENTION_RULES, content: rule);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public bool CreateRetentionRule(OcsDataRetentionRule rule)
|
||||
{
|
||||
var response = Manager.MakeRequest(HttpMethod.Post, OCS_FILE_RETENTION_RULES, content: rule);
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
public bool DeleteRetentionRule(int ruleID)
|
||||
{
|
||||
var response = Manager.MakeRequest(HttpMethod.Delete, OCS_FILE_RETENTION_RULE.FillParameters(ruleID));
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public bool DeleteRetentionRule(int ruleID)
|
||||
{
|
||||
var response = Manager.MakeRequest(HttpMethod.Delete, OCS_FILE_RETENTION_RULE.FillParameters(ruleID));
|
||||
return response.IsSuccessStatusCode;
|
||||
}
|
||||
|
||||
public OcsResponseRetention? GetRetentionRules()
|
||||
{
|
||||
return Manager.MakeRequestOcs<OcsResponseRetention>(HttpMethod.Get, OCS_FILE_RETENTION_RULES);
|
||||
}
|
||||
public OcsResponseRetention? GetRetentionRules()
|
||||
{
|
||||
return Manager.MakeRequestOcs<OcsResponseRetention>(HttpMethod.Get, OCS_FILE_RETENTION_RULES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,116 +1,110 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
public class Column
|
||||
{
|
||||
public class Column
|
||||
[JsonProperty("type")]
|
||||
private string? type;
|
||||
|
||||
[JsonProperty("subtype")]
|
||||
private string? subtype;
|
||||
|
||||
[JsonProperty("id")]
|
||||
public long ColumnId { get; set; }
|
||||
|
||||
[JsonProperty("tableId")]
|
||||
public long TableId { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonProperty("createdBy")]
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
[JsonProperty("createdAt")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
[JsonProperty("lastEditBy")]
|
||||
public string? LastEditBy { get; set; }
|
||||
|
||||
[JsonProperty("lastEditAt")]
|
||||
public DateTime LastEditAt { get; set; }
|
||||
|
||||
[JsonProperty("mandatory")]
|
||||
public bool Mandatory { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[JsonProperty("numberDefault")]
|
||||
public float? NumberDefault { get; set; }
|
||||
|
||||
[JsonProperty("numberMin")]
|
||||
public float? NumberMin { get; set; }
|
||||
|
||||
[JsonProperty("numberMax")]
|
||||
public float? NumberMax { get; set; }
|
||||
|
||||
[JsonProperty("numberDecimals")]
|
||||
public float NumberDecimals { get; set; }
|
||||
|
||||
[JsonProperty("numberPrefix")]
|
||||
public string? NumberPrefix { get; set; }
|
||||
|
||||
[JsonProperty("numberSuffix")]
|
||||
public string? NumberSuffix { get; set; }
|
||||
|
||||
[JsonProperty("textDefault")]
|
||||
public string? TextDefault { get; set; }
|
||||
|
||||
[JsonProperty("textAllowedPattern")]
|
||||
public string? TextAllowedPattern { get; set; }
|
||||
|
||||
[JsonProperty("textMaxLength")]
|
||||
public int? TextMaxLength { get; set; }
|
||||
|
||||
[JsonProperty("selectionOptions")]
|
||||
public List<ColumnSelectionOption> SelectionOptions { get; } = new();
|
||||
|
||||
[JsonProperty("selectionDefault")]
|
||||
public int? SelectionDefault { get; set; }
|
||||
|
||||
[JsonProperty("datetimeDefault")]
|
||||
public DateTime? DatetimeDefault { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ColumnType Type
|
||||
{
|
||||
[JsonProperty("type")]
|
||||
private string? type;
|
||||
|
||||
[JsonProperty("subtype")]
|
||||
private string? subtype;
|
||||
|
||||
[JsonProperty("id")]
|
||||
public long ColumnId { get; set; }
|
||||
|
||||
[JsonProperty("tableId")]
|
||||
public long TableId { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonProperty("createdBy")]
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
[JsonProperty("createdAt")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
[JsonProperty("lastEditBy")]
|
||||
public string? LastEditBy { get; set; }
|
||||
|
||||
[JsonProperty("lastEditAt")]
|
||||
public DateTime LastEditAt { get; set; }
|
||||
|
||||
[JsonProperty("mandatory")]
|
||||
public bool Mandatory { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string? Description { get; set; }
|
||||
|
||||
[JsonProperty("numberDefault")]
|
||||
public float? NumberDefault { get; set; }
|
||||
|
||||
[JsonProperty("numberMin")]
|
||||
public float? NumberMin { get; set; }
|
||||
|
||||
[JsonProperty("numberMax")]
|
||||
public float? NumberMax { get; set; }
|
||||
|
||||
[JsonProperty("numberDecimals")]
|
||||
public float NumberDecimals { get; set; }
|
||||
|
||||
[JsonProperty("numberPrefix")]
|
||||
public string? NumberPrefix { get; set; }
|
||||
|
||||
[JsonProperty("numberSuffix")]
|
||||
public string? NumberSuffix { get; set; }
|
||||
|
||||
[JsonProperty("textDefault")]
|
||||
public string? TextDefault { get; set; }
|
||||
|
||||
[JsonProperty("textAllowedPattern")]
|
||||
public string? TextAllowedPattern { get; set; }
|
||||
|
||||
[JsonProperty("textMaxLength")]
|
||||
public int? TextMaxLength { get; set; }
|
||||
|
||||
[JsonProperty("selectionOptions")]
|
||||
public List<ColumnSelectionOption> SelectionOptions { get; } = new();
|
||||
|
||||
[JsonProperty("selectionDefault")]
|
||||
public int? SelectionDefault { get; set; }
|
||||
|
||||
[JsonProperty("datetimeDefault")]
|
||||
public DateTime? DatetimeDefault { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public ColumnType Type
|
||||
get => type switch
|
||||
{
|
||||
get => type switch
|
||||
{
|
||||
"text" => ColumnType.Text,
|
||||
"selection" => ColumnType.Selection,
|
||||
"datetime" => ColumnType.DateTime,
|
||||
_ => ColumnType.Unknown,
|
||||
};
|
||||
set => type = value switch
|
||||
{
|
||||
ColumnType.Text => "text",
|
||||
ColumnType.Selection => "selection",
|
||||
ColumnType.DateTime => "datetime",
|
||||
_ => "text"
|
||||
};
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public ColumnSubtype Subtype
|
||||
"text" => ColumnType.Text,
|
||||
"selection" => ColumnType.Selection,
|
||||
"datetime" => ColumnType.DateTime,
|
||||
_ => ColumnType.Unknown,
|
||||
};
|
||||
set => type = value switch
|
||||
{
|
||||
get => subtype switch
|
||||
{
|
||||
"line" => ColumnSubtype.Line,
|
||||
"" => ColumnSubtype.None,
|
||||
_ => ColumnSubtype.Unknown,
|
||||
};
|
||||
set => subtype = value switch
|
||||
{
|
||||
ColumnSubtype.Line => "line",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
ColumnType.Text => "text",
|
||||
ColumnType.Selection => "selection",
|
||||
ColumnType.DateTime => "datetime",
|
||||
_ => "text"
|
||||
};
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public ColumnSubtype Subtype
|
||||
{
|
||||
get => subtype switch
|
||||
{
|
||||
"line" => ColumnSubtype.Line,
|
||||
"" => ColumnSubtype.None,
|
||||
_ => ColumnSubtype.Unknown,
|
||||
};
|
||||
set => subtype = value switch
|
||||
{
|
||||
ColumnSubtype.Line => "line",
|
||||
_ => ""
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
public class ColumnSelectionOption
|
||||
{
|
||||
public class ColumnSelectionOption
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public long Id { get; set; }
|
||||
[JsonProperty("id")]
|
||||
public long Id { get; set; }
|
||||
|
||||
[JsonProperty("label")]
|
||||
public string? Label { get; set; }
|
||||
}
|
||||
[JsonProperty("label")]
|
||||
public string? Label { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public enum ColumnSubtype
|
||||
{
|
||||
public enum ColumnSubtype
|
||||
{
|
||||
None,
|
||||
Unknown,
|
||||
Line
|
||||
}
|
||||
None,
|
||||
Unknown,
|
||||
Line
|
||||
}
|
||||
|
||||
@@ -1,16 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public enum ColumnType
|
||||
{
|
||||
public enum ColumnType
|
||||
{
|
||||
Unknown,
|
||||
Text,
|
||||
Selection,
|
||||
DateTime
|
||||
}
|
||||
Unknown,
|
||||
Text,
|
||||
Selection,
|
||||
DateTime
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public class Columns : List<Column>
|
||||
{
|
||||
public class Columns : List<Column>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,27 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
public class Row
|
||||
{
|
||||
public class Row
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public long RowId { get; set; } = -1;
|
||||
[JsonProperty("id")]
|
||||
public long RowId { get; set; } = -1;
|
||||
|
||||
[JsonProperty("tableId")]
|
||||
public long TableId { get; set; } = -1;
|
||||
[JsonProperty("tableId")]
|
||||
public long TableId { get; set; } = -1;
|
||||
|
||||
[JsonProperty("createdBy")]
|
||||
public string? CreatedBy { get; set; }
|
||||
[JsonProperty("createdBy")]
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
[JsonProperty("createdAt")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
[JsonProperty("createdAt")]
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
[JsonProperty("lastEditBy")]
|
||||
public string? LastEditBy { get; set; }
|
||||
[JsonProperty("lastEditBy")]
|
||||
public string? LastEditBy { get; set; }
|
||||
|
||||
[JsonProperty("lastEditAt")]
|
||||
public DateTime LastEditAt { get; set; }
|
||||
[JsonProperty("lastEditAt")]
|
||||
public DateTime LastEditAt { get; set; }
|
||||
|
||||
[JsonProperty("data")]
|
||||
public List<RowData> Data { get; set; } = new();
|
||||
}
|
||||
[JsonProperty("data")]
|
||||
public List<RowData> Data { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,12 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
public class RowData
|
||||
{
|
||||
public class RowData
|
||||
{
|
||||
[JsonProperty("columnId")]
|
||||
public long ColumnId { get; set; }
|
||||
[JsonProperty("columnId")]
|
||||
public long ColumnId { get; set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public object? Value { get; set; }
|
||||
}
|
||||
[JsonProperty("value")]
|
||||
public object? Value { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public class RowSimple : List<object>
|
||||
{
|
||||
public class RowSimple : List<object>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,9 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
public class RowUpdate
|
||||
{
|
||||
public class RowUpdate
|
||||
{
|
||||
[JsonProperty("data")]
|
||||
public Dictionary<long, object?> Data { get; set; } = new();
|
||||
}
|
||||
[JsonProperty("data")]
|
||||
public Dictionary<long, object?> Data { get; set; } = new();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public class Rows : List<Row>
|
||||
{
|
||||
public class Rows : List<Row>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model
|
||||
public class RowsSimple : List<RowSimple>
|
||||
{
|
||||
public class RowsSimple : List<RowSimple>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,86 +1,79 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables;
|
||||
|
||||
public class OcsApiTables : OcsApiBase
|
||||
{
|
||||
public class OcsApiTables : OcsApiBase
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS = new("/apps/tables/api/1/tables/{0}/rows");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_ROWS = new("/apps/tables/api/1/views/{0}/rows");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS_SIMPLE = new("/apps/tables/api/1/tables/{0}/rows/simple");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_COLUMNS = new("/apps/tables/api/1/tables/{0}/columns");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_COLUMNS = new("/apps/tables/api/1/views/{0}/columns");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_ROW = new("/apps/tables/api/1/rows/{0}");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_COLUMN = new("/apps/tables/api/1/column/{0}");
|
||||
|
||||
public OcsApiTables(OcsApi manager) : base(manager)
|
||||
{
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS = new("/apps/tables/api/1/tables/{0}/rows");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_ROWS = new("/apps/tables/api/1/views/{0}/rows");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_ROWS_SIMPLE = new("/apps/tables/api/1/tables/{0}/rows/simple");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_TABLE_COLUMNS = new("/apps/tables/api/1/tables/{0}/columns");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_VIEW_COLUMNS = new("/apps/tables/api/1/views/{0}/columns");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_ROW = new("/apps/tables/api/1/rows/{0}");
|
||||
public static readonly OcsApiUrlPath OCS_TABLES_COLUMN = new("/apps/tables/api/1/column/{0}");
|
||||
}
|
||||
|
||||
public OcsApiTables(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
public RowsSimple? GetRowsSimple(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<RowsSimple>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS_SIMPLE.FillParameters(tableId));
|
||||
}
|
||||
|
||||
public RowsSimple? GetRowsSimple(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<RowsSimple>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS_SIMPLE.FillParameters(tableId));
|
||||
}
|
||||
public Rows? GetRows(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS.FillParameters(tableId));
|
||||
}
|
||||
|
||||
public Rows? GetRows(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_TABLE_ROWS.FillParameters(tableId));
|
||||
}
|
||||
public Rows? GetViewRows(long viewId)
|
||||
{
|
||||
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_VIEW_ROWS.FillParameters(viewId));
|
||||
}
|
||||
|
||||
public Rows? GetViewRows(long viewId)
|
||||
{
|
||||
return Manager.MakeRequest<Rows>(HttpMethod.Get, OCS_TABLES_VIEW_ROWS.FillParameters(viewId));
|
||||
}
|
||||
public Row? GetRow(long rowId)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Get, OCS_TABLES_ROW.FillParameters(rowId));
|
||||
}
|
||||
|
||||
public Row? GetRow(long rowId)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Get, OCS_TABLES_ROW.FillParameters(rowId));
|
||||
}
|
||||
public Columns? GetColumns(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_TABLE_COLUMNS.FillParameters(tableId));
|
||||
}
|
||||
|
||||
public Columns? GetColumns(long tableId)
|
||||
{
|
||||
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_TABLE_COLUMNS.FillParameters(tableId));
|
||||
}
|
||||
public Columns? GetViewColumns(long viewId)
|
||||
{
|
||||
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_VIEW_COLUMNS.FillParameters(viewId));
|
||||
}
|
||||
|
||||
public Columns? GetViewColumns(long viewId)
|
||||
{
|
||||
return Manager.MakeRequest<Columns>(HttpMethod.Get, OCS_TABLES_VIEW_COLUMNS.FillParameters(viewId));
|
||||
}
|
||||
public Column? GetColumn(long columnId)
|
||||
{
|
||||
return Manager.MakeRequest<Column>(HttpMethod.Get, OCS_TABLES_COLUMN.FillParameters(columnId));
|
||||
}
|
||||
|
||||
public Column? GetColumn(long columnId)
|
||||
{
|
||||
return Manager.MakeRequest<Column>(HttpMethod.Get, OCS_TABLES_COLUMN.FillParameters(columnId));
|
||||
}
|
||||
public Row? DeleteRow(long rowId)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Delete, OCS_TABLES_ROW.FillParameters(rowId));
|
||||
}
|
||||
|
||||
public Row? DeleteRow(long rowId)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Delete, OCS_TABLES_ROW.FillParameters(rowId));
|
||||
}
|
||||
public Column? DeleteColumn(long columnId)
|
||||
{
|
||||
return Manager.MakeRequest<Column>(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId));
|
||||
}
|
||||
|
||||
public Column? DeleteColumn(long columnId)
|
||||
{
|
||||
return Manager.MakeRequest<Column>(HttpMethod.Delete, OCS_TABLES_COLUMN.FillParameters(columnId));
|
||||
}
|
||||
public Row? UpdateRow(long rowId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Put, OCS_TABLES_ROW.FillParameters(rowId), content: values);
|
||||
}
|
||||
|
||||
public Row? UpdateRow(long rowId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Put, OCS_TABLES_ROW.FillParameters(rowId), content: values);
|
||||
}
|
||||
public Row? CreateRow(long tableId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_TABLE_ROWS.FillParameters(tableId), content: values);
|
||||
}
|
||||
|
||||
public Row? CreateRow(long tableId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_TABLE_ROWS.FillParameters(tableId), content: values);
|
||||
}
|
||||
|
||||
public Row? CreateViewRow(long viewId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_VIEW_ROWS.FillParameters(viewId), content: values);
|
||||
}
|
||||
public Row? CreateViewRow(long viewId, RowUpdate values)
|
||||
{
|
||||
return Manager.MakeRequest<Row>(HttpMethod.Post, OCS_TABLES_VIEW_ROWS.FillParameters(viewId), content: values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,81 +1,75 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables;
|
||||
|
||||
public class TablesClient : ClientBase
|
||||
{
|
||||
public class TablesClient : ClientBase
|
||||
public TablesClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
public TablesClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public RowsSimple? GetRowsSimple(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRowsSimple(tableId);
|
||||
}
|
||||
public RowsSimple? GetRowsSimple(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRowsSimple(tableId);
|
||||
}
|
||||
|
||||
public Rows? GetRows(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRows(tableId);
|
||||
}
|
||||
public Rows? GetRows(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRows(tableId);
|
||||
}
|
||||
|
||||
public Rows? GetViewRows(long viewId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetViewRows(viewId);
|
||||
}
|
||||
public Rows? GetViewRows(long viewId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetViewRows(viewId);
|
||||
}
|
||||
|
||||
public Row? GetRow(long rowId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRow(rowId);
|
||||
}
|
||||
public Row? GetRow(long rowId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetRow(rowId);
|
||||
}
|
||||
|
||||
public Columns? GetColumns(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetColumns(tableId);
|
||||
}
|
||||
public Columns? GetColumns(long tableId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetColumns(tableId);
|
||||
}
|
||||
|
||||
public Columns? GetViewColumns(long viewId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetViewColumns(viewId);
|
||||
}
|
||||
public Columns? GetViewColumns(long viewId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetViewColumns(viewId);
|
||||
}
|
||||
|
||||
public Column? GetColumn(long columnId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetColumn(columnId);
|
||||
}
|
||||
public Column? GetColumn(long columnId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().GetColumn(columnId);
|
||||
}
|
||||
|
||||
public bool DeleteRow(long rowId)
|
||||
{
|
||||
return DeleteRowAdv(rowId) is not null;
|
||||
}
|
||||
public bool DeleteRow(long rowId)
|
||||
{
|
||||
return DeleteRowAdv(rowId) is not null;
|
||||
}
|
||||
|
||||
public Row? DeleteRowAdv(long rowId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().DeleteRow(rowId);
|
||||
}
|
||||
public Row? DeleteRowAdv(long rowId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().DeleteRow(rowId);
|
||||
}
|
||||
|
||||
public bool DeleteColumn(long columnId)
|
||||
{
|
||||
return DeleteColumnAdv(columnId) is not null;
|
||||
}
|
||||
public bool DeleteColumn(long columnId)
|
||||
{
|
||||
return DeleteColumnAdv(columnId) is not null;
|
||||
}
|
||||
|
||||
public Column? DeleteColumnAdv(long columnId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().DeleteColumn(columnId);
|
||||
}
|
||||
public Column? DeleteColumnAdv(long columnId)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().DeleteColumn(columnId);
|
||||
}
|
||||
|
||||
public Row? UpdateRow(long rowId, RowUpdate values)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().UpdateRow(rowId, values);
|
||||
}
|
||||
public Row? UpdateRow(long rowId, RowUpdate values)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().UpdateRow(rowId, values);
|
||||
}
|
||||
|
||||
public Row? CreateRow(long tableId, RowUpdate values)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().CreateRow(tableId, values);
|
||||
}
|
||||
public Row? CreateRow(long tableId, RowUpdate values)
|
||||
{
|
||||
return Client.Ocs.GetApi<OcsApiTables>().CreateRow(tableId, values);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Apps.Tables.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client;
|
||||
|
||||
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client
|
||||
{
|
||||
public abstract class ClientBase
|
||||
{
|
||||
protected NextcloudClient Client { get; init; }
|
||||
Nach:
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client;
|
||||
|
||||
protected ClientBase(NextcloudClient client)
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
public abstract class ClientBase
|
||||
*/
|
||||
public abstract class ClientBase
|
||||
{
|
||||
protected NextcloudClient Client { get; init; }
|
||||
|
||||
protected ClientBase(NextcloudClient client)
|
||||
{
|
||||
Client = client;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +1,28 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
|
||||
|
||||
public class CloudClient : ClientBase
|
||||
{
|
||||
public class CloudClient : ClientBase
|
||||
public CloudClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
public CloudClient(NextcloudClient client) : base(client)
|
||||
{
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Client.CurrentLogin?.LoginName))
|
||||
return GetUserInfo(Client.CurrentLogin.LoginName);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo(string username)
|
||||
{
|
||||
var result = Client.Ocs.Cloud.GetUserMeta(username);
|
||||
|
||||
if (result?.Data != null)
|
||||
return new UserInfo(result.Data);
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Client.CurrentLogin?.LoginName))
|
||||
return GetUserInfo(Client.CurrentLogin.LoginName);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public UserInfo? GetUserInfo(string username)
|
||||
{
|
||||
var result = Client.Ocs.Cloud.GetUserMeta(username);
|
||||
|
||||
if (result?.Data != null)
|
||||
return new UserInfo(result.Data);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
public class UserBackendCapabilities
|
||||
{
|
||||
public class UserBackendCapabilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines if the display name can be changed.
|
||||
/// </summary>
|
||||
public bool SetDisplayName { get; set; }
|
||||
/// <summary>
|
||||
/// Defines if the display name can be changed.
|
||||
/// </summary>
|
||||
public bool SetDisplayName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines if the password can be changed.
|
||||
/// </summary>
|
||||
public bool SetPassword { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Defines if the password can be changed.
|
||||
/// </summary>
|
||||
public bool SetPassword { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,131 +1,125 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
|
||||
public class UserInfo
|
||||
{
|
||||
public class UserInfo
|
||||
/// <summary>
|
||||
/// Defines if the user is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The location of the user's storage directory.
|
||||
/// </summary>
|
||||
public string? StorageLocation { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The uniquie user id that infos are for.
|
||||
/// </summary>
|
||||
public string? ID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The last time when the user has logged in to its account.
|
||||
/// </summary>
|
||||
public DateTime LastLogin { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The backend of the user. Common values are "Database" or "LDAP".
|
||||
/// </summary>
|
||||
public string? Backend { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Email address of the user.
|
||||
/// </summary>
|
||||
public string? Email { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname2 { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The phone number of the user.
|
||||
/// </summary>
|
||||
public string? Phone { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The address of the user.
|
||||
/// </summary>
|
||||
public string? Address { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Website of the user.
|
||||
/// </summary>
|
||||
public string? Website { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The twitter profile name of the user.
|
||||
/// </summary>
|
||||
public string? Twitter { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the groups the user is member of.
|
||||
/// </summary>
|
||||
public string[] Groups { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured language of the user.
|
||||
/// </summary>
|
||||
public string? Language { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured location of the user.
|
||||
/// </summary>
|
||||
public string? Locale { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Quota informations for the user.
|
||||
/// </summary>
|
||||
public UserQuota Quota { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Backend capabilities of the user.
|
||||
/// </summary>
|
||||
public UserBackendCapabilities BackendCapabilities { get; } = new();
|
||||
|
||||
public UserInfo(OcsResponseDataUser responseData)
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines if the user is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled { get; init; }
|
||||
Enabled = Convert.ToBoolean(responseData.Enabled);
|
||||
StorageLocation = responseData.StorageLocation;
|
||||
ID = responseData.ID;
|
||||
LastLogin = responseData.LastLogin.UnixTimeMillisecondsToDateTime();
|
||||
Backend = responseData.Backend;
|
||||
Email = responseData.Email;
|
||||
Displayname = responseData.Displayname;
|
||||
Displayname2 = responseData.Displayname2;
|
||||
Phone = responseData.Phone;
|
||||
Address = responseData.Address;
|
||||
Website = responseData.Website;
|
||||
Twitter = responseData.Twitter;
|
||||
Groups = responseData.Groups ?? Array.Empty<string>();
|
||||
Language = responseData.Language;
|
||||
Locale = responseData.Locale;
|
||||
|
||||
/// <summary>
|
||||
/// The location of the user's storage directory.
|
||||
/// </summary>
|
||||
public string? StorageLocation { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The uniquie user id that infos are for.
|
||||
/// </summary>
|
||||
public string? ID { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The last time when the user has logged in to its account.
|
||||
/// </summary>
|
||||
public DateTime LastLogin { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The backend of the user. Common values are "Database" or "LDAP".
|
||||
/// </summary>
|
||||
public string? Backend { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Email address of the user.
|
||||
/// </summary>
|
||||
public string? Email { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The displayname of the user.
|
||||
/// </summary>
|
||||
public string? Displayname2 { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The phone number of the user.
|
||||
/// </summary>
|
||||
public string? Phone { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The address of the user.
|
||||
/// </summary>
|
||||
public string? Address { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The Website of the user.
|
||||
/// </summary>
|
||||
public string? Website { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The twitter profile name of the user.
|
||||
/// </summary>
|
||||
public string? Twitter { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines the groups the user is member of.
|
||||
/// </summary>
|
||||
public string[] Groups { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured language of the user.
|
||||
/// </summary>
|
||||
public string? Language { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The configured location of the user.
|
||||
/// </summary>
|
||||
public string? Locale { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Quota informations for the user.
|
||||
/// </summary>
|
||||
public UserQuota Quota { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Backend capabilities of the user.
|
||||
/// </summary>
|
||||
public UserBackendCapabilities BackendCapabilities { get; } = new();
|
||||
|
||||
public UserInfo(OcsResponseDataUser responseData)
|
||||
if (responseData.Quota != null)
|
||||
{
|
||||
Enabled = Convert.ToBoolean(responseData.Enabled);
|
||||
StorageLocation = responseData.StorageLocation;
|
||||
ID = responseData.ID;
|
||||
LastLogin = responseData.LastLogin.UnixTimeMillisecondsToDateTime();
|
||||
Backend = responseData.Backend;
|
||||
Email = responseData.Email;
|
||||
Displayname = responseData.Displayname;
|
||||
Displayname2 = responseData.Displayname2;
|
||||
Phone = responseData.Phone;
|
||||
Address = responseData.Address;
|
||||
Website = responseData.Website;
|
||||
Twitter = responseData.Twitter;
|
||||
Groups = responseData.Groups ?? Array.Empty<string>();
|
||||
Language = responseData.Language;
|
||||
Locale = responseData.Locale;
|
||||
Quota.Free = responseData.Quota.Free ?? 0;
|
||||
Quota.Used = responseData.Quota.Used ?? 0;
|
||||
Quota.Total = responseData.Quota.Total ?? 0;
|
||||
Quota.Relative = responseData.Quota.Relative ?? 0.0F;
|
||||
Quota.Quota = responseData.Quota.Quota ?? 0;
|
||||
}
|
||||
|
||||
if (responseData.Quota != null)
|
||||
{
|
||||
Quota.Free = responseData.Quota.Free ?? 0;
|
||||
Quota.Used = responseData.Quota.Used ?? 0;
|
||||
Quota.Total = responseData.Quota.Total ?? 0;
|
||||
Quota.Relative = responseData.Quota.Relative ?? 0.0F;
|
||||
Quota.Quota = responseData.Quota.Quota ?? 0;
|
||||
}
|
||||
|
||||
if (responseData.BackendCapabilities != null)
|
||||
{
|
||||
BackendCapabilities.SetDisplayName = Convert.ToBoolean(responseData.BackendCapabilities.SetDisplayName);
|
||||
BackendCapabilities.SetPassword = Convert.ToBoolean(responseData.BackendCapabilities.SetPassword);
|
||||
}
|
||||
if (responseData.BackendCapabilities != null)
|
||||
{
|
||||
BackendCapabilities.SetDisplayName = Convert.ToBoolean(responseData.BackendCapabilities.SetDisplayName);
|
||||
BackendCapabilities.SetPassword = Convert.ToBoolean(responseData.BackendCapabilities.SetPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,29 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model
|
||||
public class UserQuota
|
||||
{
|
||||
public class UserQuota
|
||||
{
|
||||
/// <summary>
|
||||
/// Amount of free bytes left.
|
||||
/// </summary>
|
||||
public long Free { get; set; }
|
||||
/// <summary>
|
||||
/// Amount of free bytes left.
|
||||
/// </summary>
|
||||
public long Free { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Amount of already used bytes.
|
||||
/// </summary>
|
||||
public long Used { get; set; }
|
||||
/// <summary>
|
||||
/// Amount of already used bytes.
|
||||
/// </summary>
|
||||
public long Used { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total amount of all bytes (free + used).
|
||||
/// </summary>
|
||||
public long Total { get; set; }
|
||||
/// <summary>
|
||||
/// Total amount of all bytes (free + used).
|
||||
/// </summary>
|
||||
public long Total { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Relative amount of used quota in percent.
|
||||
/// </summary>
|
||||
public float Relative { get; set; }
|
||||
/// <summary>
|
||||
/// Relative amount of used quota in percent.
|
||||
/// </summary>
|
||||
public float Relative { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Total amount of bytes available.
|
||||
/// </summary>
|
||||
public long Quota { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Total amount of bytes available.
|
||||
/// </summary>
|
||||
public long Quota { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,91 +1,85 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
|
||||
public class OcsResponseDataUser : OcsResponseData
|
||||
{
|
||||
public class OcsResponseDataUser : OcsResponseData
|
||||
public class ResponseQuota
|
||||
{
|
||||
public class ResponseQuota
|
||||
{
|
||||
[JsonProperty("free")]
|
||||
public long? Free { get; set; }
|
||||
[JsonProperty("free")]
|
||||
public long? Free { get; set; }
|
||||
|
||||
[JsonProperty("used")]
|
||||
public long? Used { get; set; }
|
||||
[JsonProperty("used")]
|
||||
public long? Used { get; set; }
|
||||
|
||||
[JsonProperty("total")]
|
||||
public long? Total { get; set; }
|
||||
[JsonProperty("total")]
|
||||
public long? Total { get; set; }
|
||||
|
||||
[JsonProperty("relative")]
|
||||
public float? Relative { get; set; }
|
||||
|
||||
[JsonProperty("quota")]
|
||||
public long? Quota { get; set; }
|
||||
}
|
||||
|
||||
public class ResponseBackendCapabilities
|
||||
{
|
||||
[JsonProperty("setDisplayName")]
|
||||
public bool? SetDisplayName { get; set; }
|
||||
|
||||
[JsonProperty("setPassword")]
|
||||
public bool? SetPassword { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("enabled")]
|
||||
public bool? Enabled { get; set; }
|
||||
|
||||
[JsonProperty("storageLocation")]
|
||||
public string? StorageLocation { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string? ID { get; set; }
|
||||
|
||||
[JsonProperty("lastLogin")]
|
||||
public long? LastLogin { get; set; }
|
||||
|
||||
[JsonProperty("backend")]
|
||||
public string? Backend { get; set; }
|
||||
[JsonProperty("relative")]
|
||||
public float? Relative { get; set; }
|
||||
|
||||
[JsonProperty("quota")]
|
||||
public ResponseQuota? Quota { get; set; }
|
||||
|
||||
[JsonProperty("email")]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[JsonProperty("displayname")]
|
||||
public string? Displayname { get; set; }
|
||||
|
||||
[JsonProperty("display-name")]
|
||||
public string? Displayname2 { get; set; }
|
||||
|
||||
[JsonProperty("phone")]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[JsonProperty("address")]
|
||||
public string? Address { get; set; }
|
||||
|
||||
[JsonProperty("website")]
|
||||
public string? Website { get; set; }
|
||||
|
||||
[JsonProperty("twitter")]
|
||||
public string? Twitter { get; set; }
|
||||
|
||||
[JsonProperty("groups")]
|
||||
public string[]? Groups { get; set; }
|
||||
|
||||
[JsonProperty("language")]
|
||||
public string? Language { get; set; }
|
||||
|
||||
[JsonProperty("locale")]
|
||||
public string? Locale { get; set; }
|
||||
|
||||
[JsonProperty("backendCapabilities")]
|
||||
public ResponseBackendCapabilities? BackendCapabilities { get; set; }
|
||||
public long? Quota { get; set; }
|
||||
}
|
||||
|
||||
public class ResponseBackendCapabilities
|
||||
{
|
||||
[JsonProperty("setDisplayName")]
|
||||
public bool? SetDisplayName { get; set; }
|
||||
|
||||
[JsonProperty("setPassword")]
|
||||
public bool? SetPassword { get; set; }
|
||||
}
|
||||
|
||||
[JsonProperty("enabled")]
|
||||
public bool? Enabled { get; set; }
|
||||
|
||||
[JsonProperty("storageLocation")]
|
||||
public string? StorageLocation { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public string? ID { get; set; }
|
||||
|
||||
[JsonProperty("lastLogin")]
|
||||
public long? LastLogin { get; set; }
|
||||
|
||||
[JsonProperty("backend")]
|
||||
public string? Backend { get; set; }
|
||||
|
||||
[JsonProperty("quota")]
|
||||
public ResponseQuota? Quota { get; set; }
|
||||
|
||||
[JsonProperty("email")]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[JsonProperty("displayname")]
|
||||
public string? Displayname { get; set; }
|
||||
|
||||
[JsonProperty("display-name")]
|
||||
public string? Displayname2 { get; set; }
|
||||
|
||||
[JsonProperty("phone")]
|
||||
public string? Phone { get; set; }
|
||||
|
||||
[JsonProperty("address")]
|
||||
public string? Address { get; set; }
|
||||
|
||||
[JsonProperty("website")]
|
||||
public string? Website { get; set; }
|
||||
|
||||
[JsonProperty("twitter")]
|
||||
public string? Twitter { get; set; }
|
||||
|
||||
[JsonProperty("groups")]
|
||||
public string[]? Groups { get; set; }
|
||||
|
||||
[JsonProperty("language")]
|
||||
public string? Language { get; set; }
|
||||
|
||||
[JsonProperty("locale")]
|
||||
public string? Locale { get; set; }
|
||||
|
||||
[JsonProperty("backendCapabilities")]
|
||||
public ResponseBackendCapabilities? BackendCapabilities { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
|
||||
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
|
||||
{
|
||||
public class OcsResponseUser : OcsResponse<OcsResponseDataUser>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,18 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Ocs;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
|
||||
|
||||
public class OcsApiCloud : OcsApiBase
|
||||
{
|
||||
public class OcsApiCloud : OcsApiBase
|
||||
public readonly static OcsApiUrlPath OCS_CLOUD_USER_METADATA = new("/ocs/v1.php/cloud/users/{0}");
|
||||
|
||||
public OcsApiCloud(OcsApi manager) : base(manager)
|
||||
{
|
||||
public readonly static OcsApiUrlPath OCS_CLOUD_USER_METADATA = new("/ocs/v1.php/cloud/users/{0}");
|
||||
}
|
||||
|
||||
public OcsApiCloud(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
|
||||
public OcsResponseUser? GetUserMeta(string username)
|
||||
{
|
||||
return Manager.MakeRequestOcs<OcsResponseUser>(HttpMethod.Get, OCS_CLOUD_USER_METADATA.FillParameters(username));
|
||||
}
|
||||
public OcsResponseUser? GetUserMeta(string username)
|
||||
{
|
||||
return Manager.MakeRequestOcs<OcsResponseUser>(HttpMethod.Get, OCS_CLOUD_USER_METADATA.FillParameters(username));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
using System;
|
||||
Nach:
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
*/
|
||||
using
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
using System.Threading.Tasks;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
Nach:
|
||||
using System.Threading.Tasks;
|
||||
*/
|
||||
Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Core
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.Core;
|
||||
|
||||
public class OcsApiCore : OcsApiBase
|
||||
{
|
||||
public class OcsApiCore : OcsApiBase
|
||||
public static readonly OcsApiUrlPath OCS_CORE_APPPASSWORD = "/ocs/v2.php/core/apppassword";
|
||||
|
||||
public OcsApiCore(OcsApi manager) : base(manager)
|
||||
{
|
||||
public static readonly OcsApiUrlPath OCS_CORE_APPPASSWORD = "/ocs/v2.php/core/apppassword";
|
||||
}
|
||||
|
||||
public OcsApiCore(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
|
||||
public bool DeleteAppPassword()
|
||||
{
|
||||
using var msg = Manager.MakeRequest(HttpMethod.Delete, OCS_CORE_APPPASSWORD);
|
||||
return msg != null && msg.IsSuccessStatusCode;
|
||||
}
|
||||
public bool DeleteAppPassword()
|
||||
{
|
||||
using var msg = Manager.MakeRequest(HttpMethod.Delete, OCS_CORE_APPPASSWORD);
|
||||
return msg != null && msg.IsSuccessStatusCode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +1,34 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
|
||||
public class OcsResponseLoginFlowV2
|
||||
{
|
||||
public class OcsResponseLoginFlowV2
|
||||
public class PollData
|
||||
{
|
||||
public class PollData
|
||||
{
|
||||
/// <summary>
|
||||
/// The login token that has been created for the login process.
|
||||
/// It can be used to poll the login state.
|
||||
/// </summary>
|
||||
[JsonProperty("token")]
|
||||
public string? Token { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonProperty("endpoint")]
|
||||
public string? Endpoint { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The login token that has been created for the login process.
|
||||
/// It can be used to poll the login state.
|
||||
/// </summary>
|
||||
[JsonProperty("token")]
|
||||
public string? Token { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonProperty("poll")]
|
||||
public PollData? Poll { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The temporary login url that should be used for login.
|
||||
/// </summary>
|
||||
[JsonProperty("login")]
|
||||
public string? LoginUrl { get; set; }
|
||||
[JsonProperty("endpoint")]
|
||||
public string? Endpoint { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[JsonProperty("poll")]
|
||||
public PollData? Poll { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The temporary login url that should be used for login.
|
||||
/// </summary>
|
||||
[JsonProperty("login")]
|
||||
public string? LoginUrl { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
|
||||
public class OcsResponseLoginFlowV2Credentials
|
||||
{
|
||||
public class OcsResponseLoginFlowV2Credentials
|
||||
{
|
||||
/// <summary>
|
||||
/// The server url the login credentials are for.
|
||||
/// </summary>
|
||||
[JsonProperty("server")]
|
||||
public string? Server { get; set; }
|
||||
/// <summary>
|
||||
/// The server url the login credentials are for.
|
||||
/// </summary>
|
||||
[JsonProperty("server")]
|
||||
public string? Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The login name (username or password) used for the login.
|
||||
/// </summary>
|
||||
[JsonProperty("loginName")]
|
||||
public string? LoginName { get; set; }
|
||||
/// <summary>
|
||||
/// The login name (username or password) used for the login.
|
||||
/// </summary>
|
||||
[JsonProperty("loginName")]
|
||||
public string? LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app password that has been generated.
|
||||
/// </summary>
|
||||
[JsonProperty("appPassword")]
|
||||
public string? AppPassword { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// The app password that has been generated.
|
||||
/// </summary>
|
||||
[JsonProperty("appPassword")]
|
||||
public string? AppPassword { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2;
|
||||
|
||||
public class OcsApiLoginFlowV2 : OcsApiBase
|
||||
{
|
||||
public class OcsApiLoginFlowV2 : OcsApiBase
|
||||
private const string OCS_LOGIN_INIT = "/index.php/login/v2";
|
||||
|
||||
public OcsApiLoginFlowV2(OcsApi manager) : base(manager)
|
||||
{
|
||||
private const string OCS_LOGIN_INIT = "/index.php/login/v2";
|
||||
}
|
||||
|
||||
public OcsApiLoginFlowV2(OcsApi manager) : base(manager)
|
||||
{
|
||||
}
|
||||
public OcsResponseLoginFlowV2? Init(string url)
|
||||
{
|
||||
return Manager.MakeRequest<OcsResponseLoginFlowV2>(HttpMethod.Post, url + OCS_LOGIN_INIT);
|
||||
}
|
||||
|
||||
public OcsResponseLoginFlowV2? Init(string url)
|
||||
{
|
||||
return Manager.MakeRequest<OcsResponseLoginFlowV2>(HttpMethod.Post, url + OCS_LOGIN_INIT);
|
||||
}
|
||||
public OcsResponseLoginFlowV2Credentials? Poll(OcsResponseLoginFlowV2.PollData poll)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(poll?.Endpoint);
|
||||
ArgumentNullException.ThrowIfNull(poll?.Token);
|
||||
|
||||
public OcsResponseLoginFlowV2Credentials? Poll(OcsResponseLoginFlowV2.PollData poll)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(poll?.Endpoint);
|
||||
ArgumentNullException.ThrowIfNull(poll?.Token);
|
||||
|
||||
return Manager.MakeRequest<OcsResponseLoginFlowV2Credentials?>(HttpMethod.Post, poll.Endpoint,
|
||||
parameters: new Dictionary<string, string>
|
||||
{
|
||||
{ "token", poll.Token }
|
||||
});
|
||||
}
|
||||
return Manager.MakeRequest<OcsResponseLoginFlowV2Credentials?>(HttpMethod.Post, poll.Endpoint,
|
||||
parameters: new Dictionary<string, string>
|
||||
{
|
||||
{ "token", poll.Token }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,41 @@
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud;
|
||||
|
||||
public static class Extensions
|
||||
{
|
||||
public static class Extensions
|
||||
public static string ToBasicAuth(this OcsApiAuthCredentials? credentials)
|
||||
{
|
||||
public static string ToBasicAuth(this OcsApiAuthCredentials? credentials)
|
||||
if (credentials != null)
|
||||
{
|
||||
if (credentials != null)
|
||||
{
|
||||
var creds = $"{credentials?.LoginName}:{credentials?.AppPassword}";
|
||||
var bytes = Encoding.UTF8.GetBytes(creds);
|
||||
return "Basic " + Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
var creds = $"{credentials?.LoginName}:{credentials?.AppPassword}";
|
||||
var bytes = Encoding.UTF8.GetBytes(creds);
|
||||
return "Basic " + Convert.ToBase64String(bytes);
|
||||
}
|
||||
|
||||
public static OcsApiAuthCredentials? ToOcsApiAuthCredentials(this NextcloudLogin? login)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(login?.LoginName) && !string.IsNullOrEmpty(login?.AppPassword))
|
||||
return new OcsApiAuthCredentials(login.LoginName, login.AppPassword);
|
||||
return null;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static OcsApiUrlPath FillParameters(this OcsApiUrlPath path, params object?[] @params)
|
||||
{
|
||||
return (OcsApiUrlPath)string.Format(path, @params);
|
||||
}
|
||||
public static OcsApiAuthCredentials? ToOcsApiAuthCredentials(this NextcloudLogin? login)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(login?.LoginName) && !string.IsNullOrEmpty(login?.AppPassword))
|
||||
return new OcsApiAuthCredentials(login.LoginName, login.AppPassword);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DateTime UnixTimeMillisecondsToDateTime(this long? value)
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeMilliseconds(value ?? 0).DateTime;
|
||||
}
|
||||
public static OcsApiUrlPath FillParameters(this OcsApiUrlPath path, params object?[] @params)
|
||||
{
|
||||
return (OcsApiUrlPath)string.Format(path, @params);
|
||||
}
|
||||
|
||||
public static long ToUnixTimeMilliseconds(this DateTime value)
|
||||
{
|
||||
return new DateTimeOffset(value).ToUnixTimeMilliseconds();
|
||||
}
|
||||
public static DateTime UnixTimeMillisecondsToDateTime(this long? value)
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeMilliseconds(value ?? 0).DateTime;
|
||||
}
|
||||
|
||||
public static long ToUnixTimeMilliseconds(this DateTime value)
|
||||
{
|
||||
return new DateTimeOffset(value).ToUnixTimeMilliseconds();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
using System;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
Nach:
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
@@ -6,150 +16,147 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud.Model;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
*/
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud;
|
||||
|
||||
public class NextcloudClient : IDisposable
|
||||
{
|
||||
public class NextcloudClient : IDisposable
|
||||
private readonly List<ClientBase> clients = new();
|
||||
private NextcloudLogin? currentLogin;
|
||||
|
||||
public OcsApi Ocs { get; init; } = new();
|
||||
|
||||
public NextcloudLogin? CurrentLogin
|
||||
{
|
||||
private readonly List<ClientBase> clients = new();
|
||||
private NextcloudLogin? currentLogin;
|
||||
|
||||
public OcsApi Ocs { get; init; } = new();
|
||||
|
||||
public NextcloudLogin? CurrentLogin
|
||||
get => currentLogin;
|
||||
private set
|
||||
{
|
||||
get => currentLogin;
|
||||
private set
|
||||
{
|
||||
currentLogin = value;
|
||||
Ocs.BaseUrl = value?.Server ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public CloudClient Cloud => GetClient<CloudClient>();
|
||||
|
||||
public NextcloudClient()
|
||||
{
|
||||
Ocs.GetOcsApiAuthCredentails += Ocs_GetOcsApiAuthCredentails;
|
||||
}
|
||||
|
||||
private void Ocs_GetOcsApiAuthCredentails(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs)
|
||||
{
|
||||
if (sender == Ocs)
|
||||
eventArgs.Credentials = CurrentLogin.ToOcsApiAuthCredentials();
|
||||
}
|
||||
|
||||
public TClient GetClient<TClient>() where TClient : ClientBase
|
||||
{
|
||||
var instance = TryGetClient<TClient>();
|
||||
return instance is null ? throw new NullReferenceException() : instance;
|
||||
}
|
||||
|
||||
public TClient? TryGetClient<TClient>() where TClient : ClientBase
|
||||
{
|
||||
TClient? instance = (TClient?)clients.FirstOrDefault(n => n is TClient);
|
||||
|
||||
instance ??= (TClient?)Activator.CreateInstance(typeof(TClient), new object[] { this });
|
||||
|
||||
if (instance is not null)
|
||||
clients.Add(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public UserInfo? Login(NextcloudLogin login)
|
||||
{
|
||||
return Login(login, true);
|
||||
}
|
||||
|
||||
public UserInfo? Login(NextcloudLogin login, bool checkUser)
|
||||
{
|
||||
// Ensure we are logged out
|
||||
Logout(false);
|
||||
|
||||
// Temporary set user login
|
||||
CurrentLogin = login;
|
||||
|
||||
if (checkUser)
|
||||
{
|
||||
// Try get user info & check if user is enabled
|
||||
var userInfo = Cloud.GetUserInfo();
|
||||
var isValid = userInfo != null /*&& userInfo.Enabled*/; // Enabled is false for some (new) users but they still are able to login??
|
||||
|
||||
// If invalid, reset login credentials
|
||||
if (!isValid)
|
||||
CurrentLogin = null;
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
// Ensure we are logged out
|
||||
Logout(false);
|
||||
|
||||
// Init the login process
|
||||
var initResponse = Ocs.LoginFlowV2.Init(baseUrl);
|
||||
|
||||
if (!string.IsNullOrEmpty(initResponse?.LoginUrl) && initResponse.Poll != null)
|
||||
{
|
||||
// Open the browser
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = initResponse.LoginUrl,
|
||||
UseShellExecute = true
|
||||
});
|
||||
|
||||
// Poll for credentails in intervals
|
||||
OcsResponseLoginFlowV2Credentials? pollResponse = null;
|
||||
while (!cancellationToken.IsCancellationRequested && pollResponse is null)
|
||||
{
|
||||
// Wait 5 seconds
|
||||
Thread.Sleep(5000);
|
||||
|
||||
// Poll the credentials
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
pollResponse = Ocs.LoginFlowV2.Poll(initResponse.Poll);
|
||||
}
|
||||
|
||||
// Check login credentials
|
||||
if (pollResponse is not null)
|
||||
CurrentLogin = new(pollResponse);
|
||||
}
|
||||
|
||||
return CurrentLogin;
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
Logout(false);
|
||||
}
|
||||
|
||||
public void Logout(bool logoutOnServer)
|
||||
{
|
||||
if (CurrentLogin != null)
|
||||
{
|
||||
// Delete currently used app password
|
||||
if (logoutOnServer)
|
||||
Ocs.Core.DeleteAppPassword();
|
||||
|
||||
// Reset current login infos
|
||||
CurrentLogin = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Ocs.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
currentLogin = value;
|
||||
Ocs.BaseUrl = value?.Server ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public CloudClient Cloud => GetClient<CloudClient>();
|
||||
|
||||
public NextcloudClient()
|
||||
{
|
||||
Ocs.GetOcsApiAuthCredentails += Ocs_GetOcsApiAuthCredentails;
|
||||
}
|
||||
|
||||
private void Ocs_GetOcsApiAuthCredentails(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs)
|
||||
{
|
||||
if (sender == Ocs)
|
||||
eventArgs.Credentials = CurrentLogin.ToOcsApiAuthCredentials();
|
||||
}
|
||||
|
||||
public TClient GetClient<TClient>() where TClient : ClientBase
|
||||
{
|
||||
var instance = TryGetClient<TClient>();
|
||||
return instance is null ? throw new NullReferenceException() : instance;
|
||||
}
|
||||
|
||||
public TClient? TryGetClient<TClient>() where TClient : ClientBase
|
||||
{
|
||||
TClient? instance = (TClient?)clients.FirstOrDefault(n => n is TClient);
|
||||
|
||||
instance ??= (TClient?)Activator.CreateInstance(typeof(TClient), new object[] { this });
|
||||
|
||||
if (instance is not null)
|
||||
clients.Add(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public UserInfo? Login(NextcloudLogin login)
|
||||
{
|
||||
return Login(login, true);
|
||||
}
|
||||
|
||||
public UserInfo? Login(NextcloudLogin login, bool checkUser)
|
||||
{
|
||||
// Ensure we are logged out
|
||||
Logout(false);
|
||||
|
||||
// Temporary set user login
|
||||
CurrentLogin = login;
|
||||
|
||||
if (checkUser)
|
||||
{
|
||||
// Try get user info & check if user is enabled
|
||||
var userInfo = Cloud.GetUserInfo();
|
||||
var isValid = userInfo != null /*&& userInfo.Enabled*/; // Enabled is false for some (new) users but they still are able to login??
|
||||
|
||||
// If invalid, reset login credentials
|
||||
if (!isValid)
|
||||
CurrentLogin = null;
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public NextcloudLogin? Login(string baseUrl, CancellationToken cancellationToken)
|
||||
{
|
||||
// Ensure we are logged out
|
||||
Logout(false);
|
||||
|
||||
// Init the login process
|
||||
var initResponse = Ocs.LoginFlowV2.Init(baseUrl);
|
||||
|
||||
if (!string.IsNullOrEmpty(initResponse?.LoginUrl) && initResponse.Poll != null)
|
||||
{
|
||||
// Open the browser
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = initResponse.LoginUrl,
|
||||
UseShellExecute = true
|
||||
});
|
||||
|
||||
// Poll for credentails in intervals
|
||||
OcsResponseLoginFlowV2Credentials? pollResponse = null;
|
||||
while (!cancellationToken.IsCancellationRequested && pollResponse is null)
|
||||
{
|
||||
// Wait 5 seconds
|
||||
Thread.Sleep(5000);
|
||||
|
||||
// Poll the credentials
|
||||
if (!cancellationToken.IsCancellationRequested)
|
||||
pollResponse = Ocs.LoginFlowV2.Poll(initResponse.Poll);
|
||||
}
|
||||
|
||||
// Check login credentials
|
||||
if (pollResponse is not null)
|
||||
CurrentLogin = new(pollResponse);
|
||||
}
|
||||
|
||||
return CurrentLogin;
|
||||
}
|
||||
|
||||
public void Logout()
|
||||
{
|
||||
Logout(false);
|
||||
}
|
||||
|
||||
public void Logout(bool logoutOnServer)
|
||||
{
|
||||
if (CurrentLogin != null)
|
||||
{
|
||||
// Delete currently used app password
|
||||
if (logoutOnServer)
|
||||
Ocs.Core.DeleteAppPassword();
|
||||
|
||||
// Reset current login infos
|
||||
CurrentLogin = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Ocs.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +1,32 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud;
|
||||
|
||||
public class NextcloudLogin
|
||||
{
|
||||
public class NextcloudLogin
|
||||
/// <summary>
|
||||
/// The server url the login credentials are for.
|
||||
/// </summary>
|
||||
public string? Server { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The login name (username or password) used for the login.
|
||||
/// </summary>
|
||||
public string? LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app password that has been generated.
|
||||
/// </summary>
|
||||
public string? AppPassword { get; set; }
|
||||
|
||||
public NextcloudLogin()
|
||||
{
|
||||
/// <summary>
|
||||
/// The server url the login credentials are for.
|
||||
/// </summary>
|
||||
public string? Server { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The login name (username or password) used for the login.
|
||||
/// </summary>
|
||||
public string? LoginName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The app password that has been generated.
|
||||
/// </summary>
|
||||
public string? AppPassword { get; set; }
|
||||
|
||||
public NextcloudLogin()
|
||||
{
|
||||
}
|
||||
|
||||
public NextcloudLogin(OcsResponseLoginFlowV2Credentials response)
|
||||
{
|
||||
Server = response.Server;
|
||||
LoginName = response.LoginName;
|
||||
AppPassword = response.AppPassword;
|
||||
}
|
||||
public NextcloudLogin(OcsResponseLoginFlowV2Credentials response)
|
||||
{
|
||||
Server = response.Server;
|
||||
LoginName = response.LoginName;
|
||||
AppPassword = response.AppPassword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
public delegate void GetOcsApiAuthCredentailsEventHandler(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs);
|
||||
|
||||
public class GetOcsApiAuthCredentailsEventArgs : EventArgs
|
||||
{
|
||||
public delegate void GetOcsApiAuthCredentailsEventHandler(object sender, GetOcsApiAuthCredentailsEventArgs eventArgs);
|
||||
|
||||
public class GetOcsApiAuthCredentailsEventArgs : EventArgs
|
||||
{
|
||||
public OcsApiAuthCredentials? Credentials { get; set; }
|
||||
}
|
||||
public OcsApiAuthCredentials? Credentials { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,218 +1,226 @@
|
||||
using System;
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Xml.Linq;
|
||||
Nach:
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Cloud;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.Core;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Client.LoginFlowV2;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Json;
|
||||
*/
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
/* Nicht gemergte Änderung aus Projekt "Pilz.Networking.CloudProviders.Nextcloud (net6.0)"
|
||||
Vor:
|
||||
using
|
||||
Nach:
|
||||
using
|
||||
*/
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
public class OcsApi : IDisposable
|
||||
{
|
||||
public class OcsApi : IDisposable
|
||||
public const string CONTENT_TYPE_JSON = "application/json";
|
||||
|
||||
public event GetOcsApiAuthCredentailsEventHandler? GetOcsApiAuthCredentails;
|
||||
|
||||
private readonly HttpClient client = new();
|
||||
private readonly List<OcsApiBase> apis = new();
|
||||
|
||||
public string BaseUrl { get; set; } = string.Empty;
|
||||
|
||||
public OcsApiLoginFlowV2 LoginFlowV2 => GetApi<OcsApiLoginFlowV2>();
|
||||
public OcsApiCore Core => GetApi<OcsApiCore>();
|
||||
public OcsApiCloud Cloud => GetApi<OcsApiCloud>();
|
||||
|
||||
public TApi GetApi<TApi>() where TApi : OcsApiBase
|
||||
{
|
||||
public const string CONTENT_TYPE_JSON = "application/json";
|
||||
var instance = TryGetApi<TApi>();
|
||||
return instance is null ? throw new NullReferenceException() : instance;
|
||||
}
|
||||
|
||||
public event GetOcsApiAuthCredentailsEventHandler? GetOcsApiAuthCredentails;
|
||||
public TApi? TryGetApi<TApi>() where TApi : OcsApiBase
|
||||
{
|
||||
TApi? instance = (TApi?)apis.FirstOrDefault(n => n is TApi);
|
||||
|
||||
private readonly HttpClient client = new();
|
||||
private readonly List<OcsApiBase> apis = new();
|
||||
instance ??= (TApi?)Activator.CreateInstance(typeof(TApi), new object[] { this });
|
||||
|
||||
public string BaseUrl { get; set; } = string.Empty;
|
||||
if (instance is not null)
|
||||
apis.Add(instance);
|
||||
|
||||
public OcsApiLoginFlowV2 LoginFlowV2 => GetApi<OcsApiLoginFlowV2>();
|
||||
public OcsApiCore Core => GetApi<OcsApiCore>();
|
||||
public OcsApiCloud Cloud => GetApi<OcsApiCloud>();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public TApi GetApi<TApi>() where TApi : OcsApiBase
|
||||
public string BuildFullUrl(OcsApiUrlPath path)
|
||||
{
|
||||
return BaseUrl + path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
|
||||
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
|
||||
{
|
||||
return MakeRequestOcs<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
|
||||
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
|
||||
{
|
||||
var response = MakeRequest<OcsApiResponse<TResponse>?>(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
|
||||
if (response != null)
|
||||
return response.Ocs;
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the deserialized content of type given type.</returns>
|
||||
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
return MakeRequest<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the deserialized content of type given type.</returns>
|
||||
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
using var responseInit = MakeRequest(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
|
||||
if (responseInit != null)
|
||||
{
|
||||
var instance = TryGetApi<TApi>();
|
||||
return instance is null ? throw new NullReferenceException() : instance;
|
||||
}
|
||||
|
||||
public TApi? TryGetApi<TApi>() where TApi : OcsApiBase
|
||||
{
|
||||
TApi? instance = (TApi?)apis.FirstOrDefault(n => n is TApi);
|
||||
|
||||
instance ??= (TApi?)Activator.CreateInstance(typeof(TApi), new object[] { this });
|
||||
|
||||
if (instance is not null)
|
||||
apis.Add(instance);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public string BuildFullUrl(OcsApiUrlPath path)
|
||||
{
|
||||
return BaseUrl + path;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
|
||||
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
|
||||
{
|
||||
return MakeRequestOcs<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the given OcsResponse type from the deserialized OcsApiResponse content.</returns>
|
||||
public TResponse? MakeRequestOcs<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null) where TResponse : IOcsResponse
|
||||
{
|
||||
var response = MakeRequest<OcsApiResponse<TResponse>?>(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
|
||||
if (response != null)
|
||||
return response.Ocs;
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the deserialized content of type given type.</returns>
|
||||
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
return MakeRequest<TResponse>(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments and deserialize it to the given type.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResponse"></typeparam>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns the deserialized content of type given type.</returns>
|
||||
public TResponse? MakeRequest<TResponse>(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
using var responseInit = MakeRequest(httpMethod, url, useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
|
||||
if (responseInit != null)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
var bodyInit = responseInit.Content.ReadAsStringAsync().Result;
|
||||
return JsonConvert.DeserializeObject<TResponse>(bodyInit);
|
||||
}
|
||||
catch(FormatException) { }
|
||||
catch(JsonSerializationException) { }
|
||||
var bodyInit = responseInit.Content.ReadAsStringAsync().Result;
|
||||
return JsonConvert.DeserializeObject<TResponse>(bodyInit);
|
||||
}
|
||||
|
||||
return default;
|
||||
catch (FormatException) { }
|
||||
catch (JsonSerializationException) { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments.
|
||||
/// </summary>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns a HttpResponseMessage as result.</returns>
|
||||
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
return default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments.
|
||||
/// </summary>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns a HttpResponseMessage as result.</returns>
|
||||
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, OcsApiUrlPath url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
return MakeRequest(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments.
|
||||
/// </summary>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns a HttpResponseMessage as result.</returns>
|
||||
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
{
|
||||
OcsApiAuthCredentials? authentication;
|
||||
string @params;
|
||||
HttpContent? httpContent;
|
||||
|
||||
// Get authentication
|
||||
if (useAuthentication)
|
||||
{
|
||||
return MakeRequest(httpMethod, BuildFullUrl(url), useAuthentication: useAuthentication, parameters: parameters, content: content);
|
||||
var args = new GetOcsApiAuthCredentailsEventArgs();
|
||||
GetOcsApiAuthCredentails?.Invoke(this, args);
|
||||
authentication = args.Credentials;
|
||||
}
|
||||
else
|
||||
authentication = null;
|
||||
|
||||
/// <summary>
|
||||
/// Makes an request with the given arguments.
|
||||
/// </summary>
|
||||
/// <param name="httpMethod"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="useAuthentication"></param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <returns>Returns a HttpResponseMessage as result.</returns>
|
||||
public HttpResponseMessage MakeRequest(HttpMethod httpMethod, string url, bool useAuthentication = true, Dictionary<string, string>? parameters = null, object? content = null)
|
||||
// Parse params
|
||||
if (parameters != null)
|
||||
@params = "?" + string.Join("&", parameters.Select(p => $"{p.Key}={p.Value}"));
|
||||
else
|
||||
@params = string.Empty;
|
||||
|
||||
// Create content
|
||||
if (content is HttpContent contentHttp)
|
||||
httpContent = contentHttp;
|
||||
else if (content is OcsData || content is not null)
|
||||
{
|
||||
OcsApiAuthCredentials? authentication;
|
||||
string @params;
|
||||
HttpContent? httpContent;
|
||||
|
||||
// Get authentication
|
||||
if (useAuthentication)
|
||||
{
|
||||
var args = new GetOcsApiAuthCredentailsEventArgs();
|
||||
GetOcsApiAuthCredentails?.Invoke(this, args);
|
||||
authentication = args.Credentials;
|
||||
}
|
||||
else
|
||||
authentication = null;
|
||||
|
||||
// Parse params
|
||||
if (parameters != null)
|
||||
@params = "?" + string.Join("&", parameters.Select(p => $"{p.Key}={p.Value}"));
|
||||
else
|
||||
@params = string.Empty;
|
||||
|
||||
// Create content
|
||||
if (content is HttpContent contentHttp)
|
||||
httpContent = contentHttp;
|
||||
else if (content is OcsData || content is not null)
|
||||
{
|
||||
var stringContent = JsonConvert.SerializeObject(content);
|
||||
httpContent = new StringContent(stringContent, null, CONTENT_TYPE_JSON);
|
||||
}
|
||||
else
|
||||
httpContent = null;
|
||||
|
||||
// Send request
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
Method = httpMethod ?? HttpMethod.Post,
|
||||
RequestUri = new Uri(url + @params),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", CONTENT_TYPE_JSON },
|
||||
{ "OCS-APIREQUEST", "true" },
|
||||
//{ "Authorization", authentication.ToBasicAuth() }
|
||||
},
|
||||
Content = httpContent
|
||||
};
|
||||
|
||||
// Add authorization
|
||||
if (authentication != null)
|
||||
request.Headers.Add("Authorization", authentication.ToBasicAuth());
|
||||
|
||||
return client.Send(request);
|
||||
var stringContent = JsonConvert.SerializeObject(content);
|
||||
httpContent = new StringContent(stringContent, null, CONTENT_TYPE_JSON);
|
||||
}
|
||||
else
|
||||
httpContent = null;
|
||||
|
||||
public void Dispose()
|
||||
// Send request
|
||||
var request = new HttpRequestMessage
|
||||
{
|
||||
client.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
Method = httpMethod ?? HttpMethod.Post,
|
||||
RequestUri = new Uri(url + @params),
|
||||
Headers =
|
||||
{
|
||||
{ "Accept", CONTENT_TYPE_JSON },
|
||||
{ "OCS-APIREQUEST", "true" },
|
||||
//{ "Authorization", authentication.ToBasicAuth() }
|
||||
},
|
||||
Content = httpContent
|
||||
};
|
||||
|
||||
// Add authorization
|
||||
if (authentication != null)
|
||||
request.Headers.Add("Authorization", authentication.ToBasicAuth());
|
||||
|
||||
return client.Send(request);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
client.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
public struct OcsApiAuthCredentials
|
||||
{
|
||||
public struct OcsApiAuthCredentials
|
||||
{
|
||||
public string LoginName { get; set; }
|
||||
public string AppPassword { get; set; }
|
||||
public string LoginName { get; set; }
|
||||
public string AppPassword { get; set; }
|
||||
|
||||
public OcsApiAuthCredentials(string loginName, string appPassword)
|
||||
{
|
||||
LoginName = loginName;
|
||||
AppPassword = appPassword;
|
||||
}
|
||||
public OcsApiAuthCredentials(string loginName, string appPassword)
|
||||
{
|
||||
LoginName = loginName;
|
||||
AppPassword = appPassword;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
public abstract class OcsApiBase
|
||||
{
|
||||
public abstract class OcsApiBase
|
||||
{
|
||||
protected OcsApi Manager { get; init; }
|
||||
protected OcsApi Manager { get; init; }
|
||||
|
||||
protected OcsApiBase(OcsApi manager)
|
||||
{
|
||||
Manager = manager;
|
||||
}
|
||||
protected OcsApiBase(OcsApi manager)
|
||||
{
|
||||
Manager = manager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
public class OcsApiResponse<TOcsResponse> where TOcsResponse : IOcsResponse
|
||||
{
|
||||
public class OcsApiResponse<TOcsResponse> where TOcsResponse : IOcsResponse
|
||||
{
|
||||
[JsonProperty("ocs")]
|
||||
public TOcsResponse? Ocs { get; set; }
|
||||
}
|
||||
[JsonProperty("ocs")]
|
||||
public TOcsResponse? Ocs { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,31 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
public readonly struct OcsApiUrlPath
|
||||
{
|
||||
public readonly struct OcsApiUrlPath
|
||||
private readonly string path;
|
||||
|
||||
public OcsApiUrlPath()
|
||||
{
|
||||
private readonly string path;
|
||||
path = string.Empty;
|
||||
}
|
||||
|
||||
public OcsApiUrlPath()
|
||||
{
|
||||
path = string.Empty;
|
||||
}
|
||||
public OcsApiUrlPath(string path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public OcsApiUrlPath(string path)
|
||||
{
|
||||
this.path = path;
|
||||
}
|
||||
public static implicit operator string(OcsApiUrlPath o) => o.path;
|
||||
public static implicit operator OcsApiUrlPath(string o) => new(o);
|
||||
|
||||
public static implicit operator string(OcsApiUrlPath o) => o.path;
|
||||
public static implicit operator OcsApiUrlPath(string o) => new(o);
|
||||
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
public override readonly string ToString()
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs
|
||||
public class OcsData
|
||||
{
|
||||
public class OcsData
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public interface IOcsResponse
|
||||
{
|
||||
public interface IOcsResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public interface IOcsResponseData
|
||||
{
|
||||
public interface IOcsResponseData
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public interface IOcsResponseMeta
|
||||
{
|
||||
public interface IOcsResponseMeta
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
public class OcsResponse<TMeta, TData> : IOcsResponse where TMeta : IOcsResponseMeta where TData : IOcsResponseData
|
||||
{
|
||||
public class OcsResponse<TMeta, TData> : IOcsResponse where TMeta : IOcsResponseMeta where TData : IOcsResponseData
|
||||
{
|
||||
[JsonProperty("meta")]
|
||||
public TMeta? Meta { get; set; }
|
||||
[JsonProperty("meta")]
|
||||
public TMeta? Meta { get; set; }
|
||||
|
||||
[JsonProperty("data")]
|
||||
public TData? Data { get; set; }
|
||||
}
|
||||
|
||||
public class OcsResponse<TData> : OcsResponse<OcsResponseMeta, TData> where TData : IOcsResponseData
|
||||
{
|
||||
}
|
||||
|
||||
public class OcsResponse : OcsResponse<OcsResponseMeta, OcsResponseData>
|
||||
{
|
||||
}
|
||||
[JsonProperty("data")]
|
||||
public TData? Data { get; set; }
|
||||
}
|
||||
|
||||
public class OcsResponse<TData> : OcsResponse<OcsResponseMeta, TData> where TData : IOcsResponseData
|
||||
{
|
||||
}
|
||||
|
||||
public class OcsResponse : OcsResponse<OcsResponseMeta, OcsResponseData>
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public class OcsResponseData : IOcsResponseData
|
||||
{
|
||||
public class OcsResponseData : IOcsResponseData
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public class OcsResponseDataArray<TEntry> : List<TEntry>, IOcsResponseData where TEntry : OcsResponseDataEntry
|
||||
{
|
||||
public class OcsResponseDataArray<TEntry> : List<TEntry>, IOcsResponseData where TEntry : OcsResponseDataEntry
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
public class OcsResponseDataEntry
|
||||
{
|
||||
public class OcsResponseDataEntry
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses
|
||||
namespace Pilz.Networking.CloudProviders.Nextcloud.Ocs.Responses;
|
||||
|
||||
public class OcsResponseMeta : IOcsResponseMeta
|
||||
{
|
||||
public class OcsResponseMeta : IOcsResponseMeta
|
||||
{
|
||||
[JsonProperty("status")]
|
||||
public string? Status { get; set; }
|
||||
[JsonProperty("status")]
|
||||
public string? Status { get; set; }
|
||||
|
||||
[JsonProperty("statuscode")]
|
||||
public int? StatusCode { get; set; }
|
||||
[JsonProperty("statuscode")]
|
||||
public int? StatusCode { get; set; }
|
||||
|
||||
[JsonProperty("message")]
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
[JsonProperty("message")]
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user