예제 #1
0
 public bool IsUniqueAgentName(string agentName)
 {
     using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
     {
         using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
         {
             ((DbCommand)command).CommandText = "SELECT COUNT(AgentId) AS Cnt FROM Orion.AgentManagement.Agent WHERE Name = @Name";
             command.get_Parameters().AddWithValue("Name", (object)agentName);
             using (InformationServiceDataReader serviceDataReader = command.ExecuteReader())
                 return(!((DbDataReader)serviceDataReader).Read() || (int)((DbDataReader)serviceDataReader)[0] == 0);
         }
     }
 }
예제 #2
0
        private void ProcessDataReader()
        {
            CheckConnection();
            using (var connection = new InformationServiceConnection((IInformationService)SwisConnection))
            {
                connection.Open();
                using (var command = new InformationServiceCommand(Query, connection))
                {
                    command.CommandTimeout = timeOut;
                    command.ApplicationTag = "SwisPowerShell";

                    if (Parameters != null)
                    {
                        foreach (var paramName in Parameters.Keys)
                        {
                            command.Parameters.AddWithValue(paramName.ToString(),
                                                            PropertyBagFromDictionary(Parameters[paramName]));
                        }
                    }

                    using (var reader = command.ExecuteReader())
                    {
                        var factory    = new DataReaderObjectFactory(reader);
                        var enumerator = factory.GetEnumerator();
                        while (enumerator.MoveNext())
                        {
                            WriteObject(enumerator.Current);
                        }

                        if (reader.Errors != null)
                        {
                            StringBuilder sbWarningMessages = new StringBuilder();
                            sbWarningMessages.AppendLine("Warning :: Partial results returned");
                            foreach (var errorMessage in reader.Errors)
                            {
                                sbWarningMessages.AppendLine(string.Format("ErrorType : {0}", errorMessage.ErrorType));
                                sbWarningMessages.AppendLine(string.Format("Context : {0}", errorMessage.Context));
                                sbWarningMessages.AppendLine(string.Format("Message : {0}", errorMessage.Message));
                                sbWarningMessages.AppendLine("-------------------------------------------------");
                            }
                            WriteWarning(sbWarningMessages.ToString());
                        }
                    }
                }
            }
        }
예제 #3
0
        public IEnumerable <AgentInfo> GetAgentsByNodesFilter(
            int engineId,
            string nodesWhereClause)
        {
            List <AgentInfo> agentInfoList = new List <AgentInfo>();

            using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
                {
                    ((DbCommand)command).CommandText = string.Format("SELECT agents.AgentId, \r\n                            agents.AgentGuid, \r\n                            agents.NodeId, \r\n                            nodes.ObjectSubType,\r\n                            agents.Uri,\r\n                            agents.Name, \r\n                            agents.Hostname, \r\n                            agents.IP, \r\n                            agents.PollingEngineId,\r\n                            agents.AgentStatus, \r\n                            agents.AgentStatusMessage, \r\n                            agents.ConnectionStatus, \r\n                            agents.ConnectionStatusMessage,\r\n                            agents.OSType,\r\n                            agents.OSDistro,\r\n                            agents.OSVersion,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage\r\n                    FROM Orion.AgentManagement.Agent agents\r\n                    INNER JOIN Orion.Nodes Nodes ON Nodes.NodeID = agents.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON agents.AgentId = p.AgentId \r\n                    WHERE agents.PollingEngineId=@engineId AND agents.ConnectionStatus = @connectionStatus {0}\r\n                    ORDER BY agents.AgentId", !string.IsNullOrWhiteSpace(nodesWhereClause) ? (object)(" AND " + nodesWhereClause) : (object)string.Empty);
                    command.get_Parameters().AddWithValue("connectionStatus", (object)1);
                    command.get_Parameters().AddWithValue(nameof(engineId), (object)engineId);
                    using (IDataReader reader = (IDataReader)command.ExecuteReader())
                        agentInfoList = this.GetAgentsFromReader(reader);
                }
            }
            return(((IEnumerable <AgentInfo>)agentInfoList).Where <AgentInfo>((Func <AgentInfo, bool>)(x => x.get_NodeID().HasValue&& x.get_NodeSubType() == "Agent")));
        }
        // Token: 0x060006AC RID: 1708 RVA: 0x00029C78 File Offset: 0x00027E78
        public IEnumerable <AgentInfo> GetAgentsByNodesFilter(int engineId, string nodesWhereClause)
        {
            List <AgentInfo> source = new List <AgentInfo>();

            using (InformationServiceConnection informationServiceConnection = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand informationServiceCommand = informationServiceConnection.CreateCommand())
                {
                    informationServiceCommand.CommandText = string.Format("SELECT agents.AgentId, \r\n                            agents.AgentGuid, \r\n                            agents.NodeId, \r\n                            nodes.ObjectSubType,\r\n                            agents.Uri,\r\n                            agents.Name, \r\n                            agents.Hostname, \r\n                            agents.IP, \r\n                            agents.PollingEngineId,\r\n                            agents.AgentStatus, \r\n                            agents.AgentStatusMessage, \r\n                            agents.ConnectionStatus, \r\n                            agents.ConnectionStatusMessage,\r\n                            agents.OSType,\r\n                            agents.OSDistro,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage\r\n                    FROM Orion.AgentManagement.Agent agents\r\n                    INNER JOIN Orion.Nodes Nodes ON Nodes.NodeID = agents.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON agents.AgentId = p.AgentId \r\n                    WHERE agents.PollingEngineId=@engineId AND agents.ConnectionStatus = @connectionStatus {0}\r\n                    ORDER BY agents.AgentId", (!string.IsNullOrWhiteSpace(nodesWhereClause)) ? (" AND " + nodesWhereClause) : string.Empty);
                    informationServiceCommand.Parameters.AddWithValue("connectionStatus", 1);
                    informationServiceCommand.Parameters.AddWithValue("engineId", engineId);
                    using (IDataReader dataReader = informationServiceCommand.ExecuteReader())
                    {
                        source = this.GetAgentsFromReader(dataReader);
                    }
                }
            }
            return(from x in source
                   where x.NodeID != null && x.NodeSubType == "Agent"
                   select x);
        }
예제 #5
0
        private IEnumerable <AgentInfo> GetAgentsInfo(
            string whereClause,
            IDictionary <string, object> parameters)
        {
            List <AgentInfo> agentInfoList = new List <AgentInfo>();

            using (InformationServiceConnection systemConnectionV3 = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand command = systemConnectionV3.CreateCommand())
                {
                    ((DbCommand)command).CommandText = string.Format("SELECT a.AgentId, \r\n                            a.AgentGuid, \r\n                            a.NodeId, \r\n                            n.ObjectSubType,\r\n                            a.Uri,\r\n                            a.Name, \r\n                            a.Hostname, \r\n                            a.IP, \r\n                            a.PollingEngineId,\r\n                            a.AgentStatus, \r\n                            a.AgentStatusMessage, \r\n                            a.ConnectionStatus, \r\n                            a.ConnectionStatusMessage,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage,\r\n                            a.OSType,\r\n                            a.OSDistro,\r\n                            a.OSVersion\r\n                    FROM Orion.AgentManagement.Agent a\r\n                    LEFT JOIN Orion.Nodes n ON n.NodeID = a.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON a.AgentId = p.AgentId \r\n                    {0}\r\n                    ORDER BY a.AgentId", !string.IsNullOrEmpty(whereClause) ? (object)("WHERE " + whereClause) : (object)string.Empty);
                    if (parameters != null)
                    {
                        foreach (KeyValuePair <string, object> parameter in (IEnumerable <KeyValuePair <string, object> >)parameters)
                        {
                            command.get_Parameters().AddWithValue(parameter.Key, parameter.Value);
                        }
                    }
                    using (IDataReader reader = (IDataReader)command.ExecuteReader())
                        return((IEnumerable <AgentInfo>) this.GetAgentsFromReader(reader));
                }
            }
        }
        // Token: 0x060006AD RID: 1709 RVA: 0x00029D6C File Offset: 0x00027F6C
        private IEnumerable <AgentInfo> GetAgentsInfo(string whereClause, IDictionary <string, object> parameters)
        {
            List <AgentInfo> result = new List <AgentInfo>();

            using (InformationServiceConnection informationServiceConnection = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand informationServiceCommand = informationServiceConnection.CreateCommand())
                {
                    informationServiceCommand.CommandText = string.Format("SELECT a.AgentId, \r\n                            a.AgentGuid, \r\n                            a.NodeId, \r\n                            n.ObjectSubType,\r\n                            a.Uri,\r\n                            a.Name, \r\n                            a.Hostname, \r\n                            a.IP, \r\n                            a.PollingEngineId,\r\n                            a.AgentStatus, \r\n                            a.AgentStatusMessage, \r\n                            a.ConnectionStatus, \r\n                            a.ConnectionStatusMessage,\r\n                            p.PluginId, \r\n                            p.Status, \r\n                            p.StatusMessage,\r\n                            a.OSType,\r\n                            a.OSDistro\r\n                    FROM Orion.AgentManagement.Agent a\r\n                    LEFT JOIN Orion.Nodes n ON n.NodeID = a.NodeID\r\n                    LEFT JOIN Orion.AgentManagement.AgentPlugin p ON a.AgentId = p.AgentId \r\n                    {0}\r\n                    ORDER BY a.AgentId", (!string.IsNullOrEmpty(whereClause)) ? ("WHERE " + whereClause) : string.Empty);
                    if (parameters != null)
                    {
                        foreach (KeyValuePair <string, object> keyValuePair in parameters)
                        {
                            informationServiceCommand.Parameters.AddWithValue(keyValuePair.Key, keyValuePair.Value);
                        }
                    }
                    using (IDataReader dataReader = informationServiceCommand.ExecuteReader())
                    {
                        result = this.GetAgentsFromReader(dataReader);
                    }
                }
            }
            return(result);
        }
        // Token: 0x060006AF RID: 1711 RVA: 0x0002A004 File Offset: 0x00028204
        public bool IsUniqueAgentName(string agentName)
        {
            bool result;

            using (InformationServiceConnection informationServiceConnection = InformationServiceConnectionProvider.CreateSystemConnectionV3())
            {
                using (InformationServiceCommand informationServiceCommand = informationServiceConnection.CreateCommand())
                {
                    informationServiceCommand.CommandText = "SELECT COUNT(AgentId) AS Cnt FROM Orion.AgentManagement.Agent WHERE Name = @Name";
                    informationServiceCommand.Parameters.AddWithValue("Name", agentName);
                    using (InformationServiceDataReader informationServiceDataReader = informationServiceCommand.ExecuteReader())
                    {
                        if (informationServiceDataReader.Read())
                        {
                            result = ((int)informationServiceDataReader[0] == 0);
                        }
                        else
                        {
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }