public override void ExecuteCmdlet()
 {
     GetPSResourceGroupLogParameters parameters = new GetPSResourceGroupLogParameters
         {
             Name = Name,
             DeploymentName = DeploymentName,
             All = All.IsPresent
         };
     WriteObject(ResourcesClient.GetResourceGroupLogs(parameters), true);
 }
        public override void ExecuteCmdlet()
        {
            GetPSResourceGroupLogParameters parameters = new GetPSResourceGroupLogParameters
                {
                    Name = Name,
                    DeploymentName = DeploymentName,
                    All = All.IsPresent
                };

            // TODO: http://vstfrd:8080/Azure/RD/_workitems#_a=edit&id=3247094
            //WriteObject(ResourcesClient.GetResourceGroupLogs(parameters), true);
        }
        /// <summary>
        /// Gets event logs.
        /// </summary>
        /// <param name="parameters">Input parameters</param>
        /// <returns>Logs.</returns>
        public virtual IEnumerable <PSDeploymentEventData> GetResourceGroupLogs(GetPSResourceGroupLogParameters parameters)
        {
            if (parameters.All)
            {
                EventDataListResponse listOfEvents =
                    EventsClient.EventData.ListEventsForResourceGroup(new ListEventsForResourceGroupParameters
                {
                    ResourceGroupName = parameters.Name,
                    StartTime         = DateTime.UtcNow - TimeSpan.FromDays(EventRetentionPeriod),
                    EndTime           = DateTime.UtcNow
                });
                return(listOfEvents.EventDataCollection.Value.Select(e => e.ToPSDeploymentEventData()));
            }
            else if (!string.IsNullOrEmpty(parameters.DeploymentName))
            {
                DeploymentGetResult deploymentGetResult;
                try
                {
                    deploymentGetResult = ResourceManagementClient.Deployments.Get(parameters.Name,
                                                                                   parameters.DeploymentName);
                }
                catch
                {
                    throw new ArgumentException(string.Format(ProjectResources.DeploymentWithNameNotFound, parameters.DeploymentName));
                }

                return(GetDeploymentLogs(deploymentGetResult.Deployment.Properties.CorrelationId));
            }
            else
            {
                DeploymentListResult deploymentListResult;
                try
                {
                    deploymentListResult = ResourceManagementClient.Deployments.List(parameters.Name,
                                                                                     new DeploymentListParameters
                    {
                        Top = 1
                    });
                    if (deploymentListResult.Deployments.Count == 0)
                    {
                        throw new ArgumentException(string.Format(ProjectResources.NoDeploymentWereFound, parameters.Name));
                    }
                }
                catch
                {
                    throw new ArgumentException(string.Format(ProjectResources.NoDeploymentWereFound, parameters.Name));
                }

                return(GetDeploymentLogs(deploymentListResult.Deployments[0].Properties.CorrelationId));
            }
        }
        /// <summary>
        /// Gets event logs.
        /// </summary>
        /// <param name="parameters">Input parameters</param>
        /// <returns>Logs.</returns>
        public virtual IEnumerable<PSDeploymentEventData> GetResourceGroupLogs(GetPSResourceGroupLogParameters parameters)
        {
            if (parameters.All)
            {
                EventDataListResponse listOfEvents =
                    EventsClient.EventData.ListEventsForResourceGroup(new ListEventsForResourceGroupParameters
                        {
                            ResourceGroupName = parameters.Name,
                            StartTime = DateTime.UtcNow - TimeSpan.FromDays(EventRetentionPeriod),
                            EndTime = DateTime.UtcNow
                        });
                return listOfEvents.EventDataCollection.Value.Select(e => e.ToPSDeploymentEventData());
            }
            else if (!string.IsNullOrEmpty(parameters.DeploymentName))
            {
                DeploymentGetResult deploymentGetResult;
                try
                {
                    deploymentGetResult = ResourceManagementClient.Deployments.Get(parameters.Name,
                                                                                   parameters.DeploymentName);
                }
                catch
                {
                    throw new ArgumentException(string.Format(ProjectResources.DeploymentWithNameNotFound, parameters.DeploymentName));
                }

                return GetDeploymentLogs(deploymentGetResult.Deployment.Properties.CorrelationId);
            }
            else
            {
                DeploymentListResult deploymentListResult;
                try
                {
                    deploymentListResult = ResourceManagementClient.Deployments.List(parameters.Name,
                        new DeploymentListParameters
                        {
                            Top = 1
                        });
                    if (deploymentListResult.Deployments.Count == 0)
                    {
                        throw new ArgumentException(string.Format(ProjectResources.NoDeploymentWereFound, parameters.Name));
                    }
                }
                catch
                {
                    throw new ArgumentException(string.Format(ProjectResources.NoDeploymentWereFound, parameters.Name));
                }

                return GetDeploymentLogs(deploymentListResult.Deployments[0].Properties.CorrelationId);
            }
        }
        public void GetAzureResourceGroupLogOutputsProperties()
        {
            List<PSDeploymentEventData> result = new List<PSDeploymentEventData>();
            result.Add(new PSDeploymentEventData
                {
                    EventId = "ac7d2ab5-698a-4c33-9c19-0a93d3d7f527",
                    EventName = "Start request",
                    EventSource = "Microsoft Resources",
                    Channels = "Operation",
                    Level = "Informational",
                    Timestamp = DateTime.Now,
                    OperationId = "c0f2e85f-efb0-47d0-bf90-f983ec8be91d",
                    OperationName = "Microsoft.Resources/subscriptions/resourcegroups/deployments/write",
                    Status = "Succeeded",
                    SubStatus = "Created",
                    ResourceGroupName = "foo",
                    ResourceProvider = "Microsoft Resources",
                    ResourceUri =
                        "/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy",
                    HttpRequest = new PSDeploymentEventDataHttpRequest
                    {
                        Url = "http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy",
                        Method = "PUT",
                        ClientId = "1234",
                        ClientIpAddress = "123.123.123.123"
                    },
                    Authorization = new PSDeploymentEventDataAuthorization
                    {
                        Action = "PUT",
                        Condition = "",
                        Role = "Sender",
                        Scope = "None"
                    },
                    Claims = new Dictionary<string, string>
                            {
                                {"aud", "https://management.core.windows.net/"},
                                {"iss", "https://sts.windows.net/123456/"},
                                {"iat", "h123445"}
                            },
                    Properties = new Dictionary<string, string>()
                });

            GetPSResourceGroupLogParameters expected = new GetPSResourceGroupLogParameters();

            resourcesClientMock.Setup(f => f.GetResourceGroupLogs(It.IsAny<GetPSResourceGroupLogParameters>()))
                .Returns(result)
                .Callback((GetPSResourceGroupLogParameters r) => expected = r);

            cmdlet.Name = "foo";

            cmdlet.ExecuteCmdlet();

            Assert.Equal(1, result.Count());
            Assert.Equal("foo", expected.Name);
        }