Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,4 @@ src/designer/elsa-workflows-studio/loader
# Created by developers using GNU/Linux
.directory
launchSettings.json
/src/persistence/Elsa.Persistence.EntityFramework/Elsa.Persistence.EntityFramework.Core/Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO.Compression;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoMapper;
Expand Down Expand Up @@ -90,8 +93,9 @@ protected override void OnSaving(ElsaContext dbContext, WorkflowInstance entity)
};

var json = _contentSerializer.Serialize(data);
string compressed = Compress(json);

dbContext.Entry(entity).Property("Data").CurrentValue = json;
dbContext.Entry(entity).Property("Data").CurrentValue = compressed;
}

protected override void OnLoading(ElsaContext dbContext, WorkflowInstance entity)
Expand All @@ -111,7 +115,20 @@ protected override void OnLoading(ElsaContext dbContext, WorkflowInstance entity
entity.CurrentActivity
};

var json = (string)dbContext.Entry(entity).Property("Data").CurrentValue;
var jsonValue = (string)dbContext.Entry(entity).Property("Data").CurrentValue;
string json = "";

if (!string.IsNullOrEmpty(jsonValue))
{
if (jsonValue.StartsWith("{"))
{
json = jsonValue;
}
else
{
json = Decompress(jsonValue);
}
}

if (!string.IsNullOrWhiteSpace(json))
{
Expand All @@ -137,5 +154,46 @@ protected override void OnLoading(ElsaContext dbContext, WorkflowInstance entity
entity.Faults = data.Faults;
entity.CurrentActivity = data.CurrentActivity;
}

public static string Decompress(string input)
{
byte[] compressed = Convert.FromBase64String(input);
byte[] decompressed = Decompress(compressed);
return Encoding.UTF8.GetString(decompressed);
}

public static string Compress(string input)
{
byte[] encoded = Encoding.UTF8.GetBytes(input);
byte[] compressed = Compress(encoded);
return Convert.ToBase64String(compressed);
}

public static byte[] Decompress(byte[] input)
{
using (var memoryStream = new MemoryStream(input))
{
using (var outputStream = new MemoryStream())
{
using (var decompressStream = new GZipStream(memoryStream, CompressionMode.Decompress))
{
decompressStream.CopyTo(outputStream);
}
return outputStream.ToArray();
}
}
}

public static byte[] Compress(byte[] input)
{
using (var memoryStream = new MemoryStream())
{
using (var gzipStream = new GZipStream(memoryStream, CompressionLevel.Optimal))
{
gzipStream.Write(input, 0, input.Length);
}
return memoryStream.ToArray();
}
}
}
}
Loading