Merge branch 'master' into feature/files
This commit is contained in:
commit
88e932a0a7
14
ASC.Web.sln
14
ASC.Web.sln
@ -56,12 +56,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.ApiSystem", "common\ser
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.UrlShortener.Svc", "common\services\ASC.UrlShortener.Svc\ASC.UrlShortener.Svc.csproj", "{04A56018-C41E-4634-A185-A13E9250C75A}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ASC.Feed.Aggregator", "common\services\ASC.Feed.Aggregator\ASC.Feed.Aggregator.csproj", "{07CCC11F-76CB-448E-B15A-72E09FBB348B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Feed.Aggregator", "common\services\ASC.Feed.Aggregator\ASC.Feed.Aggregator.csproj", "{07CCC11F-76CB-448E-B15A-72E09FBB348B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Thumbnails.Svc", "common\services\ASC.Thumbnails.Svc\ASC.Thumbnails.Svc.csproj", "{1D2F61B2-B1F4-45F0-83CA-03370FD6E62C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ASC.Data.Backup", "common\services\ASC.Data.Backup\ASC.Data.Backup.csproj", "{DE3DAF51-FB29-41FC-AF41-A4BA8D91BFB6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Graph.Core", "thirdparty\Microsoft.Graph.Core\Microsoft.Graph.Core.csproj", "{D4C1A5C9-2327-4181-B7FD-005ED240B09F}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OneDrive.Sdk", "thirdparty\onedrive-sdk-csharp-master\src\OneDriveSdk\Microsoft.OneDrive.Sdk.csproj", "{D78506D2-CC97-4063-A800-B16F5A063DE9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -180,6 +184,14 @@ Global
|
||||
{DE3DAF51-FB29-41FC-AF41-A4BA8D91BFB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DE3DAF51-FB29-41FC-AF41-A4BA8D91BFB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DE3DAF51-FB29-41FC-AF41-A4BA8D91BFB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D4C1A5C9-2327-4181-B7FD-005ED240B09F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D4C1A5C9-2327-4181-B7FD-005ED240B09F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D4C1A5C9-2327-4181-B7FD-005ED240B09F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D4C1A5C9-2327-4181-B7FD-005ED240B09F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D78506D2-CC97-4063-A800-B16F5A063DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D78506D2-CC97-4063-A800-B16F5A063DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D78506D2-CC97-4063-A800-B16F5A063DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D78506D2-CC97-4063-A800-B16F5A063DE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -27,7 +27,6 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -37,7 +36,6 @@ using ASC.Core;
|
||||
|
||||
namespace ASC.Api.Core
|
||||
{
|
||||
[DataContract(Name = "date", Namespace = "")]
|
||||
[TypeConverter(typeof(ApiDateTimeTypeConverter))]
|
||||
public class ApiDateTime : IComparable<ApiDateTime>, IComparable
|
||||
{
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
|
||||
using ASC.Common.Web;
|
||||
|
||||
namespace ASC.Api.Utils
|
||||
@ -55,5 +56,10 @@ namespace ASC.Api.Utils
|
||||
{
|
||||
return item.IfNull(() => { throw new ItemNotFoundException(message); });
|
||||
}
|
||||
|
||||
public static T? NullIfDefault<T>(this T item) where T : struct
|
||||
{
|
||||
return item.Equals(default(T)) ? default(T?) : item;
|
||||
}
|
||||
}
|
||||
}
|
@ -25,14 +25,12 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Core;
|
||||
using ASC.Core.Users;
|
||||
|
||||
namespace ASC.Web.Api.Models
|
||||
{
|
||||
[DataContract(Name = "group", Namespace = "")]
|
||||
public class GroupWrapperSummary
|
||||
{
|
||||
public GroupWrapperSummary(GroupInfo group, UserManager userManager)
|
||||
|
@ -119,8 +119,8 @@ namespace ASC.Common.Threading
|
||||
|
||||
key = name + GetType().Name;
|
||||
scheduler = maxThreadsCount <= 0
|
||||
? TaskScheduler.Default
|
||||
: new LimitedConcurrencyLevelTaskScheduler(maxThreadsCount);
|
||||
? TaskScheduler.Default
|
||||
: new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, 4).ConcurrentScheduler;
|
||||
DistributedTaskCacheNotify = distributedTaskCacheNotify;
|
||||
cancelations = DistributedTaskCacheNotify.Cancelations;
|
||||
cache = DistributedTaskCacheNotify.Cache;
|
||||
|
@ -1,170 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ASC.Common.Threading
|
||||
{
|
||||
public class LimitedConcurrencyLevelTaskScheduler : TaskScheduler
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static bool busy;
|
||||
|
||||
private readonly LinkedList<Task> tasks = new LinkedList<Task>();
|
||||
|
||||
private readonly int maxDegreeOfParallelism;
|
||||
|
||||
private int delegatesQueuedOrRunning = 0;
|
||||
|
||||
|
||||
public override int MaximumConcurrencyLevel
|
||||
{
|
||||
get { return maxDegreeOfParallelism; }
|
||||
}
|
||||
|
||||
|
||||
public LimitedConcurrencyLevelTaskScheduler(int maxDegreeOfParallelism)
|
||||
{
|
||||
if (maxDegreeOfParallelism < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(maxDegreeOfParallelism));
|
||||
}
|
||||
this.maxDegreeOfParallelism = maxDegreeOfParallelism;
|
||||
}
|
||||
|
||||
|
||||
protected sealed override void QueueTask(Task task)
|
||||
{
|
||||
// Add the task to the list of tasks to be processed.
|
||||
// If there aren't enough delegates currently queued or running to process tasks, schedule another.
|
||||
lock (tasks)
|
||||
{
|
||||
tasks.AddLast(task);
|
||||
if (delegatesQueuedOrRunning < maxDegreeOfParallelism)
|
||||
{
|
||||
++delegatesQueuedOrRunning;
|
||||
NotifyThreadPoolOfPendingWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void NotifyThreadPoolOfPendingWork()
|
||||
{
|
||||
ThreadPool.UnsafeQueueUserWorkItem(_ =>
|
||||
{
|
||||
// Note that the current thread is now processing work items.
|
||||
// This is necessary to enable inlining of tasks into this thread.
|
||||
busy = true;
|
||||
try
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Task item;
|
||||
lock (tasks)
|
||||
{
|
||||
// When there are no more items to be processed, note that we're done processing, and get out.
|
||||
if (tasks.Count == 0)
|
||||
{
|
||||
--delegatesQueuedOrRunning;
|
||||
break;
|
||||
}
|
||||
|
||||
item = tasks.First.Value;
|
||||
tasks.RemoveFirst();
|
||||
}
|
||||
|
||||
TryExecuteTask(item);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
busy = false;
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
// Attempts to execute the specified task on the current thread.
|
||||
protected override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
|
||||
{
|
||||
if (busy)
|
||||
{
|
||||
// If the task was previously queued, remove it from the queue
|
||||
if (taskWasPreviouslyQueued)
|
||||
{
|
||||
// Try to run the task.
|
||||
if (TryDequeue(task))
|
||||
{
|
||||
return TryExecuteTask(task);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return TryExecuteTask(task);
|
||||
}
|
||||
}
|
||||
|
||||
return false; // If this thread isn't already processing a task, we don't support inlining
|
||||
}
|
||||
|
||||
// Attempt to remove a previously scheduled task from the scheduler.
|
||||
protected override bool TryDequeue(Task task)
|
||||
{
|
||||
lock (tasks)
|
||||
{
|
||||
return tasks.Remove(task);
|
||||
}
|
||||
}
|
||||
|
||||
// Gets an enumerable of the tasks currently scheduled on this scheduler.
|
||||
protected override IEnumerable<Task> GetScheduledTasks()
|
||||
{
|
||||
var taken = false;
|
||||
try
|
||||
{
|
||||
Monitor.TryEnter(tasks, ref taken);
|
||||
if (taken)
|
||||
{
|
||||
return tasks;
|
||||
}
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (taken)
|
||||
{
|
||||
Monitor.Exit(tasks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,33 +25,29 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ASC.Common.Threading.Progress
|
||||
{
|
||||
[DataContract(Namespace = "")]
|
||||
public abstract class ProgressBase : IProgressItem
|
||||
{
|
||||
private double _percentage;
|
||||
|
||||
protected int StepCount { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public object Id { get; set; }
|
||||
[DataMember]
|
||||
|
||||
public object Status { get; set; }
|
||||
[DataMember]
|
||||
|
||||
public object Error { get; set; }
|
||||
|
||||
[DataMember]
|
||||
|
||||
public double Percentage
|
||||
{
|
||||
get { return Math.Min(100.0, Math.Max(0, _percentage)); }
|
||||
set { _percentage = value; }
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public virtual bool IsCompleted { get; set; }
|
||||
|
||||
|
||||
|
@ -337,27 +337,18 @@ namespace ASC.Core.Billing
|
||||
Message Request(Message message);
|
||||
}
|
||||
|
||||
[DataContract(Name = "Message", Namespace = "http://schemas.datacontract.org/2004/07/BillingService")]
|
||||
[Serializable]
|
||||
public class Message
|
||||
{
|
||||
[DataMember]
|
||||
public string Content { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public MessageType Type { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "MessageType", Namespace = "http://schemas.datacontract.org/2004/07/BillingService")]
|
||||
public enum MessageType
|
||||
{
|
||||
[EnumMember]
|
||||
Undefined = 0,
|
||||
|
||||
[EnumMember]
|
||||
Data = 1,
|
||||
|
||||
[EnumMember]
|
||||
Error = 2,
|
||||
}
|
||||
|
||||
|
@ -25,60 +25,60 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ASC.Core.Billing
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(Name = "license", Namespace = "")]
|
||||
[DebuggerDisplay("{DueDate}")]
|
||||
public class License
|
||||
{
|
||||
public string OriginalLicense { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "affiliate_id")]
|
||||
public string OriginalLicense { get; set; }
|
||||
|
||||
[JsonPropertyName("affiliate_id")]
|
||||
public string AffiliateId { get; set; }
|
||||
|
||||
//[Obsolete]
|
||||
[DataMember(Name = "whitelabel")]
|
||||
public bool WhiteLabel { get; set; }
|
||||
|
||||
[DataMember(Name = "customization")]
|
||||
public bool Customization { get; set; }
|
||||
|
||||
[DataMember(Name = "end_date")]
|
||||
|
||||
[JsonPropertyName("end_date")]
|
||||
public DateTime DueDate { get; set; }
|
||||
|
||||
[DataMember(Name = "portal_count")]
|
||||
|
||||
[JsonPropertyName("portal_count")]
|
||||
public int PortalCount { get; set; }
|
||||
|
||||
[DataMember(Name = "trial")]
|
||||
public bool Trial { get; set; }
|
||||
|
||||
[DataMember(Name = "user_quota")]
|
||||
|
||||
[JsonPropertyName("user_quota")]
|
||||
public int ActiveUsers { get; set; }
|
||||
|
||||
[DataMember(Name = "customer_id")]
|
||||
|
||||
[JsonPropertyName("customer_id")]
|
||||
public string CustomerId { get; set; }
|
||||
|
||||
[DataMember(Name = "signature")]
|
||||
public string Signature { get; set; }
|
||||
|
||||
|
||||
public static License Parse(string licenseString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(licenseString)) throw new BillingNotFoundException("License file is empty");
|
||||
|
||||
var licenseJson = JObject.Parse(licenseString);
|
||||
if (licenseJson == null) throw new BillingNotFoundException("Can't parse license");
|
||||
|
||||
var license = licenseJson.ToObject<License>();
|
||||
license.OriginalLicense = licenseString;
|
||||
|
||||
return license;
|
||||
|
||||
try
|
||||
{
|
||||
var license = JsonSerializer.Deserialize<License>(licenseString);
|
||||
if (license == null) throw new BillingNotFoundException("Can't parse license");
|
||||
|
||||
license.OriginalLicense = licenseString;
|
||||
|
||||
return license;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw new BillingNotFoundException("Can't parse license");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,146 +25,99 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Core
|
||||
{
|
||||
[DataContract]
|
||||
public class Partner
|
||||
{
|
||||
[DataMember(Name = "Id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[DataMember(Name = "Email")]
|
||||
public string Email { get; set; }
|
||||
|
||||
[DataMember(Name = "FirstName")]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[DataMember(Name = "LastName")]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[DataMember(Name = "Url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[DataMember(Name = "Phone")]
|
||||
public string Phone { get; set; }
|
||||
|
||||
[DataMember(Name = "Language")]
|
||||
public string Language { get; set; }
|
||||
|
||||
[DataMember(Name = "CompanyName")]
|
||||
public string CompanyName { get; set; }
|
||||
|
||||
[DataMember(Name = "Country")]
|
||||
public string Country { get; set; }
|
||||
|
||||
[DataMember(Name = "CountryCode")]
|
||||
public string CountryCode { get; set; }
|
||||
|
||||
[DataMember(Name = "CountryHasVat")]
|
||||
public bool CountryHasVat { get; set; }
|
||||
|
||||
[DataMember(Name = "Address")]
|
||||
public string Address { get; set; }
|
||||
|
||||
[DataMember(Name = "VatId")]
|
||||
public string VatId { get; set; }
|
||||
|
||||
[DataMember(Name = "CreationDate")]
|
||||
public DateTime CreationDate { get; set; }
|
||||
|
||||
[DataMember(Name = "Status")]
|
||||
public PartnerStatus Status { get; set; }
|
||||
|
||||
[DataMember(Name = "Comment")]
|
||||
public string Comment { get; set; }
|
||||
|
||||
[DataMember(Name = "Portal")]
|
||||
public string Portal { get; set; }
|
||||
|
||||
[DataMember(Name = "PortalConfirmed")]
|
||||
public bool PortalConfirmed { get; set; }
|
||||
|
||||
[DataMember(Name = "IsAdmin")]
|
||||
public bool IsAdmin { get { return PartnerType == PartnerType.Administrator; } }
|
||||
|
||||
[DataMember(Name = "Limit")]
|
||||
public decimal Limit { get; set; }
|
||||
|
||||
[DataMember(Name = "Discount")]
|
||||
public int Discount { get; set; }
|
||||
|
||||
[DataMember(Name = "PayPalAccount")]
|
||||
public string PayPalAccount { get; set; }
|
||||
|
||||
[DataMember(Name = "Deposit")]
|
||||
public decimal Deposit { get; set; }
|
||||
|
||||
[DataMember(Name = "Removed")]
|
||||
public bool Removed { get; set; }
|
||||
|
||||
[DataMember(Name = "Currency")]
|
||||
public string Currency { get; set; }
|
||||
|
||||
[DataMember(Name = "LogoUrl")]
|
||||
public string LogoUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "DisplayName")]
|
||||
public string DisplayName { get; set; }
|
||||
|
||||
[DataMember(Name = "DisplayType")]
|
||||
public PartnerDisplayType DisplayType { get; set; }
|
||||
|
||||
[DataMember(Name = "SupportPhone")]
|
||||
public string SupportPhone { get; set; }
|
||||
|
||||
[DataMember(Name = "SupportEmail")]
|
||||
public string SupportEmail { get; set; }
|
||||
|
||||
[DataMember(Name = "SalesEmail")]
|
||||
public string SalesEmail { get; set; }
|
||||
|
||||
[DataMember(Name = "TermsUrl")]
|
||||
public string TermsUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "Theme")]
|
||||
public string Theme { get; set; }
|
||||
|
||||
[DataMember(Name = "RuAccount")]
|
||||
public string RuAccount { get; set; }
|
||||
|
||||
[DataMember(Name = "RuBank")]
|
||||
public string RuBank { get; set; }
|
||||
|
||||
[DataMember(Name = "RuKs")]
|
||||
public string RuKs { get; set; }
|
||||
|
||||
[DataMember(Name = "RuKpp")]
|
||||
public string RuKpp { get; set; }
|
||||
|
||||
[DataMember(Name = "RuBik")]
|
||||
public string RuBik { get; set; }
|
||||
|
||||
[DataMember(Name = "RuInn")]
|
||||
public string RuInn { get; set; }
|
||||
|
||||
[DataMember(Name = "PartnerType")]
|
||||
public PartnerType PartnerType { get; set; }
|
||||
|
||||
[DataMember(Name = "PaymentMethod")]
|
||||
public PartnerPaymentMethod PaymentMethod { get; set; }
|
||||
|
||||
[DataMember(Name = "PaymentUrl")]
|
||||
public string PaymentUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "AvailableCredit")]
|
||||
public decimal AvailableCredit { get; set; }
|
||||
|
||||
[DataMember(Name = "CustomEmailSignature")]
|
||||
public bool CustomEmailSignature { get; set; }
|
||||
|
||||
[DataMember(Name = "AuthorizedKey")]
|
||||
public string AuthorizedKey { get; set; }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
@ -25,11 +25,8 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
@ -111,7 +108,6 @@ namespace ASC.Core.Data
|
||||
public class DbSettingsManager
|
||||
{
|
||||
private readonly TimeSpan expirationTimeout = TimeSpan.FromMinutes(5);
|
||||
private readonly IDictionary<Type, DataContractJsonSerializer> jsonSerializers = new Dictionary<Type, DataContractJsonSerializer>();
|
||||
|
||||
internal ILog Log { get; set; }
|
||||
internal ICache Cache { get; set; }
|
||||
@ -249,7 +245,7 @@ namespace ASC.Core.Data
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
settings = Deserialize<T>(result.ToString());
|
||||
settings = Deserialize<T>(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -322,30 +318,15 @@ namespace ASC.Core.Data
|
||||
}
|
||||
|
||||
private T Deserialize<T>(string data)
|
||||
{
|
||||
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(data));
|
||||
var settings = GetJsonSerializer(typeof(T)).ReadObject(stream);
|
||||
return (T)settings;
|
||||
{
|
||||
return JsonSerializer.Deserialize<T>(data);
|
||||
}
|
||||
|
||||
private string Serialize(ISettings settings)
|
||||
{
|
||||
using var stream = new MemoryStream();
|
||||
GetJsonSerializer(settings.GetType()).WriteObject(stream, settings);
|
||||
return Encoding.UTF8.GetString(stream.ToArray());
|
||||
{
|
||||
return JsonSerializer.Serialize(settings);
|
||||
}
|
||||
|
||||
private DataContractJsonSerializer GetJsonSerializer(Type type)
|
||||
{
|
||||
lock (jsonSerializers)
|
||||
{
|
||||
if (!jsonSerializers.ContainsKey(type))
|
||||
{
|
||||
jsonSerializers[type] = new DataContractJsonSerializer(type);
|
||||
}
|
||||
return jsonSerializers[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DbSettingsManagerExtension
|
||||
|
@ -23,84 +23,41 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Core.Common.Notify.Push
|
||||
{
|
||||
[DataContract]
|
||||
public enum PushAction
|
||||
{
|
||||
[EnumMember]
|
||||
Unknown,
|
||||
|
||||
[EnumMember]
|
||||
Created,
|
||||
|
||||
[EnumMember]
|
||||
Assigned,
|
||||
|
||||
[EnumMember]
|
||||
InvitedTo,
|
||||
|
||||
[EnumMember]
|
||||
Closed,
|
||||
|
||||
[EnumMember]
|
||||
Resumed,
|
||||
|
||||
[EnumMember]
|
||||
Deleted
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public enum PushItemType
|
||||
{
|
||||
[EnumMember]
|
||||
Unknown,
|
||||
|
||||
[EnumMember]
|
||||
Task,
|
||||
|
||||
[EnumMember]
|
||||
Subtask,
|
||||
|
||||
[EnumMember]
|
||||
Milestone,
|
||||
|
||||
[EnumMember]
|
||||
Project,
|
||||
|
||||
[EnumMember]
|
||||
Message
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public enum PushModule
|
||||
{
|
||||
[EnumMember]
|
||||
Unknown,
|
||||
|
||||
[EnumMember]
|
||||
Projects
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public enum MobileAppType
|
||||
{
|
||||
[EnumMember]
|
||||
IosProjects = 0,
|
||||
|
||||
[EnumMember]
|
||||
AndroidProjects = 1,
|
||||
|
||||
[EnumMember]
|
||||
IosDocuments = 2,
|
||||
|
||||
[EnumMember]
|
||||
AndroidDocuments = 3,
|
||||
|
||||
[EnumMember]
|
||||
DesktopEditor = 4
|
||||
}
|
||||
}
|
||||
|
@ -25,38 +25,27 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Core.Common.Notify.Push
|
||||
{
|
||||
[DataContract]
|
||||
public class PushNotification
|
||||
{
|
||||
[DataMember]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Message { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ShortMessage { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public int? Badge { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public PushModule Module { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public PushAction Action { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public PushItem Item { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public PushItem ParentItem { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime QueuedOn { get; set; }
|
||||
|
||||
public static PushNotification ApiNotification(string message, int? badge)
|
||||
@ -65,16 +54,12 @@ namespace ASC.Core.Common.Notify.Push
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class PushItem
|
||||
{
|
||||
[DataMember]
|
||||
public PushItemType Type { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ID { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Description { get; set; }
|
||||
|
||||
public PushItem()
|
||||
|
@ -24,17 +24,15 @@
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System;
|
||||
|
||||
using ASC.Core.Common.Settings;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class TenantAnalyticsSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "Analytics")]
|
||||
public bool Analytics { get; set; }
|
||||
|
||||
public Guid ID
|
||||
|
@ -24,23 +24,19 @@
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System;
|
||||
|
||||
using ASC.Core.Common.Settings;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class TenantAuditSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "MaxLifeTime")]
|
||||
public const int MaxLifeTime = 180;
|
||||
|
||||
[DataMember(Name = "LoginHistoryLifeTime")]
|
||||
public int LoginHistoryLifeTime { get; set; }
|
||||
|
||||
[DataMember(Name = "AuditTrailLifeTime")]
|
||||
public int AuditTrailLifeTime { get; set; }
|
||||
|
||||
public static Guid Guid = new Guid("{8337D0FB-AD67-4552-8297-802312E7F503}");
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common.Settings;
|
||||
@ -36,13 +35,10 @@ using Microsoft.Extensions.Configuration;
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class TenantCookieSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "Index")]
|
||||
public int Index { get; set; }
|
||||
|
||||
[DataMember(Name = "LifeTime")]
|
||||
public int LifeTime { get; set; }
|
||||
|
||||
|
||||
|
@ -27,11 +27,9 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[DataContract]
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class TenantQuota : ICloneable
|
||||
{
|
||||
@ -43,44 +41,32 @@ namespace ASC.Core.Tenants
|
||||
ActiveUsers = int.MaxValue,
|
||||
};
|
||||
|
||||
[DataMember(Name = "Id", Order = 10)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DataMember(Name = "Name", Order = 20)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember(Name = "MaxFileSize", Order = 30)]
|
||||
public long MaxFileSize { get; set; }
|
||||
|
||||
[DataMember(Name = "MaxTotalSize", Order = 40)]
|
||||
public long MaxTotalSize { get; set; }
|
||||
|
||||
[DataMember(Name = "ActiveUsers", Order = 50)]
|
||||
public int ActiveUsers { get; set; }
|
||||
|
||||
[DataMember(Name = "Features", Order = 60)]
|
||||
public string Features { get; set; }
|
||||
|
||||
[DataMember(Name = "Price", Order = 70)]
|
||||
public decimal Price { get; set; }
|
||||
|
||||
[DataMember(Name = "Price2", Order = 80)]
|
||||
public decimal Price2 { get; set; }
|
||||
|
||||
[DataMember(Name = "AvangateId", Order = 90)]
|
||||
public string AvangateId { get; set; }
|
||||
|
||||
[DataMember(Name = "Visible", Order = 100)]
|
||||
public bool Visible { get; set; }
|
||||
|
||||
[DataMember(Name = "Year", Order = 110)]
|
||||
public bool Year
|
||||
{
|
||||
get { return GetFeature("year"); }
|
||||
set { SetFeature("year", value); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "Year3", Order = 110)]
|
||||
public bool Year3
|
||||
{
|
||||
get { return GetFeature("year3"); }
|
||||
|
@ -31,7 +31,7 @@ namespace ASC.Core.Common.Tests
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
|
||||
using System.Text.Json;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Data;
|
||||
using ASC.Core.Tenants;
|
||||
@ -98,12 +98,9 @@ namespace ASC.Core.Common.Tests
|
||||
MaxFileSize = 3,
|
||||
MaxTotalSize = 4,
|
||||
ActiveUsers = 30,
|
||||
};
|
||||
|
||||
var serializer = new DataContractJsonSerializer(quota1.GetType());
|
||||
using var ms = new MemoryStream();
|
||||
serializer.WriteObject(ms, quota1);
|
||||
var json = Encoding.UTF8.GetString(ms.ToArray());
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(quota1);
|
||||
Assert.AreEqual("{\"Id\":1024,\"Name\":\"quota1\",\"MaxFileSize\":3,\"MaxTotalSize\":4,\"ActiveUsers\":30,\"Features\":\"trial,year\",\"Price\":12.5,\"Price2\":45.23,\"AvangateId\":\"1\",\"Visible\":true}", json);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Web;
|
||||
|
||||
using ASC.Common;
|
||||
@ -36,7 +35,6 @@ using ASC.Core.Users;
|
||||
namespace ASC.Web.Core.Users
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class DisplayUserSettings : ISettings
|
||||
{
|
||||
public Guid ID
|
||||
@ -44,7 +42,6 @@ namespace ASC.Web.Core.Users
|
||||
get { return new Guid("2EF59652-E1A7-4814-BF71-FEB990149428"); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "IsDisableGettingStarted")]
|
||||
public bool IsDisableGettingStarted { get; set; }
|
||||
|
||||
public ISettings GetDefault(IServiceProvider serviceProvider)
|
||||
|
@ -24,17 +24,15 @@
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System;
|
||||
|
||||
using ASC.Core.Common.Settings;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class PersonalQuotaSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "MaxSpace")]
|
||||
public long MaxSpace { get; set; }
|
||||
|
||||
public Guid ID
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core.Common;
|
||||
@ -37,28 +36,20 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
namespace ASC.Web.Core.WhiteLabel
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class MailWhiteLabelSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "FooterEnabled")]
|
||||
public bool FooterEnabled { get; set; }
|
||||
|
||||
[DataMember(Name = "FooterSocialEnabled")]
|
||||
public bool FooterSocialEnabled { get; set; }
|
||||
|
||||
[DataMember(Name = "SupportUrl")]
|
||||
public string SupportUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "SupportEmail")]
|
||||
public string SupportEmail { get; set; }
|
||||
|
||||
[DataMember(Name = "SalesEmail")]
|
||||
public string SalesEmail { get; set; }
|
||||
|
||||
[DataMember(Name = "DemotUrl")]
|
||||
public string DemotUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "SiteUrl")]
|
||||
public string SiteUrl { get; set; }
|
||||
|
||||
public Guid ID
|
||||
|
@ -26,7 +26,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
@ -72,13 +71,10 @@ namespace ASC.Data.Storage.Configuration
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public abstract class BaseStorageSettings<T> : ISettings where T : class, ISettings, new()
|
||||
{
|
||||
[DataMember(Name = "Module")]
|
||||
public string Module { get; set; }
|
||||
|
||||
[DataMember(Name = "Props")]
|
||||
public Dictionary<string, string> Props { get; set; }
|
||||
|
||||
public ISettings GetDefault(IServiceProvider serviceProvider) => new T();
|
||||
@ -90,7 +86,6 @@ namespace ASC.Data.Storage.Configuration
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class StorageSettings : BaseStorageSettings<StorageSettings>
|
||||
{
|
||||
public override Guid ID
|
||||
@ -100,7 +95,6 @@ namespace ASC.Data.Storage.Configuration
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class CdnStorageSettings : BaseStorageSettings<CdnStorageSettings>
|
||||
{
|
||||
public override Guid ID
|
||||
|
@ -28,14 +28,12 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Threading;
|
||||
using ASC.Common.Threading.Progress;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common.Settings;
|
||||
@ -62,7 +60,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
static StaticUploader()
|
||||
{
|
||||
Scheduler = new LimitedConcurrencyLevelTaskScheduler(4);
|
||||
Scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, 4).ConcurrentScheduler;
|
||||
Cache = AscCache.Memory;
|
||||
Locker = new object();
|
||||
TokenSource = new CancellationTokenSource();
|
||||
@ -242,7 +240,6 @@ namespace ASC.Data.Storage
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class UploadOperationProgress : ProgressBase
|
||||
{
|
||||
private readonly string relativePath;
|
||||
|
@ -27,17 +27,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Threading;
|
||||
using ASC.Common.Threading.Progress;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common.Settings;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
@ -55,7 +55,7 @@ namespace ASC.Data.Storage
|
||||
|
||||
static StorageUploader()
|
||||
{
|
||||
Scheduler = new LimitedConcurrencyLevelTaskScheduler(4);
|
||||
Scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, 4).ConcurrentScheduler;
|
||||
TokenSource = new CancellationTokenSource();
|
||||
Cache = AscCache.Memory;
|
||||
Locker = new object();
|
||||
@ -115,7 +115,6 @@ namespace ASC.Data.Storage
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class MigrateOperation : ProgressBase
|
||||
{
|
||||
private readonly ILog Log;
|
||||
|
@ -43,13 +43,11 @@ using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.WebUtilities;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.FederatedLogin.Profile
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract(Name = "LoginProfile", Namespace = "")]
|
||||
[DebuggerDisplay("{DisplayName} ({Id})")]
|
||||
public class LoginProfile
|
||||
{
|
||||
@ -147,14 +145,12 @@ namespace ASC.FederatedLogin.Profile
|
||||
internal set { SetField(WellKnownFields.Auth, value); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "AuthorizationError")]
|
||||
public string AuthorizationError
|
||||
{
|
||||
get { return GetField(WellKnownFields.AuthError); }
|
||||
internal set { SetField(WellKnownFields.AuthError, value); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "Provider")]
|
||||
public string Provider
|
||||
{
|
||||
get { return GetField(WellKnownFields.Provider); }
|
||||
@ -177,14 +173,12 @@ namespace ASC.FederatedLogin.Profile
|
||||
get { return HashHelper.MD5(UniqueId); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "Hash")]
|
||||
public string Hash
|
||||
{
|
||||
get { return Signature?.Create(HashId); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "Serialized")]
|
||||
public string Serialized
|
||||
{
|
||||
get { return Transport(); }
|
||||
@ -415,11 +409,7 @@ namespace ASC.FederatedLogin.Profile
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
var serializer = new DataContractJsonSerializer(typeof(LoginProfile));
|
||||
serializer.WriteObject(ms, this);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
return System.Text.Json.JsonSerializer.Serialize(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -26,11 +26,9 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Feed.Aggregator
|
||||
{
|
||||
[DataContract]
|
||||
public class Feed
|
||||
{
|
||||
public Feed()
|
||||
@ -49,79 +47,55 @@ namespace ASC.Feed.Aggregator
|
||||
Variate = variate;
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public string Item { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ItemId { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Id
|
||||
{
|
||||
get { return string.Format("{0}_{1}", Item, ItemId); }
|
||||
}
|
||||
|
||||
[DataMember]
|
||||
public Guid AuthorId { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public Guid ModifiedBy { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime CreatedDate { get; private set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime ModifiedDate { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Product { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Module { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ExtraLocation { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ExtraLocationUrl { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public FeedAction Action { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Title { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string ItemUrl { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string Description { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string AdditionalInfo { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string AdditionalInfo2 { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string AdditionalInfo3 { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string AdditionalInfo4 { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public bool HasPreview { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public bool CanComment { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public object Target { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public string CommentApiUrl { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public IEnumerable<FeedComment> Comments { get; set; }
|
||||
|
||||
|
||||
|
@ -25,16 +25,14 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Core.Common.Settings;
|
||||
|
||||
namespace ASC.IPSecurity
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class IPRestrictionsSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "Enable")]
|
||||
public bool Enable { get; set; }
|
||||
|
||||
public Guid ID
|
||||
|
@ -82,7 +82,7 @@ namespace ASC.ApiSystem.Controllers
|
||||
SettingsManager settingsManager,
|
||||
ApiSystemHelper apiSystemHelper,
|
||||
CommonMethods commonMethods,
|
||||
HostedSolution hostedSolution,
|
||||
IOptionsSnapshot<HostedSolution> hostedSolutionOptions,
|
||||
CoreSettings coreSettings,
|
||||
TenantDomainValidator tenantDomainValidator,
|
||||
UserFormatter userFormatter,
|
||||
@ -98,7 +98,7 @@ namespace ASC.ApiSystem.Controllers
|
||||
SettingsManager = settingsManager;
|
||||
ApiSystemHelper = apiSystemHelper;
|
||||
CommonMethods = commonMethods;
|
||||
HostedSolution = hostedSolution;
|
||||
HostedSolution = hostedSolutionOptions.Value;
|
||||
CoreSettings = coreSettings;
|
||||
TenantDomainValidator = tenantDomainValidator;
|
||||
UserFormatter = userFormatter;
|
||||
|
@ -50,12 +50,12 @@ namespace ASC.ApiSystem.Controllers
|
||||
private ILog Log { get; }
|
||||
public TariffController(
|
||||
CommonMethods commonMethods,
|
||||
HostedSolution hostedSolution,
|
||||
IOptionsSnapshot<HostedSolution> hostedSolutionOptions,
|
||||
IOptionsMonitor<ILog> option
|
||||
)
|
||||
{
|
||||
CommonMethods = commonMethods;
|
||||
HostedSolution = hostedSolution;
|
||||
HostedSolution = hostedSolutionOptions.Value;
|
||||
Log = option.Get("ASC.ApiSystem");
|
||||
}
|
||||
|
||||
|
@ -26,21 +26,16 @@
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.ApiSystem.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class CoreSettingsModel
|
||||
{
|
||||
[DataMember(IsRequired = false)]
|
||||
public Int32 Tenant { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string Key { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
public string Value { get; set; }
|
||||
|
||||
public CoreSettingsModel()
|
||||
|
@ -24,28 +24,23 @@
|
||||
*/
|
||||
|
||||
|
||||
using ASC.ApiSystem.Interfaces;
|
||||
using ASC.ApiSystem.Interfaces;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.ApiSystem.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class SettingsModel : IModel
|
||||
{
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(255)]
|
||||
public string PortalName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public int? TenantId { get; set; }
|
||||
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string Key { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
@ -24,38 +24,30 @@
|
||||
*/
|
||||
|
||||
|
||||
using ASC.ApiSystem.Interfaces;
|
||||
using ASC.ApiSystem.Interfaces;
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.ApiSystem.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class TariffModel : IModel
|
||||
{
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string PortalName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public int? TenantId { get; set; }
|
||||
|
||||
|
||||
[DataMember]
|
||||
public int ActiveUsers { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime DueDate { get; set; }
|
||||
|
||||
[DataMember]
|
||||
[StringLength(255)]
|
||||
public string Features { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public long MaxFileSize { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public long MaxTotalSize { get; set; }
|
||||
}
|
||||
}
|
@ -26,94 +26,69 @@
|
||||
|
||||
using ASC.ApiSystem.Classes;
|
||||
using ASC.ApiSystem.Interfaces;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Tenants;
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace ASC.ApiSystem.Models
|
||||
{
|
||||
[DataContract]
|
||||
public class TenantModel : IModel
|
||||
{
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string PortalName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public int? TenantId { get; set; }
|
||||
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(255)]
|
||||
public string AffiliateId { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public string Campaign { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string FirstName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
[Email]
|
||||
[StringLength(255)]
|
||||
public string Email { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public int Industry { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(7)]
|
||||
public string Language { get; set; }
|
||||
|
||||
[DataMember(IsRequired = true)]
|
||||
[StringLength(255)]
|
||||
public string LastName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(38)]
|
||||
public string Module { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(Web.Core.Utility.PasswordSettings.MaxLength)]
|
||||
public string Password { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(255)]
|
||||
public string PartnerId { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(32)]
|
||||
public string Phone { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public string RecaptchaResponse { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(20)]
|
||||
public string Region { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public TenantStatus Status { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public bool SkipWelcome { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
[StringLength(255)]
|
||||
public string TimeZoneName { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public bool Spam { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public bool Calls { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public bool Analytics { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false)]
|
||||
public string AppKey { get; set; }
|
||||
}
|
||||
}
|
@ -59,8 +59,12 @@ namespace ASC.ApiSystem
|
||||
|
||||
services.AddHttpContextAccessor();
|
||||
|
||||
services.AddControllers()
|
||||
.AddNewtonsoftJson();
|
||||
services.AddControllers()
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
options.JsonSerializerOptions.WriteIndented = false;
|
||||
options.JsonSerializerOptions.IgnoreNullValues = true;
|
||||
});
|
||||
|
||||
services.AddMemoryCache();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using ASC.Api.Utils;
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Billing;
|
||||
@ -171,8 +172,8 @@ namespace ASC.Data.Backup
|
||||
StorageType = response.StorageType,
|
||||
StorageParams = response.StorageParams.ToDictionary(r => r.Key, r => r.Value) ?? new Dictionary<string, string>(),
|
||||
CronParams = new CronParams(response.Cron),
|
||||
BackupMail = response.BackupMail,
|
||||
BackupsStored = response.NumberOfBackupsStored,
|
||||
BackupMail = response.BackupMail.NullIfDefault(),
|
||||
BackupsStored = response.NumberOfBackupsStored.NullIfDefault(),
|
||||
LastBackupTime = response.LastBackupTime
|
||||
};
|
||||
|
||||
@ -197,9 +198,9 @@ namespace ASC.Data.Backup
|
||||
var Schedule = new CreateScheduleRequest
|
||||
{
|
||||
TenantId = TenantManager.GetCurrentTenant().TenantId,
|
||||
BackupMail = schedule.BackupMail,
|
||||
BackupMail = schedule.BackupMail == null ? false : (bool)schedule.BackupMail,
|
||||
Cron = schedule.CronParams.ToString(),
|
||||
NumberOfBackupsStored = schedule.BackupsStored,
|
||||
NumberOfBackupsStored = schedule.BackupsStored == null ? 0 : (int)schedule.BackupsStored,
|
||||
StorageType = schedule.StorageType,
|
||||
StorageParams = schedule.StorageParams
|
||||
};
|
||||
@ -344,8 +345,8 @@ namespace ASC.Data.Backup
|
||||
public BackupStorageType StorageType { get; set; }
|
||||
public Dictionary<string, string> StorageParams { get; set; }
|
||||
public CronParams CronParams { get; set; }
|
||||
public bool BackupMail { get; set; }
|
||||
public int BackupsStored { get; set; }
|
||||
public bool? BackupMail { get; set; }
|
||||
public int? BackupsStored { get; set; }
|
||||
public DateTime LastBackupTime { get; set; }
|
||||
}
|
||||
|
||||
|
@ -1,161 +1,161 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using ASC.Api.Core.Middleware;
|
||||
using ASC.Common;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.Models;
|
||||
using ASC.Web.Api.Routing;
|
||||
using ASC.Api.Core.Middleware;
|
||||
using ASC.Common;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.Models;
|
||||
using ASC.Web.Api.Routing;
|
||||
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ASC.Data.Backup.Controllers
|
||||
{
|
||||
[DefaultRoute]
|
||||
[ApiController]
|
||||
public class BackupController
|
||||
{
|
||||
private BackupAjaxHandler BackupHandler { get; }
|
||||
public BackupController(BackupAjaxHandler backupAjaxHandler)
|
||||
{
|
||||
BackupHandler = backupAjaxHandler;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Schedule</returns>
|
||||
[Read("getbackupschedule")]
|
||||
public BackupAjaxHandler.Schedule GetBackupSchedule()
|
||||
{
|
||||
return BackupHandler.GetSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage type</param>
|
||||
/// <param name="storageParams">Storage parameters</param>
|
||||
/// <param name="backupsStored">Max of the backup's stored copies</param>
|
||||
/// <param name="cronParams">Cron parameters</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
[Create("createbackupschedule")]
|
||||
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
|
||||
{
|
||||
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackupschedule")]
|
||||
public void DeleteBackupSchedule()
|
||||
{
|
||||
BackupHandler.DeleteSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a backup of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Create("startbackup")]
|
||||
public BackupProgress StartBackup(Models.Backup backup)
|
||||
{
|
||||
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Read("getbackupprogress")]
|
||||
public BackupProgress GetBackupProgress()
|
||||
{
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the backup history of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Read("getbackuphistory")]
|
||||
public List<BackupHistoryRecord> GetBackupHistory()
|
||||
{
|
||||
return BackupHandler.GetBackupHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup with the specified id
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackup/{id}")]
|
||||
public void DeleteBackup(Guid id)
|
||||
{
|
||||
BackupHandler.DeleteBackup(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete all backups of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Delete("deletebackuphistory")]
|
||||
public void DeleteBackupHistory()
|
||||
{
|
||||
BackupHandler.DeleteAllBackups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a data restore of the current portal
|
||||
/// </summary>
|
||||
/// <param name="backupId">Backup Id</param>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="notify">Notify about backup to users</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Create("startrestore")]
|
||||
public BackupProgress StartBackupRestore(BackupRestore backupRestore)
|
||||
{
|
||||
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started restore
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!!
|
||||
public BackupProgress GetRestoreProgress()
|
||||
{
|
||||
return BackupHandler.GetRestoreProgress();
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
[Read("backuptmp")]
|
||||
public string GetTempPath()
|
||||
{
|
||||
return BackupHandler.GetTmpFolder();
|
||||
}
|
||||
}
|
||||
public static class BackupControllerExtension
|
||||
{
|
||||
public static DIHelper AddBackupController(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddBackupAjaxHandler()
|
||||
.AddIpSecurityFilter();
|
||||
}
|
||||
}
|
||||
}
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ASC.Data.Backup.Controllers
|
||||
{
|
||||
[DefaultRoute]
|
||||
[ApiController]
|
||||
public class BackupController
|
||||
{
|
||||
private BackupAjaxHandler BackupHandler { get; }
|
||||
public BackupController(BackupAjaxHandler backupAjaxHandler)
|
||||
{
|
||||
BackupHandler = backupAjaxHandler;
|
||||
}
|
||||
/// <summary>
|
||||
/// Returns the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Schedule</returns>
|
||||
[Read("getbackupschedule")]
|
||||
public BackupAjaxHandler.Schedule GetBackupSchedule()
|
||||
{
|
||||
return BackupHandler.GetSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage type</param>
|
||||
/// <param name="storageParams">Storage parameters</param>
|
||||
/// <param name="backupsStored">Max of the backup's stored copies</param>
|
||||
/// <param name="cronParams">Cron parameters</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
[Create("createbackupschedule")]
|
||||
public void CreateBackupSchedule(BackupStorageType storageType, [FromQuery] Dictionary<string, string> storageParams, int backupsStored, [FromBody] BackupAjaxHandler.CronParams cronParams, bool backupMail)
|
||||
{
|
||||
BackupHandler.CreateSchedule(storageType, storageParams, backupsStored, cronParams, backupMail);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup schedule of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackupschedule")]
|
||||
public void DeleteBackupSchedule()
|
||||
{
|
||||
BackupHandler.DeleteSchedule();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a backup of the current portal
|
||||
/// </summary>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="backupMail">Include mail in the backup</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Create("startbackup")]
|
||||
public BackupProgress StartBackup(Models.Backup backup)
|
||||
{
|
||||
BackupHandler.StartBackup(backup.StorageType, backup.StorageParams ?? new Dictionary<string, string>(), backup.BackupMail);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup Progress</returns>
|
||||
[Read("getbackupprogress")]
|
||||
public BackupProgress GetBackupProgress()
|
||||
{
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the backup history of the started backup
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Read("getbackuphistory")]
|
||||
public List<BackupHistoryRecord> GetBackupHistory()
|
||||
{
|
||||
return BackupHandler.GetBackupHistory();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the backup with the specified id
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
[Delete("deletebackup/{id}")]
|
||||
public void DeleteBackup(Guid id)
|
||||
{
|
||||
BackupHandler.DeleteBackup(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete all backups of the current portal
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Backup History</returns>
|
||||
[Delete("deletebackuphistory")]
|
||||
public void DeleteBackupHistory()
|
||||
{
|
||||
BackupHandler.DeleteAllBackups();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start a data restore of the current portal
|
||||
/// </summary>
|
||||
/// <param name="backupId">Backup Id</param>
|
||||
/// <param name="storageType">Storage Type</param>
|
||||
/// <param name="storageParams">Storage Params</param>
|
||||
/// <param name="notify">Notify about backup to users</param>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Create("startrestore")]
|
||||
public BackupProgress StartBackupRestore(BackupRestore backupRestore)
|
||||
{
|
||||
BackupHandler.StartRestore(backupRestore.BackupId, backupRestore.StorageType, backupRestore.StorageParams, backupRestore.Notify);
|
||||
return BackupHandler.GetBackupProgress();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the progress of the started restore
|
||||
/// </summary>
|
||||
/// <category>Backup</category>
|
||||
/// <returns>Restore Progress</returns>
|
||||
[Read("getrestoreprogress", true)] //NOTE: this method doesn't check payment!!!
|
||||
public BackupProgress GetRestoreProgress()
|
||||
{
|
||||
return BackupHandler.GetRestoreProgress();
|
||||
}
|
||||
|
||||
///<visible>false</visible>
|
||||
[Read("backuptmp")]
|
||||
public string GetTempPath()
|
||||
{
|
||||
return BackupHandler.GetTmpFolder();
|
||||
}
|
||||
}
|
||||
public static class BackupControllerExtension
|
||||
{
|
||||
public static DIHelper AddBackupController(this DIHelper services)
|
||||
{
|
||||
return services
|
||||
.AddBackupAjaxHandler()
|
||||
.AddIpSecurityFilter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
@ -43,10 +42,8 @@ using Newtonsoft.Json;
|
||||
namespace ASC.ElasticSearch.Core
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class SearchSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "Data")]
|
||||
public string Data { get; set; }
|
||||
|
||||
public Guid ID
|
||||
@ -173,13 +170,10 @@ namespace ASC.ElasticSearch.Core
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class SearchSettingsItem
|
||||
{
|
||||
[DataMember(Name = "ID")]
|
||||
public string ID { get; set; }
|
||||
|
||||
[DataMember(Name = "Enabled")]
|
||||
public bool Enabled { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
@ -1,15 +1,11 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.ElasticSearch.Core
|
||||
{
|
||||
[DataContract]
|
||||
public class State
|
||||
{
|
||||
[DataMember]
|
||||
public string Indexing { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public DateTime? LastIndexed { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,6 @@ using System.Threading.Tasks;
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Threading;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.ElasticSearch.Core;
|
||||
@ -79,7 +78,7 @@ namespace ASC.ElasticSearch
|
||||
|
||||
public class FactoryIndexer<T> : IFactoryIndexer where T : class, ISearchItem
|
||||
{
|
||||
private static readonly TaskScheduler Scheduler = new LimitedConcurrencyLevelTaskScheduler(10);
|
||||
private static readonly TaskScheduler Scheduler = new ConcurrentExclusiveSchedulerPair(TaskScheduler.Default, 10).ConcurrentScheduler;
|
||||
|
||||
public ILog Logger { get; }
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.OneDriveSDK" Version="2.0.7" />
|
||||
<PackageReference Include="Microsoft.SharePoint.Client" Version="14.0.4762.1000" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
|
||||
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.1" />
|
||||
@ -50,6 +49,7 @@
|
||||
<ProjectReference Include="..\..\..\common\ASC.MessagingSystem\ASC.MessagingSystem.csproj" />
|
||||
<ProjectReference Include="..\..\..\common\services\ASC.ElasticSearch\ASC.ElasticSearch.csproj" />
|
||||
<ProjectReference Include="..\..\..\thirdparty\AppLimit.CloudComputing.SharpBox\AppLimit.CloudComputing.SharpBox.csproj" />
|
||||
<ProjectReference Include="..\..\..\thirdparty\onedrive-sdk-csharp-master\src\OneDriveSdk\Microsoft.OneDrive.Sdk.csproj" />
|
||||
<ProjectReference Include="..\..\..\web\ASC.Web.Core\ASC.Web.Core.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
@ -35,40 +35,39 @@ using ASC.Files.Core;
|
||||
namespace ASC.Web.Files.Classes
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class FilesSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "EnableThirdpartySettings")]
|
||||
[JsonPropertyName("EnableThirdpartySettings")]
|
||||
public bool EnableThirdpartySetting { get; set; }
|
||||
|
||||
[DataMember(Name = "FastDelete")]
|
||||
[JsonPropertyName("FastDelete")]
|
||||
public bool FastDeleteSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "StoreOriginalFiles")]
|
||||
[JsonPropertyName("StoreOriginalFiles")]
|
||||
public bool StoreOriginalFilesSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "UpdateIfExist")]
|
||||
[JsonPropertyName("UpdateIfExist")]
|
||||
public bool UpdateIfExistSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "ConvertNotify")]
|
||||
[JsonPropertyName("ConvertNotify")]
|
||||
public bool ConvertNotifySetting { get; set; }
|
||||
|
||||
[DataMember(Name = "SortedBy")]
|
||||
[JsonPropertyName("DefaultSortedBy")]
|
||||
public SortedByType DefaultSortedBySetting { get; set; }
|
||||
|
||||
[DataMember(Name = "SortedAsc")]
|
||||
[JsonPropertyName("DefaultSortedAsc")]
|
||||
public bool DefaultSortedAscSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "HideConfirmConvertSave")]
|
||||
[JsonPropertyName("HideConfirmConvertSave")]
|
||||
public bool HideConfirmConvertSaveSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "HideConfirmConvertOpen")]
|
||||
[JsonPropertyName("HideConfirmConvertOpen")]
|
||||
public bool HideConfirmConvertOpenSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "Forcesave")]
|
||||
[JsonPropertyName("Forcesave")]
|
||||
public bool ForcesaveSetting { get; set; }
|
||||
|
||||
[DataMember(Name = "StoreForcesave")]
|
||||
[JsonPropertyName("StoreForcesave")]
|
||||
public bool StoreForcesaveSetting { get; set; }
|
||||
|
||||
public ISettings GetDefault(IServiceProvider serviceProvider)
|
||||
|
@ -29,8 +29,8 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using ASC.Api.Core;
|
||||
@ -1311,10 +1311,10 @@ namespace ASC.Api.Documents
|
||||
/// <short>Get third party folder</short>
|
||||
/// <returns>Connected providers folder</returns>
|
||||
[Read("thirdparty/common")]
|
||||
public IEnumerable<Folder<string>> GetCommonThirdPartyFolders()
|
||||
public IEnumerable<FolderWrapper<string>> GetCommonThirdPartyFolders()
|
||||
{
|
||||
var parent = FileStorageServiceInt.GetFolder(GlobalFolderHelper.FolderCommon);
|
||||
return EntryManager.GetThirpartyFolders(parent);
|
||||
return EntryManager.GetThirpartyFolders(parent).Select(FolderWrapperHelper.Get).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -1637,49 +1637,43 @@ namespace ASC.Api.Documents
|
||||
/// <summary>
|
||||
/// Result of file conversation operation.
|
||||
/// </summary>
|
||||
[DataContract(Name = "operation_result", Namespace = "")]
|
||||
public class ConversationResult<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Operation Id.
|
||||
/// </summary>
|
||||
[DataMember(Name = "id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Operation type.
|
||||
/// </summary>
|
||||
[DataMember(Name = "operation")]
|
||||
[JsonPropertyName("Operation")]
|
||||
public FileOperationType OperationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Operation progress.
|
||||
/// </summary>
|
||||
[DataMember(Name = "progress")]
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Source files for operation.
|
||||
/// </summary>
|
||||
[DataMember(Name = "source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Result file of operation.
|
||||
/// </summary>
|
||||
[DataMember(Name = "result")]
|
||||
[JsonPropertyName("result")]
|
||||
public FileWrapper<T> File { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Error during conversation.
|
||||
/// </summary>
|
||||
[DataMember(Name = "error")]
|
||||
public string Error { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Is operation processed.
|
||||
/// </summary>
|
||||
[DataMember(Name = "processed")]
|
||||
public string Processed { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -25,24 +25,18 @@
|
||||
|
||||
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Name = "AuthData", Namespace = "")]
|
||||
[DebuggerDisplay("{Login} {Password} {Token} {Url}")]
|
||||
public class AuthData
|
||||
{
|
||||
[DataMember(Name = "login")]
|
||||
public string Login { get; set; }
|
||||
|
||||
[DataMember(Name = "password")]
|
||||
public string Password { get; set; }
|
||||
|
||||
[DataMember(Name = "token")]
|
||||
public string Token { get; set; }
|
||||
|
||||
[DataMember(Name = "url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
public AuthData(string url = null, string login = null, string password = null, string token = null)
|
||||
|
@ -1,51 +1,50 @@
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Files.Resources;
|
||||
using ASC.Web.Core.Users;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Name = "editHistory", Namespace = "")]
|
||||
[DebuggerDisplay("{ID} v{Version}")]
|
||||
public class EditHistory
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DebuggerDisplay("{ID} v{Version}")]
|
||||
public class EditHistory
|
||||
{
|
||||
public EditHistory(
|
||||
IOptionsMonitor<ILog> options,
|
||||
@ -60,37 +59,38 @@ namespace ASC.Files.Core
|
||||
UserManager = userManager;
|
||||
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
||||
}
|
||||
|
||||
public int ID;
|
||||
[DataMember(Name = "key")] public string Key;
|
||||
[DataMember(Name = "version")] public int Version;
|
||||
[DataMember(Name = "versionGroup")] public int VersionGroup;
|
||||
|
||||
[DataMember(Name = "user")] public EditHistoryAuthor ModifiedBy;
|
||||
|
||||
[DataMember(Name = "changeshistory", EmitDefaultValue = false)] public string ChangesString;
|
||||
|
||||
[DataMember(Name = "changes", EmitDefaultValue = false)]
|
||||
public List<EditHistoryChanges> Changes
|
||||
{
|
||||
get
|
||||
{
|
||||
var changes = new List<EditHistoryChanges>();
|
||||
if (string.IsNullOrEmpty(ChangesString)) return changes;
|
||||
|
||||
//new scheme
|
||||
Exception newSchemeException = null;
|
||||
try
|
||||
{
|
||||
var jObject = JObject.Parse(ChangesString);
|
||||
ServerVersion = jObject.Value<string>("serverVersion");
|
||||
|
||||
var jChanges = jObject.Value<JArray>("changes");
|
||||
|
||||
changes = jChanges.Children()
|
||||
.Select(jChange =>
|
||||
{
|
||||
var jUser = jChange.Value<JObject>("user");
|
||||
|
||||
public int ID { get; set; }
|
||||
public string Key { get; set; }
|
||||
public int Version { get; set; }
|
||||
public int VersionGroup { get; set; }
|
||||
|
||||
[JsonPropertyName("user")]
|
||||
public EditHistoryAuthor ModifiedBy { get; set; }
|
||||
|
||||
[JsonPropertyName("changeshistory")]
|
||||
public string ChangesString { get; set; }
|
||||
|
||||
public List<EditHistoryChanges> Changes
|
||||
{
|
||||
get
|
||||
{
|
||||
var changes = new List<EditHistoryChanges>();
|
||||
if (string.IsNullOrEmpty(ChangesString)) return changes;
|
||||
|
||||
//new scheme
|
||||
Exception newSchemeException = null;
|
||||
try
|
||||
{
|
||||
var jObject = JObject.Parse(ChangesString);
|
||||
ServerVersion = jObject.Value<string>("serverVersion");
|
||||
|
||||
var jChanges = jObject.Value<JArray>("changes");
|
||||
|
||||
changes = jChanges.Children()
|
||||
.Select(jChange =>
|
||||
{
|
||||
var jUser = jChange.Value<JObject>("user");
|
||||
return new EditHistoryChanges(TenantUtil)
|
||||
{
|
||||
Date = jChange.Value<string>("created"),
|
||||
@ -99,24 +99,24 @@ namespace ASC.Files.Core
|
||||
Id = new Guid(jUser.Value<string>("id") ?? Guid.Empty.ToString()),
|
||||
Name = jUser.Value<string>("name"),
|
||||
},
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
return changes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
newSchemeException = ex;
|
||||
}
|
||||
|
||||
//old scheme
|
||||
//todo: delete
|
||||
try
|
||||
{
|
||||
var jChanges = JArray.Parse(ChangesString);
|
||||
|
||||
changes = jChanges.Children<JObject>()
|
||||
.Select(jChange =>
|
||||
};
|
||||
})
|
||||
.ToList();
|
||||
return changes;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
newSchemeException = ex;
|
||||
}
|
||||
|
||||
//old scheme
|
||||
//todo: delete
|
||||
try
|
||||
{
|
||||
var jChanges = JArray.Parse(ChangesString);
|
||||
|
||||
changes = jChanges.Children<JObject>()
|
||||
.Select(jChange =>
|
||||
new EditHistoryChanges(TenantUtil)
|
||||
{
|
||||
Date = jChange.Value<string>("date"),
|
||||
@ -125,27 +125,27 @@ namespace ASC.Files.Core
|
||||
Id = new Guid(jChange.Value<string>("userid") ?? Guid.Empty.ToString()),
|
||||
Name = jChange.Value<string>("username")
|
||||
}
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("DeSerialize new scheme exception", newSchemeException);
|
||||
Logger.Error("DeSerialize old scheme exception", ex);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public DateTime ModifiedOn;
|
||||
|
||||
[DataMember(Name = "created")]
|
||||
public string ModifiedOnString
|
||||
{
|
||||
get { return ModifiedOn.Equals(default) ? null : ModifiedOn.ToString("g"); }
|
||||
set { throw new NotImplementedException(); }
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error("DeSerialize new scheme exception", newSchemeException);
|
||||
Logger.Error("DeSerialize old scheme exception", ex);
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public DateTime ModifiedOn;
|
||||
|
||||
[JsonPropertyName("created")]
|
||||
public string ModifiedOnString
|
||||
{
|
||||
get { return ModifiedOn.Equals(default) ? null : ModifiedOn.ToString("g"); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public ILog Logger { get; }
|
||||
@ -154,12 +154,11 @@ namespace ASC.Files.Core
|
||||
public UserManager UserManager { get; }
|
||||
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
|
||||
|
||||
[DataMember(Name = "serverVersion", EmitDefaultValue = false)] public string ServerVersion;
|
||||
}
|
||||
|
||||
[DataContract(Name = "user", Namespace = "")]
|
||||
[DebuggerDisplay("{Id} {Name}")]
|
||||
public class EditHistoryAuthor
|
||||
public string ServerVersion;
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Id} {Name}")]
|
||||
public class EditHistoryAuthor
|
||||
{
|
||||
public EditHistoryAuthor(
|
||||
AuthContext authContext,
|
||||
@ -170,88 +169,85 @@ namespace ASC.Files.Core
|
||||
UserManager = userManager;
|
||||
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
||||
}
|
||||
|
||||
[DataMember(Name = "id")] public Guid Id;
|
||||
|
||||
private string _name;
|
||||
|
||||
[DataMember(Name = "name")]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
UserInfo user;
|
||||
return
|
||||
Id.Equals(AuthContext.CurrentAccount.ID)
|
||||
? FilesCommonResource.Author_Me
|
||||
: Id.Equals(Guid.Empty)
|
||||
|| Id.Equals(ASC.Core.Configuration.Constants.Guest.ID)
|
||||
|| (user = UserManager.GetUsers(Id)).Equals(Constants.LostUser)
|
||||
? string.IsNullOrEmpty(_name)
|
||||
? FilesCommonResource.Guest
|
||||
: _name
|
||||
: user.DisplayUserName(false, DisplayUserSettingsHelper);
|
||||
}
|
||||
set { _name = value; }
|
||||
|
||||
public Guid Id { get; set; }
|
||||
|
||||
private string _name;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
UserInfo user;
|
||||
return
|
||||
Id.Equals(AuthContext.CurrentAccount.ID)
|
||||
? FilesCommonResource.Author_Me
|
||||
: Id.Equals(Guid.Empty)
|
||||
|| Id.Equals(ASC.Core.Configuration.Constants.Guest.ID)
|
||||
|| (user = UserManager.GetUsers(Id)).Equals(Constants.LostUser)
|
||||
? string.IsNullOrEmpty(_name)
|
||||
? FilesCommonResource.Guest
|
||||
: _name
|
||||
: user.DisplayUserName(false, DisplayUserSettingsHelper);
|
||||
}
|
||||
set { _name = value; }
|
||||
}
|
||||
|
||||
public AuthContext AuthContext { get; }
|
||||
public UserManager UserManager { get; }
|
||||
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "change", Namespace = "")]
|
||||
[DebuggerDisplay("{Author.Name}")]
|
||||
public class EditHistoryChanges
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Author.Name}")]
|
||||
public class EditHistoryChanges
|
||||
{
|
||||
public EditHistoryChanges(TenantUtil tenantUtil)
|
||||
{
|
||||
TenantUtil = tenantUtil;
|
||||
}
|
||||
|
||||
[DataMember(Name = "user")] public EditHistoryAuthor Author;
|
||||
|
||||
private DateTime _date;
|
||||
|
||||
[DataMember(Name = "created")]
|
||||
public string Date
|
||||
{
|
||||
get { return _date.Equals(default) ? null : _date.ToString("g"); }
|
||||
set
|
||||
{
|
||||
if (DateTime.TryParse(value, out _date))
|
||||
{
|
||||
_date = TenantUtil.DateTimeFromUtc(_date);
|
||||
}
|
||||
}
|
||||
|
||||
[JsonPropertyName("user")]
|
||||
public EditHistoryAuthor Author { get; set; }
|
||||
|
||||
private DateTime _date;
|
||||
|
||||
[JsonPropertyName("created")]
|
||||
public string Date
|
||||
{
|
||||
get { return _date.Equals(default) ? null : _date.ToString("g"); }
|
||||
set
|
||||
{
|
||||
if (DateTime.TryParse(value, out _date))
|
||||
{
|
||||
_date = TenantUtil.DateTimeFromUtc(_date);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TenantUtil TenantUtil { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "data")]
|
||||
[DebuggerDisplay("{Version}")]
|
||||
public class EditHistoryData
|
||||
{
|
||||
[DataMember(Name = "changesUrl", EmitDefaultValue = false)] public string ChangesUrl;
|
||||
|
||||
[DataMember(Name = "key")] public string Key;
|
||||
|
||||
[DataMember(Name = "previous", EmitDefaultValue = false)] public EditHistoryUrl Previous;
|
||||
|
||||
[DataMember(Name = "token", EmitDefaultValue = false)] public string Token;
|
||||
|
||||
[DataMember(Name = "url")] public string Url;
|
||||
|
||||
[DataMember(Name = "version")] public int Version;
|
||||
}
|
||||
|
||||
[DataContract(Name = "url")]
|
||||
[DebuggerDisplay("{Key} - {Url}")]
|
||||
public class EditHistoryUrl
|
||||
{
|
||||
[DataMember(Name = "key")] public string Key;
|
||||
|
||||
[DataMember(Name = "url")] public string Url;
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Version}")]
|
||||
public class EditHistoryData
|
||||
{
|
||||
public string ChangesUrl { get; set; }
|
||||
|
||||
public string Key { get; set; }
|
||||
|
||||
public EditHistoryUrl Previous { get; set; }
|
||||
|
||||
public string Token { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
|
||||
public int Version { get; set; }
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Key} - {Url}")]
|
||||
public class EditHistoryUrl
|
||||
{
|
||||
public string Key { get; set; }
|
||||
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
@ -23,21 +23,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Web.Files.Core.Entries
|
||||
{
|
||||
[DataContract(Name = "encrypted_data", Namespace = "")]
|
||||
public class EncryptedData
|
||||
{
|
||||
[DataMember(Name = "publicKey")]
|
||||
public string PublicKey;
|
||||
public string PublicKey { get; set; }
|
||||
|
||||
[DataMember(Name = "fileHash")]
|
||||
public string FileHash;
|
||||
public string FileHash { get; set; }
|
||||
|
||||
[DataMember(Name = "data")]
|
||||
public string Data;
|
||||
public string Data { get; set; }
|
||||
}
|
||||
}
|
@ -26,7 +26,6 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
@ -37,14 +36,11 @@ using ASC.Web.Studio.Core;
|
||||
|
||||
namespace ASC.Web.Files.Core.Entries
|
||||
{
|
||||
[DataContract(Name = "account", Namespace = "")]
|
||||
public class EncryptionAddress
|
||||
{
|
||||
[DataMember(Name = "address")]
|
||||
public string Address;
|
||||
public string Address { get; set; }
|
||||
|
||||
[DataMember(Name = "publicKey")]
|
||||
public string PublicKey;
|
||||
public string PublicKey { get; set; }
|
||||
}
|
||||
|
||||
public class EncryptionAddressHelper
|
||||
|
@ -26,8 +26,7 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Web.Core.Files;
|
||||
using ASC.Web.Files.Classes;
|
||||
using ASC.Web.Files.Utils;
|
||||
@ -36,24 +35,22 @@ using ASC.Web.Studio.Core;
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[Flags]
|
||||
[DataContract(Namespace = "")]
|
||||
public enum FileStatus
|
||||
{
|
||||
[EnumMember] None = 0x0,
|
||||
None = 0x0,
|
||||
|
||||
[EnumMember] IsEditing = 0x1,
|
||||
IsEditing = 0x1,
|
||||
|
||||
[EnumMember] IsNew = 0x2,
|
||||
IsNew = 0x2,
|
||||
|
||||
[EnumMember] IsConverting = 0x4,
|
||||
IsConverting = 0x4,
|
||||
|
||||
[EnumMember] IsOriginal = 0x8,
|
||||
IsOriginal = 0x8,
|
||||
|
||||
[EnumMember] IsEditingAlone = 0x10
|
||||
IsEditingAlone = 0x10
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract(Name = "file", Namespace = "")]
|
||||
[DebuggerDisplay("{Title} ({ID} v{Version})")]
|
||||
public class File<T> : FileEntry<T>
|
||||
{
|
||||
@ -75,13 +72,11 @@ namespace ASC.Files.Core
|
||||
|
||||
public T FolderID { get; set; }
|
||||
|
||||
[DataMember(Name = "version")]
|
||||
public int Version { get; set; }
|
||||
|
||||
[DataMember(Name = "version_group")]
|
||||
[JsonPropertyName("version_group")]
|
||||
public int VersionGroup { get; set; }
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "comment")]
|
||||
public string Comment { get; set; }
|
||||
|
||||
public string PureTitle
|
||||
@ -90,7 +85,6 @@ namespace ASC.Files.Core
|
||||
set { base.Title = value; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "title", IsRequired = true)]
|
||||
public override string Title
|
||||
{
|
||||
get
|
||||
@ -102,10 +96,10 @@ namespace ASC.Files.Core
|
||||
set { base.Title = value; }
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = true, Name = "content_length", IsRequired = true)]
|
||||
[JsonPropertyName("content_length")]
|
||||
public long ContentLength { get; set; }
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "content_length_string", IsRequired = true)]
|
||||
[JsonPropertyName("content_length_string")]
|
||||
public string ContentLengthString
|
||||
{
|
||||
get { return FileSizeComment.FilesSizeToString(ContentLength); }
|
||||
@ -137,7 +131,7 @@ namespace ASC.Files.Core
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "file_status")]
|
||||
[JsonPropertyName("file_status")]
|
||||
public FileStatus FileStatus
|
||||
{
|
||||
get
|
||||
@ -162,10 +156,9 @@ namespace ASC.Files.Core
|
||||
set { _status = value; }
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "locked")]
|
||||
public bool Locked { get; set; }
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "locked_by")]
|
||||
[JsonPropertyName("locked_by")]
|
||||
public string LockedBy { get; set; }
|
||||
|
||||
public override bool IsNew
|
||||
@ -180,7 +173,6 @@ namespace ASC.Files.Core
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(EmitDefaultValue = false, Name = "encrypted")]
|
||||
public bool Encrypted { get; set; }
|
||||
|
||||
public ForcesaveType Forcesave { get; set; }
|
||||
@ -225,7 +217,7 @@ namespace ASC.Files.Core
|
||||
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
[JsonPropertyName("folder_id")]
|
||||
public override T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
|
@ -25,14 +25,12 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Files.Core.Security;
|
||||
using ASC.Web.Files.Classes;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Name = "entry", Namespace = "")]
|
||||
[Serializable]
|
||||
public abstract class FileEntry : ICloneable
|
||||
{
|
||||
@ -41,56 +39,52 @@ namespace ASC.Files.Core
|
||||
Global = global;
|
||||
}
|
||||
|
||||
[DataMember(Name = "title", IsRequired = true)]
|
||||
public virtual string Title { get; set; }
|
||||
|
||||
[DataMember(Name = "create_by_id")]
|
||||
[JsonPropertyName("create_by_id")]
|
||||
public Guid CreateBy { get; set; }
|
||||
|
||||
[DataMember(Name = "create_by")]
|
||||
[JsonPropertyName("create_by")]
|
||||
public string CreateByString
|
||||
{
|
||||
get { return !CreateBy.Equals(Guid.Empty) ? Global.GetUserName(CreateBy) : _createByString; }
|
||||
set { _createByString = value; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "create_on")]
|
||||
[JsonPropertyName("create_on")]
|
||||
public string CreateOnString
|
||||
{
|
||||
get { return CreateOn.Equals(default) ? null : CreateOn.ToString("g"); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "modified_on")]
|
||||
[JsonPropertyName("modified_on")]
|
||||
public string ModifiedOnString
|
||||
{
|
||||
get { return ModifiedOn.Equals(default) ? null : ModifiedOn.ToString("g"); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "modified_by_id")]
|
||||
[JsonPropertyName("modified_by_id")]
|
||||
public Guid ModifiedBy { get; set; }
|
||||
|
||||
[DataMember(Name = "modified_by")]
|
||||
[JsonPropertyName("modified_by")]
|
||||
public string ModifiedByString
|
||||
{
|
||||
get { return !ModifiedBy.Equals(Guid.Empty) ? Global.GetUserName(ModifiedBy) : _modifiedByString; }
|
||||
set { _modifiedByString = value; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "error", EmitDefaultValue = false)]
|
||||
public string Error { get; set; }
|
||||
|
||||
[DataMember(Name = "access")]
|
||||
public FileShare Access { get; set; }
|
||||
|
||||
[DataMember(Name = "shared")]
|
||||
public bool Shared { get; set; }
|
||||
|
||||
[DataMember(Name = "provider_id", EmitDefaultValue = false)]
|
||||
[JsonPropertyName("provider_id")]
|
||||
public int ProviderId { get; set; }
|
||||
|
||||
[DataMember(Name = "provider_key", EmitDefaultValue = false)]
|
||||
[JsonPropertyName("provider_key")]
|
||||
public string ProviderKey { get; set; }
|
||||
public bool ProviderEntry
|
||||
{
|
||||
@ -127,7 +121,6 @@ namespace ASC.Files.Core
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "entry", Namespace = "")]
|
||||
[Serializable]
|
||||
public abstract class FileEntry<T> : FileEntry, ICloneable
|
||||
{
|
||||
@ -135,11 +128,9 @@ namespace ASC.Files.Core
|
||||
{
|
||||
}
|
||||
|
||||
[DataMember(Name = "id")]
|
||||
public T ID { get; set; }
|
||||
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
[JsonPropertyName("folder_id")]
|
||||
public abstract T FolderIdDisplay
|
||||
{
|
||||
get;
|
||||
|
@ -26,31 +26,22 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Web.Files.Classes;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Namespace = "")]
|
||||
public enum FolderType
|
||||
{
|
||||
[EnumMember] DEFAULT = 0,
|
||||
|
||||
[EnumMember] COMMON = 1,
|
||||
|
||||
[EnumMember] BUNCH = 2,
|
||||
|
||||
[EnumMember] TRASH = 3,
|
||||
|
||||
[EnumMember] USER = 5,
|
||||
|
||||
[EnumMember] SHARE = 6,
|
||||
|
||||
[EnumMember] Projects = 8
|
||||
DEFAULT = 0,
|
||||
COMMON = 1,
|
||||
BUNCH = 2,
|
||||
TRASH = 3,
|
||||
USER = 5,
|
||||
SHARE = 6,
|
||||
Projects = 8
|
||||
}
|
||||
|
||||
[DataContract(Name = "folder", Namespace = "")]
|
||||
[DebuggerDisplay("{Title} ({ID})")]
|
||||
public class Folder<T> : FileEntry<T>
|
||||
{
|
||||
@ -58,19 +49,14 @@ namespace ASC.Files.Core
|
||||
|
||||
public T ParentFolderID { get; set; }
|
||||
|
||||
[DataMember(Name = "total_files")]
|
||||
public int TotalFiles { get; set; }
|
||||
|
||||
[DataMember(Name = "total_sub_folder")]
|
||||
public int TotalSubFolders { get; set; }
|
||||
|
||||
[DataMember(Name = "shareable", EmitDefaultValue = false)]
|
||||
public bool Shareable { get; set; }
|
||||
|
||||
[DataMember(Name = "isnew")]
|
||||
public int NewForMe { get; set; }
|
||||
|
||||
[DataMember(Name = "folder_url", EmitDefaultValue = false)]
|
||||
public string FolderUrl { get; set; }
|
||||
|
||||
public override bool IsNew
|
||||
@ -81,7 +67,6 @@ namespace ASC.Files.Core
|
||||
|
||||
private T _folderIdDisplay;
|
||||
|
||||
[DataMember(Name = "folder_id")]
|
||||
public override T FolderIdDisplay
|
||||
{
|
||||
get
|
||||
|
@ -1,16 +1,10 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Namespace = "")]
|
||||
public enum ForcesaveType
|
||||
{
|
||||
[EnumMember] None = 0,
|
||||
|
||||
[EnumMember] Command = 1,
|
||||
|
||||
[EnumMember] User = 2,
|
||||
|
||||
[EnumMember] Timer = 3
|
||||
None = 0,
|
||||
Command = 1,
|
||||
User = 2,
|
||||
Timer = 3
|
||||
}
|
||||
}
|
@ -24,38 +24,29 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
using System.Diagnostics;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract(Name = "sorted_by_type", Namespace = "")]
|
||||
public enum SortedByType
|
||||
{
|
||||
[EnumMember] DateAndTime,
|
||||
|
||||
[EnumMember] AZ,
|
||||
|
||||
[EnumMember] Size,
|
||||
|
||||
[EnumMember] Author,
|
||||
|
||||
[EnumMember] Type,
|
||||
|
||||
[EnumMember] New,
|
||||
|
||||
[EnumMember] DateAndTimeCreation
|
||||
|
||||
DateAndTime,
|
||||
AZ,
|
||||
Size,
|
||||
Author,
|
||||
Type,
|
||||
New,
|
||||
DateAndTimeCreation
|
||||
}
|
||||
|
||||
[DataContract(Name = "orderBy", IsReference = true, Namespace = "")]
|
||||
[DebuggerDisplay("{SortedBy} {IsAsc}")]
|
||||
public class OrderBy
|
||||
{
|
||||
[DataMember(Name = "is_asc")]
|
||||
[JsonPropertyName("is_asc")]
|
||||
public bool IsAsc { get; set; }
|
||||
|
||||
[DataMember(Name = "property")]
|
||||
[JsonPropertyName("property")]
|
||||
public SortedByType SortedBy { get; set; }
|
||||
|
||||
public OrderBy(SortedByType sortedByType, bool isAsc)
|
||||
|
@ -299,7 +299,7 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
parent.ParentFolderID = prevVisible.ID;
|
||||
}
|
||||
|
||||
parent.Shareable = FileSharing.CanSetAccess(parent) || parent.FolderType == FolderType.SHARE;
|
||||
parent.Shareable =FileSharing.CanSetAccess(parent) || parent.FolderType == FolderType.SHARE;
|
||||
|
||||
entries = entries.Where(x => x.FileEntryType == FileEntryType.Folder || !FileConverter.IsConverting((File<T>)x));
|
||||
|
||||
|
@ -28,7 +28,6 @@ using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Files.Core
|
||||
{
|
||||
[DataContract]
|
||||
public enum FilterType
|
||||
{
|
||||
[EnumMember] None = 0,
|
||||
|
@ -23,36 +23,17 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ASC.Files.Core.Security
|
||||
{
|
||||
[DataContract(Name = "fileShare", Namespace = "")]
|
||||
public enum FileShare
|
||||
{
|
||||
[EnumMember(Value = "0")]
|
||||
None,
|
||||
|
||||
[EnumMember(Value = "1")]
|
||||
ReadWrite,
|
||||
|
||||
[EnumMember(Value = "2")]
|
||||
Read,
|
||||
|
||||
[EnumMember(Value = "3")]
|
||||
Restrict,
|
||||
|
||||
[EnumMember(Value = "4")]
|
||||
Varies,
|
||||
|
||||
[EnumMember(Value = "5")]
|
||||
Review,
|
||||
|
||||
[EnumMember(Value = "6")]
|
||||
Comment,
|
||||
|
||||
[EnumMember(Value = "7")]
|
||||
FillForms,
|
||||
}
|
||||
}
|
@ -1,508 +1,499 @@
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security;
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Security;
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Common;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Common;
|
||||
using ASC.Core.Common.Configuration;
|
||||
using ASC.Core.Users;
|
||||
using ASC.FederatedLogin;
|
||||
using ASC.FederatedLogin.Helpers;
|
||||
using ASC.FederatedLogin.LoginProviders;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Data;
|
||||
using ASC.Files.Core.Security;
|
||||
using ASC.Core.Users;
|
||||
using ASC.FederatedLogin;
|
||||
using ASC.FederatedLogin.Helpers;
|
||||
using ASC.FederatedLogin.LoginProviders;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Data;
|
||||
using ASC.Files.Core.Security;
|
||||
using ASC.Files.Resources;
|
||||
using ASC.MessagingSystem;
|
||||
using ASC.Web.Core.Files;
|
||||
using ASC.Web.Core.Users;
|
||||
using ASC.Web.Files.Classes;
|
||||
using ASC.Web.Files.HttpHandlers;
|
||||
using ASC.Web.Files.Services.WCFService;
|
||||
using ASC.Web.Files.ThirdPartyApp;
|
||||
using ASC.Web.Files.Utils;
|
||||
using ASC.Web.Studio.Core;
|
||||
|
||||
using DocuSign.eSign.Api;
|
||||
using DocuSign.eSign.Client;
|
||||
using DocuSign.eSign.Model;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ASC.MessagingSystem;
|
||||
using ASC.Web.Core.Files;
|
||||
using ASC.Web.Core.Users;
|
||||
using ASC.Web.Files.Classes;
|
||||
using ASC.Web.Files.HttpHandlers;
|
||||
using ASC.Web.Files.Services.WCFService;
|
||||
using ASC.Web.Files.ThirdPartyApp;
|
||||
using ASC.Web.Files.Utils;
|
||||
using ASC.Web.Studio.Core;
|
||||
|
||||
using DocuSign.eSign.Api;
|
||||
using DocuSign.eSign.Client;
|
||||
using DocuSign.eSign.Model;
|
||||
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Web.Files.Helpers
|
||||
{
|
||||
public class DocuSignToken
|
||||
{
|
||||
public ILog Log { get; set; }
|
||||
|
||||
public const string AppAttr = "docusign";
|
||||
|
||||
public TokenHelper TokenHelper { get; }
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ASC.Web.Files.Helpers
|
||||
{
|
||||
public class DocuSignToken
|
||||
{
|
||||
public ILog Log { get; set; }
|
||||
|
||||
public const string AppAttr = "docusign";
|
||||
|
||||
public TokenHelper TokenHelper { get; }
|
||||
public AuthContext AuthContext { get; }
|
||||
public ConsumerFactory ConsumerFactory { get; }
|
||||
|
||||
public DocuSignToken(
|
||||
TokenHelper tokenHelper,
|
||||
IOptionsMonitor<ILog> options,
|
||||
AuthContext authContext,
|
||||
ConsumerFactory consumerFactory)
|
||||
{
|
||||
TokenHelper = tokenHelper;
|
||||
public ConsumerFactory ConsumerFactory { get; }
|
||||
|
||||
public DocuSignToken(
|
||||
TokenHelper tokenHelper,
|
||||
IOptionsMonitor<ILog> options,
|
||||
AuthContext authContext,
|
||||
ConsumerFactory consumerFactory)
|
||||
{
|
||||
TokenHelper = tokenHelper;
|
||||
AuthContext = authContext;
|
||||
ConsumerFactory = consumerFactory;
|
||||
Log = options.CurrentValue;
|
||||
}
|
||||
|
||||
public OAuth20Token GetToken()
|
||||
{
|
||||
return TokenHelper.GetToken(AppAttr);
|
||||
}
|
||||
|
||||
public void DeleteToken(Guid? userId = null)
|
||||
{
|
||||
TokenHelper.DeleteToken(AppAttr, userId);
|
||||
}
|
||||
|
||||
public void SaveToken(OAuth20Token token)
|
||||
{
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
TokenHelper.SaveToken(new Token(token, AppAttr));
|
||||
}
|
||||
|
||||
internal string GetRefreshedToken(OAuth20Token token)
|
||||
{
|
||||
if (token.IsExpired)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Info("DocuSign refresh token for user " + AuthContext.CurrentAccount.ID);
|
||||
|
||||
var refreshed = ConsumerFactory.Get<DocuSignLoginProvider>().RefreshToken(token.RefreshToken);
|
||||
|
||||
if (refreshed != null)
|
||||
{
|
||||
token.AccessToken = refreshed.AccessToken;
|
||||
token.RefreshToken = refreshed.RefreshToken;
|
||||
token.ExpiresIn = refreshed.ExpiresIn;
|
||||
token.Timestamp = DateTime.UtcNow;
|
||||
|
||||
SaveToken(token);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("DocuSign refresh token for user " + AuthContext.CurrentAccount.ID, ex);
|
||||
}
|
||||
}
|
||||
return token.AccessToken;
|
||||
}
|
||||
}
|
||||
|
||||
public class DocuSignHelper
|
||||
{
|
||||
public ILog Log { get; set; }
|
||||
|
||||
public const string UserField = "userId";
|
||||
|
||||
public static readonly List<string> SupportedFormats = new List<string>
|
||||
{
|
||||
".as", ".asl", ".doc", ".docm", ".docx", ".dot", ".dotm", ".dotx", ".htm", ".html", ".msg", ".pdf", ".pdx", ".rtf", ".txt", ".wpd", ".wps", ".wpt", ".xps",
|
||||
".emz", ".svg", ".svgz", ".vdx", ".vss", ".vst",
|
||||
".bmp", ".cdr", ".dcx", ".gif", ".ico", ".jpg", ".jpeg", ".pct", ".pic", ".png", ".rgb", ".sam", ".tga", ".tif", ".tiff", ".wpg",
|
||||
".dps", ".dpt", ".pot", ".potx", ".pps", ".ppt", ".pptm", ".pptx",
|
||||
".csv", ".et", ".ett", ".xls", ".xlsm", ".xlsx", ".xlt"
|
||||
};
|
||||
|
||||
public static long MaxFileSize = 25L * 1024L * 1024L;
|
||||
|
||||
public static int MaxEmailLength = 10000;
|
||||
|
||||
public DocuSignToken DocuSignToken { get; }
|
||||
public FileSecurity FileSecurity { get; }
|
||||
public IDaoFactory DaoFactory { get; }
|
||||
public BaseCommonLinkUtility BaseCommonLinkUtility { get; }
|
||||
public UserManager UserManager { get; }
|
||||
public AuthContext AuthContext { get; }
|
||||
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
|
||||
public FileMarker FileMarker { get; }
|
||||
public GlobalFolderHelper GlobalFolderHelper { get; }
|
||||
public FilesMessageService FilesMessageService { get; }
|
||||
public FilesLinkUtility FilesLinkUtility { get; }
|
||||
ConsumerFactory = consumerFactory;
|
||||
Log = options.CurrentValue;
|
||||
}
|
||||
|
||||
public OAuth20Token GetToken()
|
||||
{
|
||||
return TokenHelper.GetToken(AppAttr);
|
||||
}
|
||||
|
||||
public void DeleteToken(Guid? userId = null)
|
||||
{
|
||||
TokenHelper.DeleteToken(AppAttr, userId);
|
||||
}
|
||||
|
||||
public void SaveToken(OAuth20Token token)
|
||||
{
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
TokenHelper.SaveToken(new Token(token, AppAttr));
|
||||
}
|
||||
|
||||
internal string GetRefreshedToken(OAuth20Token token)
|
||||
{
|
||||
if (token.IsExpired)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log.Info("DocuSign refresh token for user " + AuthContext.CurrentAccount.ID);
|
||||
|
||||
var refreshed = ConsumerFactory.Get<DocuSignLoginProvider>().RefreshToken(token.RefreshToken);
|
||||
|
||||
if (refreshed != null)
|
||||
{
|
||||
token.AccessToken = refreshed.AccessToken;
|
||||
token.RefreshToken = refreshed.RefreshToken;
|
||||
token.ExpiresIn = refreshed.ExpiresIn;
|
||||
token.Timestamp = DateTime.UtcNow;
|
||||
|
||||
SaveToken(token);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("DocuSign refresh token for user " + AuthContext.CurrentAccount.ID, ex);
|
||||
}
|
||||
}
|
||||
return token.AccessToken;
|
||||
}
|
||||
}
|
||||
|
||||
public class DocuSignHelper
|
||||
{
|
||||
public ILog Log { get; set; }
|
||||
|
||||
public const string UserField = "userId";
|
||||
|
||||
public static readonly List<string> SupportedFormats = new List<string>
|
||||
{
|
||||
".as", ".asl", ".doc", ".docm", ".docx", ".dot", ".dotm", ".dotx", ".htm", ".html", ".msg", ".pdf", ".pdx", ".rtf", ".txt", ".wpd", ".wps", ".wpt", ".xps",
|
||||
".emz", ".svg", ".svgz", ".vdx", ".vss", ".vst",
|
||||
".bmp", ".cdr", ".dcx", ".gif", ".ico", ".jpg", ".jpeg", ".pct", ".pic", ".png", ".rgb", ".sam", ".tga", ".tif", ".tiff", ".wpg",
|
||||
".dps", ".dpt", ".pot", ".potx", ".pps", ".ppt", ".pptm", ".pptx",
|
||||
".csv", ".et", ".ett", ".xls", ".xlsm", ".xlsx", ".xlt"
|
||||
};
|
||||
|
||||
public static long MaxFileSize = 25L * 1024L * 1024L;
|
||||
|
||||
public static int MaxEmailLength = 10000;
|
||||
|
||||
public DocuSignToken DocuSignToken { get; }
|
||||
public FileSecurity FileSecurity { get; }
|
||||
public IDaoFactory DaoFactory { get; }
|
||||
public BaseCommonLinkUtility BaseCommonLinkUtility { get; }
|
||||
public UserManager UserManager { get; }
|
||||
public AuthContext AuthContext { get; }
|
||||
public DisplayUserSettingsHelper DisplayUserSettingsHelper { get; }
|
||||
public FileMarker FileMarker { get; }
|
||||
public GlobalFolderHelper GlobalFolderHelper { get; }
|
||||
public FilesMessageService FilesMessageService { get; }
|
||||
public FilesLinkUtility FilesLinkUtility { get; }
|
||||
public IServiceProvider ServiceProvider { get; }
|
||||
public ConsumerFactory ConsumerFactory { get; }
|
||||
|
||||
public DocuSignHelper(
|
||||
DocuSignToken docuSignToken,
|
||||
FileSecurity fileSecurity,
|
||||
IDaoFactory daoFactory,
|
||||
IOptionsMonitor<ILog> options,
|
||||
BaseCommonLinkUtility baseCommonLinkUtility,
|
||||
UserManager userManager,
|
||||
AuthContext authContext,
|
||||
DisplayUserSettingsHelper displayUserSettingsHelper,
|
||||
FileMarker fileMarker,
|
||||
GlobalFolderHelper globalFolderHelper,
|
||||
FilesMessageService filesMessageService,
|
||||
FilesLinkUtility filesLinkUtility,
|
||||
public DocuSignHelper(
|
||||
DocuSignToken docuSignToken,
|
||||
FileSecurity fileSecurity,
|
||||
IDaoFactory daoFactory,
|
||||
IOptionsMonitor<ILog> options,
|
||||
BaseCommonLinkUtility baseCommonLinkUtility,
|
||||
UserManager userManager,
|
||||
AuthContext authContext,
|
||||
DisplayUserSettingsHelper displayUserSettingsHelper,
|
||||
FileMarker fileMarker,
|
||||
GlobalFolderHelper globalFolderHelper,
|
||||
FilesMessageService filesMessageService,
|
||||
FilesLinkUtility filesLinkUtility,
|
||||
IServiceProvider serviceProvider,
|
||||
ConsumerFactory consumerFactory)
|
||||
{
|
||||
DocuSignToken = docuSignToken;
|
||||
FileSecurity = fileSecurity;
|
||||
DaoFactory = daoFactory;
|
||||
BaseCommonLinkUtility = baseCommonLinkUtility;
|
||||
UserManager = userManager;
|
||||
AuthContext = authContext;
|
||||
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
||||
FileMarker = fileMarker;
|
||||
GlobalFolderHelper = globalFolderHelper;
|
||||
FilesMessageService = filesMessageService;
|
||||
FilesLinkUtility = filesLinkUtility;
|
||||
ConsumerFactory consumerFactory)
|
||||
{
|
||||
DocuSignToken = docuSignToken;
|
||||
FileSecurity = fileSecurity;
|
||||
DaoFactory = daoFactory;
|
||||
BaseCommonLinkUtility = baseCommonLinkUtility;
|
||||
UserManager = userManager;
|
||||
AuthContext = authContext;
|
||||
DisplayUserSettingsHelper = displayUserSettingsHelper;
|
||||
FileMarker = fileMarker;
|
||||
GlobalFolderHelper = globalFolderHelper;
|
||||
FilesMessageService = filesMessageService;
|
||||
FilesLinkUtility = filesLinkUtility;
|
||||
ServiceProvider = serviceProvider;
|
||||
ConsumerFactory = consumerFactory;
|
||||
Log = options.CurrentValue;
|
||||
}
|
||||
|
||||
public bool ValidateToken(OAuth20Token token)
|
||||
{
|
||||
GetDocuSignAccount(token);
|
||||
return true;
|
||||
}
|
||||
|
||||
public string SendDocuSign<T>(T fileId, DocuSignData docuSignData, IDictionary<string, StringValues> requestHeaders)
|
||||
{
|
||||
if (docuSignData == null) throw new ArgumentNullException("docuSignData");
|
||||
var token = DocuSignToken.GetToken();
|
||||
var account = GetDocuSignAccount(token);
|
||||
|
||||
var configuration = GetConfiguration(account, token);
|
||||
var document = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out var sourceFile);
|
||||
|
||||
var url = CreateEnvelope(account.AccountId, document, docuSignData, configuration);
|
||||
|
||||
FilesMessageService.Send(sourceFile, requestHeaders, MessageAction.DocumentSendToSign, "DocuSign", sourceFile.Title);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private DocuSignAccount GetDocuSignAccount(OAuth20Token token)
|
||||
{
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
var userInfoString = RequestHelper.PerformRequest(ConsumerFactory.Get<DocuSignLoginProvider>().DocuSignHost + "/oauth/userinfo",
|
||||
headers: new Dictionary<string, string> { { "Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token) } });
|
||||
|
||||
Log.Debug("DocuSing userInfo: " + userInfoString);
|
||||
|
||||
var userInfo = (DocuSignUserInfo)JsonConvert.DeserializeObject(userInfoString, typeof(DocuSignUserInfo));
|
||||
|
||||
if (userInfo.Accounts == null || userInfo.Accounts.Count == 0) throw new Exception("Account is null");
|
||||
|
||||
var account = userInfo.Accounts[0];
|
||||
return account;
|
||||
}
|
||||
|
||||
private DocuSign.eSign.Client.Configuration GetConfiguration(DocuSignAccount account, OAuth20Token token)
|
||||
{
|
||||
if (account == null) throw new ArgumentNullException("account");
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
var apiClient = new ApiClient(account.BaseUri + "/restapi");
|
||||
|
||||
var configuration = new DocuSign.eSign.Client.Configuration { ApiClient = apiClient };
|
||||
configuration.AddDefaultHeader("Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token));
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Document CreateDocument<T>(T fileId, string documentName, string folderId, out File<T> file)
|
||||
{
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
file = fileDao.GetFile(fileId);
|
||||
if (file == null) throw new Exception(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (!FileSecurity.CanRead(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
if (!SupportedFormats.Contains(FileUtility.GetFileExtension(file.Title))) throw new ArgumentException(FilesCommonResource.ErrorMassage_NotSupportedFormat);
|
||||
if (file.ContentLength > MaxFileSize) throw new Exception(FileSizeComment.GetFileSizeExceptionString(MaxFileSize));
|
||||
|
||||
byte[] fileBytes;
|
||||
using (var stream = fileDao.GetFileStream(file))
|
||||
{
|
||||
var buffer = new byte[16 * 1024];
|
||||
using var ms = new MemoryStream();
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
}
|
||||
fileBytes = ms.ToArray();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(documentName))
|
||||
{
|
||||
documentName = file.Title;
|
||||
}
|
||||
|
||||
var document = new Document
|
||||
{
|
||||
DocumentBase64 = Convert.ToBase64String(fileBytes),
|
||||
DocumentFields = new List<NameValue>
|
||||
{
|
||||
new NameValue {Name = FilesLinkUtility.FolderId, Value = folderId},
|
||||
new NameValue {Name = FilesLinkUtility.FileTitle, Value = file.Title},
|
||||
},
|
||||
DocumentId = "1", //file.ID.ToString(),
|
||||
FileExtension = FileUtility.GetFileExtension(file.Title),
|
||||
Name = documentName,
|
||||
};
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
private string CreateEnvelope(string accountId, Document document, DocuSignData docuSignData, DocuSign.eSign.Client.Configuration configuration)
|
||||
{
|
||||
var eventNotification = new EventNotification
|
||||
{
|
||||
EnvelopeEvents = new List<EnvelopeEvent>
|
||||
{
|
||||
//new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Sent.ToString()},
|
||||
//new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Delivered.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Completed.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Declined.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Voided.ToString()},
|
||||
},
|
||||
IncludeDocumentFields = "true",
|
||||
//RecipientEvents = new List<RecipientEvent>
|
||||
// {
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Sent"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Delivered"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Completed"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Declined"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "AuthenticationFailed"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "AutoResponded"},
|
||||
// },
|
||||
Url = BaseCommonLinkUtility.GetFullAbsolutePath(DocuSignHandlerService.Path(FilesLinkUtility) + "?" + FilesLinkUtility.Action + "=webhook"),
|
||||
};
|
||||
|
||||
Log.Debug("DocuSign hook url: " + eventNotification.Url);
|
||||
|
||||
var signers = new List<Signer>();
|
||||
docuSignData.Users.ForEach(uid =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = UserManager.GetUsers(uid);
|
||||
signers.Add(new Signer
|
||||
{
|
||||
Email = user.Email,
|
||||
Name = user.DisplayUserName(false, DisplayUserSettingsHelper),
|
||||
RecipientId = user.ID.ToString(),
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Signer is undefined", ex);
|
||||
}
|
||||
});
|
||||
|
||||
var envelopeDefinition = new EnvelopeDefinition
|
||||
{
|
||||
CustomFields = new CustomFields
|
||||
{
|
||||
TextCustomFields = new List<TextCustomField>
|
||||
{
|
||||
new TextCustomField {Name = UserField, Value = AuthContext.CurrentAccount.ID.ToString()},
|
||||
}
|
||||
},
|
||||
Documents = new List<Document> { document },
|
||||
EmailBlurb = docuSignData.Message,
|
||||
EmailSubject = docuSignData.Name,
|
||||
EventNotification = eventNotification,
|
||||
Recipients = new Recipients
|
||||
{
|
||||
Signers = signers,
|
||||
},
|
||||
Status = "created",
|
||||
};
|
||||
|
||||
var envelopesApi = new EnvelopesApi(configuration);
|
||||
var envelopeSummary = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
|
||||
|
||||
Log.Debug("DocuSign createdEnvelope: " + envelopeSummary.EnvelopeId);
|
||||
|
||||
var envelopeId = envelopeSummary.EnvelopeId;
|
||||
var url = envelopesApi.CreateSenderView(accountId, envelopeId, new ReturnUrlRequest
|
||||
{
|
||||
ReturnUrl = BaseCommonLinkUtility.GetFullAbsolutePath(DocuSignHandlerService.Path(FilesLinkUtility) + "?" + FilesLinkUtility.Action + "=redirect")
|
||||
});
|
||||
Log.Debug("DocuSign senderView: " + url.Url);
|
||||
|
||||
return url.Url;
|
||||
}
|
||||
|
||||
public File<T> SaveDocument<T>(string envelopeId, string documentId, string documentName, T folderId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(envelopeId)) throw new ArgumentNullException("envelopeId");
|
||||
if (string.IsNullOrEmpty(documentId)) throw new ArgumentNullException("documentId");
|
||||
|
||||
var token = DocuSignToken.GetToken();
|
||||
var account = GetDocuSignAccount(token);
|
||||
var configuration = GetConfiguration(account, token);
|
||||
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
if (string.IsNullOrEmpty(documentName))
|
||||
{
|
||||
documentName = "new.pdf";
|
||||
}
|
||||
|
||||
Folder<T> folder;
|
||||
if (folderId == null
|
||||
|| (folder = folderDao.GetFolder(folderId)) == null
|
||||
|| folder.RootFolderType == FolderType.TRASH
|
||||
|| !FileSecurity.CanCreate(folder))
|
||||
{
|
||||
if (GlobalFolderHelper.FolderMy != 0)
|
||||
{
|
||||
folderId = GlobalFolderHelper.GetFolderMy<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
}
|
||||
}
|
||||
|
||||
var file = ServiceProvider.GetService<File<T>>();
|
||||
file.FolderID = folderId;
|
||||
file.Comment = FilesCommonResource.CommentCreateByDocuSign;
|
||||
file.Title = FileUtility.ReplaceFileExtension(documentName, ".pdf");
|
||||
|
||||
var envelopesApi = new EnvelopesApi(configuration);
|
||||
Log.Info("DocuSign webhook get stream: " + documentId);
|
||||
using (var stream = envelopesApi.GetDocument(account.AccountId, envelopeId, documentId))
|
||||
{
|
||||
file.ContentLength = stream.Length;
|
||||
file = fileDao.SaveFile(file, stream);
|
||||
}
|
||||
|
||||
FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title);
|
||||
|
||||
FileMarker.MarkAsNew(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
[DataContract]
|
||||
[DebuggerDisplay("{AccountId} {BaseUri}")]
|
||||
private class DocuSignAccount
|
||||
{
|
||||
[DataMember(Name = "account_id", EmitDefaultValue = false)]
|
||||
public string AccountId { get; set; }
|
||||
|
||||
[DataMember(Name = "base_uri", EmitDefaultValue = false)]
|
||||
public string BaseUri { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
private class DocuSignUserInfo
|
||||
{
|
||||
[DataMember(Name = "accounts", EmitDefaultValue = false)]
|
||||
public List<DocuSignAccount> Accounts { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "docusign_data", Namespace = "")]
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class DocuSignData
|
||||
{
|
||||
[DataMember(Name = "folderId")]
|
||||
public string FolderId { get; set; }
|
||||
|
||||
[DataMember(Name = "message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
[DataMember(Name = "name", IsRequired = true, EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember(Name = "users")]
|
||||
public ItemList<Guid> Users { get; set; }
|
||||
}
|
||||
|
||||
public enum DocuSignStatus
|
||||
{
|
||||
Draft,
|
||||
Sent,
|
||||
Delivered,
|
||||
Completed,
|
||||
Declined,
|
||||
Voided,
|
||||
}
|
||||
|
||||
public static class DocuSignHelperExtension
|
||||
{
|
||||
public static DIHelper AddDocuSignTokenService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<DocuSignToken>();
|
||||
return services
|
||||
.AddAuthContextService()
|
||||
.AddDocuSignLoginProviderService()
|
||||
.AddTokenHelperService();
|
||||
}
|
||||
|
||||
public static DIHelper AddDocuSignHelperService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<DocuSignHelper>();
|
||||
|
||||
return services
|
||||
.AddDocuSignLoginProviderService()
|
||||
.AddFileSecurityService()
|
||||
.AddDaoFactoryService()
|
||||
.AddBaseCommonLinkUtilityService()
|
||||
.AddUserManagerService()
|
||||
.AddAuthContextService()
|
||||
.AddDisplayUserSettingsService()
|
||||
.AddFileMarkerService()
|
||||
.AddGlobalFolderHelperService()
|
||||
.AddFilesMessageService()
|
||||
.AddDocuSignTokenService()
|
||||
.AddFilesLinkUtilityService()
|
||||
;
|
||||
}
|
||||
}
|
||||
Log = options.CurrentValue;
|
||||
}
|
||||
|
||||
public bool ValidateToken(OAuth20Token token)
|
||||
{
|
||||
GetDocuSignAccount(token);
|
||||
return true;
|
||||
}
|
||||
|
||||
public string SendDocuSign<T>(T fileId, DocuSignData docuSignData, IDictionary<string, StringValues> requestHeaders)
|
||||
{
|
||||
if (docuSignData == null) throw new ArgumentNullException("docuSignData");
|
||||
var token = DocuSignToken.GetToken();
|
||||
var account = GetDocuSignAccount(token);
|
||||
|
||||
var configuration = GetConfiguration(account, token);
|
||||
var document = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out var sourceFile);
|
||||
|
||||
var url = CreateEnvelope(account.AccountId, document, docuSignData, configuration);
|
||||
|
||||
FilesMessageService.Send(sourceFile, requestHeaders, MessageAction.DocumentSendToSign, "DocuSign", sourceFile.Title);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private DocuSignAccount GetDocuSignAccount(OAuth20Token token)
|
||||
{
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
var userInfoString = RequestHelper.PerformRequest(ConsumerFactory.Get<DocuSignLoginProvider>().DocuSignHost + "/oauth/userinfo",
|
||||
headers: new Dictionary<string, string> { { "Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token) } });
|
||||
|
||||
Log.Debug("DocuSing userInfo: " + userInfoString);
|
||||
|
||||
var userInfo = (DocuSignUserInfo)JsonConvert.DeserializeObject(userInfoString, typeof(DocuSignUserInfo));
|
||||
|
||||
if (userInfo.Accounts == null || userInfo.Accounts.Count == 0) throw new Exception("Account is null");
|
||||
|
||||
var account = userInfo.Accounts[0];
|
||||
return account;
|
||||
}
|
||||
|
||||
private DocuSign.eSign.Client.Configuration GetConfiguration(DocuSignAccount account, OAuth20Token token)
|
||||
{
|
||||
if (account == null) throw new ArgumentNullException("account");
|
||||
if (token == null) throw new ArgumentNullException("token");
|
||||
|
||||
var apiClient = new ApiClient(account.BaseUri + "/restapi");
|
||||
|
||||
var configuration = new DocuSign.eSign.Client.Configuration { ApiClient = apiClient };
|
||||
configuration.AddDefaultHeader("Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token));
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Document CreateDocument<T>(T fileId, string documentName, string folderId, out File<T> file)
|
||||
{
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
file = fileDao.GetFile(fileId);
|
||||
if (file == null) throw new Exception(FilesCommonResource.ErrorMassage_FileNotFound);
|
||||
if (!FileSecurity.CanRead(file)) throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_ReadFile);
|
||||
if (!SupportedFormats.Contains(FileUtility.GetFileExtension(file.Title))) throw new ArgumentException(FilesCommonResource.ErrorMassage_NotSupportedFormat);
|
||||
if (file.ContentLength > MaxFileSize) throw new Exception(FileSizeComment.GetFileSizeExceptionString(MaxFileSize));
|
||||
|
||||
byte[] fileBytes;
|
||||
using (var stream = fileDao.GetFileStream(file))
|
||||
{
|
||||
var buffer = new byte[16 * 1024];
|
||||
using var ms = new MemoryStream();
|
||||
int read;
|
||||
while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
ms.Write(buffer, 0, read);
|
||||
}
|
||||
fileBytes = ms.ToArray();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(documentName))
|
||||
{
|
||||
documentName = file.Title;
|
||||
}
|
||||
|
||||
var document = new Document
|
||||
{
|
||||
DocumentBase64 = Convert.ToBase64String(fileBytes),
|
||||
DocumentFields = new List<NameValue>
|
||||
{
|
||||
new NameValue {Name = FilesLinkUtility.FolderId, Value = folderId},
|
||||
new NameValue {Name = FilesLinkUtility.FileTitle, Value = file.Title},
|
||||
},
|
||||
DocumentId = "1", //file.ID.ToString(),
|
||||
FileExtension = FileUtility.GetFileExtension(file.Title),
|
||||
Name = documentName,
|
||||
};
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
private string CreateEnvelope(string accountId, Document document, DocuSignData docuSignData, DocuSign.eSign.Client.Configuration configuration)
|
||||
{
|
||||
var eventNotification = new EventNotification
|
||||
{
|
||||
EnvelopeEvents = new List<EnvelopeEvent>
|
||||
{
|
||||
//new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Sent.ToString()},
|
||||
//new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Delivered.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Completed.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Declined.ToString()},
|
||||
new EnvelopeEvent {EnvelopeEventStatusCode = DocuSignStatus.Voided.ToString()},
|
||||
},
|
||||
IncludeDocumentFields = "true",
|
||||
//RecipientEvents = new List<RecipientEvent>
|
||||
// {
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Sent"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Delivered"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Completed"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "Declined"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "AuthenticationFailed"},
|
||||
// new RecipientEvent {RecipientEventStatusCode = "AutoResponded"},
|
||||
// },
|
||||
Url = BaseCommonLinkUtility.GetFullAbsolutePath(DocuSignHandlerService.Path(FilesLinkUtility) + "?" + FilesLinkUtility.Action + "=webhook"),
|
||||
};
|
||||
|
||||
Log.Debug("DocuSign hook url: " + eventNotification.Url);
|
||||
|
||||
var signers = new List<Signer>();
|
||||
docuSignData.Users.ForEach(uid =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = UserManager.GetUsers(uid);
|
||||
signers.Add(new Signer
|
||||
{
|
||||
Email = user.Email,
|
||||
Name = user.DisplayUserName(false, DisplayUserSettingsHelper),
|
||||
RecipientId = user.ID.ToString(),
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Signer is undefined", ex);
|
||||
}
|
||||
});
|
||||
|
||||
var envelopeDefinition = new EnvelopeDefinition
|
||||
{
|
||||
CustomFields = new CustomFields
|
||||
{
|
||||
TextCustomFields = new List<TextCustomField>
|
||||
{
|
||||
new TextCustomField {Name = UserField, Value = AuthContext.CurrentAccount.ID.ToString()},
|
||||
}
|
||||
},
|
||||
Documents = new List<Document> { document },
|
||||
EmailBlurb = docuSignData.Message,
|
||||
EmailSubject = docuSignData.Name,
|
||||
EventNotification = eventNotification,
|
||||
Recipients = new Recipients
|
||||
{
|
||||
Signers = signers,
|
||||
},
|
||||
Status = "created",
|
||||
};
|
||||
|
||||
var envelopesApi = new EnvelopesApi(configuration);
|
||||
var envelopeSummary = envelopesApi.CreateEnvelope(accountId, envelopeDefinition);
|
||||
|
||||
Log.Debug("DocuSign createdEnvelope: " + envelopeSummary.EnvelopeId);
|
||||
|
||||
var envelopeId = envelopeSummary.EnvelopeId;
|
||||
var url = envelopesApi.CreateSenderView(accountId, envelopeId, new ReturnUrlRequest
|
||||
{
|
||||
ReturnUrl = BaseCommonLinkUtility.GetFullAbsolutePath(DocuSignHandlerService.Path(FilesLinkUtility) + "?" + FilesLinkUtility.Action + "=redirect")
|
||||
});
|
||||
Log.Debug("DocuSign senderView: " + url.Url);
|
||||
|
||||
return url.Url;
|
||||
}
|
||||
|
||||
public File<T> SaveDocument<T>(string envelopeId, string documentId, string documentName, T folderId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(envelopeId)) throw new ArgumentNullException("envelopeId");
|
||||
if (string.IsNullOrEmpty(documentId)) throw new ArgumentNullException("documentId");
|
||||
|
||||
var token = DocuSignToken.GetToken();
|
||||
var account = GetDocuSignAccount(token);
|
||||
var configuration = GetConfiguration(account, token);
|
||||
|
||||
var fileDao = DaoFactory.GetFileDao<T>();
|
||||
var folderDao = DaoFactory.GetFolderDao<T>();
|
||||
if (string.IsNullOrEmpty(documentName))
|
||||
{
|
||||
documentName = "new.pdf";
|
||||
}
|
||||
|
||||
Folder<T> folder;
|
||||
if (folderId == null
|
||||
|| (folder = folderDao.GetFolder(folderId)) == null
|
||||
|| folder.RootFolderType == FolderType.TRASH
|
||||
|| !FileSecurity.CanCreate(folder))
|
||||
{
|
||||
if (GlobalFolderHelper.FolderMy != 0)
|
||||
{
|
||||
folderId = GlobalFolderHelper.GetFolderMy<T>();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
|
||||
}
|
||||
}
|
||||
|
||||
var file = ServiceProvider.GetService<File<T>>();
|
||||
file.FolderID = folderId;
|
||||
file.Comment = FilesCommonResource.CommentCreateByDocuSign;
|
||||
file.Title = FileUtility.ReplaceFileExtension(documentName, ".pdf");
|
||||
|
||||
var envelopesApi = new EnvelopesApi(configuration);
|
||||
Log.Info("DocuSign webhook get stream: " + documentId);
|
||||
using (var stream = envelopesApi.GetDocument(account.AccountId, envelopeId, documentId))
|
||||
{
|
||||
file.ContentLength = stream.Length;
|
||||
file = fileDao.SaveFile(file, stream);
|
||||
}
|
||||
|
||||
FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title);
|
||||
|
||||
FileMarker.MarkAsNew(file);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
|
||||
[DebuggerDisplay("{AccountId} {BaseUri}")]
|
||||
private class DocuSignAccount
|
||||
{
|
||||
[JsonPropertyName("account_id")]
|
||||
public string AccountId { get; set; }
|
||||
|
||||
[JsonPropertyName("base_uri")]
|
||||
public string BaseUri { get; set; }
|
||||
}
|
||||
|
||||
private class DocuSignUserInfo
|
||||
{
|
||||
public List<DocuSignAccount> Accounts { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class DocuSignData
|
||||
{
|
||||
public string FolderId { get; set; }
|
||||
|
||||
public string Message { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public ItemList<Guid> Users { get; set; }
|
||||
}
|
||||
|
||||
public enum DocuSignStatus
|
||||
{
|
||||
Draft,
|
||||
Sent,
|
||||
Delivered,
|
||||
Completed,
|
||||
Declined,
|
||||
Voided,
|
||||
}
|
||||
|
||||
public static class DocuSignHelperExtension
|
||||
{
|
||||
public static DIHelper AddDocuSignTokenService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<DocuSignToken>();
|
||||
return services
|
||||
.AddAuthContextService()
|
||||
.AddDocuSignLoginProviderService()
|
||||
.AddTokenHelperService();
|
||||
}
|
||||
|
||||
public static DIHelper AddDocuSignHelperService(this DIHelper services)
|
||||
{
|
||||
services.TryAddScoped<DocuSignHelper>();
|
||||
|
||||
return services
|
||||
.AddDocuSignLoginProviderService()
|
||||
.AddFileSecurityService()
|
||||
.AddDaoFactoryService()
|
||||
.AddBaseCommonLinkUtilityService()
|
||||
.AddUserManagerService()
|
||||
.AddAuthContextService()
|
||||
.AddDisplayUserSettingsService()
|
||||
.AddFileMarkerService()
|
||||
.AddGlobalFolderHelperService()
|
||||
.AddFilesMessageService()
|
||||
.AddDocuSignTokenService()
|
||||
.AddFilesLinkUtilityService()
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
@ -24,9 +24,8 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Api.Core;
|
||||
using ASC.Api.Utils;
|
||||
using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
@ -36,39 +35,32 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Namespace = "")]
|
||||
public abstract class FileEntryWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = true)]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public FileShare Access { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public bool Shared { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 50)]
|
||||
public ApiDateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 51, EmitDefaultValue = false)]
|
||||
public EmployeeWraper CreatedBy { get; set; }
|
||||
|
||||
private ApiDateTime _updated;
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 52, EmitDefaultValue = false)]
|
||||
public ApiDateTime Updated
|
||||
{
|
||||
get
|
||||
@ -80,28 +72,23 @@ namespace ASC.Api.Documents
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 41, EmitDefaultValue = false)]
|
||||
public FolderType RootFolderType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 41, EmitDefaultValue = false)]
|
||||
public EmployeeWraper UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 55, EmitDefaultValue = false)]
|
||||
public bool ProviderItem { get; set; }
|
||||
public bool? ProviderItem { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 56, EmitDefaultValue = false)]
|
||||
public string ProviderKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Order = 57, EmitDefaultValue = false)]
|
||||
public int ProviderId { get; set; }
|
||||
public int? ProviderId { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -118,9 +105,9 @@ namespace ASC.Api.Documents
|
||||
Updated = apiDateTimeHelper.Get(entry.ModifiedOn);
|
||||
UpdatedBy = employeeWraperHelper.Get(entry.ModifiedBy);
|
||||
RootFolderType = entry.RootFolderType;
|
||||
ProviderItem = entry.ProviderEntry;
|
||||
ProviderItem = entry.ProviderEntry.NullIfDefault();
|
||||
ProviderKey = entry.ProviderKey;
|
||||
ProviderId = entry.ProviderId;
|
||||
ProviderId = entry.ProviderId.NullIfDefault();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -134,12 +121,10 @@ namespace ASC.Api.Documents
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Namespace = "")]
|
||||
public abstract class FileEntryWrapper<T> : FileEntryWrapper
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember]
|
||||
public T Id { get; set; }
|
||||
|
||||
|
||||
@ -189,9 +174,9 @@ namespace ASC.Api.Documents
|
||||
Updated = ApiDateTimeHelper.Get(entry.ModifiedOn),
|
||||
UpdatedBy = EmployeeWraperHelper.Get(entry.ModifiedBy),
|
||||
RootFolderType = entry.RootFolderType,
|
||||
ProviderItem = entry.ProviderEntry,
|
||||
ProviderItem = entry.ProviderEntry.NullIfDefault(),
|
||||
ProviderKey = entry.ProviderKey,
|
||||
ProviderId = entry.ProviderId
|
||||
ProviderId = entry.ProviderId.NullIfDefault()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Files.Core;
|
||||
@ -39,52 +39,43 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Name = "operation_result", Namespace = "")]
|
||||
public class FileOperationWraper
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "id", IsRequired = false)]
|
||||
public string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "operation", IsRequired = false)]
|
||||
[JsonPropertyName("Operation")]
|
||||
public FileOperationType OperationType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "progress", IsRequired = false)]
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "error", IsRequired = false)]
|
||||
public string Error { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "processed", IsRequired = false)]
|
||||
public string Processed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "finished", IsRequired = false)]
|
||||
public bool Finished { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "url", IsRequired = false)]
|
||||
public string Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "files", IsRequired = true, EmitDefaultValue = true)]
|
||||
public List<FileEntryWrapper> Files { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "folders", IsRequired = true, EmitDefaultValue = true)]
|
||||
public List<FileEntryWrapper> Folders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
@ -36,17 +35,14 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Name = "share", Namespace = "")]
|
||||
public class FileShareParams
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "shareTo", Order = 0)]
|
||||
public Guid ShareTo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(Name = "access", Order = 1)]
|
||||
public FileShare Access { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
@ -26,9 +26,9 @@
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Api.Core;
|
||||
using ASC.Api.Utils;
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
using ASC.Files.Core;
|
||||
@ -45,70 +45,57 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Name = "file", Namespace = "")]
|
||||
public class FileWrapper<T> : FileEntryWrapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public T FolderId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public int Version { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public int VersionGroup { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = true)]
|
||||
public string ContentLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = true)]
|
||||
public long PureContentLength { get; set; }
|
||||
public long? PureContentLength { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public FileStatus FileStatus { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public string ViewUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public string WebUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public FileType FileType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public string FileExst { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public string Comment { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false)]
|
||||
public bool Encrypted { get; set; }
|
||||
public bool? Encrypted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
@ -198,9 +185,9 @@ namespace ASC.Api.Documents
|
||||
result.VersionGroup = file.VersionGroup;
|
||||
result.ContentLength = file.ContentLengthString;
|
||||
result.FileStatus = file.FileStatus;
|
||||
result.PureContentLength = file.ContentLength;
|
||||
result.PureContentLength = file.ContentLength.NullIfDefault();
|
||||
result.Comment = file.Comment;
|
||||
result.Encrypted = file.Encrypted;
|
||||
result.Encrypted = file.Encrypted.NullIfDefault();
|
||||
try
|
||||
{
|
||||
result.ViewUrl = CommonLinkUtility.GetFullAbsolutePath(file.DownloadUrl);
|
||||
|
@ -27,7 +27,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -39,42 +38,34 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Name = "content", Namespace = "")]
|
||||
public class FolderContentWrapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = false)]
|
||||
public List<FileWrapper<T>> Files { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = false)]
|
||||
public List<FileEntryWrapper> Folders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = true)]
|
||||
public FolderWrapper<T> Current { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = true)]
|
||||
public object PathParts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = true)]
|
||||
public int StartIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = true)]
|
||||
public int Count { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = false, EmitDefaultValue = true)]
|
||||
public int Total { get; set; }
|
||||
|
||||
public int New { get; set; }
|
||||
|
@ -25,9 +25,9 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Api.Core;
|
||||
using ASC.Api.Utils;
|
||||
using ASC.Common;
|
||||
using ASC.Core;
|
||||
using ASC.Files.Core;
|
||||
@ -40,28 +40,23 @@ namespace ASC.Api.Documents
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataContract(Name = "folder", Namespace = "")]
|
||||
public class FolderWrapper<T> : FileEntryWrapper<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(IsRequired = true, EmitDefaultValue = true)]
|
||||
public T ParentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public int FilesCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = true, IsRequired = false)]
|
||||
public int FoldersCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[DataMember(EmitDefaultValue = false, IsRequired = false)]
|
||||
public bool IsShareable { get; set; }
|
||||
public bool? IsShareable { get; set; }
|
||||
|
||||
public int New { get; set; }
|
||||
|
||||
@ -91,7 +86,7 @@ namespace ASC.Api.Documents
|
||||
FilesCount = new Random().Next(),
|
||||
FoldersCount = new Random().Next(),
|
||||
ParentId = new Random().Next(),
|
||||
IsShareable = false
|
||||
IsShareable = null
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -135,7 +130,7 @@ namespace ASC.Api.Documents
|
||||
|
||||
result.FilesCount = folder.TotalFiles;
|
||||
result.FoldersCount = folder.TotalSubFolders;
|
||||
result.IsShareable = folder.Shareable;
|
||||
result.IsShareable = folder.Shareable.NullIfDefault();
|
||||
result.New = folder.NewForMe;
|
||||
|
||||
return result;
|
||||
|
@ -29,9 +29,10 @@ using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Web;
|
||||
|
||||
using ASC.Common;
|
||||
@ -68,7 +69,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
External,
|
||||
}
|
||||
|
||||
[DataContract(Name = "editorConfig", Namespace = "")]
|
||||
public class Configuration<T>
|
||||
{
|
||||
public static readonly Dictionary<FileType, string> DocType = new Dictionary<FileType, string>
|
||||
@ -99,10 +99,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
#region Property
|
||||
|
||||
[DataMember(Name = "document")]
|
||||
public DocumentConfig<T> Document { get; set; }
|
||||
|
||||
[DataMember(Name = "documentType")]
|
||||
public string DocumentType
|
||||
{
|
||||
set { }
|
||||
@ -113,13 +111,10 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "editorConfig")]
|
||||
public EditorConfiguration<T> EditorConfig { get; set; }
|
||||
|
||||
[DataMember(Name = "token", EmitDefaultValue = false)]
|
||||
public string Token { get; set; }
|
||||
|
||||
[DataMember(Name = "type")]
|
||||
public string Type
|
||||
{
|
||||
set { EditorType = (EditorType)Enum.Parse(typeof(EditorType), value, true); }
|
||||
@ -137,23 +132,18 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "error", EmitDefaultValue = false)]
|
||||
[JsonPropertyName("Error")]
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
public static string Serialize(Configuration<T> configuration)
|
||||
{
|
||||
using var ms = new MemoryStream();
|
||||
var serializer = new DataContractJsonSerializer(typeof(Configuration<T>));
|
||||
serializer.WriteObject(ms, configuration);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
return JsonSerializer.Serialize(configuration);
|
||||
}
|
||||
}
|
||||
#region Nested Classes
|
||||
|
||||
[DataContract(Name = "document", Namespace = "")]
|
||||
public class DocumentConfig<T>
|
||||
{
|
||||
public string SharedLinkKey;
|
||||
@ -171,34 +161,28 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private string _title = null;
|
||||
|
||||
|
||||
[DataMember(Name = "fileType")]
|
||||
public string FileType
|
||||
{
|
||||
set { }
|
||||
get { return Info.File.ConvertedExtension.Trim('.'); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "info")]
|
||||
public InfoConfig<T> Info { get; set; }
|
||||
|
||||
[DataMember(Name = "key")]
|
||||
public string Key
|
||||
{
|
||||
set { _key = value; }
|
||||
get { return DocumentServiceConnector.GenerateRevisionId(_key); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "permissions")]
|
||||
public PermissionsConfig Permissions { get; set; }
|
||||
|
||||
[DataMember(Name = "title")]
|
||||
public string Title
|
||||
{
|
||||
set { _title = value; }
|
||||
get { return _title ?? Info.File.Title; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "url")]
|
||||
public string Url
|
||||
{
|
||||
set { _fileUri = DocumentServiceConnector.ReplaceCommunityAdress(value); }
|
||||
@ -216,7 +200,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private PathProvider PathProvider { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "info", Namespace = "")]
|
||||
public class InfoConfig<T>
|
||||
{
|
||||
public File<T> File;
|
||||
@ -231,7 +214,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
|
||||
[Obsolete("Use owner (since v5.4)")]
|
||||
[DataMember(Name = "author")]
|
||||
public string Author
|
||||
{
|
||||
set { }
|
||||
@ -239,14 +221,12 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
|
||||
[Obsolete("Use uploaded (since v5.4)")]
|
||||
[DataMember(Name = "created")]
|
||||
public string Created
|
||||
{
|
||||
set { }
|
||||
get { return File.CreateOnString; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "folder", EmitDefaultValue = false)]
|
||||
public string Folder
|
||||
{
|
||||
set { }
|
||||
@ -265,21 +245,18 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "owner")]
|
||||
public string Owner
|
||||
{
|
||||
set { }
|
||||
get { return File.CreateByString; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "uploaded")]
|
||||
public string Uploaded
|
||||
{
|
||||
set { }
|
||||
get { return File.CreateOnString; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "sharingSettings", EmitDefaultValue = false)]
|
||||
public ItemList<AceShortWrapper> SharingSettings
|
||||
{
|
||||
set { }
|
||||
@ -304,36 +281,26 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private FileSharing FileSharing { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "permissions", Namespace = "")]
|
||||
public class PermissionsConfig
|
||||
{
|
||||
[Obsolete("Since DS v5.5")]
|
||||
[DataMember(Name = "changeHistory")]
|
||||
public bool ChangeHistory { get; set; } = false;
|
||||
|
||||
[DataMember(Name = "comment")]
|
||||
public bool Comment { get; set; } = true;
|
||||
|
||||
[DataMember(Name = "download")]
|
||||
public bool Download { get; set; } = true;
|
||||
|
||||
[DataMember(Name = "edit")]
|
||||
public bool Edit { get; set; } = true;
|
||||
|
||||
[DataMember(Name = "fillForms")]
|
||||
public bool FillForms { get; set; } = true;
|
||||
|
||||
[DataMember(Name = "print")]
|
||||
public bool Print { get; set; } = true;
|
||||
|
||||
[DataMember(Name = "rename")]
|
||||
public bool Rename { get; set; } = false;
|
||||
|
||||
[DataMember(Name = "review")]
|
||||
public bool Review { get; set; } = true;
|
||||
}
|
||||
|
||||
[DataContract(Name = "editorConfig", Namespace = "")]
|
||||
public class EditorConfiguration<T>
|
||||
{
|
||||
public EditorConfiguration(
|
||||
@ -381,7 +348,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private readonly UserInfo _userInfo;
|
||||
private EmbeddedConfig _embeddedConfig;
|
||||
|
||||
[DataMember(Name = "actionLink", EmitDefaultValue = false)]
|
||||
public ActionLinkConfig ActionLink { get; set; }
|
||||
|
||||
public string ActionLinkString
|
||||
@ -391,11 +357,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(value)))
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(ActionLinkConfig));
|
||||
ActionLink = (ActionLinkConfig)serializer.ReadObject(ms);
|
||||
}
|
||||
JsonSerializer.Deserialize<ActionLinkConfig>(value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
@ -404,10 +366,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "callbackUrl", EmitDefaultValue = false)]
|
||||
public string CallbackUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "createUrl", EmitDefaultValue = false)]
|
||||
public string CreateUrl
|
||||
{
|
||||
set { }
|
||||
@ -420,23 +380,18 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "plugins", EmitDefaultValue = false)]
|
||||
public PluginsConfig Plugins { get; set; }
|
||||
|
||||
[DataMember(Name = "customization", EmitDefaultValue = false)]
|
||||
public CustomizationConfig<T> Customization { get; set; }
|
||||
|
||||
[DataMember(Name = "embedded", EmitDefaultValue = false)]
|
||||
public EmbeddedConfig Embedded
|
||||
{
|
||||
set { _embeddedConfig = value; }
|
||||
get { return _configuration.Document.Info.Type == EditorType.Embedded ? _embeddedConfig : null; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "fileChoiceUrl", EmitDefaultValue = false)]
|
||||
public string FileChoiceUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "lang")]
|
||||
public string Lang
|
||||
{
|
||||
set { }
|
||||
@ -444,10 +399,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
|
||||
//todo: remove old feild after release 5.2+
|
||||
[DataMember(Name = "mergeFolderUrl", EmitDefaultValue = false)]
|
||||
public string MergeFolderUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "mode")]
|
||||
public string Mode
|
||||
{
|
||||
set { }
|
||||
@ -459,13 +412,10 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private FilesLinkUtility FilesLinkUtility { get; }
|
||||
private BaseCommonLinkUtility BaseCommonLinkUtility { get; }
|
||||
|
||||
[DataMember(Name = "saveAsUrl", EmitDefaultValue = false)]
|
||||
public string SaveAsUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "sharingSettingsUrl", EmitDefaultValue = false)]
|
||||
public string SharingSettingsUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "user")]
|
||||
public UserConfig User { get; set; }
|
||||
|
||||
private string GetCreateUrl(FileType fileType)
|
||||
@ -497,56 +447,41 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
|
||||
#endregion
|
||||
|
||||
[DataContract(Name = "actionLink", Namespace = "")]
|
||||
public class ActionLinkConfig
|
||||
{
|
||||
[DataMember(Name = "action", EmitDefaultValue = false)]
|
||||
public ActionConfig Action { get; set; }
|
||||
|
||||
|
||||
[DataContract(Name = "action", Namespace = "")]
|
||||
public class ActionConfig
|
||||
{
|
||||
[DataMember(Name = "type", EmitDefaultValue = false)]
|
||||
public string Type { get; set; }
|
||||
|
||||
[DataMember(Name = "data", EmitDefaultValue = false)]
|
||||
public string Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public static string Serialize(ActionLinkConfig actionLinkConfig)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(ActionLinkConfig));
|
||||
serializer.WriteObject(ms, actionLinkConfig);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
}
|
||||
return JsonSerializer.Serialize(actionLinkConfig);
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "embedded", Namespace = "")]
|
||||
public class EmbeddedConfig
|
||||
{
|
||||
public string ShareLinkParam { get; set; }
|
||||
|
||||
[DataMember(Name = "embedUrl", EmitDefaultValue = false)]
|
||||
public string EmbedUrl
|
||||
{
|
||||
set { }
|
||||
get { return BaseCommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.FilesBaseAbsolutePath + FilesLinkUtility.EditorPage + "?" + FilesLinkUtility.Action + "=embedded" + ShareLinkParam); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "saveUrl", EmitDefaultValue = false)]
|
||||
public string SaveUrl
|
||||
{
|
||||
set { }
|
||||
get { return BaseCommonLinkUtility.GetFullAbsolutePath(FilesLinkUtility.FileHandlerPath + "?" + FilesLinkUtility.Action + "=download" + ShareLinkParam); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "shareUrl", EmitDefaultValue = false)]
|
||||
public string ShareUrl
|
||||
{
|
||||
set { }
|
||||
@ -556,7 +491,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
public BaseCommonLinkUtility BaseCommonLinkUtility { get; }
|
||||
public FilesLinkUtility FilesLinkUtility { get; }
|
||||
|
||||
[DataMember(Name = "toolbarDocked")]
|
||||
public string ToolbarDocked { get => "top"; }
|
||||
|
||||
public EmbeddedConfig(BaseCommonLinkUtility baseCommonLinkUtility, FilesLinkUtility filesLinkUtility)
|
||||
@ -566,10 +500,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "plugins", Namespace = "")]
|
||||
public class PluginsConfig
|
||||
{
|
||||
[DataMember(Name = "pluginsData", EmitDefaultValue = false)]
|
||||
public string[] PluginsData
|
||||
{
|
||||
set { }
|
||||
@ -605,7 +537,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "customization", Namespace = "")]
|
||||
public class CustomizationConfig<T>
|
||||
{
|
||||
public CustomizationConfig(
|
||||
@ -651,17 +582,14 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
public bool IsRetina = false;
|
||||
|
||||
|
||||
[DataMember(Name = "about")]
|
||||
public bool About
|
||||
{
|
||||
set { }
|
||||
get { return !CoreBaseSettings.Standalone && !CoreBaseSettings.CustomMode; }
|
||||
}
|
||||
|
||||
[DataMember(Name = "customer")]
|
||||
public CustomerConfig<T> Customer { get; set; }
|
||||
|
||||
[DataMember(Name = "feedback", EmitDefaultValue = false)]
|
||||
public FeedbackConfig Feedback
|
||||
{
|
||||
set { }
|
||||
@ -679,8 +607,7 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "forcesave", EmitDefaultValue = false)]
|
||||
public bool Forcesave
|
||||
public bool? Forcesave
|
||||
{
|
||||
set { }
|
||||
get
|
||||
@ -692,7 +619,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "goback", EmitDefaultValue = false)]
|
||||
public GobackConfig Goback
|
||||
{
|
||||
set { }
|
||||
@ -739,7 +665,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "loaderLogo", EmitDefaultValue = false)]
|
||||
public string LoaderLogo
|
||||
{
|
||||
set { }
|
||||
@ -751,7 +676,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "loaderName", EmitDefaultValue = false)]
|
||||
public string LoaderName
|
||||
{
|
||||
set { }
|
||||
@ -763,10 +687,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "logo")]
|
||||
public LogoConfig<T> Logo { get; set; }
|
||||
|
||||
[DataMember(Name = "reviewDisplay", EmitDefaultValue = false)]
|
||||
public string ReviewDisplay
|
||||
{
|
||||
set { }
|
||||
@ -786,7 +708,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private BaseCommonLinkUtility BaseCommonLinkUtility { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "customer", Namespace = "")]
|
||||
public class CustomerConfig<T>
|
||||
{
|
||||
public CustomerConfig(
|
||||
@ -806,14 +727,12 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
[DataMember(Name = "logo")]
|
||||
public string Logo
|
||||
{
|
||||
set { }
|
||||
get { return BaseCommonLinkUtility.GetFullAbsolutePath(TenantLogoHelper.GetLogo(WhiteLabelLogoTypeEnum.Dark, !_configuration.EditorConfig.Customization.IsRetina)); }
|
||||
}
|
||||
|
||||
[DataMember(Name = "name")]
|
||||
public string Name
|
||||
{
|
||||
set { }
|
||||
@ -829,24 +748,18 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private TenantLogoHelper TenantLogoHelper { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "feedback", Namespace = "")]
|
||||
public class FeedbackConfig
|
||||
{
|
||||
[DataMember(Name = "url")]
|
||||
public string Url { get; set; }
|
||||
|
||||
[DataMember(Name = "visible")]
|
||||
public bool Visible { get => true; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "goback", Namespace = "")]
|
||||
public class GobackConfig
|
||||
{
|
||||
[DataMember(Name = "url", EmitDefaultValue = false)]
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "logo", Namespace = "")]
|
||||
public class LogoConfig<T>
|
||||
{
|
||||
public LogoConfig(
|
||||
@ -865,7 +778,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
[DataMember(Name = "image")]
|
||||
public string Image
|
||||
{
|
||||
set { }
|
||||
@ -878,7 +790,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "imageEmbedded", EmitDefaultValue = false)]
|
||||
public string ImageEmbedded
|
||||
{
|
||||
set { }
|
||||
@ -891,7 +802,6 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "url")]
|
||||
public string Url
|
||||
{
|
||||
set { }
|
||||
@ -903,13 +813,10 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
private SettingsManager SettingsManager { get; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "user", Namespace = "")]
|
||||
public class UserConfig
|
||||
{
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[DataMember(Name = "name", EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
|
@ -23,72 +23,44 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
|
||||
namespace ASC.Web.Files.Services.DocumentService
|
||||
{
|
||||
[DataContract(Name = "docServiceParams", Namespace = "")]
|
||||
public class DocumentServiceParams
|
||||
{
|
||||
[DataMember(Name = "displayName")]
|
||||
public string DisplayName;
|
||||
|
||||
[DataMember(Name = "docKeyForTrack")]
|
||||
public string DocKeyForTrack;
|
||||
|
||||
[DataMember(Name = "editByUrl")]
|
||||
public bool EditByUrl;
|
||||
|
||||
[DataMember(Name = "email")]
|
||||
public string Email;
|
||||
|
||||
[DataMember(Name = "fileId", EmitDefaultValue = false)]
|
||||
public string FileId;
|
||||
|
||||
[DataMember(Name = "fileProviderKey", EmitDefaultValue = false)]
|
||||
public string FileProviderKey;
|
||||
|
||||
[DataMember(Name = "fileVersion", EmitDefaultValue = false)]
|
||||
public int FileVersion;
|
||||
|
||||
[DataMember(Name = "linkToEdit")]
|
||||
public string LinkToEdit;
|
||||
|
||||
[DataMember(Name = "openHistory", EmitDefaultValue = false)]
|
||||
public bool OpenHistory;
|
||||
|
||||
[DataMember(Name = "openinigDate")]
|
||||
public string OpeninigDate;
|
||||
|
||||
[DataMember(Name = "serverErrorMessage")]
|
||||
public string ServerErrorMessage;
|
||||
|
||||
[DataMember(Name = "shareLinkParam")]
|
||||
public string ShareLinkParam;
|
||||
|
||||
[DataMember(Name = "tabId")]
|
||||
public string TabId;
|
||||
|
||||
[DataMember(Name = "thirdPartyApp")]
|
||||
public bool ThirdPartyApp;
|
||||
|
||||
[DataMember(Name = "canGetUsers")]
|
||||
public bool CanGetUsers;
|
||||
|
||||
|
||||
public static string Serialize(DocumentServiceParams docServiceParams)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof (DocumentServiceParams));
|
||||
serializer.WriteObject(ms, docServiceParams);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
}
|
||||
return System.Text.Json.JsonSerializer.Serialize(docServiceParams);
|
||||
}
|
||||
}
|
||||
}
|
@ -31,9 +31,8 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Web;
|
||||
|
||||
@ -136,10 +135,8 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataContract(Name = "response", Namespace = "")]
|
||||
public class TrackResponse
|
||||
{
|
||||
[DataMember(Name = "error")]
|
||||
public int Error
|
||||
{
|
||||
set { }
|
||||
@ -151,21 +148,13 @@ namespace ASC.Web.Files.Services.DocumentService
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "message", EmitDefaultValue = false)]
|
||||
public string Message = null;
|
||||
public string Message { get; set; }
|
||||
|
||||
[DataMember(Name = "addresses", EmitDefaultValue = false)]
|
||||
public string[] Addresses = null;
|
||||
public string[] Addresses { get; set; }
|
||||
|
||||
public static string Serialize(TrackResponse response)
|
||||
{
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
var serializer = new DataContractJsonSerializer(typeof(TrackResponse));
|
||||
serializer.WriteObject(ms, response);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
return Encoding.UTF8.GetString(ms.GetBuffer(), 0, (int)ms.Length);
|
||||
}
|
||||
return JsonSerializer.Serialize(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Files.Resources;
|
||||
@ -74,31 +73,22 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
}
|
||||
|
||||
|
||||
[DataContract(Name = "error", Namespace = "")]
|
||||
class FileError
|
||||
{
|
||||
[DataMember(Name = "Detail")]
|
||||
public string Detail { get; set; }
|
||||
|
||||
[DataMember(Name = "message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
[DataMember(Name = "inner")]
|
||||
public FileErrorInner Inner { get; set; }
|
||||
|
||||
[DataContract(Name = "error", Namespace = "")]
|
||||
internal class FileErrorInner
|
||||
{
|
||||
[DataMember(Name = "message")]
|
||||
public string Message { get; set; }
|
||||
|
||||
[DataMember(Name = "type")]
|
||||
public string Type { get; set; }
|
||||
|
||||
[DataMember(Name = "source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[DataMember(Name = "stack")]
|
||||
public string Stack { get; set; }
|
||||
}
|
||||
|
||||
|
@ -24,17 +24,15 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
[DataContract]
|
||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||
public enum FileConflictResolveType
|
||||
{
|
||||
[EnumMember] Skip = 0,
|
||||
[EnumMember] Overwrite = 1,
|
||||
[EnumMember] Duplicate = 2
|
||||
{
|
||||
Skip = 0,
|
||||
Overwrite = 1,
|
||||
Duplicate = 2
|
||||
}
|
||||
}
|
@ -23,36 +23,27 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService.FileOperations
|
||||
{
|
||||
[DataContract(Name = "operation_result", Namespace = "")]
|
||||
public class FileOperationResult
|
||||
{
|
||||
[DataMember(Name = "id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[DataMember(Name = "operation")]
|
||||
[JsonPropertyName("operation")]
|
||||
public FileOperationType OperationType { get; set; }
|
||||
|
||||
[DataMember(Name = "progress")]
|
||||
public int Progress { get; set; }
|
||||
|
||||
[DataMember(Name = "source")]
|
||||
public string Source { get; set; }
|
||||
|
||||
[DataMember(Name = "result")]
|
||||
public string Result { get; set; }
|
||||
|
||||
[DataMember(Name = "error")]
|
||||
public string Error { get; set; }
|
||||
|
||||
[DataMember(Name = "processed")]
|
||||
public string Processed { get; set; }
|
||||
|
||||
[DataMember(Name = "finished")]
|
||||
public bool Finished { get; set; }
|
||||
}
|
||||
}
|
@ -25,66 +25,53 @@
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Files.Core;
|
||||
using ASC.Files.Core.Security;
|
||||
using ASC.Files.Resources;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService
|
||||
{
|
||||
[DataContract(Name = "ace_collection", Namespace = "")]
|
||||
public class AceCollection
|
||||
{
|
||||
[DataMember(Name = "entries", Order = 1)]
|
||||
public ItemList<string> Entries { get; set; }
|
||||
|
||||
[DataMember(Name = "aces", Order = 2)]
|
||||
public ItemList<AceWrapper> Aces { get; set; }
|
||||
|
||||
[DataMember(Name = "message", Order = 3, IsRequired = false)]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "ace_wrapper", Namespace = "")]
|
||||
public class AceWrapper
|
||||
{
|
||||
[DataMember(Name = "id", Order = 1)]
|
||||
public Guid SubjectId { get; set; }
|
||||
|
||||
[DataMember(Name = "title", Order = 2, EmitDefaultValue = false)]
|
||||
[JsonPropertyName("title")]
|
||||
public string SubjectName { get; set; }
|
||||
|
||||
[DataMember(Name = "link", Order = 3, EmitDefaultValue = false)]
|
||||
public string Link { get; set; }
|
||||
|
||||
[DataMember(Name = "is_group", Order = 4)]
|
||||
[JsonPropertyName("is_group")]
|
||||
public bool SubjectGroup { get; set; }
|
||||
|
||||
[DataMember(Name = "owner", Order = 5)]
|
||||
public bool Owner { get; set; }
|
||||
|
||||
[DataMember(Name = "ace_status", Order = 6)]
|
||||
[JsonPropertyName("ace_status")]
|
||||
public FileShare Share { get; set; }
|
||||
|
||||
[DataMember(Name = "locked", Order = 7)]
|
||||
[JsonPropertyName("locked")]
|
||||
public bool LockedRights { get; set; }
|
||||
|
||||
[DataMember(Name = "disable_remove", Order = 8)]
|
||||
[JsonPropertyName("disable_remove")]
|
||||
public bool DisableRemove { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Name = "sharingSettings", Namespace = "")]
|
||||
public class AceShortWrapper
|
||||
{
|
||||
[DataMember(Name = "user")]
|
||||
public string User { get; set; }
|
||||
|
||||
[DataMember(Name = "permissions")]
|
||||
public string Permissions { get; set; }
|
||||
|
||||
[DataMember(Name = "isLink", EmitDefaultValue = false, IsRequired = false)]
|
||||
public bool IsLink { get; set; }
|
||||
public bool? IsLink { get; set; }
|
||||
|
||||
public AceShortWrapper(AceWrapper aceWrapper)
|
||||
{
|
||||
|
@ -24,25 +24,21 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Files.Core;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService
|
||||
{
|
||||
[DataContract(Name = "composite_data", Namespace = "")]
|
||||
public class DataWrapper<T>
|
||||
{
|
||||
[DataMember(IsRequired = false, Name = "entries", EmitDefaultValue = false)]
|
||||
public ItemList<FileEntry> Entries { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false, Name = "total")]
|
||||
public int Total { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false, Name = "path_parts")]
|
||||
[JsonPropertyName("path_parts")]
|
||||
public ItemList<T> FolderPathParts { get; set; }
|
||||
|
||||
[DataMember(IsRequired = false, Name = "folder_info")]
|
||||
[JsonPropertyName("folder_info")]
|
||||
public Folder<T> FolderInfo { get; set; }
|
||||
|
||||
public int New { get; set; }
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Core.Users;
|
||||
using ASC.Web.Core.Users;
|
||||
@ -33,27 +32,22 @@ using ASC.Web.Files.Services.DocumentService;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService
|
||||
{
|
||||
[DataContract(Name = "mention", Namespace = "")]
|
||||
public class MentionWrapper
|
||||
{
|
||||
[DataMember(Name = "email", EmitDefaultValue = false)]
|
||||
public string Email
|
||||
{
|
||||
get { return User.Email; }
|
||||
set { }
|
||||
}
|
||||
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public string Id
|
||||
{
|
||||
get { return User.ID.ToString(); }
|
||||
set { }
|
||||
}
|
||||
|
||||
[DataMember(Name = "hasAccess", EmitDefaultValue = false)]
|
||||
public bool HasAccess { get; set; }
|
||||
|
||||
[DataMember(Name = "name", EmitDefaultValue = false)]
|
||||
public string Name
|
||||
{
|
||||
get { return User.DisplayUserName(false, DisplayUserSettingsHelper); }
|
||||
@ -71,17 +65,12 @@ namespace ASC.Web.Files.Services.WCFService
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[DataContract(Name = "message", Namespace = "")]
|
||||
public class MentionMessageWrapper
|
||||
{
|
||||
[DataMember(Name = "actionLink")]
|
||||
public ActionLinkConfig ActionLink { get; set; }
|
||||
|
||||
[DataMember(Name = "emails")]
|
||||
public List<string> Emails { get; set; }
|
||||
|
||||
[DataMember(Name = "message")]
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
@ -24,27 +24,25 @@
|
||||
*/
|
||||
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using ASC.Files.Core;
|
||||
|
||||
namespace ASC.Web.Files.Services.WCFService
|
||||
{
|
||||
[DataContract(Name = "third_party", Namespace = "")]
|
||||
public class ThirdPartyParams
|
||||
{
|
||||
[DataMember(Name = "auth_data", EmitDefaultValue = false)]
|
||||
[JsonPropertyName("auth_data")]
|
||||
public AuthData AuthData { get; set; }
|
||||
|
||||
[DataMember(Name = "corporate")]
|
||||
public bool Corporate { get; set; }
|
||||
|
||||
[DataMember(Name = "customer_title")]
|
||||
[JsonPropertyName("customer_title")]
|
||||
public string CustomerTitle { get; set; }
|
||||
|
||||
[DataMember(Name = "provider_id")]
|
||||
[JsonPropertyName("provider_id")]
|
||||
public string ProviderId { get; set; }
|
||||
|
||||
[DataMember(Name = "provider_key")]
|
||||
[JsonPropertyName("provider_key")]
|
||||
public string ProviderKey { get; set; }
|
||||
}
|
||||
}
|
@ -30,7 +30,6 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Security;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
@ -774,7 +773,6 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract(Name = "operation_result", Namespace = "")]
|
||||
internal class ConvertFileOperationResult : FileOperationResult
|
||||
{
|
||||
public DateTime StartDateTime { get; set; }
|
||||
|
@ -27,13 +27,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Common.Caching;
|
||||
|
||||
namespace ASC.Web.Files.Utils
|
||||
{
|
||||
[DataContract]
|
||||
public class FileTracker
|
||||
{
|
||||
private const string TRACKER = "filesTracker";
|
||||
@ -43,7 +41,7 @@ namespace ASC.Web.Files.Utils
|
||||
public static readonly TimeSpan CacheTimeout = TimeSpan.FromSeconds(60);
|
||||
public static readonly TimeSpan CheckRightTimeout = TimeSpan.FromMinutes(1);
|
||||
|
||||
[DataMember] private readonly Dictionary<Guid, TrackInfo> _editingBy;
|
||||
private readonly Dictionary<Guid, TrackInfo> _editingBy;
|
||||
|
||||
|
||||
private FileTracker()
|
||||
@ -223,18 +221,18 @@ namespace ASC.Web.Files.Utils
|
||||
}
|
||||
|
||||
|
||||
[DataContract]
|
||||
|
||||
internal class TrackInfo
|
||||
{
|
||||
[DataMember] public DateTime CheckRightTime;
|
||||
public DateTime CheckRightTime;
|
||||
|
||||
[DataMember] public DateTime TrackTime;
|
||||
public DateTime TrackTime;
|
||||
|
||||
[DataMember] public Guid UserId;
|
||||
public Guid UserId;
|
||||
|
||||
[DataMember] public bool NewScheme;
|
||||
public bool NewScheme;
|
||||
|
||||
[DataMember] public bool EditingAlone;
|
||||
public bool EditingAlone;
|
||||
|
||||
public TrackInfo()
|
||||
{
|
||||
|
49
thirdparty/Microsoft.Graph.Core/Authentication/DelegateAuthenticationProvider.cs
vendored
Normal file
49
thirdparty/Microsoft.Graph.Core/Authentication/DelegateAuthenticationProvider.cs
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Authenticate request async delegate.
|
||||
/// </summary>
|
||||
/// <param name="request">The <see cref="HttpRequestMessage"/> to authenticate.</param>
|
||||
/// <returns></returns>
|
||||
public delegate Task AuthenticateRequestAsyncDelegate(HttpRequestMessage request);
|
||||
|
||||
/// <summary>
|
||||
/// A default <see cref="IAuthenticationProvider"/> implementation.
|
||||
/// </summary>
|
||||
public class DelegateAuthenticationProvider : IAuthenticationProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs an <see cref="DelegateAuthenticationProvider"/>.
|
||||
/// </summary>
|
||||
public DelegateAuthenticationProvider(AuthenticateRequestAsyncDelegate authenticateRequestAsyncDelegate)
|
||||
{
|
||||
this.AuthenticateRequestAsyncDelegate = authenticateRequestAsyncDelegate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the delegate for authenticating requests.
|
||||
/// </summary>
|
||||
public AuthenticateRequestAsyncDelegate AuthenticateRequestAsyncDelegate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Authenticates the specified request message.
|
||||
/// </summary>
|
||||
/// <param name="request">The <see cref="HttpRequestMessage"/> to authenticate.</param>
|
||||
public Task AuthenticateRequestAsync(HttpRequestMessage request)
|
||||
{
|
||||
if (this.AuthenticateRequestAsyncDelegate != null)
|
||||
{
|
||||
return this.AuthenticateRequestAsyncDelegate(request);
|
||||
}
|
||||
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
}
|
||||
}
|
22
thirdparty/Microsoft.Graph.Core/Authentication/IAuthenticationProvider.cs
vendored
Normal file
22
thirdparty/Microsoft.Graph.Core/Authentication/IAuthenticationProvider.cs
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for authenticating requests.
|
||||
/// </summary>
|
||||
public interface IAuthenticationProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Authenticates the specified request message.
|
||||
/// </summary>
|
||||
/// <param name="request">The <see cref="HttpRequestMessage"/> to authenticate.</param>
|
||||
/// <returns>The task to await.</returns>
|
||||
Task AuthenticateRequestAsync(HttpRequestMessage request);
|
||||
}
|
||||
}
|
113
thirdparty/Microsoft.Graph.Core/CoreConstants.cs
vendored
Normal file
113
thirdparty/Microsoft.Graph.Core/CoreConstants.cs
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
/// <summary>
|
||||
/// Constants for the Graph Core library.
|
||||
/// </summary>
|
||||
public static class CoreConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// Polling interval for task completion.
|
||||
/// </summary>
|
||||
public const int PollingIntervalInMs = 5000;
|
||||
|
||||
/// <summary>
|
||||
/// Header constants.
|
||||
/// </summary>
|
||||
public static class Headers
|
||||
{
|
||||
/// Authorization bearer.
|
||||
public const string Bearer = "Bearer";
|
||||
|
||||
/// SDK Version header
|
||||
public const string SdkVersionHeaderName = "SdkVersion";
|
||||
|
||||
/// SDK Version header
|
||||
public const string SdkVersionHeaderValueFormatString = "{0}-dotnet-{1}.{2}.{3}";
|
||||
|
||||
/// Content-Type header
|
||||
public const string FormUrlEncodedContentType = "application/x-www-form-urlencoded";
|
||||
|
||||
/// Throw-site header
|
||||
public const string ThrowSiteHeaderName = "X-ThrowSite";
|
||||
|
||||
/// Client Request Id
|
||||
public const string ClientRequestId = "client-request-id";
|
||||
|
||||
/// Feature Flag
|
||||
public const string FeatureFlag = "FeatureFlag";
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MimeType constants.
|
||||
/// </summary>
|
||||
public static class MimeTypeNames
|
||||
{
|
||||
/// <summary>
|
||||
/// MimeTypeNames.Application constants.
|
||||
/// </summary>
|
||||
public static class Application
|
||||
{
|
||||
/// JSON content type value
|
||||
public const string Json = "application/json";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Serialization constants.
|
||||
/// </summary>
|
||||
public static class Serialization
|
||||
{
|
||||
/// OData type
|
||||
public const string ODataType = "@odata.type";
|
||||
|
||||
/// OData next link
|
||||
internal const string ODataNextLink = "@nextLink";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Batch request constants.
|
||||
/// </summary>
|
||||
public static class BatchRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum number of individual requests.
|
||||
/// </summary>
|
||||
public const int MaxNumberOfRequests = 20;
|
||||
|
||||
internal const string Id = "id";
|
||||
|
||||
internal const string Url = "url";
|
||||
|
||||
internal const string Body = "body";
|
||||
|
||||
internal const string DependsOn = "dependsOn";
|
||||
|
||||
internal const string Method = "method";
|
||||
|
||||
internal const string Requests = "requests";
|
||||
|
||||
internal const string Responses = "responses";
|
||||
|
||||
internal const string Status = "status";
|
||||
|
||||
internal const string Headers = "headers";
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encoding constants
|
||||
/// </summary>
|
||||
public static class Encoding
|
||||
{
|
||||
/// gzip encoding.
|
||||
public const string GZip = "gzip";
|
||||
}
|
||||
}
|
||||
}
|
23
thirdparty/Microsoft.Graph.Core/Exceptions/ClientException.cs
vendored
Normal file
23
thirdparty/Microsoft.Graph.Core/Exceptions/ClientException.cs
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Graph client exception.
|
||||
/// </summary>
|
||||
public class ClientException : ServiceException
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new client exception.
|
||||
/// </summary>
|
||||
/// <param name="error">The error that triggered the exception.</param>
|
||||
/// <param name="innerException">The possible innerException.</param>
|
||||
public ClientException(Error error, Exception innerException = null) : base(error, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
141
thirdparty/Microsoft.Graph.Core/Exceptions/Error.cs
vendored
Normal file
141
thirdparty/Microsoft.Graph.Core/Exceptions/Error.cs
vendored
Normal file
@ -0,0 +1,141 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// The error object contained in 400 and 500 responses returned from the service.
|
||||
/// Models OData protocol, 9.4 Error Response Body
|
||||
/// http://docs.oasis-open.org/odata/odata/v4.01/csprd05/part1-protocol/odata-v4.01-csprd05-part1-protocol.html#_Toc14172757
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
public class Error
|
||||
{
|
||||
/// <summary>
|
||||
/// This code represents the HTTP status code when this Error object accessed from the ServiceException.Error object.
|
||||
/// This code represent a sub-code when the Error object is in the InnerError or ErrorDetails object.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "code", Required = Required.Default)]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The error message.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "message", Required = Required.Default)]
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the target of the error, for example, the name of the property in error.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "target", Required = Required.Default)]
|
||||
public string Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An array of details that describe the error[s] encountered with the request.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "details", Required = Required.Default)]
|
||||
public IEnumerable<ErrorDetail> Details { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The inner error of the response. These are additional error objects that may be more specific than the top level error.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "innererror", Required = Required.Default)]
|
||||
public Error InnerError { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Throw site of the error.
|
||||
/// </summary>
|
||||
public string ThrowSite { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or set the client-request-id header returned in the response headers collection.
|
||||
/// </summary>
|
||||
public string ClientRequestId { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// The AdditionalData property bag.
|
||||
/// </summary>
|
||||
[JsonExtensionData(ReadData = true)]
|
||||
public IDictionary<string, object> AdditionalData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Concatenates the error into a string.
|
||||
/// </summary>
|
||||
/// <returns>A human-readable string error response.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var errorStringBuilder = new StringBuilder();
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Code))
|
||||
{
|
||||
errorStringBuilder.AppendFormat("Code: {0}", this.Code);
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Message))
|
||||
{
|
||||
errorStringBuilder.AppendFormat("Message: {0}", this.Message);
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Target))
|
||||
{
|
||||
errorStringBuilder.AppendFormat("Target: {0}", this.Target);
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (this.Details != null && this.Details.GetEnumerator().MoveNext())
|
||||
{
|
||||
errorStringBuilder.Append("Details:");
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
|
||||
int i = 0;
|
||||
foreach (var detail in this.Details)
|
||||
{
|
||||
errorStringBuilder.AppendFormat("\tDetail{0}:{1}", i, detail.ToString());
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.InnerError != null)
|
||||
{
|
||||
errorStringBuilder.Append("Inner error:");
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
errorStringBuilder.Append("\t" + this.InnerError.ToString());
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.ThrowSite))
|
||||
{
|
||||
errorStringBuilder.AppendFormat("Throw site: {0}", this.ThrowSite);
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.ClientRequestId))
|
||||
{
|
||||
errorStringBuilder.AppendFormat("ClientRequestId: {0}", this.ClientRequestId);
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (this.AdditionalData != null && this.AdditionalData.GetEnumerator().MoveNext())
|
||||
{
|
||||
errorStringBuilder.Append("AdditionalData:");
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
foreach (var prop in this.AdditionalData)
|
||||
{
|
||||
errorStringBuilder.AppendFormat("\t{0}: {1}", prop.Key, prop.Value.ToString());
|
||||
errorStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
return errorStringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
73
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorConstants.cs
vendored
Normal file
73
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorConstants.cs
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
internal static class ErrorConstants
|
||||
{
|
||||
internal static class Codes
|
||||
{
|
||||
internal static string GeneralException = "generalException";
|
||||
|
||||
internal static string InvalidRequest = "invalidRequest";
|
||||
|
||||
internal static string ItemNotFound = "itemNotFound";
|
||||
|
||||
internal static string NotAllowed = "notAllowed";
|
||||
|
||||
internal static string Timeout = "timeout";
|
||||
|
||||
internal static string TooManyRedirects = "tooManyRedirects";
|
||||
|
||||
internal static string TooManyRetries = "tooManyRetries";
|
||||
|
||||
internal static string MaximumValueExceeded = "MaximumValueExceeded";
|
||||
|
||||
internal static string InvalidArgument = "invalidArgument";
|
||||
}
|
||||
|
||||
internal static class Messages
|
||||
{
|
||||
internal static string AuthenticationProviderMissing = "Authentication provider is required before sending a request.";
|
||||
|
||||
internal static string BaseUrlMissing = "Base URL cannot be null or empty.";
|
||||
|
||||
internal static string InvalidTypeForDateConverter = "DateConverter can only serialize objects of type Date.";
|
||||
|
||||
internal static string LocationHeaderNotSetOnRedirect = "Location header not present in redirection response.";
|
||||
|
||||
internal static string OverallTimeoutCannotBeSet = "Overall timeout cannot be set after the first request is sent.";
|
||||
|
||||
internal static string RequestTimedOut = "The request timed out.";
|
||||
|
||||
internal static string RequestUrlMissing = "Request URL is required to send a request.";
|
||||
|
||||
internal static string TooManyRedirectsFormatString = "More than {0} redirects encountered while sending the request.";
|
||||
|
||||
internal static string TooManyRetriesFormatString = "More than {0} retries encountered while sending the request.";
|
||||
|
||||
internal static string UnableToCreateInstanceOfTypeFormatString = "Unable to create an instance of type {0}.";
|
||||
|
||||
internal static string UnableToDeserializeDate = "Unable to deserialize the returned Date.";
|
||||
|
||||
internal static string UnexpectedExceptionOnSend = "An error occurred sending the request.";
|
||||
|
||||
internal static string UnexpectedExceptionResponse = "Unexpected exception returned from the service.";
|
||||
|
||||
internal static string MaximumValueExceeded = "{0} exceeds the maximum value of {1}.";
|
||||
|
||||
internal static string NullParameter = "{0} parameter cannot be null.";
|
||||
|
||||
internal static string UnableToDeserializexContent = "Unable to deserialize content.";
|
||||
|
||||
internal static string InvalidDependsOnRequestId = "Corresponding batch request id not found for the specified dependsOn relation.";
|
||||
|
||||
internal static string ExpiredUploadSession = "Upload session expired. Upload cannot resume";
|
||||
|
||||
internal static string NoResponseForUpload = "No Response Received for upload.";
|
||||
|
||||
public static string InvalidProxyArgument = "Proxy cannot be set more once. Proxy can only be set on the proxy or defaultHttpHandler argument and not both.";
|
||||
}
|
||||
}
|
||||
}
|
85
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorDetail.cs
vendored
Normal file
85
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorDetail.cs
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
/// <summary>
|
||||
/// The error details object.
|
||||
/// Models OData protocol, 9.4 Error Response Body details object.
|
||||
/// http://docs.oasis-open.org/odata/odata/v4.01/csprd05/part1-protocol/odata-v4.01-csprd05-part1-protocol.html#_Toc14172757
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
public class ErrorDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// This code serves as a sub-status for the error code specified in the Error object.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "code", Required = Required.Default)]
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The error message.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "message", Required = Required.Default)]
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the target of the error, for example, the name of the property in error.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "target", Required = Required.Default)]
|
||||
public string Target { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The AdditionalData property bag.
|
||||
/// </summary>
|
||||
[JsonExtensionData(ReadData = true)]
|
||||
public IDictionary<string, object> AdditionalData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Concatenates the error detail into a string.
|
||||
/// </summary>
|
||||
/// <returns>A string representation of an ErrorDetail object.</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
var errorDetailsStringBuilder = new StringBuilder();
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Code))
|
||||
{
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
errorDetailsStringBuilder.AppendFormat("\t\tCode: {0}", this.Code);
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Message))
|
||||
{
|
||||
errorDetailsStringBuilder.AppendFormat("\t\tMessage: {0}", this.Message);
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(this.Target))
|
||||
{
|
||||
errorDetailsStringBuilder.AppendFormat("\t\tTarget: {0}", this.Target);
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
if (this.AdditionalData != null && this.AdditionalData.GetEnumerator().MoveNext())
|
||||
{
|
||||
errorDetailsStringBuilder.Append("\t\tAdditionalData:");
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
foreach (var prop in this.AdditionalData)
|
||||
{
|
||||
errorDetailsStringBuilder.AppendFormat("\t{0} : {1}", prop.Key, prop.Value.ToString());
|
||||
errorDetailsStringBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
}
|
||||
|
||||
return errorDetailsStringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
29
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorResponse.cs
vendored
Normal file
29
thirdparty/Microsoft.Graph.Core/Exceptions/ErrorResponse.cs
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// The error response object from the service on an unsuccessful call.
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
public class ErrorResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="Error"/> returned by the service.
|
||||
/// </summary>
|
||||
[JsonProperty(PropertyName = "error")]
|
||||
public Error Error { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Additional data returned in the call.
|
||||
/// </summary>
|
||||
[JsonExtensionData(ReadData = true)]
|
||||
public IDictionary<string, object> AdditionalData { get; set; }
|
||||
}
|
||||
}
|
112
thirdparty/Microsoft.Graph.Core/Exceptions/ServiceException.cs
vendored
Normal file
112
thirdparty/Microsoft.Graph.Core/Exceptions/ServiceException.cs
vendored
Normal file
@ -0,0 +1,112 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// Graph service exception.
|
||||
/// </summary>
|
||||
public class ServiceException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new service exception.
|
||||
/// </summary>
|
||||
/// <param name="error">The error that triggered the exception.</param>
|
||||
/// <param name="innerException">The possible innerException.</param>
|
||||
public ServiceException(Error error, Exception innerException = null)
|
||||
: this(error, responseHeaders: null, statusCode: default(System.Net.HttpStatusCode), innerException: innerException)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new service exception.
|
||||
/// </summary>
|
||||
/// <param name="error">The error that triggered the exception.</param>
|
||||
/// <param name="innerException">The possible innerException.</param>
|
||||
/// <param name="responseHeaders">The HTTP response headers from the response.</param>
|
||||
/// <param name="statusCode">The HTTP status code from the response.</param>
|
||||
public ServiceException(Error error, System.Net.Http.Headers.HttpResponseHeaders responseHeaders, System.Net.HttpStatusCode statusCode, Exception innerException = null)
|
||||
: base(error?.ToString(), innerException)
|
||||
{
|
||||
this.Error = error;
|
||||
this.ResponseHeaders = responseHeaders;
|
||||
this.StatusCode = statusCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new service exception.
|
||||
/// </summary>
|
||||
/// <param name="error">The error that triggered the exception.</param>
|
||||
/// <param name="innerException">The possible innerException.</param>
|
||||
/// <param name="responseHeaders">The HTTP response headers from the response.</param>
|
||||
/// <param name="statusCode">The HTTP status code from the response.</param>
|
||||
/// <param name="rawResponseBody">The raw JSON response body.</param>
|
||||
public ServiceException(Error error,
|
||||
System.Net.Http.Headers.HttpResponseHeaders responseHeaders,
|
||||
System.Net.HttpStatusCode statusCode,
|
||||
string rawResponseBody,
|
||||
Exception innerException = null)
|
||||
: this(error, responseHeaders, statusCode, innerException)
|
||||
{
|
||||
this.RawResponseBody = rawResponseBody;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The error from the service exception.
|
||||
/// </summary>
|
||||
public Error Error { get; }
|
||||
|
||||
// ResponseHeaders and StatusCode exposed as pass-through.
|
||||
|
||||
/// <summary>
|
||||
/// The HTTP response headers from the response.
|
||||
/// </summary>
|
||||
public System.Net.Http.Headers.HttpResponseHeaders ResponseHeaders { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The HTTP status code from the response.
|
||||
/// </summary>
|
||||
public System.Net.HttpStatusCode StatusCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Provide the raw JSON response body.
|
||||
/// </summary>
|
||||
public string RawResponseBody { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a given error code has been returned in the response at any level in the error stack.
|
||||
/// </summary>
|
||||
/// <param name="errorCode">The error code.</param>
|
||||
/// <returns>True if the error code is in the stack.</returns>
|
||||
public bool IsMatch(string errorCode)
|
||||
{
|
||||
if (string.IsNullOrEmpty(errorCode))
|
||||
{
|
||||
throw new ArgumentException("errorCode cannot be null or empty", "errorCode");
|
||||
}
|
||||
|
||||
var currentError = this.Error;
|
||||
|
||||
while (currentError != null)
|
||||
{
|
||||
if (string.Equals(currentError.Code, errorCode, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
currentError = currentError.InnerError;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString()
|
||||
{
|
||||
return $@"Status Code: {this.StatusCode}{Environment.NewLine}{base.ToString()}";
|
||||
}
|
||||
}
|
||||
}
|
171
thirdparty/Microsoft.Graph.Core/Extensions/BaseRequestExtensions.cs
vendored
Normal file
171
thirdparty/Microsoft.Graph.Core/Extensions/BaseRequestExtensions.cs
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="BaseRequest"/>
|
||||
/// </summary>
|
||||
public static class BaseRequestExtensions
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Sets the default authentication provider to the default Authentication Middleware Handler for this request.
|
||||
/// This only works with the default authentication handler.
|
||||
/// If you use a custom authentication handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <returns></returns>
|
||||
internal static T WithDefaultAuthProvider<T>(this T baseRequest) where T : IBaseRequest
|
||||
{
|
||||
string authOptionKey = typeof(AuthenticationHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(authOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[authOptionKey] as AuthenticationHandlerOption).AuthenticationProvider = baseRequest.Client.AuthenticationProvider;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthenticationHandlerOption { AuthenticationProvider = baseRequest.Client.AuthenticationProvider });
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the PerRequestAuthProvider delegate handler to the default Authentication Middleware Handler to authenticate a single request.
|
||||
/// The PerRequestAuthProvider delegate handler must be set to the GraphServiceClient instance before using this extension method otherwise, it defaults to the default authentication provider.
|
||||
/// This only works with the default authentication handler.
|
||||
/// If you use a custom authentication handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <returns></returns>
|
||||
public static T WithPerRequestAuthProvider<T>(this T baseRequest) where T : IBaseRequest
|
||||
{
|
||||
if (baseRequest.Client.PerRequestAuthProvider != null)
|
||||
{
|
||||
string authOptionKey = typeof(AuthenticationHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(authOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[authOptionKey] as AuthenticationHandlerOption).AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider();
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(authOptionKey, new AuthenticationHandlerOption { AuthenticationProvider = baseRequest.Client.PerRequestAuthProvider() });
|
||||
}
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets a ShouldRetry delegate to the default Retry Middleware Handler for this request.
|
||||
/// This only works with the default Retry Middleware Handler.
|
||||
/// If you use a custom Retry Middleware Handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <param name="shouldRetry">A <see cref="Func{Int32, Int32, HttpResponseMessage, Boolean}"/> for the request.</param>
|
||||
/// <returns></returns>
|
||||
public static T WithShouldRetry<T>(this T baseRequest, Func<int, int, HttpResponseMessage, bool> shouldRetry) where T : IBaseRequest
|
||||
{
|
||||
string retryOptionKey = typeof(RetryHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryHandlerOption).ShouldRetry = shouldRetry;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryHandlerOption { ShouldRetry = shouldRetry });
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum number of retries to the default Retry Middleware Handler for this request.
|
||||
/// This only works with the default Retry Middleware Handler.
|
||||
/// If you use a custom Retry Middleware Handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <param name="maxRetry">The maxRetry for the request.</param>
|
||||
/// <returns></returns>
|
||||
public static T WithMaxRetry<T>(this T baseRequest, int maxRetry) where T : IBaseRequest
|
||||
{
|
||||
string retryOptionKey = typeof(RetryHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryHandlerOption).MaxRetry = maxRetry;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryHandlerOption { MaxRetry = maxRetry });
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum time for request retries to the default Retry Middleware Handler for this request.
|
||||
/// This only works with the default Retry Middleware Handler.
|
||||
/// If you use a custom Retry Middleware Handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <param name="retriesTimeLimit">The retriestimelimit for the request in seconds.</param>
|
||||
/// <returns></returns>
|
||||
public static T WithMaxRetry<T>(this T baseRequest, TimeSpan retriesTimeLimit) where T : IBaseRequest
|
||||
{
|
||||
string retryOptionKey = typeof(RetryHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(retryOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[retryOptionKey] as RetryHandlerOption).RetriesTimeLimit = retriesTimeLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(retryOptionKey, new RetryHandlerOption { RetriesTimeLimit = retriesTimeLimit });
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the maximum number of redirects to the default Redirect Middleware Handler for this request.
|
||||
/// This only works with the default Redirect Middleware Handler.
|
||||
/// If you use a custom Redirect Middleware Handler, you have to handle it's retrieval in your implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <param name="maxRedirects">Maximum number of redirects allowed for the request</param>
|
||||
/// <returns></returns>
|
||||
public static T WithMaxRedirects<T>(this T baseRequest, int maxRedirects) where T : IBaseRequest
|
||||
{
|
||||
string redirectOptionKey = typeof(RedirectHandlerOption).ToString();
|
||||
if (baseRequest.MiddlewareOptions.ContainsKey(redirectOptionKey))
|
||||
{
|
||||
(baseRequest.MiddlewareOptions[redirectOptionKey] as RedirectHandlerOption).MaxRedirect = maxRedirects;
|
||||
}
|
||||
else
|
||||
{
|
||||
baseRequest.MiddlewareOptions.Add(redirectOptionKey, new RedirectHandlerOption { MaxRedirect = maxRedirects });
|
||||
}
|
||||
return baseRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces the default response handler with a custom response handler for this request.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="baseRequest">The <see cref="BaseRequest"/> for the request.</param>
|
||||
/// <param name="responseHandler">The <see cref="IResponseHandler"/> for the request.</param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="System.ArgumentNullException">If responseHandler is null.</exception>
|
||||
public static T WithResponseHandler<T>(this T baseRequest, IResponseHandler responseHandler) where T : BaseRequest
|
||||
{
|
||||
baseRequest.ResponseHandler = responseHandler ?? throw new ArgumentNullException(nameof(responseHandler));
|
||||
|
||||
return baseRequest;
|
||||
}
|
||||
}
|
||||
}
|
52
thirdparty/Microsoft.Graph.Core/Extensions/HttpClientExtensions.cs
vendored
Normal file
52
thirdparty/Microsoft.Graph.Core/Extensions/HttpClientExtensions.cs
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
||||
internal static class HttpClientExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds featureflag to existing header values.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">The http client to set FeatureUsage header.</param>
|
||||
/// <param name="featureFlag">The Feature usage flag to set.</param>
|
||||
internal static void SetFeatureFlag(this HttpClient httpClient, FeatureFlag featureFlag)
|
||||
{
|
||||
// If feature flag header exists, add incoming flag to existing bitfield values and replace existing header with the computed bitfield total.
|
||||
if (httpClient.DefaultRequestHeaders.TryGetValues(CoreConstants.Headers.FeatureFlag, out var flags))
|
||||
{
|
||||
// Add incoming flag to existing feature flag values.
|
||||
foreach (string flag in flags)
|
||||
if (Enum.TryParse(Convert.ToInt32(flag, 16).ToString(), out FeatureFlag targetFeatureFlag))
|
||||
featureFlag |= targetFeatureFlag;
|
||||
|
||||
// Remove current header value.
|
||||
httpClient.DefaultRequestHeaders.Remove(CoreConstants.Headers.FeatureFlag);
|
||||
}
|
||||
|
||||
// Add/Replace new computed bitfield.
|
||||
httpClient.DefaultRequestHeaders.Add(CoreConstants.Headers.FeatureFlag, Enum.Format(typeof(FeatureFlag), featureFlag, "x"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a featureflag existing in the default header values.
|
||||
/// </summary>
|
||||
/// <param name="httpClient">The http client to set FeatureUsage header.</param>
|
||||
/// <param name="featureFlag">The Feature usage flag to check for.</param>
|
||||
internal static bool ContainsFeatureFlag(this HttpClient httpClient, FeatureFlag featureFlag)
|
||||
{
|
||||
if (httpClient.DefaultRequestHeaders.TryGetValues(CoreConstants.Headers.FeatureFlag, out var flags))
|
||||
{
|
||||
string flag = flags.FirstOrDefault();
|
||||
if (Enum.TryParse(Convert.ToInt32(flag, 16).ToString(), out FeatureFlag targetFeatureFlag))
|
||||
return targetFeatureFlag.HasFlag(featureFlag);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
126
thirdparty/Microsoft.Graph.Core/Extensions/HttpRequestMessageExtensions.cs
vendored
Normal file
126
thirdparty/Microsoft.Graph.Core/Extensions/HttpRequestMessageExtensions.cs
vendored
Normal file
@ -0,0 +1,126 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="HttpRequestMessage"/>
|
||||
/// </summary>
|
||||
public static class HttpRequestMessageExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Checks the HTTP request's content to determine if it's buffered or streamed content.
|
||||
/// </summary>
|
||||
/// <param name="httpRequestMessage">The <see cref="HttpRequestMessage"/>needs to be sent.</param>
|
||||
/// <returns></returns>
|
||||
internal static bool IsBuffered(this HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
HttpContent requestContent = httpRequestMessage.Content;
|
||||
|
||||
if ((httpRequestMessage.Method == HttpMethod.Put || httpRequestMessage.Method == HttpMethod.Post || httpRequestMessage.Method.Method.Equals("PATCH"))
|
||||
&& requestContent != null && (requestContent.Headers.ContentLength == null || (int)requestContent.Headers.ContentLength == -1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get's feature request header value from the incoming <see cref="HttpRequestMessage"/>
|
||||
/// </summary>
|
||||
/// <param name="httpRequestMessage">The <see cref="HttpRequestMessage"/> object</param>
|
||||
/// <returns></returns>
|
||||
internal static FeatureFlag GetFeatureFlags(this HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
httpRequestMessage.Headers.TryGetValues(CoreConstants.Headers.FeatureFlag, out IEnumerable<string> flags);
|
||||
|
||||
if (!Enum.TryParse(flags?.FirstOrDefault(), out FeatureFlag featureFlag))
|
||||
{
|
||||
featureFlag = FeatureFlag.None;
|
||||
}
|
||||
|
||||
return featureFlag;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new HTTP request by copying previous HTTP request's headers and properties from response's request message.
|
||||
/// </summary>
|
||||
/// <param name="originalRequest">The previous <see cref="HttpRequestMessage"/> needs to be copy.</param>
|
||||
/// <returns>The <see cref="HttpRequestMessage"/>.</returns>
|
||||
/// <remarks>
|
||||
/// Re-issue a new HTTP request with the previous request's headers and properities
|
||||
/// </remarks>
|
||||
internal static async Task<HttpRequestMessage> CloneAsync(this HttpRequestMessage originalRequest)
|
||||
{
|
||||
var newRequest = new HttpRequestMessage(originalRequest.Method, originalRequest.RequestUri);
|
||||
|
||||
// Copy request headers.
|
||||
foreach (var header in originalRequest.Headers)
|
||||
newRequest.Headers.TryAddWithoutValidation(header.Key, header.Value);
|
||||
|
||||
// Copy request properties.
|
||||
foreach (var property in originalRequest.Properties)
|
||||
newRequest.Properties.Add(property);
|
||||
|
||||
// Set Content if previous request had one.
|
||||
if (originalRequest.Content != null)
|
||||
{
|
||||
// HttpClient doesn't rewind streams and we have to explicitly do so.
|
||||
await originalRequest.Content.ReadAsStreamAsync().ContinueWith(t => {
|
||||
if (t.Result.CanSeek)
|
||||
t.Result.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
newRequest.Content = new StreamContent(t.Result);
|
||||
});
|
||||
|
||||
// Copy content headers.
|
||||
if (originalRequest.Content.Headers != null)
|
||||
foreach (var contentHeader in originalRequest.Content.Headers)
|
||||
newRequest.Content.Headers.TryAddWithoutValidation(contentHeader.Key, contentHeader.Value);
|
||||
}
|
||||
|
||||
return newRequest;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="GraphRequestContext"/> from <see cref="HttpRequestMessage"/>
|
||||
/// </summary>
|
||||
/// <param name="httpRequestMessage">The <see cref="HttpRequestMessage"/> representation of the request.</param>
|
||||
/// <returns></returns>
|
||||
public static GraphRequestContext GetRequestContext(this HttpRequestMessage httpRequestMessage)
|
||||
{
|
||||
GraphRequestContext requestContext = new GraphRequestContext();
|
||||
if (httpRequestMessage.Properties.TryGetValue(typeof(GraphRequestContext).ToString(), out var requestContextObject))
|
||||
{
|
||||
requestContext = (GraphRequestContext)requestContextObject;
|
||||
}
|
||||
return requestContext;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="IMiddlewareOption"/> from <see cref="HttpRequestMessage"/>
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="httpRequestMessage">The <see cref="HttpRequestMessage"/> representation of the request.</param>
|
||||
/// <returns>A middleware option</returns>
|
||||
public static T GetMiddlewareOption<T>(this HttpRequestMessage httpRequestMessage) where T : IMiddlewareOption
|
||||
{
|
||||
IMiddlewareOption option = null;
|
||||
GraphRequestContext requestContext = httpRequestMessage.GetRequestContext();
|
||||
if (requestContext.MiddlewareOptions != null)
|
||||
{
|
||||
requestContext.MiddlewareOptions.TryGetValue(typeof(T).ToString(), out option);
|
||||
}
|
||||
return (T)option;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
28
thirdparty/Microsoft.Graph.Core/Extensions/SerializerExtentions.cs
vendored
Normal file
28
thirdparty/Microsoft.Graph.Core/Extensions/SerializerExtentions.cs
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ISerializer"/>
|
||||
/// </summary>
|
||||
public static class SerializerExtentions
|
||||
{
|
||||
/// <summary>
|
||||
/// Serialize an object into a <see cref="HttpContent"/> object
|
||||
/// </summary>
|
||||
/// <param name="serializer"></param>
|
||||
/// <param name="source"></param>
|
||||
/// <returns></returns>
|
||||
public static HttpContent SerializeAsJsonContent(this ISerializer serializer, object source )
|
||||
{
|
||||
var stringContent = serializer.SerializeObject(source);
|
||||
return new StringContent(stringContent, Encoding.UTF8, "application/json");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
104
thirdparty/Microsoft.Graph.Core/Helpers/ExtractSelectHelper.cs
vendored
Normal file
104
thirdparty/Microsoft.Graph.Core/Helpers/ExtractSelectHelper.cs
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class to extract $select or $expand parameters from strongly-typed expressions.
|
||||
/// </summary>
|
||||
public static class ExpressionExtractHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Extract referenced members of the type T from the given expression as a list of strings
|
||||
/// </summary>
|
||||
/// <param name="expression">The expression to search</param>
|
||||
/// <param name="error">Message about what's wrong with the expression if return value is null</param>
|
||||
/// <returns>A comma-separated list of strings or null</returns>
|
||||
public static string ExtractMembers<T>(Expression<Func<T, object>> expression, out string error)
|
||||
{
|
||||
error = null;
|
||||
if (expression == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(expression));
|
||||
}
|
||||
|
||||
// Search s => s.Foo
|
||||
var memberExpression = expression.Body as MemberExpression;
|
||||
if (memberExpression != null)
|
||||
{
|
||||
return ProcessSimpleMemberExpression<T>(memberExpression, ref error);
|
||||
}
|
||||
|
||||
// Search s => s.BarFromBaseType
|
||||
// Property base type expressions introduce an intermediate conversion operator.
|
||||
var convertExpression = expression.Body as UnaryExpression;
|
||||
if (convertExpression?.NodeType == ExpressionType.Convert)
|
||||
{
|
||||
memberExpression = convertExpression.Operand as MemberExpression;
|
||||
if (memberExpression != null)
|
||||
{
|
||||
return ProcessSimpleMemberExpression<T>(memberExpression, ref error);
|
||||
}
|
||||
}
|
||||
|
||||
// Search s => new { [Foo = ]s.Foo, [bar = ]s.Bar }
|
||||
// We'd prefer not to support the variant with named anonymous type members, but the expression trees don't differentiate,
|
||||
// between implicit and explicit naming, so there's no way to throw an error.
|
||||
var newExpression = expression.Body as NewExpression;
|
||||
if (newExpression != null)
|
||||
{
|
||||
if (newExpression.Arguments == null || newExpression.Arguments.Count == 0)
|
||||
{
|
||||
error = "Lambda expression must provide initializer for new anonymous type.";
|
||||
return null;
|
||||
}
|
||||
if (newExpression.Arguments.Any(a =>
|
||||
{
|
||||
var memberArgument = a as MemberExpression;
|
||||
return memberArgument == null ||
|
||||
!(memberArgument.Expression is ParameterExpression) ||
|
||||
!memberArgument.Member.DeclaringType.GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo());
|
||||
}))
|
||||
{
|
||||
error = $"Anonymous type in lambda expression may only be initialized with direct members of type {typeof(T).Name}";
|
||||
return null;
|
||||
}
|
||||
|
||||
// Search only for direct members of the lambda's parameter
|
||||
// Should already be validated above, but doesn't hurt to be sure.
|
||||
var members = from m in newExpression.Arguments.OfType<MemberExpression>()
|
||||
where m.Expression is ParameterExpression && m.Member.DeclaringType.GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo())
|
||||
select GetMemberWireName(m.Member);
|
||||
return string.Join(",", members);
|
||||
}
|
||||
error = "Unrecognized lambda expression.";
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string ProcessSimpleMemberExpression<T>(MemberExpression memberExpression, ref string error)
|
||||
{
|
||||
if (!memberExpression.Member.DeclaringType.GetTypeInfo().IsAssignableFrom(typeof (T).GetTypeInfo()))
|
||||
{
|
||||
error = $"Anonymous type in lambda expression may only be initialized with direct members of type {typeof (T).Name}";
|
||||
return null;
|
||||
}
|
||||
return GetMemberWireName(memberExpression.Member);
|
||||
}
|
||||
|
||||
private static string GetMemberWireName(MemberInfo member)
|
||||
{
|
||||
var jsonProperty = member.GetCustomAttribute<Newtonsoft.Json.JsonPropertyAttribute>();
|
||||
if (jsonProperty != null && !string.IsNullOrWhiteSpace(jsonProperty.PropertyName))
|
||||
{
|
||||
return jsonProperty.PropertyName;
|
||||
}
|
||||
return StringHelper.ConvertIdentifierToLowerCamelCase(member.Name);
|
||||
}
|
||||
}
|
||||
}
|
138
thirdparty/Microsoft.Graph.Core/Helpers/ReadOnlySubStream.cs
vendored
Normal file
138
thirdparty/Microsoft.Graph.Core/Helpers/ReadOnlySubStream.cs
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ---------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Helper stream class to represent a slice of a larger stream to save memory when dealing with large streams
|
||||
/// and remove the extra copy operations
|
||||
/// This class is inspired from System.IO.Compression in dot net core. Reference implementation can be found here
|
||||
/// https://github.com/dotnet/corefx/blob/d59f6e5a1bdabdd05317fd727efb59345e328b80/src/System.IO.Compression/src/System/IO/Compression/ZipCustomStreams.cs#L147
|
||||
/// </summary>
|
||||
internal class ReadOnlySubStream : Stream
|
||||
{
|
||||
private readonly long _startInSuperStream;
|
||||
private long _positionInSuperStream;
|
||||
private readonly long _endInSuperStream;
|
||||
private readonly Stream _superStream;
|
||||
private bool _canRead;
|
||||
private bool _isDisposed;
|
||||
|
||||
public ReadOnlySubStream(Stream superStream, long startPosition, long maxLength)
|
||||
{
|
||||
this._startInSuperStream = startPosition;
|
||||
this._positionInSuperStream = startPosition;
|
||||
this._endInSuperStream = startPosition + maxLength;
|
||||
this._superStream = superStream;
|
||||
this._canRead = true;
|
||||
this._isDisposed = false;
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
return _endInSuperStream - _startInSuperStream;
|
||||
}
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
return _positionInSuperStream - _startInSuperStream;
|
||||
}
|
||||
set
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
throw new NotSupportedException("seek not support");
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanRead => _superStream.CanRead && _canRead;
|
||||
|
||||
public override bool CanSeek => false;
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
private void ThrowIfDisposed()
|
||||
{
|
||||
if (_isDisposed)
|
||||
throw new ObjectDisposedException(GetType().ToString(), nameof(this._superStream));
|
||||
}
|
||||
|
||||
private void ThrowIfCantRead()
|
||||
{
|
||||
if (!CanRead)
|
||||
throw new NotSupportedException("read not support");
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
// parameter validation sent to _superStream.Read
|
||||
int origCount = count;
|
||||
|
||||
ThrowIfDisposed();
|
||||
ThrowIfCantRead();
|
||||
|
||||
if (_superStream.Position != _positionInSuperStream)
|
||||
_superStream.Seek(_positionInSuperStream, SeekOrigin.Begin);
|
||||
if (_positionInSuperStream + count > _endInSuperStream)
|
||||
count = (int)(_endInSuperStream - _positionInSuperStream);
|
||||
|
||||
Debug.Assert(count >= 0);
|
||||
Debug.Assert(count <= origCount);
|
||||
|
||||
int ret = _superStream.Read(buffer, offset, count);
|
||||
|
||||
_positionInSuperStream += ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
throw new NotSupportedException("seek not support");
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
throw new NotSupportedException("seek and write not support");
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
throw new NotSupportedException("write not support");
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
throw new NotSupportedException("write not support");
|
||||
}
|
||||
|
||||
// Close the stream for reading. Note that this does NOT close the superStream (since
|
||||
// the subStream is just 'a chunk' of the super-stream
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && !_isDisposed)
|
||||
{
|
||||
_canRead = false;
|
||||
_isDisposed = true;
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
62
thirdparty/Microsoft.Graph.Core/Helpers/StringHelper.cs
vendored
Normal file
62
thirdparty/Microsoft.Graph.Core/Helpers/StringHelper.cs
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Linq;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for string casing.
|
||||
/// </summary>
|
||||
public static class StringHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts the type string to title case.
|
||||
/// </summary>
|
||||
/// <param name="typeString">The type string.</param>
|
||||
/// <returns>The converted string.</returns>
|
||||
public static string ConvertTypeToTitleCase(string typeString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(typeString))
|
||||
{
|
||||
var stringSegments = typeString.Split('.').Select(
|
||||
segment => string.Concat(segment.Substring(0, 1).ToUpperInvariant(), segment.Substring(1)));
|
||||
return string.Join(".", stringSegments);
|
||||
}
|
||||
|
||||
return typeString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the type string to lower camel case.
|
||||
/// </summary>
|
||||
/// <param name="typeString">The type string.</param>
|
||||
/// <returns>The converted string.</returns>
|
||||
public static string ConvertTypeToLowerCamelCase(string typeString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(typeString))
|
||||
{
|
||||
var stringSegments = typeString.Split('.').Select(
|
||||
segment => string.Concat(segment.Substring(0, 1).ToLowerInvariant(), segment.Substring(1)));
|
||||
return string.Join(".", stringSegments);
|
||||
}
|
||||
|
||||
return typeString;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the identifier string to lower camel case.
|
||||
/// </summary>
|
||||
/// <param name="identifierString">The identifier string.</param>
|
||||
/// <returns>The converted string.</returns>
|
||||
public static string ConvertIdentifierToLowerCamelCase(string identifierString)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(identifierString))
|
||||
{
|
||||
return string.Concat(identifierString.Substring(0, 1).ToLowerInvariant(), identifierString.Substring(1));
|
||||
}
|
||||
return identifierString;
|
||||
}
|
||||
}
|
||||
}
|
54
thirdparty/Microsoft.Graph.Core/Helpers/UrlHelper.cs
vendored
Normal file
54
thirdparty/Microsoft.Graph.Core/Helpers/UrlHelper.cs
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
|
||||
/// <summary>
|
||||
/// Helper class for working with URLs.
|
||||
/// </summary>
|
||||
public static class UrlHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Parse query options from the URL.
|
||||
/// </summary>
|
||||
/// <param name="resultUri"></param>
|
||||
/// <returns></returns>
|
||||
public static IDictionary<string, string> GetQueryOptions(Uri resultUri)
|
||||
{
|
||||
string[] queryParams = null;
|
||||
var queryValues = new Dictionary<string, string>();
|
||||
|
||||
int fragmentIndex = resultUri.AbsoluteUri.IndexOf("#", StringComparison.Ordinal);
|
||||
if (fragmentIndex > 0 && fragmentIndex < resultUri.AbsoluteUri.Length + 1)
|
||||
{
|
||||
queryParams = resultUri.AbsoluteUri.Substring(fragmentIndex + 1).Split('&');
|
||||
}
|
||||
else if (fragmentIndex < 0)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(resultUri.Query))
|
||||
{
|
||||
queryParams = resultUri.Query.TrimStart('?').Split('&');
|
||||
}
|
||||
}
|
||||
|
||||
if (queryParams != null)
|
||||
{
|
||||
foreach (var param in queryParams)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(param))
|
||||
{
|
||||
string[] kvp = param.Split('=');
|
||||
queryValues.Add(kvp[0], WebUtility.UrlDecode(kvp[1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return queryValues;
|
||||
}
|
||||
}
|
||||
}
|
21
thirdparty/Microsoft.Graph.Core/LICENSE.txt
vendored
Normal file
21
thirdparty/Microsoft.Graph.Core/LICENSE.txt
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Microsoft Corporation
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
33
thirdparty/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
vendored
Normal file
33
thirdparty/Microsoft.Graph.Core/Microsoft.Graph.Core.csproj
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft Graph Core Client Library implements core functionality used by Microsoft Graph client libraries.</Description>
|
||||
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
|
||||
<AssemblyTitle>Microsoft Graph Core Client Library</AssemblyTitle>
|
||||
<Authors>Microsoft</Authors>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<PreserveCompilationContext>false</PreserveCompilationContext>
|
||||
<AssemblyName>Microsoft.Graph.Core</AssemblyName>
|
||||
<PackageId>Microsoft.Graph.Core</PackageId>
|
||||
<PackageTags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</PackageTags>
|
||||
<PackageProjectUrl>https://developer.microsoft.com/graph</PackageProjectUrl>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
|
||||
<RepositoryUrl>https://github.com/microsoftgraph/msgraph-sdk-dotnet</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="System.Net.Http" Version="4.3.3" />
|
||||
<PackageReference Include="System.ValueTuple" Version="4.3.0" />
|
||||
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\LICENSE.txt">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>
|
||||
</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
23
thirdparty/Microsoft.Graph.Core/Microsoft.Graph.Core.nuspec
vendored
Normal file
23
thirdparty/Microsoft.Graph.Core/Microsoft.Graph.Core.nuspec
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>Microsoft.Graph.Core</id>
|
||||
<version>1.20.1.4</version>
|
||||
<title>Microsoft Graph Core Client Library</title>
|
||||
<authors>Microsoft</authors>
|
||||
<owners>Microsoft</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>Microsoft Graph Core Client Library implements core functionality used by Microsoft Graph client libraries.</description>
|
||||
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
|
||||
<projectUrl>https://developer.microsoft.com/graph</projectUrl>
|
||||
<license type="expression">MIT</license>
|
||||
<tags>Microsoft Office365;Graph;GraphServiceClient;Outlook;OneDrive;AzureAD;GraphAPI;Productivity;SharePoint;Intune;SDK</tags>
|
||||
<dependencies>
|
||||
<group>
|
||||
<dependency id="Newtonsoft.Json" version="12.0.3" />
|
||||
<dependency id="System.ValueTuple" version="4.5.0" />
|
||||
<dependency id="System.Diagnostics.DiagnosticSource" version="4.7.0" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
</package>
|
45
thirdparty/Microsoft.Graph.Core/Models/AsyncOperationStatus.cs
vendored
Normal file
45
thirdparty/Microsoft.Graph.Core/Models/AsyncOperationStatus.cs
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// The type AsyncOperationStatus.
|
||||
/// </summary>
|
||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
|
||||
[JsonConverter(typeof(DerivedTypeConverter))]
|
||||
public partial class AsyncOperationStatus
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets operation.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "operation", Required = Required.Default)]
|
||||
public string Operation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets percentageComplete.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "percentageComplete", Required = Required.Default)]
|
||||
public double? PercentageComplete { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets status.
|
||||
/// </summary>
|
||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "status", Required = Required.Default)]
|
||||
public string Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets additional data.
|
||||
/// </summary>
|
||||
[JsonExtensionData(ReadData = true)]
|
||||
public IDictionary<string, object> AdditionalData { get; set; }
|
||||
|
||||
}
|
||||
}
|
55
thirdparty/Microsoft.Graph.Core/Models/BatchRequestStep.cs
vendored
Normal file
55
thirdparty/Microsoft.Graph.Core/Models/BatchRequestStep.cs
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
|
||||
/// <summary>
|
||||
/// A single batch request step.
|
||||
/// </summary>
|
||||
public class BatchRequestStep
|
||||
{
|
||||
/// <summary>
|
||||
/// A unique batch request id property.
|
||||
/// </summary>
|
||||
public string RequestId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A http request message for an individual batch request operation.
|
||||
/// </summary>
|
||||
public HttpRequestMessage Request { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// An OPTIONAL array of batch request ids specifying the order of execution for individual batch requests.
|
||||
/// </summary>
|
||||
public List<string> DependsOn { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new <see cref="BatchRequestStep"/>.
|
||||
/// </summary>
|
||||
/// <param name="requestId">A unique batch request id.</param>
|
||||
/// <param name="httpRequestMessage">A http request message for an individual batch request operation.</param>
|
||||
/// <param name="dependsOn">An OPTIONAL array of batch request ids specifying the order of execution for individual batch requests.</param>
|
||||
public BatchRequestStep(string requestId, HttpRequestMessage httpRequestMessage, List<string> dependsOn = null)
|
||||
{
|
||||
RequestId = (!string.IsNullOrEmpty(requestId)) ? requestId : throw new ClientException(
|
||||
new Error
|
||||
{
|
||||
Code = ErrorConstants.Codes.InvalidArgument,
|
||||
Message = string.Format(ErrorConstants.Messages.NullParameter, nameof(requestId))
|
||||
});
|
||||
|
||||
Request = httpRequestMessage ?? throw new ClientException(new Error
|
||||
{
|
||||
Code = ErrorConstants.Codes.InvalidArgument,
|
||||
Message = string.Format(ErrorConstants.Messages.NullParameter, nameof(httpRequestMessage))
|
||||
});
|
||||
|
||||
DependsOn = dependsOn;
|
||||
}
|
||||
}
|
||||
}
|
160
thirdparty/Microsoft.Graph.Core/Models/CollectionPage.cs
vendored
Normal file
160
thirdparty/Microsoft.Graph.Core/Models/CollectionPage.cs
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// A page of results from a collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the item contained within the collection.</typeparam>
|
||||
public class CollectionPage<T> : ICollectionPage<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates the collection page.
|
||||
/// </summary>
|
||||
public CollectionPage()
|
||||
{
|
||||
this.CurrentPage = new List<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the collection page.
|
||||
/// </summary>
|
||||
/// <param name="currentPage">The current page.</param>
|
||||
public CollectionPage(IList<T> currentPage)
|
||||
{
|
||||
this.CurrentPage = currentPage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The current page.
|
||||
/// </summary>
|
||||
public IList<T> CurrentPage { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the index of an item in the current page.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to get the index for.</param>
|
||||
/// <returns></returns>
|
||||
public int IndexOf(T item)
|
||||
{
|
||||
return this.CurrentPage.IndexOf(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Insert an item into the current page.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to insert the item at.</param>
|
||||
/// <param name="item">The item to insert.</param>
|
||||
public void Insert(int index, T item)
|
||||
{
|
||||
this.CurrentPage.Insert(index, item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the item at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to remove an item at.</param>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
this.CurrentPage.RemoveAt(index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Access the item at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The item's index.</param>
|
||||
/// <returns>The item of type T.</returns>
|
||||
public T this[int index]
|
||||
{
|
||||
get { return this.CurrentPage[index]; }
|
||||
set { this.CurrentPage[index] = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an item to the current page.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to add.</param>
|
||||
public void Add(T item)
|
||||
{
|
||||
this.CurrentPage.Add(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove all items from the current page.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
this.CurrentPage.Clear();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Determine whether the current page contains the given item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to search for.</param>
|
||||
/// <returns>True if the item is found.</returns>
|
||||
public bool Contains(T item)
|
||||
{
|
||||
return this.CurrentPage.Contains(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the elements of the current page to the given array starting at the given index.
|
||||
/// </summary>
|
||||
/// <param name="array">The array to copy elements to.</param>
|
||||
/// <param name="arrayIndex">The start index.</param>
|
||||
public void CopyTo(T[] array, int arrayIndex)
|
||||
{
|
||||
this.CurrentPage.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of elements in the current page.
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return this.CurrentPage.Count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the current page is readonly.
|
||||
/// </summary>
|
||||
public bool IsReadOnly
|
||||
{
|
||||
get { return this.CurrentPage.IsReadOnly; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an item from the current page.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to remove.</param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(T item)
|
||||
{
|
||||
return this.CurrentPage.Remove(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates through the current page.
|
||||
/// </summary>
|
||||
/// <returns>The enumerator for the current page.</returns>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return this.CurrentPage.GetEnumerator();
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.CurrentPage.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The additional data property bag.
|
||||
/// </summary>
|
||||
public IDictionary<string, object> AdditionalData { get; set; }
|
||||
}
|
||||
}
|
84
thirdparty/Microsoft.Graph.Core/Models/Date.cs
vendored
Normal file
84
thirdparty/Microsoft.Graph.Core/Models/Date.cs
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
/// <summary>
|
||||
/// Custom Date model for serialization
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DateConverter))]
|
||||
public class Date
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal Date constructor
|
||||
/// </summary>
|
||||
/// <param name="dateTime"></param>
|
||||
internal Date(DateTime dateTime)
|
||||
{
|
||||
this.DateTime = dateTime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Date object from a year, month, and day.
|
||||
/// </summary>
|
||||
/// <param name="year">The year.</param>
|
||||
/// <param name="month">The month.</param>
|
||||
/// <param name="day">The day of the month.</param>
|
||||
public Date(int year, int month, int day)
|
||||
: this(new DateTime(year, month, day))
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The DateTime object.
|
||||
/// </summary>
|
||||
internal DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date's year.
|
||||
/// </summary>
|
||||
public int Year
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.DateTime.Year;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date's month.
|
||||
/// </summary>
|
||||
public int Month
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.DateTime.Month;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The date's day.
|
||||
/// </summary>
|
||||
public int Day
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.DateTime.Day;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the date to a string.
|
||||
/// </summary>
|
||||
/// <returns>The string value of the date in the format "yyyy-MM-dd".</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return this.DateTime.ToString("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
}
|
47
thirdparty/Microsoft.Graph.Core/Models/Duration.cs
vendored
Normal file
47
thirdparty/Microsoft.Graph.Core/Models/Duration.cs
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
/// <summary>
|
||||
/// Represents an edm.duration value.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(DurationConverter))]
|
||||
public class Duration
|
||||
{
|
||||
internal TimeSpan TimeSpan { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create a Duration object from a TimeSpan.
|
||||
/// </summary>
|
||||
/// <param name="timeSpan"></param>
|
||||
public Duration(TimeSpan timeSpan)
|
||||
{
|
||||
this.TimeSpan = timeSpan;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a Duration object from an ISO8601 duration.
|
||||
/// </summary>
|
||||
/// <param name="duration">An ISO8601 duration. http://en.wikipedia.org/wiki/ISO_8601#Durations </param>
|
||||
public Duration(string duration)
|
||||
{
|
||||
// Convert an ISO8601 duration to a TimeSpan.
|
||||
this.TimeSpan = XmlConvert.ToTimeSpan(duration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert the stored TimeSpan into an ISO8601 duration.
|
||||
/// </summary>
|
||||
/// <returns>An ISO8601 duration. For example, PT1M is "period time of 1 minute"</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return XmlConvert.ToString(this.TimeSpan);
|
||||
}
|
||||
}
|
||||
}
|
25
thirdparty/Microsoft.Graph.Core/Models/ICollectionPage.cs
vendored
Normal file
25
thirdparty/Microsoft.Graph.Core/Models/ICollectionPage.cs
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for collection pages.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the collection.</typeparam>
|
||||
public interface ICollectionPage<T> : IList<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// The current page of the collection.
|
||||
/// </summary>
|
||||
IList<T> CurrentPage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The additional data property bag.
|
||||
/// </summary>
|
||||
IDictionary<string, object> AdditionalData { get; set; }
|
||||
}
|
||||
}
|
31
thirdparty/Microsoft.Graph.Core/Models/IUploadSession.cs
vendored
Normal file
31
thirdparty/Microsoft.Graph.Core/Models/IUploadSession.cs
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
// ------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Microsoft.Graph
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// The IUploadSession interface
|
||||
/// </summary>
|
||||
public interface IUploadSession
|
||||
{
|
||||
/// <summary>
|
||||
/// Expiration date of the upload session
|
||||
/// </summary>
|
||||
DateTimeOffset? ExpirationDateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ranges yet to be uploaded to the server
|
||||
/// </summary>
|
||||
IEnumerable<string> NextExpectedRanges { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL for upload
|
||||
/// </summary>
|
||||
string UploadUrl { get; set; }
|
||||
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user