Sets the next counter value for the specified serial number generator.
//Preconditions:
// 1. Start Microsoft Visual Studio.
// 2. Click File > New > Project > C#, Windows, Console > Console App.
// 3. Type RenameBomCSharp in Project name.
// 4. For Location, click ... and navigate to the folder where to create the project.
// 5. Click Next.
// 6. Select Framework.
// 7. Click Create.
// 8. Add dependencies and safely pass arrays of structures.
// 9. Copy the code below to Program.cs.
//10. Change the namespace to match your project name.
//11. Add a serial number generator called “NSN” using the Admin tool.
//12. Ensure that parameters of Login match your vault.
//Postconditions:
//1. Open the Admin Tool.
//2. Observe that the next counter value for the NSN serial number generator is 9.
//Program.cs:
using System;
using System.Linq;
using System.Text;
using EPDM.Interop.epdm;
using EPDM.Interop.EPDMResultCode;
namespace SetNextCounterVal
{
class Program
{
static string userName = "Admin";
static string vaultName = "JEB12";
static string serNoGenName = "NSN";
static int newCounterValue = 9;
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder();
try
{
sb.AppendFormat("UserName: {0}", userName).AppendLine();
sb.AppendFormat("VaultName: {0}", vaultName).AppendLine();
IEdmVault11 vault = (IEdmVault11)(new EdmVault5());
if (!vault.IsLoggedIn)
vault.Login(userName, "password", vaultName);
IEdmSerNoGen7 serNoGen7 = (IEdmSerNoGen7)vault.CreateUtility(EdmUtility.EdmUtil_SerNoGen);
string[] names = { };
serNoGen7.GetSerialNumberNames(out names);
sb.AppendFormat("Serial number generators present in vault: {0}", String.Join(",", names)).AppendLine();
if (names.Contains(serNoGenName))
{
IEdmSerNoGen8 serNoGen8 = (IEdmSerNoGen8)serNoGen7;
serNoGen8.SetSerNoNextCounterVal(serNoGenName, newCounterValue);
sb.AppendFormat("Serial number generator's {0} next counter value set to {1}", serNoGenName, newCounterValue).AppendLine();
}
else
{
sb.AppendFormat("There is no {0} serial number generator present in vault", serNoGenName).AppendLine();
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
var errorType = typeof(EdmResultErrorCodes_e);
if (Enum.IsDefined(errorType, ex.ErrorCode))
sb.AppendFormat("Edm error occurred: {0}", Enum.GetName(errorType, ex.ErrorCode)).AppendLine();
else
sb.AppendLine("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
}
catch (Exception ex)
{
sb.AppendFormat("Error occurred: {0}", ex.Message).AppendLine();
}
Console.WriteLine(sb.ToString());
Console.WriteLine("Please press any key to exit");
Console.ReadKey();
}
}
}