Merge branch 'feature/docspace-backup' of github.com:ONLYOFFICE/AppServer into feature/docspace-backup
This commit is contained in:
commit
27b7da5977
@ -28,7 +28,11 @@ namespace ASC.Data.Backup.Core.IntegrationEvents.Events;
|
|||||||
|
|
||||||
[ProtoContract]
|
[ProtoContract]
|
||||||
public record BackupRestoreRequestIntegrationEvent : IntegrationEvent
|
public record BackupRestoreRequestIntegrationEvent : IntegrationEvent
|
||||||
{
|
{
|
||||||
|
private BackupRestoreRequestIntegrationEvent() : base()
|
||||||
|
{
|
||||||
|
StorageParams = new Dictionary<string, string>();
|
||||||
|
}
|
||||||
public BackupRestoreRequestIntegrationEvent(BackupStorageType storageType,
|
public BackupRestoreRequestIntegrationEvent(BackupStorageType storageType,
|
||||||
int tenantId,
|
int tenantId,
|
||||||
Guid createBy,
|
Guid createBy,
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
|
|
||||||
namespace ASC.Data.Backup.Services;
|
namespace ASC.Data.Backup.Services;
|
||||||
|
|
||||||
[Transient]
|
[Transient(Additional = typeof(RestoreProgressItemExtention))]
|
||||||
public class RestoreProgressItem : BaseBackupProgressItem
|
public class RestoreProgressItem : BaseBackupProgressItem
|
||||||
{
|
{
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
@ -237,4 +237,12 @@ public class RestoreProgressItem : BaseBackupProgressItem
|
|||||||
{
|
{
|
||||||
return MemberwiseClone();
|
return MemberwiseClone();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class RestoreProgressItemExtention
|
||||||
|
{
|
||||||
|
public static void Register(DIHelper services)
|
||||||
|
{
|
||||||
|
services.TryAdd<RestorePortalTask>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,37 @@
|
|||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace ASC.EventBus.Serializers;
|
namespace ASC.EventBus.Serializers;
|
||||||
|
|
||||||
public class ProtobufSerializer : IIntegrationEventSerializer
|
public class ProtobufSerializer : IIntegrationEventSerializer
|
||||||
{
|
{
|
||||||
private readonly SynchronizedCollection<string> _processedProtoTypes;
|
private readonly SynchronizedCollection<string> _processedProtoTypes;
|
||||||
private readonly int _baseFieldNumber;
|
private int _baseFieldNumber;
|
||||||
|
|
||||||
public ProtobufSerializer()
|
public ProtobufSerializer()
|
||||||
{
|
{
|
||||||
_processedProtoTypes = new SynchronizedCollection<string>();
|
_processedProtoTypes = new SynchronizedCollection<string>();
|
||||||
_baseFieldNumber = 100;
|
_baseFieldNumber = 100;
|
||||||
}
|
|
||||||
|
Array.ForEach(AppDomain.CurrentDomain.GetAssemblies(), a => BuildTypeModelFromAssembly(a));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildTypeModelFromAssembly(Assembly assembly)
|
||||||
|
{
|
||||||
|
if (!assembly.GetName().Name.StartsWith("ASC.")) return;
|
||||||
|
|
||||||
|
var types = assembly.GetExportedTypes()
|
||||||
|
.Where(t => t.GetCustomAttributes<ProtoContractAttribute>().Any());
|
||||||
|
|
||||||
|
foreach (var type in types)
|
||||||
|
{
|
||||||
|
ProcessProtoType(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public byte[] Serialize<T>(T? item)
|
public byte[] Serialize<T>(T? item)
|
||||||
{
|
{
|
||||||
@ -46,9 +64,7 @@ public class ProtobufSerializer : IIntegrationEventSerializer
|
|||||||
{
|
{
|
||||||
return Array.Empty<byte>();
|
return Array.Empty<byte>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessProtoType(item.GetType());
|
|
||||||
|
|
||||||
using var ms = new MemoryStream();
|
using var ms = new MemoryStream();
|
||||||
|
|
||||||
Serializer.Serialize(ms, item);
|
Serializer.Serialize(ms, item);
|
||||||
@ -58,9 +74,7 @@ public class ProtobufSerializer : IIntegrationEventSerializer
|
|||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public T Deserialize<T>(byte[] serializedObject)
|
public T Deserialize<T>(byte[] serializedObject)
|
||||||
{
|
{
|
||||||
ProcessProtoType(typeof(T));
|
|
||||||
|
|
||||||
using var ms = new MemoryStream(serializedObject);
|
using var ms = new MemoryStream(serializedObject);
|
||||||
|
|
||||||
return Serializer.Deserialize<T>(ms);
|
return Serializer.Deserialize<T>(ms);
|
||||||
@ -69,8 +83,6 @@ public class ProtobufSerializer : IIntegrationEventSerializer
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public object Deserialize(byte[] serializedObject, Type returnType)
|
public object Deserialize(byte[] serializedObject, Type returnType)
|
||||||
{
|
{
|
||||||
ProcessProtoType(returnType);
|
|
||||||
|
|
||||||
using var ms = new MemoryStream(serializedObject);
|
using var ms = new MemoryStream(serializedObject);
|
||||||
|
|
||||||
return Serializer.Deserialize(returnType, ms);
|
return Serializer.Deserialize(returnType, ms);
|
||||||
@ -83,7 +95,7 @@ public class ProtobufSerializer : IIntegrationEventSerializer
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (protoType.BaseType == null && protoType.BaseType == typeof(object))
|
if (protoType.BaseType == null || protoType.BaseType == typeof(object))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -95,9 +107,11 @@ public class ProtobufSerializer : IIntegrationEventSerializer
|
|||||||
if (!baseType.GetSubtypes().Any(s => s.DerivedType == itemType))
|
if (!baseType.GetSubtypes().Any(s => s.DerivedType == itemType))
|
||||||
{
|
{
|
||||||
baseType.AddSubType(_baseFieldNumber, protoType);
|
baseType.AddSubType(_baseFieldNumber, protoType);
|
||||||
|
|
||||||
|
_baseFieldNumber++;
|
||||||
|
|
||||||
|
_processedProtoTypes.Add(protoType.FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
_processedProtoTypes.Add(protoType.FullName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user