|
How To: Use CipherSafe™ API to Perform Administrative Tasks (C#/VB.NET)
The code below demonstrates how to use the CipherSafe™ API,
to perfrom various administrative tasks.
Code samples are provided in
C#
and
Visual Basic.NET.
C# code
[printer-friendly version]
using System;
using Obviex.CipherSafe;
public class CipherSafeAdminDemo
{
[STAThread]
static void Main(string[] args)
{
try
{
ApplicationTypeList appTypes = new ApplicationTypeList();
foreach (ApplicationType appType in appTypes)
{
ApplicationProfile app;
app = ApplicationProfile.Create(
appType.Type,
"Test",
@"c:\dummy");
for (int i=1; i<=9; i++)
{
app[String.Format("Value #{0}", i)] =
String.Format("Data #{0}", i);
}
for (int i=1; i<=9; i += 2)
{
app[String.Format("Value #{0}", i)] =
String.Format("New Data #{0}", i);
}
for (int i=2; i<=9; i += 2)
{
app[String.Format("Value #{0}", i)] = null;
}
if (ApplicationType.IsDir(app.Type))
app.Update("New Test");
}
foreach (ApplicationType appType in appTypes)
{
Console.WriteLine(appType.Name.ToUpper());
ApplicationProfileList apps;
apps = new ApplicationProfileList(appType.Type);
foreach (ApplicationProfile app in apps)
{
Console.WriteLine(" " +
app.Name +
" (" +
app.Path +
")");
foreach (ProfileItem item in app)
{
Console.WriteLine(" " +
item.Name +
" = " +
item.Value);
}
if (ApplicationType.IsFile(app.Type))
app.Delete();
}
}
}
catch (DetailedException ex)
{
Console.WriteLine(ex.Messages);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
^ Back to top
VB.NET code
[printer-friendly version]
Imports System
Imports Obviex.CipherSafe
Module Module1
Sub Main()
Try
Dim i As Integer
Dim appType As ApplicationType
Dim appTypes As New ApplicationTypeList()
For Each appType In appTypes
Dim app As ApplicationProfile
app = ApplicationProfile.Create( _
appType.Type, _
"Test", _
"c:\dummy")
For i=1 To 9
app(String.Format("Value #{0}", i)) = _
String.Format("Data #{0}", i)
Next
For i=1 To 9 Step 2
app(String.Format("Value #{0}", i)) = _
String.Format("New Data #{0}", i)
Next
For i=2 To 9 Step 2
app(String.Format("Value #{0}", i)) = Nothing
Next
If (ApplicationType.IsDir(app.Type) = True) Then
app.Update("New Test")
End If
Next
For Each appType In appTypes
Console.WriteLine(appType.Name.ToUpper())
Dim apps As ApplicationProfileList
apps = New ApplicationProfileList(appType.Type)
Dim app As ApplicationProfile
For Each app In apps
Console.WriteLine(" " & _
app.Name & _
" (" & _
app.Path & _
")")
Dim item As ProfileItem
For Each item in app
Console.WriteLine(" " & _
item.Name & _
" = " & _
item.Value)
Next
If (ApplicationType.IsFile(app.Type) = True) Then
app.Delete()
End If
Next
Next
Catch ex As DetailedException
Console.WriteLine(ex.Messages)
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Module
^ Back to top
|