我已经搜索了所有内容,但找不到我需要的答案。因此,感谢所有帮助。
在 Autodesk 的 Vault 工作组中,许可分配给使用 Vault 工作组的用户。但是,当所有的许可证都被使用时,很难知道谁还在登录并且目前没有使用保险库。
所以为了解决这个问题,我想写一个程序,给我一个连接用户的列表。到目前为止,我找到了一些代码来向我展示 Vault 工作组中的所有用户,但这些信息是无用的,因为我知道所有用户帐户。我只需要当前连接的用户。
到目前为止我得到的代码:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void PrintUsers(object sender, RoutedEventArgs e)
{
MyVault.AdminSample.PrintUserInfo();
}
}
class MyVaultServiceManager : System.IDisposable
{
// We will incapsulate the WebServiceManager here.
// The WebServiceManager will be used for our Vault server calls.
private WebServiceManager _svcManager = null;
public WebServiceManager Services
{ get { return _svcManager; } }
public enum Mode { ReadOnly, ReadWrite };
// Preventing usage of the default constructor - made it private
private MyVaultServiceManager() { }
// Constructor.
// Parameter: - Log in as read-only, which doesn't consume
// a license.
//===============================================================
public MyVaultServiceManager(Mode i_ReadWriteMode)
{
UserPasswordCredentials login = new UserPasswordCredentials(
"localhost", "Vault", "Administrator", "",
(i_ReadWriteMode == Mode.ReadOnly));
// Yeah, we shouldn't hardcode the credentials here,
// but this is just a sample
_svcManager = new WebServiceManager(login);
}
void System.IDisposable.Dispose()
{
_svcManager.Dispose();
}
}
class AdminSample
{
// Lists all the users along with their roles and the vaults they
// have access to.
//===============================================================
public static void PrintUserInfo()
{
try
{
using (MyVaultServiceManager mgr = new MyVaultServiceManager(
MyVaultServiceManager.Mode.ReadOnly))
{
// The GetAllUsers method provides all the users' info
//-----------------------------------------------------
User[] users = mgr.Services.AdminService.GetAllUsers();
TextWriter tmp = Console.Out;
FileStream filestream = new FileStream("Vault_Users.txt", FileMode.Create);
var streamwriter = new StreamWriter(filestream);
streamwriter.AutoFlush = true;
Console.SetOut(streamwriter);
foreach (User user in users)
{
UserInfo userInfo = mgr.Services.AdminService.GetUserInfoByUserId(user.Id);
Console.WriteLine(user.Name);
if (userInfo.Roles != null && userInfo.Roles.Length > 0)
{
Console.WriteLine(" Roles:");
foreach (Role role in userInfo.Roles)
{
Console.WriteLine(" ID: " + role.Id + " | Name: " + role.Name);
}
}
if (userInfo.Vaults != null && userInfo.Vaults.Length > 0)
{
Console.WriteLine(" Vaults:");
foreach (KnowledgeVault vault in userInfo.Vaults)
{
Console.WriteLine(" ID: " + vault.Id + " | Name: " + vault.Name);
}
}
Console.WriteLine("");
}
Console.SetOut(tmp);
streamwriter.Close();
filestream.Close();
MessageBox.Show("Done!", "Completed!");
} // using
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
} // PrintUserInfo()
}