Skip to content
Draft
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
177 changes: 27 additions & 150 deletions Samples/Client.Net4/UA Sample Client.csproj
Original file line number Diff line number Diff line change
@@ -1,167 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{D7601329-530D-4537-B9B9-D9D53D5F81F6}</ProjectGuid>
<TargetFramework>net8.0-windows</TargetFramework>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<UseWindowsForms>true</UseWindowsForms>
<NoWarn>$(NoWarn);CA1416</NoWarn>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<RootNamespace>Opc.Ua.Sample</RootNamespace>
<AssemblyName>Opc.Ua.SampleClient</AssemblyName>
<ApplicationIcon>App.ico</ApplicationIcon>
<StartupObject>Opc.Ua.Sample.Program</StartupObject>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<SignAssembly>false</SignAssembly>
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
<ApplicationManifest>app.manifest</ApplicationManifest>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<ProjectGuid>{D7601329-530D-4537-B9B9-D9D53D5F81F6}</ProjectGuid>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.IdentityModel">
<RequiredTargetFramework>3.0</RequiredTargetFramework>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\AssemblyVersionInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<Content Include="App.config">
<SubType>Designer</SubType>
</Content>
<EmbeddedResource Include="SampleClientForm.resx">
<DependentUpon>SampleClientForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="App.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<Content Include="Opc.Ua.SampleClient.Config.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<SubType>Designer</SubType>
</Content>
<Content Include="Opc.Ua.SampleClient.Endpoints.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</Content>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="SampleClientForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SampleClientForm.Designer.cs">
<DependentUpon>SampleClientForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ClientControls.Net4\UA Client Controls.csproj">
<Project>{A247D2EE-14FC-463D-A9BA-6CFF1EF22B7A}</Project>
<Name>UA Client Controls</Name>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\Controls.Net4\UA Sample Controls.csproj">
<Project>{92AE819B-4938-4502-AC32-67063F9893CD}</Project>
<Name>UA Sample Controls</Name>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\Opc.Ua.Sample\Opc.Ua.Sample.csproj">
<Project>{bcb915b6-b5c3-45bc-9c8b-f43008df0c14}</Project>
<Name>Opc.Ua.Sample</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="app.manifest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions">
<Version>10.0.0</Version>
</PackageReference>
<PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Bindings.Https">
<Version>1.5.378.11-preview</Version>
<Version>1.5.378.10-preview</Version>
</PackageReference>
<PackageReference Include="System.Net.Http">
<Version>4.3.4</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<BaseNuGetRuntimeIdentifier>win7-x64</BaseNuGetRuntimeIdentifier>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ClientControls.Net4\UA Client Controls.csproj" />
<ProjectReference Include="..\Controls.Net4\UA Sample Controls.csproj" />
<ProjectReference Include="..\Opc.Ua.Sample\Opc.Ua.Sample.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="Opc.Ua.SampleClient.Config.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Opc.Ua.SampleClient.Endpoints.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="App.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>
68 changes: 68 additions & 0 deletions Samples/ClientControls.Net4/ClientUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Opc.Ua.Configuration;

namespace Opc.Ua.Client.Controls
{
Expand All @@ -58,6 +59,14 @@ public static void HandleException(ILogger logger, string caption, Exception e)
ExceptionDlg.Show(logger, caption, e);
}

/// <summary>
/// Handles an exception (backward-compatible overload).
/// </summary>
public static void HandleException(string caption, Exception e)
{
ExceptionDlg.Show(caption, e);
}

/// <summary>
/// Returns the application icon.
/// </summary>
Expand All @@ -73,6 +82,57 @@ public static System.Drawing.Icon GetAppIcon()
}
}

/// <summary>
/// Selects the endpoint to use (backward-compatible sync wrapper).
/// </summary>
public static EndpointDescription SelectEndpoint(string discoveryUrl, bool useSecurity)
{
// Create a temporary application configuration for discovery
var configuration = new ApplicationConfiguration
{
ApplicationName = "UA Client",
ApplicationType = ApplicationType.Client,
SecurityConfiguration = new SecurityConfiguration()
};

try
{
return CoreClientUtils.SelectEndpointAsync(configuration, discoveryUrl, useSecurity, 15000).GetAwaiter().GetResult();
}
catch
{
return null;
}
}

/// <summary>
/// Gets the display text for an attribute value (backward-compatible sync wrapper).
/// </summary>
public static string GetAttributeDisplayText(ISession session, uint attributeId, Variant value)
{
try
{
return GetAttributeDisplayTextAsync(session, attributeId, value).GetAwaiter().GetResult();
}
catch
{
return Utils.Format("{0}", value);
}
}

/// <summary>
/// Discovers servers (backward-compatible sync wrapper).
/// </summary>
/// <remarks>
/// This method now requires async approach - returns empty collection for compatibility.
/// Use the async discovery methods for actual server discovery.
/// </remarks>
public static IList<string> DiscoverServers(ApplicationConfiguration configuration)
{
// Discovery now requires async methods - return empty collection for compatibility
return new List<string>();
}

#region DisplayText Lookup
/// <summary>
/// Gets the display text for the access level attribute.
Expand Down Expand Up @@ -303,6 +363,14 @@ public static async Task<string> GetAttributeDisplayTextAsync(ISession session,
#endregion

#region Browse
/// <summary>
/// Browses the address space and returns the references found (sync wrapper).
/// </summary>
public static ReferenceDescriptionCollection Browse(ISession session, ViewDescription view, BrowseDescriptionCollection nodesToBrowse, bool throwOnError)
{
return BrowseAsync(session, view, nodesToBrowse, throwOnError).GetAwaiter().GetResult();
}

/// <summary>
/// Browses the address space and returns the references found.
/// </summary>
Expand Down
8 changes: 4 additions & 4 deletions Samples/ClientControls.Net4/Common/ConnectServerCtrl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public Session Connect()
(String.IsNullOrEmpty(SessionName))?m_configuration.ApplicationName:SessionName,
60000,
UserIdentity,
PreferredLocales);
PreferredLocales).GetAwaiter().GetResult();

// set up keep alive callback.
m_session.KeepAlive += new KeepAliveEventHandler(Session_KeepAlive);
Expand Down Expand Up @@ -323,7 +323,7 @@ public void Disconnect()
/// </summary>
public void Discover(string hostName)
{
string endpointUrl = new DiscoverServerDlg().ShowDialog(m_configuration, hostName);
string endpointUrl = new DiscoverServerDlg().ShowDialog(m_configuration, hostName, null);

if (endpointUrl != null)
{
Expand Down Expand Up @@ -403,7 +403,7 @@ private void UpdateStatus(bool error, DateTime time, string status, params objec
/// <summary>
/// Handles a keep alive event from a session.
/// </summary>
private void Session_KeepAlive(Session session, KeepAliveEventArgs e)
private void Session_KeepAlive(ISession session, KeepAliveEventArgs e)
{
if (this.InvokeRequired)
{
Expand Down Expand Up @@ -500,7 +500,7 @@ private void Server_ReconnectComplete(object sender, EventArgs e)
{
var session = m_session;
session.KeepAlive -= Session_KeepAlive;
m_session = m_reconnectHandler.Session;
m_session = m_reconnectHandler.Session as Session;
m_session.KeepAlive += Session_KeepAlive;
Utils.SilentDispose(session);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ internal void Initialize(X509Certificate2 certificate)
continue;
}

if (extension.Oid.Value == X509AuthorityKeyIdentifierExtension.AuthorityKeyIdentifier2Oid)
if (extension.Oid.Value == Opc.Ua.Security.Certificates.X509AuthorityKeyIdentifierExtension.AuthorityKeyIdentifier2Oid)
{
X509AuthorityKeyIdentifierExtension keyId = new X509AuthorityKeyIdentifierExtension(extension, extension.Critical);
Opc.Ua.Security.Certificates.X509AuthorityKeyIdentifierExtension keyId = new Opc.Ua.Security.Certificates.X509AuthorityKeyIdentifierExtension(extension, extension.Critical);
AddItem(new FieldInfo("AuthorityKeyIdentifier", keyId.Format(false)));
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ public ReferenceDescription Reference
#endregion

#region Event Handlers
private async void BrowseBTN_ClickAsync(object sender, EventArgs e)
private void BrowseBTN_ClickAsync(object sender, EventArgs e)
{
try
{
ReferenceDescription reference = await new SelectNodeDlg().ShowDialogAsync(m_browser.Session as Session, RootId, null, "", Telemetry, default, null);
ReferenceDescription reference = new SelectNodeDlg().ShowDialog(m_browser.Session as Session, RootId, (ViewDescription)null, (string)null);

if (reference != null && reference.NodeId != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public UserIdentity ShowDialog(IUserIdentity identity, string caption)
if (token != null)
{
UserNameTB.Text = token.UserName;
PasswordTB.Text = token.DecryptedPassword;
PasswordTB.Text = Encoding.UTF8.GetString(token.DecryptedPassword);
}
}

Expand All @@ -77,7 +77,7 @@ public UserIdentity ShowDialog(IUserIdentity identity, string caption)
return null;
}

return new UserIdentity(UserNameTB.Text, PasswordTB.Text);
return new UserIdentity(UserNameTB.Text, Encoding.UTF8.GetBytes(PasswordTB.Text));
}
}
}
13 changes: 13 additions & 0 deletions Samples/ClientControls.Net4/ExceptionDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ public static void Show(ILogger logger, string caption, Exception e)
new ExceptionDlg(logger).ShowDialog(caption, e);
}

/// <summary>
/// Displays the exception in a dialog (backward-compatible overload without logger).
/// </summary>
public static void Show(string caption, Exception e)
{
// check if running as a service.
if (!Environment.UserInteractive)
{
return;
}
new ExceptionDlg(null).ShowDialog(caption, e);
}

/// <summary>
/// Display the exception in the dialog.
/// </summary>
Expand Down
Loading
Loading