Merge branch 'feature/docspace-backup' of github.com:ONLYOFFICE/AppServer into feature/docspace-backup

This commit is contained in:
Tatiana Lopaeva 2022-07-29 09:24:25 +03:00
commit 27b7da5977
3 changed files with 44 additions and 18 deletions

View File

@ -29,6 +29,10 @@ namespace ASC.Data.Backup.Core.IntegrationEvents.Events;
[ProtoContract]
public record BackupRestoreRequestIntegrationEvent : IntegrationEvent
{
private BackupRestoreRequestIntegrationEvent() : base()
{
StorageParams = new Dictionary<string, string>();
}
public BackupRestoreRequestIntegrationEvent(BackupStorageType storageType,
int tenantId,
Guid createBy,

View File

@ -51,7 +51,7 @@
namespace ASC.Data.Backup.Services;
[Transient]
[Transient(Additional = typeof(RestoreProgressItemExtention))]
public class RestoreProgressItem : BaseBackupProgressItem
{
private readonly IConfiguration _configuration;
@ -238,3 +238,11 @@ public class RestoreProgressItem : BaseBackupProgressItem
return MemberwiseClone();
}
}
public static class RestoreProgressItemExtention
{
public static void Register(DIHelper services)
{
services.TryAdd<RestorePortalTask>();
}
}

View File

@ -26,19 +26,37 @@
#nullable enable
using System.Reflection;
namespace ASC.EventBus.Serializers;
public class ProtobufSerializer : IIntegrationEventSerializer
{
private readonly SynchronizedCollection<string> _processedProtoTypes;
private readonly int _baseFieldNumber;
private int _baseFieldNumber;
public ProtobufSerializer()
{
_processedProtoTypes = new SynchronizedCollection<string>();
_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/>
public byte[] Serialize<T>(T? item)
{
@ -47,8 +65,6 @@ public class ProtobufSerializer : IIntegrationEventSerializer
return Array.Empty<byte>();
}
ProcessProtoType(item.GetType());
using var ms = new MemoryStream();
Serializer.Serialize(ms, item);
@ -59,8 +75,6 @@ public class ProtobufSerializer : IIntegrationEventSerializer
/// <inheritdoc/>
public T Deserialize<T>(byte[] serializedObject)
{
ProcessProtoType(typeof(T));
using var ms = new MemoryStream(serializedObject);
return Serializer.Deserialize<T>(ms);
@ -69,8 +83,6 @@ public class ProtobufSerializer : IIntegrationEventSerializer
/// <inheritdoc/>
public object Deserialize(byte[] serializedObject, Type returnType)
{
ProcessProtoType(returnType);
using var ms = new MemoryStream(serializedObject);
return Serializer.Deserialize(returnType, ms);
@ -83,7 +95,7 @@ public class ProtobufSerializer : IIntegrationEventSerializer
return;
}
if (protoType.BaseType == null && protoType.BaseType == typeof(object))
if (protoType.BaseType == null || protoType.BaseType == typeof(object))
{
return;
}
@ -95,9 +107,11 @@ public class ProtobufSerializer : IIntegrationEventSerializer
if (!baseType.GetSubtypes().Any(s => s.DerivedType == itemType))
{
baseType.AddSubType(_baseFieldNumber, protoType);
}
_processedProtoTypes.Add(protoType.FullName);
_baseFieldNumber++;
_processedProtoTypes.Add(protoType.FullName);
}
}
}