Skip to content

Commit

Permalink
Add Segment Analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
FacuMasino committed Mar 18, 2024
1 parent 2356cac commit 03ddae8
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 11 deletions.
14 changes: 13 additions & 1 deletion ImprimirPolizas/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.3" newVersion="7.0.0.3" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
80 changes: 79 additions & 1 deletion ImprimirPolizas/ImprimirPolizas.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@
<Reference Include="BouncyCastle.Crypto, Version=1.8.9.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\packages\BouncyCastle.1.8.9\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Coroutine.NET, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Coroutine.NET.1.4.0\lib\netstandard2.0\Coroutine.NET.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.0.0\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.WebView2.Core, Version=1.0.1823.32, Culture=neutral, PublicKeyToken=2a8ab48044d2601e, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.WebView2.1.0.1823.32\lib\net45\Microsoft.Web.WebView2.Core.dll</HintPath>
</Reference>
Expand All @@ -90,19 +99,88 @@
<HintPath>..\packages\PdfiumViewer.2.13.0.0\lib\net20\PdfiumViewer.dll</HintPath>
</Reference>
<Reference Include="PresentationFramework" />
<Reference Include="Segment.Analytics.CSharp, Version=2.3.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Segment.Analytics.CSharp.2.3.4\lib\netstandard2.0\Segment.Analytics.CSharp.dll</HintPath>
</Reference>
<Reference Include="Serialization.NET, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Serialization.NET.1.4.0\lib\netstandard2.0\Serialization.NET.dll</HintPath>
</Reference>
<Reference Include="Sovran.NET, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Sovran.NET.1.4.0\lib\netstandard2.0\Sovran.NET.dll</HintPath>
</Reference>
<Reference Include="System">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll</HintPath>
</Reference>
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
<Reference Include="System.IO, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.IO.4.3.0\lib\net462\System.IO.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http, Version=4.1.1.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Encoding, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.Primitives, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Security.Cryptography.X509Certificates, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll</HintPath>
<Private>True</Private>
<Private>True</Private>
</Reference>
<Reference Include="System.Text.Encodings.Web, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll</HintPath>
</Reference>
<Reference Include="System.Text.Json, Version=7.0.0.3, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.7.0.3\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
Expand Down
4 changes: 2 additions & 2 deletions ImprimirPolizas/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.2.0")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyVersion("1.1.3.0")]
[assembly: AssemblyFileVersion("1.1.3.0")]
6 changes: 3 additions & 3 deletions ImprimirPolizas/ScTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum DownloadOpt
policy = 1,
policyCard = 2,
paymentTC = 3,
paymentProof = 5,
paymentReceipt = 5,
coupons = 6,
invoice = 7,
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public static string GetFileName(string pcNumber, DownloadOpt opt)
case DownloadOpt.policy:
fileName += "FrentePoliza.pdf";
break;
case DownloadOpt.paymentProof:
case DownloadOpt.paymentReceipt:
fileName += "ComprobantePago.pdf";
break;
case DownloadOpt.policyCard:
Expand Down Expand Up @@ -146,7 +146,7 @@ public static string GetOptionName(DownloadOpt opt)
{
case ScTools.DownloadOpt.policy:
return "Frente de póliza";
case ScTools.DownloadOpt.paymentProof:
case ScTools.DownloadOpt.paymentReceipt:
return "Comprobante de pago";
case ScTools.DownloadOpt.policyCard:
return "Tarjeta Seguro Obligatorio";
Expand Down
52 changes: 50 additions & 2 deletions ImprimirPolizas/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using PdfiumViewer;
using Segment.Analytics;
using Segment.Serialization;
using static ImprimirPolizas.ScTools;

namespace ImprimirPolizas
{
Expand All @@ -21,6 +25,10 @@ private enum IconState
Ready = 1,
Error = 2,
}
static readonly Configuration SegmentConfig = new Configuration("3agF8DVa82eZaBk1GYxaiYqhAi2f9fv1",
flushAt: 20,
flushInterval: 30);
Analytics analytics = new Analytics(SegmentConfig);

public frmMain()
{
Expand All @@ -29,6 +37,7 @@ public frmMain()

private void Form1_Load(object sender, EventArgs e)
{
analytics.Track("app_open");
EnableWhenReady(); // Verificar disponibilidad servidor
// Habilitar opciones iniciales
options[0] = (int)ScTools.DownloadOpt.policy;
Expand Down Expand Up @@ -225,6 +234,7 @@ private async void BtnPrint_Click(object sender, EventArgs e)
SetIconStatus(opt, IconState.Ready);
// Se actualizan las estadísticas pero sin esperar respuesta
_ = ScTools.UpdateStats(opt == ScTools.DownloadOpt.policy, rbPrint.Checked);
TrackAction(opt, rbPrint.Checked); // Send Analytics
}
catch (Exception ex)
{
Expand Down Expand Up @@ -268,7 +278,7 @@ private void SetIconStatus(ScTools.DownloadOpt opt, IconState icon)
case ScTools.DownloadOpt.policyCard:
pbCard.Image = img;
break;
case ScTools.DownloadOpt.paymentProof:
case ScTools.DownloadOpt.paymentReceipt:
pbPayment.Image = img;
break;
case ScTools.DownloadOpt.coupons:
Expand Down Expand Up @@ -362,7 +372,7 @@ private void ChkPaymentProof_CheckedChanged(object sender, EventArgs e)
EnableBtnPrint();
if (chkPaymentProof.Checked)
{
options[2] = (int)ScTools.DownloadOpt.paymentProof;
options[2] = (int)ScTools.DownloadOpt.paymentReceipt;
}
else
{
Expand Down Expand Up @@ -416,6 +426,7 @@ private void FrmMain_FormClosed(object sender, FormClosedEventArgs e)

private void LnkDownloads_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
analytics.Track("btn_download_click");
OpenDownloadsFolder();
}

Expand Down Expand Up @@ -445,5 +456,42 @@ private void chkInvoice_CheckedChanged(object sender, EventArgs e)
}
}

private void TrackAction(ScTools.DownloadOpt opt, bool isPrinting)
{
string eventName = isPrinting ? "print_" : "download_";
eventName += GetDocName(opt);
analytics.Track(eventName, new JsonObject
{
["document"] = GetDocName(opt),
});
}

private string GetDocName(ScTools.DownloadOpt opt)
{
string docName;
switch (opt)
{
case DownloadOpt.policy:
docName = "policy";
break;
case DownloadOpt.paymentReceipt:
docName = "paymentReceipt";
break;
case DownloadOpt.policyCard:
docName = "policyCard";
break;
case DownloadOpt.coupons:
docName = "coupons";
break;
case DownloadOpt.invoice:
docName = "invoice";
break;
default:
docName = "unknown";
break;
}
return docName;
}

}
}
21 changes: 21 additions & 0 deletions ImprimirPolizas/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,30 @@
<packages>
<package id="Autoupdater.NET.Official" version="1.8.4" targetFramework="net48" />
<package id="BouncyCastle" version="1.8.9" targetFramework="net48" />
<package id="Coroutine.NET" version="1.4.0" targetFramework="net48" />
<package id="Microsoft.Bcl.AsyncInterfaces" version="7.0.0" targetFramework="net48" />
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0" targetFramework="net48" />
<package id="Microsoft.Web.WebView2" version="1.0.1823.32" targetFramework="net48" />
<package id="Newtonsoft.Json" version="13.0.3" targetFramework="net48" />
<package id="PdfiumViewer" version="2.13.0.0" targetFramework="net48" />
<package id="PdfiumViewer.Native.x86.v8-xfa" version="2018.4.8.256" targetFramework="net48" />
<package id="PdfiumViewer.Native.x86_64.v8-xfa" version="2018.4.8.256" targetFramework="net48" />
<package id="Segment.Analytics.CSharp" version="2.3.4" targetFramework="net48" />
<package id="Serialization.NET" version="1.4.0" targetFramework="net48" />
<package id="Sovran.NET" version="1.4.0" targetFramework="net48" />
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
<package id="System.IO" version="4.3.0" targetFramework="net48" />
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
<package id="System.Net.Http" version="4.3.4" targetFramework="net48" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
<package id="System.Runtime" version="4.3.0" targetFramework="net48" />
<package id="System.Runtime.CompilerServices.Unsafe" version="6.0.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Algorithms" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Encoding" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.Primitives" version="4.3.0" targetFramework="net48" />
<package id="System.Security.Cryptography.X509Certificates" version="4.3.0" targetFramework="net48" />
<package id="System.Text.Encodings.Web" version="7.0.0" targetFramework="net48" />
<package id="System.Text.Json" version="7.0.3" targetFramework="net48" />
<package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net48" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
</packages>
4 changes: 2 additions & 2 deletions autoupdater.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>1.1.2.0</version>
<url>https://github.com/FacuMasino/imprimir-polizas-utility/releases/download/v1.1.2/ImprimirPolizasV1.1.2.zip</url>
<version>1.1.3.0</version>
<url>https://github.com/FacuMasino/imprimir-polizas-utility/releases/download/v1.1.3/ImprimirPolizasV1.1.3.zip</url>
<mandatory mode="2">true</mandatory>
</item>

0 comments on commit 03ddae8

Please sign in to comment.