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

Da login fix #83

Open
wants to merge 8 commits into
base: master
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
33 changes: 26 additions & 7 deletions h-opc/Da/DaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ protected OpcDa.Server Server
/// </summary>
public void Connect()
{
if (Status == OpcStatus.Connected)
return;
_server = new OpcDa.Server(new Factory(), _url);
_server.Connect();
var root = new DaNode(string.Empty, string.Empty);
RootNode = root;
AddNodeToCache(root);
Connect(() => _server.Connect());
}

/// <summary>
Expand Down Expand Up @@ -299,6 +293,31 @@ private static void CheckResult(IResult result, string tag)
if (result.ResultID.ToString() != "S_OK")
throw new OpcException(string.Format("Invalid response from the server. (Response Status: {0}, Opc Tag: {1})", result.ResultID, tag));
}

/// <summary>
/// Connect using username and password credentials
/// </summary>
/// <param name="userName">the username to use with NetworkCredentials</param>
/// <param name="password">the password to use with NetworkCredentials</param>
public void Connect(string userName, string password)
{
Connect(() => _server.Connect(new ConnectData(new System.Net.NetworkCredential(userName, password))));
}

/// <summary>
/// Main connection method, used to keep the connection logic in one place
/// </summary>
/// <param name="connect">the action which calls the correct overload of OpcDa.Server.Connect()</param>
private void Connect(Action connect)
{
if (Status == OpcStatus.Connected)
return;
_server = new OpcDa.Server(new Factory(), _url);
connect.Invoke();
var root = new DaNode(string.Empty, string.Empty);
RootNode = root;
AddNodeToCache(root);
}
}
}

9 changes: 0 additions & 9 deletions tests/tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@
<Compile Include="DaTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<None Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="packages.config" />
<None Include="Settings.StyleCop" />
</ItemGroup>
Expand Down