Skip to content

Commit d0301f0

Browse files
authored
Add files via upload
1 parent f94f39b commit d0301f0

11 files changed

Lines changed: 5468 additions & 0 deletions
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
namespace QRCodeCustomAPIs.Plugins
2+
{
3+
public abstract class AbstractQRCode
4+
{
5+
protected QRCodeData QrCodeData { get; set; }
6+
7+
protected AbstractQRCode()
8+
{
9+
}
10+
11+
protected AbstractQRCode(QRCodeData data)
12+
{
13+
QrCodeData = data;
14+
}
15+
16+
/// <summary>
17+
/// Set a QRCodeData object that will be used to generate QR code. Used in COM Objects connections
18+
/// </summary>
19+
/// <param name="data">Need a QRCodeData object generated by QRCodeGenerator.CreateQrCode()</param>
20+
virtual public void SetQRCodeData(QRCodeData data)
21+
{
22+
QrCodeData = data;
23+
}
24+
25+
public void Dispose()
26+
{
27+
QrCodeData?.Dispose();
28+
QrCodeData = null;
29+
}
30+
}
31+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
3+
namespace QRCodeCustomAPIs.Plugins
4+
{
5+
public class DataTooLongException : Exception
6+
{
7+
public DataTooLongException(string eccLevel, string encodingMode, int maxSizeByte) : base(
8+
$"The given payload exceeds the maximum size of the QR code standard. The maximum size allowed for the choosen paramters (ECC level={eccLevel}, EncodingMode={encodingMode}) is {maxSizeByte} byte."
9+
)
10+
{ }
11+
12+
public DataTooLongException(string eccLevel, string encodingMode, int version, int maxSizeByte) : base(
13+
$"The given payload exceeds the maximum size of the QR code standard. The maximum size allowed for the choosen paramters (ECC level={eccLevel}, EncodingMode={encodingMode}, FixedVersion={version}) is {maxSizeByte} byte."
14+
)
15+
{ }
16+
}
17+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.Xrm.Sdk;
2+
using System;
3+
using static QRCodeCustomAPIs.Plugins.PayloadGenerator;
4+
5+
namespace QRCodeCustomAPIs.Plugins
6+
{
7+
public class GenerateQRCodeUrl : IPlugin
8+
{
9+
public void Execute(IServiceProvider serviceProvider)
10+
{
11+
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
12+
string url = context.InputParameters["Url"] as string;
13+
bool success = false;
14+
string base64Result = "";
15+
try
16+
{
17+
QRCodeGenerator qrGenerator = new QRCodeGenerator();
18+
Url payloadUrl = new Url(url);
19+
QRCodeData qrCodeData = qrGenerator.CreateQrCode(payloadUrl);
20+
PngByteQRCode png = new PngByteQRCode(qrCodeData);
21+
byte[] byteResult = png.GetGraphic(20);
22+
base64Result = Convert.ToBase64String(byteResult);
23+
success = true;
24+
}
25+
catch { }
26+
context.OutputParameters["Success"] = success;
27+
context.OutputParameters["Base64Result"] = base64Result;
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)