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

DisplayInTile sample #98

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
158 changes: 81 additions & 77 deletions Samples/Platform SDK/DisplayInTileSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,93 +5,97 @@
// 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 Genetec.Dap.CodeSamples;
using Genetec.Sdk;
using Genetec.Sdk.Entities;
using Genetec.Sdk.Queries;

SdkResolver.Initialize();

await RunSample();

async Task RunSample()
{
using System;
using System.Linq;
using System.Threading.Tasks;
using Genetec.Sdk;
using Sdk.Entities;
using Sdk.Queries;

class Program
const string server = "localhost";
const string username = "admin";
const string password = "";

// Replace with your actual camera GUID
Guid cameraGuid = Guid.Parse("your-camera-guid-here");

using var engine = new Engine();

ConnectionStateCode state = await engine.LogOnAsync(server, username, password);

if (state == ConnectionStateCode.Success)
{
static Program() => SdkResolver.Initialize();
await LoadApplications();
DisplayCameraInTiles();
}
else
{
Console.WriteLine($"Logon failed: {state}");
}

static async Task Main()
Console.WriteLine("Press any key to exit...");
Console.ReadKey();

// Load all applications into the engine's entity cache
async Task LoadApplications()
{
Console.WriteLine("Loading applications...");
var query = (EntityConfigurationQuery)engine.ReportManager.CreateReportQuery(ReportType.EntityConfiguration);
query.EntityTypeFilter.Add(EntityType.Application);
await Task.Factory.FromAsync(query.BeginQuery, query.EndQuery, null);
}

// Display the camera feed in tiles on all available Security Desk monitors
void DisplayCameraInTiles()
{
if (engine.GetEntity(cameraGuid) is not Camera)
{
Console.WriteLine($"Camera with GUID {cameraGuid} not found.");
return;
}

Console.WriteLine("Searching for online Security Desk applications...");

// Get all online Security Desk applications
List<Application> securityDeskApps = engine.GetEntities(EntityType.Application)
.OfType<Application>()
.Where(app => app.ApplicationType == ApplicationType.SecurityDesk && app.IsOnline)
.ToList();

Console.WriteLine($"Found {securityDeskApps.Count} online Security Desk application(s).");

Console.WriteLine("Retrieving monitors from Security Desk applications...");

// Get all monitors from these applications
List<int> monitors = securityDeskApps.SelectMany(app => app.Monitors)
.Select(engine.GetEntity)
.OfType<Monitor>()
.Select(monitor => monitor.LogicalId.GetValueOrDefault())
.ToList();

Console.WriteLine($"Found {monitors.Count} monitor(s).");

// Display camera on each monitor
foreach (var monitor in monitors)
{
const string server = "localhost";
const string username = "admin";
const string password = "";

// Replace with your actual camera GUID
Guid cameraGuid = Guid.Parse("00000000-0000-0000-0000-000000000000");

using var engine = new Engine();

ConnectionStateCode state = await engine.LogOnAsync(server, username, password);

if (state == ConnectionStateCode.Success)
{
await LoadApplications();
DisplayCameraInTiles();
}
else
{
Console.WriteLine($"Logon failed: {state}");
}

Console.WriteLine("Press any key to exit...");
Console.ReadKey();

// Load all applications into the engine
async Task LoadApplications()
{
Console.WriteLine("Loading applications...");
var query = (EntityConfigurationQuery)engine.ReportManager.CreateReportQuery(ReportType.EntityConfiguration);
query.EntityTypeFilter.Add(EntityType.Application);
await Task.Factory.FromAsync(query.BeginQuery, query.EndQuery, null);
}

// Display the camera feed in tiles on all available Security Desk monitors
void DisplayCameraInTiles()
{
Console.WriteLine("Searching for online Security Desk applications...");

// Get all online Security Desk applications
var securityDeskApps = engine.GetEntities(EntityType.Application)
.OfType<Application>()
.Where(app => app.ApplicationType == ApplicationType.SecurityDesk && app.IsOnline)
.ToList();

Console.WriteLine($"Found {securityDeskApps.Count} online Security Desk application(s).");

Console.WriteLine("Retrieving monitors from Security Desk applications...");

// Get all monitors from these applications
var monitors = securityDeskApps.SelectMany(app => app.Monitors)
.Select(engine.GetEntity)
.OfType<Monitor>()
.Select(monitor => monitor.MonitorId)
.ToList();

Console.WriteLine($"Found {monitors.Count} monitor(s).");

// Display camera on each monitor
foreach (var monitor in monitors)
{

string xmlContent = $@"

string xmlContent = $@"
<TileContentGroup>
<Contents>
<VideoContent Camera=""{cameraGuid}"" VideoMode=""Live"" />
</Contents>
</TileContentGroup>";

Console.WriteLine($"Displaying camera on monitor ID: {monitor}");
engine.ActionManager.DisplayInTile(monitor, xmlContent);
}
}
Console.WriteLine($"Displaying camera on monitor ID: {monitor}");
engine.ActionManager.DisplayInTile(monitor, xmlContent);
}
}
}