diff --git a/.vscode/launch.json b/.vscode/launch.json index a757ce1..b01b2a3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -34,6 +34,7 @@ "preLaunchTask": "build C# project", "program": "${workspaceFolder}/csharp/bin/Debug/net6.0/csharp-cross-platform.dll", "args": [], + "justMyCode": false, "cwd": "${workspaceFolder}/csharp", "environment": [ { diff --git a/README.md b/README.md index 47af159..757cba4 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,24 @@ App Center Interop example for c++/c#(winforms). +# App Center Build with this project + +> this steps will be called from the custom build scripts on App Center +> So you will need to set the following environment variables +> APPCENTER_APP_SECRET + +- on this example the c++ project will contain the app center application secret +- build the project with the secret like this: + ```ps1 + meson builddir '-DAPPCENTER_APP_SECRET=""' + cd builddir + meson compile + ``` +- this will generate a dll that needs to be copied to the c# project binary folder +- do the common steps for the c# project + +# From scratch guide + ## C# first Steps - Create a new C# project. diff --git a/cpp/meson.build b/cpp/meson.build index 09b392a..a67c55c 100644 --- a/cpp/meson.build +++ b/cpp/meson.build @@ -16,6 +16,11 @@ if host_machine.system() == 'linux' myApp_deps += [gtkmm_dep] endif +## add app center app secret to arguments +myApp_args += [ + '-DAPPCENTER_APP_SECRET="'+get_option('APPCENTER_APP_SECRET')+'"', +] + # we compile the c++ application as a shared library myApp_lib = library('myapp', diff --git a/cpp/src/main.cpp b/cpp/src/main.cpp index cc67fcc..dbb04ce 100644 --- a/cpp/src/main.cpp +++ b/cpp/src/main.cpp @@ -2,6 +2,10 @@ #include #include +#ifndef APPCENTER_APP_SECRET +#define APPCENTER_APP_SECRET "" +#endif + #define myAppLIBRARY_EXPORT #include @@ -24,5 +28,9 @@ myAppAPI void setupAppCenterCallbacks( Interop::AppCenter::setTrackEventCallback(trackEventCallback); Interop::AppCenter::setTrackEventCallback(trackEventExtraCallback); } - +// this will retrieve the AppCenter app secret +myAppAPI const char* getAppCenterAppSecret() { + constexpr const char *appSecret = APPCENTER_APP_SECRET; + return appSecret; +} } diff --git a/csharp/csharp.csproj b/csharp/csharp.csproj index 928c39f..62c8dd6 100644 --- a/csharp/csharp.csproj +++ b/csharp/csharp.csproj @@ -6,12 +6,14 @@ enable true enable + 2116154c-7e25-4d69-b324-cdf42e3a7b68 + \ No newline at end of file diff --git a/csharp/source/Program.cs b/csharp/source/Program.cs index 50efd2a..b350941 100644 --- a/csharp/source/Program.cs +++ b/csharp/source/Program.cs @@ -7,6 +7,9 @@ namespace csharp; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; +// secrets +using Microsoft.Extensions.Configuration; + static class Program { /// @@ -26,7 +29,7 @@ static void Main() Crashes.TrackError(args.Exception); }; // this will start the App Center SDK - AppCenter.Start("{Your App Secret}", typeof(Analytics), typeof(Crashes)); + AppCenter.Start(AppCenterCpp.getAppSecret(), typeof(Analytics), typeof(Crashes)); // this will setup the callbacks for C++ AppCenterCpp.setup(); // this will initialize the C++ app diff --git a/csharp/source/interop/AppCenter.cs b/csharp/source/interop/AppCenter.cs index 07e92f8..7822657 100644 --- a/csharp/source/interop/AppCenter.cs +++ b/csharp/source/interop/AppCenter.cs @@ -25,20 +25,28 @@ public static void initApp() dllEntry(); } + public static string getAppSecret() + { + var result = getAppCenterAppSecret(); + var strResult = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(result); + return strResult ?? ""; + } + + [DllImport("myApp")] + private static extern IntPtr getAppCenterAppSecret(); + // the C++ dll entry point - [DllImport("myApp.dll", EntryPoint = "dllEntry")] + [DllImport("myApp", EntryPoint = "dllEntry")] private static extern void dllEntry(); - [DllImport("myApp.dll")] + [DllImport("myApp")] private static extern void setupAppCenterCallbacks(TrackEventDelegate normal, TrackEventExtraDelegate extra); private static void trackEventFunc(string eventName) { - Console.WriteLine("trackEventFunc: " + eventName); Analytics.TrackEvent(eventName); } private static void trackEventFunc(string eventName, string properties) { - Console.WriteLine("trackEventFunc: " + eventName + " " + properties); // convert the properties string(json) to a dictionary var props = JsonConvert.DeserializeObject>(properties); Analytics.TrackEvent(eventName, props); diff --git a/meson_options.txt b/meson_options.txt new file mode 100644 index 0000000..4536177 --- /dev/null +++ b/meson_options.txt @@ -0,0 +1 @@ +option('APPCENTER_APP_SECRET', type : 'string', value : '', description : 'AppCenter app secret') \ No newline at end of file