From 99b5e6f483541db2ad882e6d678b07059a3b595e Mon Sep 17 00:00:00 2001 From: Andre Lafleur Date: Sun, 9 Jun 2024 09:56:56 -0400 Subject: [PATCH] CopyConfiguration sample --- CopyConfiguratonSample/App.config | 6 ++ .../CopyConfiguratonSample.exe.cert | 5 ++ .../CopyConfiguratonSample.csproj | 65 ++++++++++++++ .../EntityManagerExtensions.cs | 49 ++++++++++ CopyConfiguratonSample/Program.cs | 90 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++++ Genetec.Dap.CodeSamples.sln | 19 ++-- 7 files changed, 262 insertions(+), 8 deletions(-) create mode 100644 CopyConfiguratonSample/App.config create mode 100644 CopyConfiguratonSample/Certificates/CopyConfiguratonSample.exe.cert create mode 100644 CopyConfiguratonSample/CopyConfiguratonSample.csproj create mode 100644 CopyConfiguratonSample/EntityManagerExtensions.cs create mode 100644 CopyConfiguratonSample/Program.cs create mode 100644 CopyConfiguratonSample/Properties/AssemblyInfo.cs diff --git a/CopyConfiguratonSample/App.config b/CopyConfiguratonSample/App.config new file mode 100644 index 0000000..aee9adf --- /dev/null +++ b/CopyConfiguratonSample/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CopyConfiguratonSample/Certificates/CopyConfiguratonSample.exe.cert b/CopyConfiguratonSample/Certificates/CopyConfiguratonSample.exe.cert new file mode 100644 index 0000000..2e0f1c7 --- /dev/null +++ b/CopyConfiguratonSample/Certificates/CopyConfiguratonSample.exe.cert @@ -0,0 +1,5 @@ + + Genetec + Demo Certificate for SDK Development only + KxsD11z743Hf5Gq9mv3+5ekxzemlCiUXkTFY5ba1NOGcLCmGstt2n0zYE9NsNimv + \ No newline at end of file diff --git a/CopyConfiguratonSample/CopyConfiguratonSample.csproj b/CopyConfiguratonSample/CopyConfiguratonSample.csproj new file mode 100644 index 0000000..d23b8b3 --- /dev/null +++ b/CopyConfiguratonSample/CopyConfiguratonSample.csproj @@ -0,0 +1,65 @@ + + + + + Debug + AnyCPU + {94719A4C-BE85-4BCF-82D7-A9D98F98F028} + Exe + Genetec.Dap.CodeSamples + CopyConfiguratonSample + v4.8.1 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + 8 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + 8 + + + + $(GSC_SDK)\Genetec.Sdk.dll + False + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + + + \ No newline at end of file diff --git a/CopyConfiguratonSample/EntityManagerExtensions.cs b/CopyConfiguratonSample/EntityManagerExtensions.cs new file mode 100644 index 0000000..1a8e918 --- /dev/null +++ b/CopyConfiguratonSample/EntityManagerExtensions.cs @@ -0,0 +1,49 @@ +// Copyright 2024 Genetec Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +namespace Genetec.Dap.CodeSamples +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Threading.Tasks; + using Sdk; + using Sdk.EventsArgs; + using Sdk.Workflows.EntityManager; + + static class EntityManagerExtensions + { + public static async Task CopyConfigurationAsync(this IEntityManager manager, Guid source, IEnumerable destinations, IProgress progress = null, params CopyConfigOption[] options) + { + var taskCompletionSource = new TaskCompletionSource(); + + EventHandler copyConfigFinished = (s, e) => taskCompletionSource.TrySetResult(e); + manager.CopyConfigFinished += copyConfigFinished; + + EventHandler copyConfigProgress = null; + if (progress != null) + { + copyConfigProgress = (s, e) => progress.Report(e.ProgressPercentage); + manager.CopyConfigProgress += copyConfigProgress; + } + + try + { + manager.CopyConfiguration(source, destinations.ToList(), options.ToList()); + return await taskCompletionSource.Task; + } + finally + { + manager.CopyConfigFinished -= copyConfigFinished; + if (copyConfigProgress != null) + { + manager.CopyConfigProgress -= copyConfigProgress; + } + } + } + } +} \ No newline at end of file diff --git a/CopyConfiguratonSample/Program.cs b/CopyConfiguratonSample/Program.cs new file mode 100644 index 0000000..3148055 --- /dev/null +++ b/CopyConfiguratonSample/Program.cs @@ -0,0 +1,90 @@ +// Copyright 2024 Genetec Inc. +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + +namespace Genetec.Dap.CodeSamples +{ + using System; + using System.Threading.Tasks; + using Sdk; + using Sdk.EventsArgs; + + class Program + { + static Program() => SdkResolver.Initialize(); + + static async Task Main() + { + const string server = "localhost"; + const string username = "admin"; + const string password = ""; + + using var engine = new Engine(); + + ConnectionStateCode state = await engine.LogOnAsync(server, username, password); + + if (state == ConnectionStateCode.Success) + { + // TODO: Replace the following example GUIDs with the actual source and destination GUIDs. + // These GUIDs should correspond to the entities you want to copy the configuration from and to. + var source = new Guid("00000000-0000-0000-0000-000000000000"); + var destination = new Guid("00000000-0000-0000-0000-000000000000"); + + // TODO: Define any options required for the copy operation. + // This array should contain the specific options you need for your copy configuration. + CopyConfigOption[] options = { + // Add your CopyConfigOption values here + }; + + var progress = new Progress(percent => Console.WriteLine($"Progress: {percent}%")); + + try + { + CopyConfigResultEventArgs result = await engine.EntityManager.CopyConfigurationAsync(source, new[] { destination }, progress, options); + DisplayResult(result); + } + catch (Exception ex) + { + Console.WriteLine($"Error during configuration copy: {ex.Message}"); + } + } + else + { + Console.WriteLine($"Logon failed: {state}"); + } + + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + + void DisplayResult(CopyConfigResultEventArgs result) + { + Console.WriteLine("Copy Configuration Result:"); + Console.WriteLine($"Succeeded: {result.Succeeded}"); + + if (!result.Succeeded) + { + Console.WriteLine($"Error: {result.Error}"); + } + + foreach (var status in result.ResultDetails) + { + Console.WriteLine($"Entity GUID: {status.EntityGuid}"); + Console.WriteLine($"Succeeded: {status.Succeeded}"); + + if (!status.Succeeded) + { + Console.WriteLine($"Error Message: {status.ErrorMessage}"); + + if (status.Exception != null) + { + Console.WriteLine($"Exception: {status.Exception.Message}"); + } + } + } + } + } + } +} diff --git a/CopyConfiguratonSample/Properties/AssemblyInfo.cs b/CopyConfiguratonSample/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..31c24f1 --- /dev/null +++ b/CopyConfiguratonSample/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("CopyConfiguratonSample")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Genetec Inc.")] +[assembly: AssemblyProduct("CopyConfiguratonSample")] +[assembly: AssemblyCopyright("Copyright © Genetec 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("94719a4c-be85-4bcf-82d7-a9d98f98f028")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Genetec.Dap.CodeSamples.sln b/Genetec.Dap.CodeSamples.sln index aa94781..031620d 100644 --- a/Genetec.Dap.CodeSamples.sln +++ b/Genetec.Dap.CodeSamples.sln @@ -108,6 +108,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VisitorManagerSample", "Vis EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccessControlUnitSample", "AccessControlUnitSample\AccessControlUnitSample.csproj", "{7BCE5199-8B5B-4905-8CAA-5ABC3ACAAD00}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CopyConfiguratonSample", "CopyConfiguratonSample\CopyConfiguratonSample.csproj", "{94719A4C-BE85-4BCF-82D7-A9D98F98F028}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -274,18 +276,14 @@ Global {9C1FCCB7-A08D-4140-BFF8-949F036C50AA}.Debug|Any CPU.Build.0 = Debug|Any CPU {9C1FCCB7-A08D-4140-BFF8-949F036C50AA}.Release|Any CPU.ActiveCfg = Release|Any CPU {9C1FCCB7-A08D-4140-BFF8-949F036C50AA}.Release|Any CPU.Build.0 = Release|Any CPU - {DD133C7E-1BE3-436D-91AA-DD298A30F72E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DD133C7E-1BE3-436D-91AA-DD298A30F72E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DD133C7E-1BE3-436D-91AA-DD298A30F72E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DD133C7E-1BE3-436D-91AA-DD298A30F72E}.Release|Any CPU.Build.0 = Release|Any CPU - {649419F6-7E22-419D-BFF4-A6674215CFDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {649419F6-7E22-419D-BFF4-A6674215CFDB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {649419F6-7E22-419D-BFF4-A6674215CFDB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {649419F6-7E22-419D-BFF4-A6674215CFDB}.Release|Any CPU.Build.0 = Release|Any CPU {80235DD0-E10A-4D5A-B904-3FFAF947AE00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {80235DD0-E10A-4D5A-B904-3FFAF947AE00}.Debug|Any CPU.Build.0 = Debug|Any CPU {80235DD0-E10A-4D5A-B904-3FFAF947AE00}.Release|Any CPU.ActiveCfg = Release|Any CPU {80235DD0-E10A-4D5A-B904-3FFAF947AE00}.Release|Any CPU.Build.0 = Release|Any CPU + {649419F6-7E22-419D-BFF4-A6674215CFDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {649419F6-7E22-419D-BFF4-A6674215CFDB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {649419F6-7E22-419D-BFF4-A6674215CFDB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {649419F6-7E22-419D-BFF4-A6674215CFDB}.Release|Any CPU.Build.0 = Release|Any CPU {B622A780-E98F-4E65-B5CA-C305E6B45965}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {B622A780-E98F-4E65-B5CA-C305E6B45965}.Debug|Any CPU.Build.0 = Debug|Any CPU {B622A780-E98F-4E65-B5CA-C305E6B45965}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -302,6 +300,10 @@ Global {7BCE5199-8B5B-4905-8CAA-5ABC3ACAAD00}.Debug|Any CPU.Build.0 = Debug|Any CPU {7BCE5199-8B5B-4905-8CAA-5ABC3ACAAD00}.Release|Any CPU.ActiveCfg = Release|Any CPU {7BCE5199-8B5B-4905-8CAA-5ABC3ACAAD00}.Release|Any CPU.Build.0 = Release|Any CPU + {94719A4C-BE85-4BCF-82D7-A9D98F98F028}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94719A4C-BE85-4BCF-82D7-A9D98F98F028}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94719A4C-BE85-4BCF-82D7-A9D98F98F028}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94719A4C-BE85-4BCF-82D7-A9D98F98F028}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -355,6 +357,7 @@ Global Shared\Shared.projitems*{7eb16455-8e54-4033-b32d-909bcad1609d}*SharedItemsImports = 4 Shared\Shared.projitems*{80235dd0-e10a-4d5a-b904-3ffaf947ae00}*SharedItemsImports = 4 Shared\Shared.projitems*{847cf4d4-2b00-4c6a-848a-f0908d705669}*SharedItemsImports = 4 + Shared\Shared.projitems*{94719a4c-be85-4bcf-82d7-a9d98f98f028}*SharedItemsImports = 4 Shared\Shared.projitems*{9683a716-b265-4195-a8d4-4d46095f1013}*SharedItemsImports = 4 Shared\Shared.projitems*{9c1fccb7-a08d-4140-bff8-949f036c50aa}*SharedItemsImports = 4 Shared\Shared.projitems*{a2b97d24-662d-400d-a3e7-1d8760bc8b4b}*SharedItemsImports = 4