/// <summary>
        /// Gets one or more elastic job agents from the service.
        /// </summary>
        /// <returns></returns>
        protected override IEnumerable <AzureSqlElasticJobAgentModel> GetEntity()
        {
            ICollection <AzureSqlElasticJobAgentModel> results = null;

            // Returns a list of agents
            if (this.Name == null)
            {
                results = ModelAdapter.ListAgents(this.ResourceGroupName, this.ServerName);
            }
            // Returns an agent
            else
            {
                results = new List <AzureSqlElasticJobAgentModel>();
                results.Add(ModelAdapter.GetAgent(this.ResourceGroupName, this.ServerName, this.Name));
            }

            return(results);
        }
Beispiel #2
0
        /// <summary>
        /// Check to see if the agent already exists in this resource group.
        /// </summary>
        /// <returns>Null if the agent doesn't exist. Otherwise throws exception</returns>
        protected override IEnumerable <AzureSqlElasticJobAgentModel> GetEntity()
        {
            try
            {
                WriteDebugWithTimestamp("AgentName: {0}", Name);
                return(new List <AzureSqlElasticJobAgentModel> {
                    ModelAdapter.GetAgent(this.ResourceGroupName, this.ServerName, this.Name)
                });
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    // The agent does not exist
                    throw new PSArgumentException(
                              string.Format(Properties.Resources.AzureElasticJobAgentNotExists, this.Name, this.ServerName),
                              "AgentName");
                }

                // Unexpected exception encountered
                throw;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Check to see if the agent already exists in this resource group.
        /// </summary>
        /// <returns>Null if the agent doesn't exist. Otherwise throws exception</returns>
        protected override IEnumerable <AzureSqlElasticJobAgentModel> GetEntity()
        {
            try
            {
                WriteDebugWithTimestamp("AgentName: {0}", Name);
                ModelAdapter.GetAgent(this.ResourceGroupName, this.ServerName, this.Name);
            }
            catch (CloudException ex)
            {
                if (ex.Response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    // This is what we want.  We looked and there is no agent with this name.
                    return(null);
                }

                // Unexpected exception encountered
                throw;
            }

            // The agent already exists
            throw new PSArgumentException(
                      string.Format(Properties.Resources.AzureElasticJobAgentExists, this.Name, this.ServerName),
                      "AgentName");
        }