Beispiel #1
0
        private static void ConvertTemplate(IEnumerable <XElement> images, List <Template> templates, string desktopType)
        {
            foreach (var item in images)
            {
                var name          = (string)item.Element("name").Value;
                var description   = (string)item.Element("displaytext").Value;
                var id            = (string)item.Element("id").Value;
                var ready         = (string)item.Element("status").Value;
                var ostypename    = (string)item.Element("ostypename").Value;
                var size          = item.Element("size") == null ? "Calculating" : (string)item.Element("size").Value;
                var owner         = "Self";
                var inventoryPath = XenDesktopInventoryItem.GetTemplatePathFromName(name);
                var tmplt         = new Template()
                {
                    DesktopType   = desktopType,
                    InventoryPath = inventoryPath,
                    Name          = name,
                    Description   = description,
                    Id            = id,
                    Ready         = ready,
                    OsType        = ostypename,
                    Size          = size,
                    Owner         = owner,
                };

                logger.Debug("Enumerated template " + tmplt.ToString());
                templates.Add(tmplt);
            }
        }
Beispiel #2
0
        public static List <XenDesktopInventoryItem> GetInventoryItems(string scriptName, string xenDestkopPath)
        {
            var result = new List <XenDesktopInventoryItem>();

            try
            {
                var psNets = InvokeScript(scriptName, xenDestkopPath);

                foreach (PSObject item in psNets)
                {
                    string name    = (string)item.Members["Name"].Value;
                    string id      = (string)item.Members["FullPath"].Value;
                    var    newRsrc = new XenDesktopInventoryItem()
                    {
                        Name = name,
                        Id   = id
                    };

                    logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                    result.Add(newRsrc);
                } // End foreach.
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
            return(result);
        }
Beispiel #3
0
        public static List <XenDesktopInventoryItem> GetActiveDirectoryUsers()
        {
            var ldapPath = DT2.Properties.Settings.Default.LdapPath;
            var users    = new List <XenDesktopInventoryItem>();

            try
            {
                // Search for all users in domain
                // see http://msdn.microsoft.com/en-us/library/ms180885(v=vs.80).aspx
                //
                //this is the connection to your active directory
                DirectoryEntry entry = new DirectoryEntry(ldapPath);
                // Create a DirectorySearcher object.
                DirectorySearcher mySearcher = new DirectorySearcher(entry);
                // Create a SearchResultCollection object to hold a collection of SearchResults
                // returned by the FindAll method.
                SearchResultCollection searchResult = mySearcher.FindAll();

                foreach (SearchResult item in searchResult)
                {
                    if (item.Properties["samaccountname"].Count == 0)
                    {
                        continue;
                    }

                    int samaccounttype = (int)item.Properties["samaccounttype"][0];
                    if (samaccounttype != 0x30000000 && samaccounttype != 0x10000000)
                    {
                        continue;
                    }

                    var acctName = (string)item.Properties["samaccountname"][0];
                    if (UsersSkipList.Contains(acctName))
                    {
                        continue;
                    }

                    var user = new XenDesktopInventoryItem
                    {
                        Id   = acctName,
                        Name = acctName
                    };
                    users.Add(user);
                }
                users.Sort(new Comparison <XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));
            }
            catch (System.Exception ex)
            {
                var errmsg = "Problem searching for users in " + ldapPath + "  Details: " + ex.Message;
                logger.Error(errmsg);
            }
            return(users);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// Faster when data retrieved directly through CSSDK
        /// </remarks>
        public static List <XenDesktopInventoryItem> GetServiceOfferingList()
        {
            var result = new List <XenDesktopInventoryItem>();

            try
            {
                var psNets = InvokeScript(ScriptNames.GetServiceOfferings, XenDesktopHostingUnitPath);

                // Use service offerings with DIaaS in name or description
                foreach (PSObject item in psNets)
                {
                    string desc = (string)item.Members["Description"].Value;
                    string name = (string)item.Members["Name"].Value;

                    if (!desc.Contains("DIaaS") && !name.Contains("DIaaS"))
                    {
                        continue;
                    }
                    string id      = (string)item.Members["FullPath"].Value;
                    var    newRsrc = new XenDesktopInventoryItem()
                    {
                        Name = name,
                        Id   = id
                    };

                    logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                    result.Add(newRsrc);
                } // End foreach.

                if (result.Count == 0)
                {
                    foreach (PSObject item in psNets)
                    {
                        string name    = (string)item.Members["Name"].Value;
                        string id      = (string)item.Members["FullPath"].Value;
                        var    newRsrc = new XenDesktopInventoryItem()
                        {
                            Name = name,
                            Id   = id
                        };

                        logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                        result.Add(newRsrc);
                    } // End foreach.
                }
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
            return(result);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// Faster when data retrieved directly through CSSDK
        /// </remarks>
        public static List<XenDesktopInventoryItem> GetServiceOfferingList()
        {
            var result = new List<XenDesktopInventoryItem>();
            try
            {
                var psNets = InvokeScript(ScriptNames.GetServiceOfferings, XenDesktopHostingUnitPath);

                // Use service offerings with DIaaS in name or description
                foreach (PSObject item in psNets)
                {
                    string desc = (string) item.Members["Description"].Value;
                    string name = (string)item.Members["Name"].Value;

                    if (!desc.Contains("DIaaS") && !name.Contains("DIaaS"))
                    {
                        continue;
                    }
                    string id = (string) item.Members["FullPath"].Value;
                    var newRsrc = new XenDesktopInventoryItem()
                    {
                        Name = name,
                        Id = id
                    };

                    logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                    result.Add(newRsrc);
                } // End foreach.

                if (result.Count == 0)
                {
                    foreach (PSObject item in psNets)
                    {
                        string name = (string) item.Members["Name"].Value;
                        string id = (string) item.Members["FullPath"].Value;
                        var newRsrc = new XenDesktopInventoryItem()
                        {
                            Name = name,
                            Id = id
                        };

                        logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                        result.Add(newRsrc);
                    } // End foreach.
                }
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
            return result;
        }
 public static int Compare(XenDesktopInventoryItem x, XenDesktopInventoryItem y)
 {
     return x.Name.CompareTo(y.Name);
 }
        public static List<XenDesktopInventoryItem> GetInventoryItems(string scriptName, string xenDestkopPath)
        {
            var result = new List<XenDesktopInventoryItem>();
            try
            {
                var psNets = InvokeScript(scriptName, xenDestkopPath);

                foreach (PSObject item in psNets)
                {
                    string name = (string)item.Members["Name"].Value;
                    string id = (string)item.Members["FullPath"].Value;
                    var newRsrc = new XenDesktopInventoryItem()
                    {
                        Name = name,
                        Id = id
                    };

                    logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                    result.Add(newRsrc);
                } // End foreach.
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
            return result;
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <remarks>
        /// Faster when data retrieved directly through CSSDK
        /// </remarks>
        public static List <XenDesktopInventoryItem> GetServiceOfferingList()
        {
            var result = new List <XenDesktopInventoryItem>();

            if (DT2.Properties.Settings.Default.TestDisableServiceOfferingGet)
            {
                result.Add(new XenDesktopInventoryItem()
                {
                    Name = "TinyInstance", Uuid = "f1a234ae-1d5a-4fbc-817f-40c0c65e4e32", Id = @"XDHyp:\HostingUnits\CloudPlatformHost\TinyInstance.serviceoffering"
                });
                result.Add(new XenDesktopInventoryItem()
                {
                    Name = "SmallInstance", Uuid = "68416055-1d04-4e30-a290-740b8871fab0", Id = @"XDHyp:\HostingUnits\CloudPlatformHost\SmallInstance.serviceoffering"
                });
                result.Add(new XenDesktopInventoryItem()
                {
                    Name = "MediumInstance", Uuid = "9ad659d8-fe83-409f-8f65-2af4e4c7efb9", Id = @"XDHyp:\HostingUnits\CloudPlatformHost\MediumInstance.serviceoffering"
                });
                result.Add(new XenDesktopInventoryItem()
                {
                    Name = "LargeInstance", Uuid = "567c52c9-0e1e-4def-ac49-396d9f1c2c98", Id = @"XDHyp:\HostingUnits\CloudPlatformHost\LargeInstance.serviceoffering"
                });
                return(result);
            }
            try
            {
                var psNets = InvokeScript(ScriptNames.GetServiceOfferings, XenDesktopHostingUnitPath);

                // Use service offerings with DIaaS in name or description
                foreach (PSObject item in psNets)
                {
                    string desc = (string)item.Members["Description"].Value;
                    string name = (string)item.Members["Name"].Value;

                    if (!desc.Contains("DIaaS") && !name.Contains("DIaaS"))
                    {
                        continue;
                    }
                    string uuid    = (string)item.Members["Id"].Value;
                    string id      = (string)item.Members["FullPath"].Value;
                    var    newRsrc = new XenDesktopInventoryItem()
                    {
                        Name = name,
                        Id   = id,
                        Uuid = uuid
                    };

                    logger.Debug("Adding " + name + " Id " + id + " to theb list of resources");
                    result.Add(newRsrc);
                } // End foreach.

                if (result.Count == 0)
                {
                    foreach (PSObject item in psNets)
                    {
                        string name    = (string)item.Members["Name"].Value;
                        string uuid    = (string)item.Members["Id"].Value;
                        string id      = (string)item.Members["FullPath"].Value;
                        var    newRsrc = new XenDesktopInventoryItem()
                        {
                            Name = name,
                            Id   = id,
                            Uuid = uuid
                        };

                        logger.Debug("Adding " + name + " Id " + id + " to the list of resources");
                        result.Add(newRsrc);
                    } // End foreach.
                }
            }
            catch (Exception e)
            {
                var errMsg = e.Message;
                logger.Error(errMsg);
            }
            return(result);
        }
Beispiel #9
0
 public static int Compare(XenDesktopInventoryItem x, XenDesktopInventoryItem y)
 {
     return(x.Name.CompareTo(y.Name));
 }
Beispiel #10
0
        public static List <XenDesktopInventoryItem> GetActiveDirectoryUsers(string query)
        {
            var users      = new List <XenDesktopInventoryItem>();
            var grps       = new List <XenDesktopInventoryItem>();
            var usersFinal = new List <XenDesktopInventoryItem>();

            LoginViewModel clientId =
                LoginViewModel.JsonDeserialize(((FormsIdentity)HttpContext.Current.User.Identity).Ticket);

            logger.Debug("Find users and groups in domain of " + clientId.UserName);

            string searchDomain = clientId.DomainName;

            try
            {
                PrincipalContext adController = new PrincipalContext(ContextType.Domain, searchDomain, clientId.UserName, clientId.Password);

                UserPrincipal user = new UserPrincipal(adController);
                user.SamAccountName = query;
                PrincipalSearcher usrSrch = new PrincipalSearcher(user);
                PrincipalSearchResult <Principal> userSearchResult = usrSrch.FindAll();
                logger.Debug("Search for users netted " + userSearchResult.Count() + " results.");

                GroupPrincipal grp = new GroupPrincipal(adController);
                grp.SamAccountName = query;
                PrincipalSearcher grpSrch = new PrincipalSearcher(grp);
                PrincipalSearchResult <Principal> grpSearchResult = grpSrch.FindAll();
                logger.Debug("Search for groups netted " + grpSearchResult.Count() + " results.");

                int grpCount = 20;
                foreach (var currGrp in grpSearchResult)
                {
                    if (UsersSkipList.Contains(currGrp.SamAccountName))
                    {
                        continue;
                    }

                    var userRsrc = new XenDesktopInventoryItem
                    {
                        Id   = searchDomain + "\\" + currGrp.SamAccountName,
                        Name = searchDomain + "\\" + currGrp.SamAccountName + "(group)"
                    };

                    grps.Add(userRsrc);

                    grpCount--;
                    if (grpCount < 0)
                    {
                        break;
                    }
                }
                grps.Sort(new Comparison <XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));

                int userCount = 100;
                foreach (var currUser in userSearchResult)
                {
                    if (UsersSkipList.Contains(currUser.SamAccountName))
                    {
                        continue;
                    }

                    var userRsrc = new XenDesktopInventoryItem
                    {
                        Id   = searchDomain + "\\" + currUser.SamAccountName,
                        Name = searchDomain + "\\" + currUser.SamAccountName
                    };

                    users.Add(userRsrc);

                    userCount--;
                    if (userCount < 0)
                    {
                        break;
                    }
                }

                users.Sort(new Comparison <XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));
                usersFinal = grps.Concat(users).ToList();
            }
            catch (System.Exception ex)
            {
                var errmsg = "Problem searching for users in " + searchDomain + "  Details: " + ex.Message;
                logger.Error(errmsg);
                logger.Error(ex);
            }
            return(usersFinal);
        }
Beispiel #11
0
        public static List<XenDesktopInventoryItem> GetActiveDirectoryUsers(string query)
        {
            var users = new List<XenDesktopInventoryItem>();
            var grps = new List<XenDesktopInventoryItem>();
            var usersFinal = new List<XenDesktopInventoryItem>();

            LoginViewModel clientId =
                LoginViewModel.JsonDeserialize(((FormsIdentity)HttpContext.Current.User.Identity).Ticket);
            logger.Debug("Find users and groups in domain of " + clientId.UserName);

            string searchDomain = clientId.DomainName;

            try
            {
                PrincipalContext adController = new PrincipalContext(ContextType.Domain, searchDomain, clientId.UserName, clientId.Password );

                UserPrincipal user = new UserPrincipal(adController);
                user.SamAccountName = query;
                PrincipalSearcher usrSrch = new PrincipalSearcher(user);
                PrincipalSearchResult<Principal> userSearchResult = usrSrch.FindAll();
                logger.Debug("Search for users netted " + userSearchResult.Count() + " results.");

                GroupPrincipal grp = new GroupPrincipal(adController);
                grp.SamAccountName = query;
                PrincipalSearcher grpSrch = new PrincipalSearcher(grp);
                PrincipalSearchResult<Principal> grpSearchResult =grpSrch.FindAll();
                logger.Debug("Search for groups netted " + grpSearchResult.Count() + " results.");

                int grpCount = 20;
                foreach (var currGrp in grpSearchResult)
                {
                    if (UsersSkipList.Contains(currGrp.SamAccountName))
                    {
                        continue;
                    }

                    var userRsrc = new XenDesktopInventoryItem
                    {
                        Id = searchDomain + "\\" + currGrp.SamAccountName,
                        Name = searchDomain + "\\" + currGrp.SamAccountName + "(group)"
                    };

                    grps.Add(userRsrc);

                    grpCount--;
                    if (grpCount < 0)
                    {
                        break;
                    }
                }
                grps.Sort(new Comparison<XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));

                int userCount = 100;
                foreach (var currUser in userSearchResult)
                {
                    if (UsersSkipList.Contains(currUser.SamAccountName))
                    {
                        continue;
                    }

                    var userRsrc = new XenDesktopInventoryItem
                        {
                            Id = searchDomain + "\\" + currUser.SamAccountName,
                            Name = searchDomain + "\\" + currUser.SamAccountName
                        };

                    users.Add(userRsrc);

                    userCount--;
                    if (userCount < 0)
                    {
                        break;
                    }
                }

                users.Sort(new Comparison<XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));
                usersFinal = grps.Concat(users).ToList();
            }
            catch (System.Exception ex)
            {
                var errmsg = "Problem searching for users in " + searchDomain + "  Details: " + ex.Message;
                logger.Error(errmsg);
                logger.Error(ex);
            }
            return usersFinal;
        }
Beispiel #12
0
        public static List<XenDesktopInventoryItem> GetActiveDirectoryUsers()
        {
            var ldapPath = DT2.Properties.Settings.Default.LdapPath;
            var users = new List<XenDesktopInventoryItem>();
            try
            {
                // Search for all users in domain
                // see http://msdn.microsoft.com/en-us/library/ms180885(v=vs.80).aspx
                //
                //this is the connection to your active directory
                DirectoryEntry entry = new DirectoryEntry(ldapPath);
                // Create a DirectorySearcher object.
                DirectorySearcher mySearcher = new DirectorySearcher(entry);
                // Create a SearchResultCollection object to hold a collection of SearchResults
                // returned by the FindAll method.
                SearchResultCollection searchResult = mySearcher.FindAll();

                foreach (SearchResult item in searchResult)
                {
                    if (item.Properties["samaccountname"].Count == 0)
                    {
                        continue;
                    }

                    int samaccounttype = (int) item.Properties["samaccounttype"][0];
                    if (samaccounttype != 0x30000000 && samaccounttype != 0x10000000)
                    {
                        continue;
                    }

                    var acctName = (string) item.Properties["samaccountname"][0];
                    if (UsersSkipList.Contains(acctName))
                    {
                        continue;
                    }

                    var user = new XenDesktopInventoryItem
                    {
                        Id = acctName,
                        Name = acctName
                    };
                    users.Add(user);
                }
                users.Sort(new Comparison<XenDesktopInventoryItem>(XenDesktopInventoryItem.Compare));
            }
            catch (System.Exception ex)
            {
                var errmsg = "Problem searching for users in " + ldapPath + "  Details: " + ex.Message;
                logger.Error(errmsg);
            }
            return users;
        }