static void Main(string[] args)
{
Console.Write("Enter username: "******"Enter password: "******"Getting list of PI Data Archives...");
Dictionary<string, string> serversWebId = client.GetDataServersWebIdAsync().Result;
foreach (var server in serversWebId)
{
Console.WriteLine(server.Key);
}
do
{
Console.Write("Please type in name of the PI Data Archive: ");
string myPI = Console.ReadLine();
Console.Write("Please type in name of the tag: ");
string myTag = Console.ReadLine();
if (IsRead())
{
dynamic value = client.GetTagValueAsync(serversWebId[myPI], myTag).Result;
Console.WriteLine("Current value = {0}", value);
}
else
{
Console.Write("Value to write? ");
string valueToWrite = Console.ReadLine();
client.WriteTagValueAsync(serversWebId[myPI], myTag, valueToWrite).Wait();
Console.WriteLine("Value written.");
}
Console.WriteLine("Press any key to continue (esc to exit)...");
} while (Console.ReadKey().Key != ConsoleKey.Escape);
}
catch (InvalidOperationException ex)
{
Console.WriteLine(ex.Message);
}
catch (KeyNotFoundException)
{
Console.WriteLine("The specified PI Data Archive cannot be found.");
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine(e.Message);
}
}
finally
{
client.Dispose();
Console.ReadKey();
}
}