Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyConfiguration sample #18

Merged
merged 2 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CopyConfiguratonSample/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ClientCertificate>
<CompanyName>Genetec</CompanyName>
<ApplicationName>Demo Certificate for SDK Development only</ApplicationName>
<ApplicationId>KxsD11z743Hf5Gq9mv3+5ekxzemlCiUXkTFY5ba1NOGcLCmGstt2n0zYE9NsNimv</ApplicationId>
</ClientCertificate>
65 changes: 65 additions & 0 deletions CopyConfiguratonSample/CopyConfiguratonSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{94719A4C-BE85-4BCF-82D7-A9D98F98F028}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Genetec.Dap.CodeSamples</RootNamespace>
<AssemblyName>CopyConfiguratonSample</AssemblyName>
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>8</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="Genetec.Sdk">
<HintPath>$(GSC_SDK)\Genetec.Sdk.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="EntityManagerExtensions.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="Certificates\CopyConfiguratonSample.exe.cert">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
49 changes: 49 additions & 0 deletions CopyConfiguratonSample/EntityManagerExtensions.cs
Original file line number Diff line number Diff line change
@@ -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<CopyConfigResultEventArgs> CopyConfigurationAsync(this IEntityManager manager, Guid source, IEnumerable<Guid> destinations, IProgress<int> progress = null, params CopyConfigOption[] options)
{
var taskCompletionSource = new TaskCompletionSource<CopyConfigResultEventArgs>();

EventHandler<CopyConfigResultEventArgs> copyConfigFinished = (s, e) => taskCompletionSource.TrySetResult(e);
manager.CopyConfigFinished += copyConfigFinished;

EventHandler<CopyConfigProgressEventArgs> 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;
}
}
}
}
}
90 changes: 90 additions & 0 deletions CopyConfiguratonSample/Program.cs
Original file line number Diff line number Diff line change
@@ -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<int>(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}");
}
}
}
}
}
}
}
36 changes: 36 additions & 0 deletions CopyConfiguratonSample/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
7 changes: 7 additions & 0 deletions Genetec.Dap.CodeSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThumbnailQuerySample", "Thu
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
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EventMonitoringSample", "EventMonitoringSample\EventMonitoringSample.csproj", "{534DB081-2747-4FB6-B269-C3EEDBD9F30D}"
EndProject
Global
Expand Down Expand Up @@ -324,6 +326,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
{534DB081-2747-4FB6-B269-C3EEDBD9F30D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{534DB081-2747-4FB6-B269-C3EEDBD9F30D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{534DB081-2747-4FB6-B269-C3EEDBD9F30D}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -384,6 +390,7 @@ Global
Shared\Shared.projitems*{80235dd0-e10a-4d5a-b904-3ffaf947ae00}*SharedItemsImports = 4
Shared\Shared.projitems*{81b35a77-4551-4f33-866a-95b2e47111ef}*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*{8c2ce84c-ef36-4940-b031-c8a933dbf6eb}*SharedItemsImports = 4
Shared\Shared.projitems*{9683a716-b265-4195-a8d4-4d46095f1013}*SharedItemsImports = 4
Shared\Shared.projitems*{9c1fccb7-a08d-4140-bff8-949f036c50aa}*SharedItemsImports = 4
Expand Down