AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
SessionExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using System.Collections.Generic;
5 
6 namespace HoloToolkit.Sharing
7 {
11  public static class SessionExtensions
12  {
24  public static string GetUnusedName(this Session session, string baseName, int excludedUserId = int.MaxValue)
25  {
26  List<string> nameList = new List<string>();
27  return GetUnusedName(session, baseName, excludedUserId, nameList);
28  }
29 
43  public static string GetUnusedName(this Session session, string baseName, int excludedUserId, List<string> cachedList)
44  {
45  cachedList.Clear();
46 
47  for (int i = 0; i < session.GetUserCount(); i++)
48  {
49  using (var user = session.GetUser(i))
50  using (var userName = user.GetName())
51  {
52  string userNameString = userName.GetString();
53  if (user.GetID() != excludedUserId && userNameString.StartsWith(baseName))
54  {
55  cachedList.Add(userNameString);
56  }
57  }
58  }
59 
60  cachedList.Sort();
61 
62  int counter = 0;
63  string currentName = baseName;
64  while (cachedList.Contains(currentName))
65  {
66  currentName = baseName + (++counter);
67  }
68 
69  return currentName;
70  }
71  }
72 }
virtual User GetUser(int i)
Definition: Session.cs:75
Extensions methods for the Session class.
static string GetUnusedName(this Session session, string baseName, int excludedUserId=int.MaxValue)
Returns an unused username that can be used for this session.
virtual int GetUserCount()
Definition: Session.cs:70
static string GetUnusedName(this Session session, string baseName, int excludedUserId, List< string > cachedList)
Returns an unused username that can be used for this session.