public static UpdateContactProfile ToSdkContactProfile(this PSContactProfile contactProfile) { if (contactProfile == null) { return(null); } return(new UpdateContactProfile { FirstName = contactProfile.FirstName, LastName = contactProfile.LastName, PhoneNumber = contactProfile.PhoneNumber, Country = contactProfile.Country, PreferredContactMethod = contactProfile.PreferredContactMethod, PreferredTimeZone = contactProfile.PreferredTimeZone, PreferredSupportLanguage = contactProfile.PreferredSupportLanguage, PrimaryEmailAddress = contactProfile.PrimaryEmailAddress, AdditionalEmailAddresses = contactProfile.AdditionalEmailAddresses }); }
public override void ExecuteCmdlet() { var contactObject = new PSContactProfile { FirstName = this.FirstName, LastName = this.LastName, PrimaryEmailAddress = this.PrimaryEmailAddress, PreferredTimeZone = this.PreferredTimeZone, PreferredSupportLanguage = this.PreferredSupportLanguage, PhoneNumber = this.PhoneNumber, AdditionalEmailAddresses = this.AdditionalEmailAddress, Country = this.Country, PreferredContactMethod = this.PreferredContactMethod.ToString() }; if (this.ShouldProcess("Creating contact profile")) { this.WriteObject(contactObject); } }
public static ContactProfile ToContactProfile(this PSContactProfile psContactProfile) { if (psContactProfile == null) { return(null); } return(new ContactProfile { FirstName = psContactProfile.FirstName, LastName = psContactProfile.LastName, PhoneNumber = psContactProfile.PhoneNumber, Country = psContactProfile.Country, PreferredContactMethod = psContactProfile.PreferredContactMethod, PreferredTimeZone = psContactProfile.PreferredTimeZone, PreferredSupportLanguage = psContactProfile.PreferredSupportLanguage, PrimaryEmailAddress = psContactProfile.PrimaryEmailAddress, AdditionalEmailAddresses = psContactProfile.AdditionalEmailAddresses?.ToList() }); }
public override void ExecuteCmdlet() { try { if (this.IsParameterBound(c => this.ProblemStartTime)) { if (this.ProblemStartTime == DateTime.MinValue || this.ProblemStartTime > DateTime.Now) { throw new PSArgumentException(string.Format("ProblemStartTime {0} is not valid.", this.ProblemStartTime)); } } var problemClassificationResourceId = ResourceIdentifierHelper.BuildResourceIdentifier(this.ProblemClassificationId, ResourceType.ProblemClassifications); var checkNameAvailabilityInput = new CheckNameAvailabilityInput { Type = Management.Support.Models.Type.MicrosoftSupportSupportTickets, Name = this.Name }; var checkNameAvailabilityResult = this.SupportClient.SupportTickets.CheckNameAvailability(checkNameAvailabilityInput); if (checkNameAvailabilityResult.NameAvailable.HasValue && !checkNameAvailabilityResult.NameAvailable.Value) { throw new PSArgumentException(string.Format("A SupportTicket with name '{0}' cannot be created for the reason {1}.", this.Name, checkNameAvailabilityResult.Reason)); } if (this.IsParameterBound(c => c.TechnicalTicketResourceId)) { var technicalResourceId = new ResourceIdentifier(this.TechnicalTicketResourceId); if (!technicalResourceId.Subscription.Equals(this.SupportClient.SubscriptionId, StringComparison.OrdinalIgnoreCase)) { throw new PSArgumentException(string.Format("TechnicalResourceId {0} does not belong in subscription {1}.", this.TechnicalTicketResourceId, this.SupportClient.SubscriptionId)); } var resourceClient = AzureSession.Instance.ClientFactory.CreateArmClient <ResourceManagementClient>( DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager); var oDataQuery = new ODataQuery <GenericResourceFilter>($"resourceGroup eq '{technicalResourceId.ResourceGroupName}' and resourceType eq '{technicalResourceId.ResourceType}' and name eq '{technicalResourceId.ResourceName}'"); var result = resourceClient.Resources.List(oDataQuery); if (result.Count() != 1) { throw new Exception(string.Format("TechnicalResourceId {0} was not found in subscription {1}.", this.TechnicalTicketResourceId, this.SupportClient.SubscriptionId)); } } var customHeaders = new Dictionary <string, List <string> >(); if (!string.IsNullOrEmpty(this.CSPHomeTenantId)) { if (!Guid.TryParse(this.CSPHomeTenantId, out var result)) { throw new PSArgumentException(string.Format("CSPHomeTenantId {0} is not a valid Guid.", this.CSPHomeTenantId)); } var auxToken = AzureSession.Instance.AuthenticationFactory.Authenticate(this.DefaultContext.Account, this.DefaultContext.Environment, this.CSPHomeTenantId, null, "Never", null); customHeaders.Add(AUX_HEADER_NAME, new List <string> { $"{AUX_TOKEN_PREFIX} {auxToken.AccessToken}" }); } PSContactProfile contactObject = null; if (this.ParameterSetName.Equals(CreateSupportTicketWithContactObjectParameterSet) || this.ParameterSetName.Equals(CreateQuotaSupportTicketWithContactObjectParameterSet) || this.ParameterSetName.Equals(CreateTechnicalSupportTicketWithContactObjectParameterSet)) { contactObject = this.CustomerContactDetail; } else { contactObject = new PSContactProfile { FirstName = this.CustomerFirstName, LastName = this.CustomerLastName, PrimaryEmailAddress = this.CustomerPrimaryEmailAddress, PreferredTimeZone = this.CustomerPreferredTimeZone, PreferredSupportLanguage = this.CustomerPreferredSupportLanguage, PhoneNumber = this.CustomerPhoneNumber, AdditionalEmailAddresses = this.AdditionalEmailAddress, Country = this.CustomerCountry, PreferredContactMethod = this.PreferredContactMethod.ToString() }; } var supportTicket = new PSSupportTicket { Title = this.Title, Description = this.Description, ServiceId = $"/providers/Microsoft.Support/services/{problemClassificationResourceId.ParentResource}", ProblemClassificationId = this.ProblemClassificationId, Severity = this.Severity.ToString(), Require24X7Response = this.Require24X7Response.IsPresent ? true : (bool?)null, ProblemStartTime = this.IsParameterBound(c => this.ProblemStartTime) ? this.ProblemStartTime.ToUniversalTime() : (DateTime?)null, ContactDetail = contactObject, TechnicalTicketResourceId = this.TechnicalTicketResourceId, QuotaTicketDetail = this.QuotaTicketDetail, }; if (this.ShouldProcess(this.Name, string.Format("Creating a new SupportTicket with name '{0}'.", this.Name))) { var sdkSupportTicket = supportTicket.ToSdkSupportTicket(); var result = this.SupportClient.CreateSupportTicketForSubscription(this.Name, sdkSupportTicket, customHeaders); this.WriteObject(result.ToPSSupportTicket()); } } catch (ExceptionResponseException ex) { throw new PSArgumentException(string.Format("Error response received. Error Message: '{0}'", ex.Response.Content)); } }