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

Add net8 samples and contextual action sample #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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>{28019A04-A3CF-404D-9004-F970D1D2AE2F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ContextualAction</RootNamespace>
<AssemblyName>ContextualAction</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug\Genetec.Sdk.Samples\ContextualAction\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release\Genetec.Sdk.Samples\ContextualAction\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Genetec.Sdk">
<HintPath>$(GSC_SDK)\Genetec.Sdk.dll</HintPath>
</Reference>
<Reference Include="Genetec.Sdk.Workspace">
<HintPath>$(GSC_SDK)\Genetec.Sdk.Workspace.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<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="Module.cs" />
<Compile Include="PopupMessageContextualAction.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Resources\Message.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
26 changes: 26 additions & 0 deletions Samples-Workspace/Genetec.Sdk.Samples/ContextualAction/Module.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Genetec.Sdk.Workspace.Services;

namespace ContextualActionSample
{
public class Module : Genetec.Sdk.Workspace.Modules.Module
{
private IContextualActionsService m_contextualActionsService;
private PopupMessageContextualAction m_popupMessageContextualAction;

public override void Load()
{
m_contextualActionsService = Workspace.Services.Get<IContextualActionsService>();
if (m_contextualActionsService != null)
{
m_popupMessageContextualAction = new PopupMessageContextualAction();
m_popupMessageContextualAction.Initialize(Workspace);
m_contextualActionsService.Register(m_popupMessageContextualAction);
}
}

public override void Unload()
{
m_contextualActionsService?.Unregister(m_popupMessageContextualAction);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using ContextualAction;
using Genetec.Sdk.Entities;
using Genetec.Sdk.Workspace;
using Genetec.Sdk.Workspace.ContextualAction;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Media.Imaging;

namespace ContextualActionSample
{
internal class PopupMessageContextualAction : Genetec.Sdk.Workspace.ContextualAction.ContextualAction
{
public override Guid Id => Guid.Parse("02c619f7-b44c-41e3-a8a2-3379b7159e52");

public PopupMessageContextualAction()
{
Name = "Popup Message";
Icon = Resources.Message.ToBitmapSource();
}

public override bool CanExecute(ContextualActionContext context)
{
if (context is EntityBrowserContextualActionContext || context is SystemStatusContextualActionContext)
return true;

return false;
}

public override bool Execute(ContextualActionContext context)
{
string caption;
Entity selectedEntity;

if (context is EntityBrowserContextualActionContext ebContext)
{
caption = "Hello there Entity Browser user!!!";
selectedEntity = Workspace.Sdk.GetEntity(ebContext.SelectedEntities.FirstOrDefault());
}
else if (context is SystemStatusContextualActionContext ssContext)
{
caption = "Hello there System Status user!!!";
selectedEntity = Workspace.Sdk.GetEntity(ssContext.SelectedEntities.FirstOrDefault());
}
else
return false;

if (selectedEntity == null)
MessageBox.Show("Please select an entity", caption);
else
MessageBox.Show($"My name is {selectedEntity.Name}.\r\nI'm a {selectedEntity.EntityType}.\r\nMy GUID is {selectedEntity.Guid}.\r\nNice to meet you 😊", caption);

return true;
}
}

public static class Extentions
{
public static BitmapSource ToBitmapSource(this Bitmap source)
{
BitmapSource bitmapSource;
var bitmap = source.GetHbitmap(Color.FromArgb(0, 0, 0, 0));

try
{
bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
bitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
catch (Win32Exception)
{
bitmapSource = null;
}

return bitmapSource;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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("ContextualAction")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("Genetec Inc.")]
[assembly: AssemblyProduct("ContextualAction")]
[assembly: AssemblyCopyright("Copyright © 2024 Genetec Inc.")]
[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("28019a04-a3cf-404d-9004-f970d1d2ae2f")]

// 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("5.12.0.0")]
[assembly: AssemblyVersion("5.12.0.0")]
[assembly: AssemblyFileVersion("5.12.2181.44")]

[assembly:AssemblyInformationalVersion("5.12.0.0")]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading