Skip to content

Commit

Permalink
* sync 8/31/2022 version: 2022.2.18
Browse files Browse the repository at this point in the history
  • Loading branch information
FastReports-bot committed Aug 31, 2022
1 parent 5febefc commit 67fb60b
Show file tree
Hide file tree
Showing 17 changed files with 440 additions and 103 deletions.
6 changes: 6 additions & 0 deletions FastReport.Base/BandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,12 @@ internal void FixHeightWithComponentsShift(float deltaY)
}
}

/// <inheritdoc/>
public override List<ValidationError> Validate()
{
return new List<ValidationError>();
}

/// <inheritdoc/>
public override void Serialize(FRWriter writer)
{
Expand Down
19 changes: 16 additions & 3 deletions FastReport.Base/Barcode/BarcodeDatamatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,15 @@ private void Draw(byte[] data, int dataSize, DmParams dm)

private static void MakePadding(byte[] data, int position, int count)
{
// set to ascii mode
if ((count > 0) && (position > 0))
{
if (data[position - 1] != 254)
data[position] = 254;
position++;
count--;
}

//already in ascii mode
if (count <= 0)
return;
Expand Down Expand Up @@ -733,7 +742,7 @@ private static int C40OrTextEncodation(byte[] text, int textOffset, int textLeng
ptrIn = last0;
encPtr = last1;
}
if (encPtr / 3 * 2 > dataLength - 2)
if (encPtr / 3 * 2 > dataLength - 1)
{
return -1;
}
Expand All @@ -744,8 +753,12 @@ private static int C40OrTextEncodation(byte[] text, int textOffset, int textLeng
data[dataOffset + ptrOut++] = (byte)(a / 256);
data[dataOffset + ptrOut++] = (byte)a;
}
data[ptrOut++] = (byte)254;
i = AsciiEncodation(text, ptrIn, textLength - ptrIn, data, ptrOut, dataLength - ptrOut);
i = 0;
if (textLength - ptrIn > 0)
{
data[ptrOut++] = (byte)254;
i = AsciiEncodation(text, ptrIn, textLength - ptrIn, data, ptrOut, dataLength - ptrOut);
}
if (i < 0)
return i;
return ptrOut + i;
Expand Down
10 changes: 10 additions & 0 deletions FastReport.Base/Data/JsonConnection/JsonDataSourceConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public partial class JsonDataSourceConnection : DataConnectionBase
private JsonArray jsonInternal = null;
private JsonSchema jsonSchema = null;
private string jsonSchemaString = "";
private bool simpleStructure;

#endregion Private Fields

Expand All @@ -53,6 +54,14 @@ internal JsonSchema JsonSchema
}
}

internal bool SimpleStructure
{
get
{
return simpleStructure;
}
}

#endregion Internal Properties

#region Public Constructors
Expand Down Expand Up @@ -182,6 +191,7 @@ private void InitConnection()
private void InitConnection(bool rebuildSchema)
{
JsonDataSourceConnectionStringBuilder builder = new JsonDataSourceConnectionStringBuilder(ConnectionString);
simpleStructure = builder.SimpleStructure;
JsonBase obj = null;
string jsonText = builder.Json.Trim();
if (jsonText.Length > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public string JsonSchema
}
}



/// <summary>
/// Gets or sets json url encoding
/// </summary>
Expand All @@ -85,7 +87,102 @@ public string Encoding
}
}

public Dictionary<string, string> Headers { get; set; }
/// <summary>
/// Set or get headers of the connection string.
///
/// </summary>
/// <remarks>
/// Returns copy of dictionary. If you need to update values, set the dictionary again!
/// </remarks>
public Dictionary<string, string> Headers
{
get
{
var numberformat = CultureInfo.InvariantCulture.NumberFormat;
Dictionary<string, string> headers = new Dictionary<string, string>();
object result;
string header = string.Empty;
string[] splittedHeader;
int headerIteration = 0;
while (TryGetValue("Header" + headerIteration.ToString(numberformat), out result) && result != null)
{
header = (string)result;

if (!string.IsNullOrWhiteSpace(header))
{
splittedHeader = header.Split(':');

string headerKey = splittedHeader[0], headerVal = splittedHeader[1];

if (Regex.IsMatch(headerKey, @"^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$"))
{
var base64str = Convert.FromBase64String(headerKey);
headerKey = System.Text.Encoding.UTF8.GetString(base64str);
}

if (Regex.IsMatch(headerVal, @"^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$"))
{
var base64str = Convert.FromBase64String(headerVal);
headerVal = System.Text.Encoding.UTF8.GetString(base64str);
}

headers[headerKey] = headerVal;
}
headerIteration++;
}
return headers;
}
set
{
var numberformat = CultureInfo.InvariantCulture.NumberFormat;
int headerIteration = 0;

while (Remove("Header" + headerIteration.ToString(numberformat)))
{
headerIteration++;
}

if (value != null)
{
headerIteration = 0;
foreach (var header in value)
{
var headerKey = header.Key;
var headerVal = header.Value;
if (headerKey.Contains(":"))
{
headerKey = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(headerKey));
}

if (headerVal.Contains(":"))
{
headerVal = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(headerVal));
}

base["Header" + headerIteration.ToString(numberformat)] = headerKey + ":" + headerVal;
headerIteration++;
}
}
}
}

/// <summary>
/// Gets or sets simple structure value
/// </summary>
public bool SimpleStructure
{
get
{
object result;
if (TryGetValue("SimpleStructure", out result) && result != null)
return result.ToString().ToLower() == "true";
return false;
}
set
{
base["SimpleStructure"] = value ? "true" : "false";
}
}



Expand All @@ -99,7 +196,6 @@ public string Encoding
public JsonDataSourceConnectionStringBuilder()
{
ConnectionString = "";
Headers = new Dictionary<string, string>();
}

/// <summary>
Expand All @@ -111,76 +207,8 @@ public JsonDataSourceConnectionStringBuilder(string connectionString)
: base()
{
ConnectionString = connectionString;
Headers = new Dictionary<string, string>();
//while (ConnectionString.Contains("Header="))
//{
object result;
string header = string.Empty;
string[] splittedHeader;
int headerIteration = 0;
while (TryGetValue("Header" + headerIteration.ToString(CultureInfo.InvariantCulture.NumberFormat), out result) && result != null)
{
header = (string)result;

if (!string.IsNullOrWhiteSpace(header))
{
splittedHeader = header.Split(':');

string headerKey = splittedHeader[0], headerVal = splittedHeader[1];

if (Regex.IsMatch(headerKey, @"^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$"))
{
var base64str = Convert.FromBase64String(headerKey);
headerKey = System.Text.Encoding.UTF8.GetString(base64str);
}

if (Regex.IsMatch(headerVal, @"^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)?$"))
{
var base64str = Convert.FromBase64String(headerVal);
headerVal = System.Text.Encoding.UTF8.GetString(base64str);
}

Headers.Add(headerKey, headerVal);
//ConnectionString = ConnectionString.Replace(header, string.Empty);
}

headerIteration++;
}
//}
}

#endregion Public Constructors

// escape / ; " :
public override string ToString()
{
//TODO: do via stringbuilder
//string connString = $"Json={Json};JsonSchema={JsonSchema};Encoding={Encoding}";
StringBuilder builder = new StringBuilder();
builder.Append("Json=").Append(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Json)))
.Append(";JsonSchema=").Append(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonSchema)))
.Append(";Encoding=").Append(Encoding);
//string connString = "Json=" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Json))
// + ";JsonSchema=" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(JsonSchema)) + ";Encoding=" + Encoding;
int headerIteration = 0;
foreach (var header in Headers)
{
var headerKey = header.Key;
var headerVal = header.Value;
if (headerKey.Contains(";") || headerKey.Contains(":") || headerKey.Contains("\"") || headerKey.Contains("\'"))
{
headerKey = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(headerKey));
}

if (headerVal.Contains(";") || headerVal.Contains(":") || headerVal.Contains("\"") || headerVal.Contains("\'"))
{
headerVal = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(headerVal));
}

builder.Append(";Header").Append(headerIteration.ToString(CultureInfo.InvariantCulture.NumberFormat)).Append("=").Append(headerKey).Append(":").Append(headerVal);
//connString += ";Header" + headerIteration + "=" + headerKey + ":" + headerVal;
}
return builder.ToString();
}
}
}
Loading

0 comments on commit 67fb60b

Please sign in to comment.