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

DiagnosticServer and Logger samples #17

Merged
merged 5 commits into from
Jul 8, 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 DiagnosticServerSample/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>
65 changes: 65 additions & 0 deletions DiagnosticServerSample/DiagnosticServerSample.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>{4D27A27E-A287-4366-89DC-E89571B07321}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Genetec.Dap.CodeSamples</RootNamespace>
<AssemblyName>DiagnosticServer</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.Runtime.Serialization">
<HintPath>..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8.1\System.Runtime.Serialization.dll</HintPath>
</Reference>
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="InstanceLogger.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="StaticLogger.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="..\Shared\Shared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
44 changes: 44 additions & 0 deletions DiagnosticServerSample/InstanceLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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 Genetec.Sdk.Diagnostics.Logging;
using Genetec.Sdk.Diagnostics.Logging.Core;

class InstanceLogger : IDisposable
{
private readonly Logger m_logger;

public InstanceLogger()
{
m_logger = Logger.CreateInstanceLogger(this);
}

public void Dispose()
{
m_logger.Dispose();
}

public void LogDebugMessage()
{
m_logger.TraceDebug("This is a debug message");
}

/// <summary>
/// Executes a debug method and returns a result message.
/// </summary>
/// <returns>A string containing the output message of this sample debug method.</returns>
[DebugMethod(Description = "Executes a sample debug method", DisplayName = "Sample Debug Method", IsHidden = false, IsSecured = false)]
[UserCommand("Genetec.Dap.Samples")]
public string ExecuteSampleDebugMethod()
{
return "This is the result of executing the sample debug method.";
}
}
}
72 changes: 72 additions & 0 deletions DiagnosticServerSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// 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.Diagnostics;
using System.Threading.Tasks;
using Sdk.Diagnostics;

class Program
{
static Program() => SdkResolver.Initialize();

static async Task Main()
{
await InitializeAndStartServer();

LogDebugMessage();

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

Cleanup();
}

static void LogDebugMessage()
{
using var logger = new InstanceLogger();
logger.LogDebugMessage();

StaticLogger.LogDebugMessage();
}

static async Task InitializeAndStartServer()
{
const int diagnosticServerPort = 4523;
const int webServerPort = 6023;
const string password = ""; // The password is optional, by default, it's an empty string

try
{
DiagnosticServer.Instance.InitializeServer(diagnosticServerPort, webServerPort, password);

var url = $"http://localhost:{webServerPort}/Console";
Console.WriteLine($"Console started: {url}");
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });

// Wait for a few seconds to ensure the web browser has enough time to load the page
await Task.Delay(5000); // Adjust the delay as necessary
}
catch (Exception ex)
{
Console.WriteLine($"Error initializing server: {ex.Message}");
Console.WriteLine(ex.StackTrace);
}
}

static void Cleanup()
{
if (DiagnosticServer.IsInstanceCreated && DiagnosticServer.Instance.IsInitialized)
{
DiagnosticServer.Instance.Dispose();
Console.WriteLine("Diagnostic server disposed.");
}
}
}
}
35 changes: 35 additions & 0 deletions DiagnosticServerSample/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Reflection;
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("DiagnosticServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Genetec Inc.")]
[assembly: AssemblyProduct("DiagnosticServer")]
[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("4d27a27e-a287-4366-89dc-e89571b07321")]

// 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")]
33 changes: 33 additions & 0 deletions DiagnosticServerSample/StaticLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 Genetec.Sdk.Diagnostics.Logging;
using Genetec.Sdk.Diagnostics.Logging.Core;

static class StaticLogger
{
private static readonly Logger s_logger = Logger.CreateClassLogger(typeof(StaticLogger));

public static void LogDebugMessage()
{
s_logger.TraceDebug("This is a debug message");
}

/// <summary>
/// Executes a static debug method and returns a result message.
/// </summary>
/// <returns>A string containing the output message of this sample static debug method.</returns>
[DebugMethod(Description = "Executes a sample static debug method", DisplayName = "Sample Static Debug Method", IsHidden = false, IsSecured = false)]
[UserCommand("Genetec.Dap.Samples")]
public static string ExecuteSampleDebugMethod()
{
return "This is the result of executing the sample static debug method.";
}
}
}
19 changes: 13 additions & 6 deletions Genetec.Dap.CodeSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TileWidgetSample", "TileWid
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TilePropertiesSample", "TilePropertiesSample\TilePropertiesSample.csproj", "{5E8C6571-B661-4FA0-AE8F-D9214B166F4B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggerSample", "LoggerSample\LoggerSample.csproj", "{4D27A27E-A287-4366-89DC-E89571B07321}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlarmMonitoringSample", "AlarmMonitoringSample\AlarmMonitoringSample.csproj", "{464C76EA-DA3E-4957-BBC3-2B8591E64349}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SecurityManagerSample", "SecurityManagerSample\SecurityManagerSample.csproj", "{49274831-CE4C-4B89-91B9-61C7DEDA2A26}"
Expand Down Expand Up @@ -118,6 +116,10 @@ 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}") = "DiagnosticServerSample", "DiagnosticServerSample\DiagnosticServerSample.csproj", "{4D27A27E-A287-4366-89DC-E89571B07321}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LoggerSample", "LoggerSample\LoggerSample.csproj", "{15571F2E-64D8-46A7-AA36-A630D52A5878}"
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}"
Expand Down Expand Up @@ -180,10 +182,6 @@ Global
{5E8C6571-B661-4FA0-AE8F-D9214B166F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E8C6571-B661-4FA0-AE8F-D9214B166F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E8C6571-B661-4FA0-AE8F-D9214B166F4B}.Release|Any CPU.Build.0 = Release|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Release|Any CPU.Build.0 = Release|Any CPU
{464C76EA-DA3E-4957-BBC3-2B8591E64349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{464C76EA-DA3E-4957-BBC3-2B8591E64349}.Debug|Any CPU.Build.0 = Debug|Any CPU
{464C76EA-DA3E-4957-BBC3-2B8591E64349}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -344,6 +342,14 @@ 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
{4D27A27E-A287-4366-89DC-E89571B07321}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4D27A27E-A287-4366-89DC-E89571B07321}.Release|Any CPU.Build.0 = Release|Any CPU
{15571F2E-64D8-46A7-AA36-A630D52A5878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{15571F2E-64D8-46A7-AA36-A630D52A5878}.Debug|Any CPU.Build.0 = Debug|Any CPU
{15571F2E-64D8-46A7-AA36-A630D52A5878}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15571F2E-64D8-46A7-AA36-A630D52A5878}.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
Expand Down Expand Up @@ -397,6 +403,7 @@ Global
Shared\Shared.projitems*{08316764-72e6-4a9d-be64-132bf06a303d}*SharedItemsImports = 4
Shared\Shared.projitems*{0905d84f-59bc-4a31-bce5-916fec9b169c}*SharedItemsImports = 4
Shared\Shared.projitems*{0c0757f1-6a2b-4258-af4e-5a10964e8142}*SharedItemsImports = 4
Shared\Shared.projitems*{15571f2e-64d8-46a7-aa36-a630d52a5878}*SharedItemsImports = 4
Shared\Shared.projitems*{16ccb28d-f9a2-489c-9783-d92eee687b71}*SharedItemsImports = 4
Shared\Shared.projitems*{177adf02-8114-4594-88d1-ca6fbb92fa7a}*SharedItemsImports = 4
Shared\Shared.projitems*{1d9df30c-817e-45af-9071-03edc92429ce}*SharedItemsImports = 4
Expand Down
7 changes: 7 additions & 0 deletions LoggerSample/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8.1" />
</startup>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="consoleTraceListener" type="System.Diagnostics.ConsoleTraceListener"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
32 changes: 32 additions & 0 deletions LoggerSample/InstanceLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 Sdk.Diagnostics.Logging.Core;

class InstanceLogger : IDisposable
{
private readonly Logger m_logger;

public InstanceLogger()
{
m_logger = Logger.CreateInstanceLogger(this);
}

public void Dispose()
{
m_logger.Dispose();
}

public void LogDebugMessage()
{
m_logger.TraceDebug("This is a debug message");
}
}
}
Loading