Enterprise Framework

Software Solutions in the Enterprise

Virtual Box - Resize VMDK by Changing Type To VDI and Converting Back to VMDK

 Found a great article on stack overflow for increasing Virtual Box VMDK Storage Size.  It's by converting to another type VDI  and then converting back to VMDK


VBoxManage clonehd "source.vmdk" "cloned.vdi" --format vdi
VBoxManage modifyhd "cloned.vdi" --resize 51200
VBoxManage clonehd "cloned.vdi" "resized.vmdk" --format vmdk


Stripe Events Switch Statement


switch ($event)

{

    case "account.updated": //describes an account, Occurs whenever an account status or property has changed.

    case "account.application.deauthorized": //describes an application, Occurs whenever a user deauthorizes an application. Sent to the related application only., child parameters

    case "account.external_account.created": //describes an external account (e.g., card or bank account), Occurs whenever an external account is created.

    case "account.external_account.deleted": //describes an external account (e.g., card or bank account), Occurs whenever an external account is deleted.

    case "account.external_account.updated": //describes an external account (e.g., card or bank account), Occurs whenever an external account is updated.

    case "application_fee.created": //describes an application fee, Occurs whenever an application fee is created on a charge.

    case "application_fee.refunded": //describes an application fee, Occurs whenever an application fee is refunded, whether from refunding a charge or from refunding the application fee directly, including partial refunds.

    case "application_fee.refund.updated": //describes a fee refund, Occurs whenever an application fee refund is updated.

    case "balance.available": //describes a balance, Occurs whenever your Stripe balance has been updated (e.g., when a charge is available to be paid out). By default, Stripe automatically transfers funds in your balance to your bank account on a daily basis.

    case "bitcoin.receiver.created": //describes a bitcoin receiver, Occurs whenever a receiver has been created.

    case "bitcoin.receiver.filled": //describes a bitcoin receiver, Occurs whenever a receiver is filled (i.e., when it has received enough bitcoin to process a payment of the same amount).

    case "bitcoin.receiver.updated": //describes a bitcoin receiver, Occurs whenever a receiver is updated.

    case "bitcoin.receiver.transaction.created": //describes a bitcoin receiver, Occurs whenever bitcoin is pushed to a receiver., Occurs whenever an account capability is updated.

    case "charge.captured": //describes a charge, Occurs whenever a previously uncaptured charge is captured.

    case "charge.failed": //describes a charge, Occurs whenever a failed charge attempt occurs.

    case "charge.pending": //describes a charge, Occurs whenever a pending charge is created.

    case "charge.refunded": //describes a charge, Occurs whenever a charge is refunded, including partial refunds.

    case "charge.succeeded": //describes a charge, Occurs whenever a new charge is created and is successful.

    case "charge.updated": //describes a charge, Occurs whenever a charge description or metadata is updated.

    case "charge.dispute.closed": //describes a dispute, Occurs when a dispute is closed and the dispute status changes to charge_refunded, lost, warning_closed, or won.

    case "charge.dispute.created": //describes a dispute, Occurs whenever a customer disputes a charge with their bank.

    case "charge.dispute.funds_reinstated": //describes a dispute, Occurs when funds are reinstated to your account after a dispute is won.

    case "charge.dispute.funds_withdrawn": //describes a dispute, Occurs when funds are removed from your account due to a dispute.

    case "charge.dispute.updated": //describes a dispute, Occurs when the dispute is updated (usually with evidence).

    case "charge.refund.updated": //describes a refund, Occurs whenever a refund is updated on selected payment methods.

    case "coupon.created": //describes a coupon, Occurs whenever a coupon is created.

    case "coupon.deleted": //describes a coupon, Occurs whenever a coupon is deleted.

    case "coupon.updated": //describes a coupon, Occurs whenever a coupon is updated.

    case "customer.created": //describes a customer, Occurs whenever a new customer is created.

    case "customer.deleted": //describes a customer, Occurs whenever a customer is deleted.

    case "customer.updated": //describes a customer, Occurs whenever any property of a customer changes.

    case "customer.discount.created": //describes a discount, Occurs whenever a coupon is attached to a customer.

    case "customer.discount.deleted": //describes a discount, Occurs whenever a coupon is removed from a customer.

    case "customer.discount.updated": //describes a discount, Occurs whenever a customer is switched from one coupon to another.

    case "customer.source.created": //describes a source (e.g., card), Occurs whenever a new source is created for a customer.

    case "customer.source.deleted": //describes a source (e.g., card), Occurs whenever a source is removed from a customer.

    case "customer.source.updated": //describes a source (e.g., card), Occurs whenever a source's details are changed.

    case "customer.subscription.created": //describes a subscription, Occurs whenever a customer is signed up for a new plan.

    case "customer.subscription.deleted": //describes a subscription, Occurs whenever a customer's subscription ends.

    case "customer.subscription.trial_will_end": //describes a subscription, Occurs three days before the trial period of a subscription is scheduled to end.

    case "customer.subscription.updated": //describes a subscription, Occurs whenever a subscription changes (e.g., switching from one plan to another or changing the status from trial to active).

    case "invoice.created": //describes an invoice, Occurs whenever a new invoice is created. See Using Webhooks with Subscriptions to learn how webhooks can be used with, and affect, this event.

    case "invoice.payment_failed": //describes an invoice, Occurs whenever an invoice payment attempt fails, either due to a declined payment or the lack of a stored payment method.

    case "invoice.payment_succeeded": //describes an invoice, Occurs whenever an invoice payment attempt succeeds.

    case "invoice.sent": //describes an invoice, Occurs whenever an invoice email is sent out.

    case "invoice.upcoming": //describes an invoice, Occurs X number of days before a subscription is scheduled to create an invoice that is charged automatically, where X is determined by your subscriptions settings.

    case "invoice.updated": //describes an invoice, Occurs whenever an invoice changes (e.g., the invoice amount).

    case "invoiceitem.created": //describes an invoiceitem, Occurs whenever an invoice item is created.

    case "invoiceitem.deleted": //describes an invoiceitem, Occurs whenever an invoice item is deleted.

    case "invoiceitem.updated": //describes an invoiceitem, Occurs whenever an invoice item is updated.

    case "order.created": //describes an order, Occurs whenever an order is created.

    case "order.payment_failed": //describes an order, Occurs whenever an order payment attempt fails.

    case "order.payment_succeeded": //describes an order, Occurs whenever an order payment attempt succeeds.

    case "order.updated": //describes an order, Occurs whenever an order is updated.

    case "order_return.created": //describes an order return, Occurs whenever an order return is created.

    case "payout.canceled": //describes a payout, Occurs whenever a payout is canceled.

    case "payout.created": //describes a payout, Occurs whenever a payout is created.

    case "payout.failed": //describes a payout, Occurs whenever a payout attempt fails.

    case "payout.paid": //describes a payout, Occurs whenever a payout is expected to be available in the destination account. If the payout fails, a payout.failed notification is additionally sent at a later time.

    case "payout.updated": //describes a payout, Occurs whenever the metadata of a payout is updated.

    case "plan.created": //describes a plan, Occurs whenever a plan is created.

    case "plan.deleted": //describes a plan, Occurs whenever a plan is deleted.

    case "plan.updated": //describes a plan, Occurs whenever a plan is updated.

    case "product.created": //describes a product, Occurs whenever a product is created.

    case "product.deleted": //describes a product, Occurs whenever a product is deleted.

    case "product.updated": //describes a product, Occurs whenever a product is updated.

    case "recipient.created": //describes a recipient, Occurs whenever a recipient is created.

    case "recipient.deleted": //describes a recipient, Occurs whenever a recipient is deleted.

    case "recipient.updated": //describes a recipient, Occurs whenever a recipient is updated.

    case "review.closed": //describes a review, Occurs whenever a review is closed. The review's reason field indicates why (e.g., approved, refunded, refunded_as_fraud, disputed.

    case "review.opened": //describes a review, Occurs whenever a review is opened.

    case "scheduled_query_run.created": //describes a scheduled query run, Occurs whenever a sigma scheduled query run completes.

    case "sku.created": //describes a sku, Occurs whenever a SKU is created.

    case "sku.deleted": //describes a sku, Occurs whenever a SKU is deleted.

    case "sku.updated": //describes a sku, Occurs whenever a SKU is updated.

    case "source.canceled": //describes a source (e.g., card), Occurs whenever a source is canceled.

    case "source.chargeable": //describes a source (e.g., card)    case "capability.updated": //describes a capability, Occurs whenever a source transitions to chargeable.

    case "source.failed": //describes a source (e.g., card)" Occurs whenever a source fails.

    case "source.transaction.created": //describes a transaction    

    case "capability.updated": //describes a capability    

    case "source.failed": //describes a source (e.g., card)" Occurs whenever a source fails., Occurs whenever a source transaction is created.

    case "transfer.created": //describes a transfer": //, Occurs whenever a transfer is created.

    case "transfer.reversed": //describes a transfer": //    

    case "capability.updated": //describes a capability, Occurs whenever a transfer is reversed, including partial reversals.

    case "transfer.updated": // describes a transfer, Occurs whenever the description or metadata of a transfer is updated.

    case "ping": //has no descriptionm May be sent by Stripe at any time to see if a provided webhook URL is working.

      break;

  }


Azure Application Gateway with SSL Offloading - IIS Url Rewrite from HTTP to HTTPS Redirect

<rewrite> 

<rules> 

<rule name="HTTP To HTTPS Redirect Behind App Gtwy" stopProcessing="true"> 

<match url="^(.*)$" ignoreCase="false" /> 

<conditions logicalGrouping="MatchAny"> 

<add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" /> 

</conditions> 

<action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" /> 

</rule> 

</rules> 

</rewrite>


You can also do this HTTP to HTTPS redirect through the Application Gateway using PowerShell.

https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-configure-redirect-powershell


Create PFX from Azure App Service Certificate Service

I recently created a Azure App Service Certificate that I wanted to use with Azure Application Gateway.  However, this requires you to upload an PFX file and there isn't an option to generate one from Azure App Service Certificate.  However, I found an article that can generate the PFX for you from the App Service Certificate;

https://blogs.msdn.microsoft.com/appserviceteam/2017/02/24/creating-a-local-pfx-copy-of-app-service-certificate/

The step by step I had to do:

1.  Verify new certificate was valid and not expired

2.  Install the Azure PowerShell commandlets. Install instructions from https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps?view=azurermps-6.7.0&viewFallbackFrom=azurermps-6.2.0

Open Powershell ISE as Administrator

4.  Run:  Install-Module -Name AzureRM

Sign into Azure

# Import the module into the PowerShell session

5.  Run:  Import-Module AzureRM

# Connect to Azure with an interactive dialog for sign-in

6.  Run:  Connect-AzureRmAccount

Paste the below into the Powershell Window

Function Export-AppServiceCertificate
{
###########################################################

Param(
[Parameter(Mandatory=$true,Position=1,HelpMessage="ARM Login Url")]
[string]$loginId,

[Parameter(Mandatory=$true,HelpMessage="Subscription Id")]
[string]$subscriptionId,

[Parameter(Mandatory=$true,HelpMessage="Resource Group Name")]
[string]$resourceGroupName,

[Parameter(Mandatory=$true,HelpMessage="Name of the App Service Certificate Resource")]
[string]$name
)

###########################################################

Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId

## Get the KeyVault Resource Url and KeyVault Secret Name were the certificate is stored
$ascResource= Get-AzureRmResource -ResourceId "/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.CertificateRegistration/certificateOrders/$name"
$certProps = Get-Member -InputObject $ascResource.Properties.certificates[0] -MemberType NoteProperty
$certificateName = $certProps[0].Name
$keyVaultId = $ascResource.Properties.certificates[0].$certificateName.KeyVaultId
$keyVaultSecretName = $ascResource.Properties.certificates[0].$certificateName.KeyVaultSecretName

## Split the resource URL of KeyVault and get KeyVaultName and KeyVaultResourceGroupName
$keyVaultIdParts = $keyVaultId.Split("/")
$keyVaultName = $keyVaultIdParts[$keyVaultIdParts.Length - 1]
$keyVaultResourceGroupName = $keyVaultIdParts[$keyVaultIdParts.Length - 5]

## --- !! NOTE !! ----
## Only users who can set the access policy and has the the right RBAC permissions can set the access policy on KeyVault, if the command fails contact the owner of the KeyVault
Set-AzureRmKeyVaultAccessPolicy -ResourceGroupName $keyVaultResourceGroupName -VaultName $keyVaultName -UserPrincipalName $loginId -PermissionsToSecrets get
Write-Host "Get Secret Access to account $loginId has been granted from the KeyVault, please check and remove the policy after exporting the certificate"

## Getting the secret from the KeyVault
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$pfxCertObject= New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @([Convert]::FromBase64String($secret.SecretValueText),"",[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 50 | % {[char]$_})
$currentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[io.file]::WriteAllBytes(".\appservicecertificate.pfx",$pfxCertObject.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12,$pfxPassword))

## --- !! NOTE !! ----
## Remove the Access Policy required for exporting the certificate once you have exported the certificate to prevent giving the account prolonged access to the KeyVault
## The account will be completely removed from KeyVault access policy and will prevent to account from accessing any keys/secrets/certificates on the KeyVault, 
## Run the following command if you are sure that the account is not used for any other access on the KeyVault or login to the portal and change the access policy accordingly.
# Remove-AzureRmKeyVaultAccessPolicy -ResourceGroupName $keyVaultResourceGroupName -VaultName $keyVaultName -UserPrincipalName $loginId
# Write-Host "Access to account $loginId has been removed from the KeyVault"

# Print the password for the exported certificate
Write-Host "Created an App Service Certificate copy at: $currentDirectory\appservicecertificate.pfx"
Write-Warning "For security reasons, do not store the PFX password. Use it directly from the console as required."
Write-Host "PFX password: $pfxPassword"
}

Then execute the following:

Export-AppServiceCertificate -loginId youremail@domain.com -subscriptionId ########-####-####-####-############ -resourceGroupName YourCertResourceGroupName -name NameOfCertificate
 


Mac Sierra : Git Completion and Bash Prompt With Branch Update

The following will help get GIT completion setup locally on Mac Sierra.  Not correctly loading the git-completion.bash or git-prompt.sh can result in getting the following error: 


ERROR:   __git_ps1: command not found


Check that you did not mistype the file name as that could result in the script not being found and ran.


STEPS:

$ cd ~/Downloads       

$ curl -OL https://github.com/git/git/raw/master/contrib/completion/git-completion.bash

$ mv git-completion.bash ~/.git-completion.bash

$ sudo nano ~/.bashrc

ADD .bashrc CONTENTS
===============================
 
if [ -f ~/.git-completion.bash ]; then
    source ~/.git-completion.bash
fi
 


$ cd ~/Downloads/

$ curl -OL https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
 
$ mv ~/Downloads/git-prompt.sh ~/.git-prompt.sh

 
UPDATE .bash_profile CONTENTS
===============================
 
if [ -f ~/.git-prompt.sh ]; then
    source ~/.git-prompt.sh
fi
 
export PS1='\h:\u \W$(__git_ps1 "(%s)") $ '

Error: Microsoft Graph Development connecting to Outlook API returns Sign In Trouble Bad Request

After registering your app in https://apps.dev.microsoft.com/ and trying to connect to the Microsoft Outlook API using Microsoft Graph, you get the following Error:

Sign In
Sorry, but we’re having trouble signing you in.

We received a bad request.


CODE : THINGS TO CHECK

Make sure your API key and Password are correct in your app code.

API : THINGS TO CHECK

  1. Go to the Application Registration Portal at https://apps.dev.microsoft.com/
  2. Select your application
  3. Add your local development urls, 
    1. http://localhost
    2. http://localhost:8080
    3. https://localhost:44300
Make sure the redirect being passed from the code to Graph is passing a Url registered in the Application Registration Portal.  If successful, you should see:

App publisher website: localhost




Error : Entity Framework : Update-Database

Error : Entity Framework : Update-Database

PM> Update-Database -ConnectionString "data source=.;Integrated Security=true;initial catalog=my_db" -ConnectionProviderName "System.Data.SqlClient" -Verbose

Using StartUp project 'Integration Services Project1'.

Using NuGet project 'MyDataProject'.

Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.DataWarehouse.VsIntegration.Shell.Project.Extensibility.ProjectExt' in assembly 'Microsoft.DataWarehouse.VsIntegration, 

Version=13.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' is not marked as serializable."

At C:\Source\Repos\MyApplication\packages\EntityFramework.6.1.3\tools\EntityFramework.psm1:720 char:5

+     $domain.SetData('startUpProject', $startUpProject)

+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : SerializationException

 System.NullReferenceException: Object reference not set to an instance of an object.

   at System.Data.Entity.Migrations.Extensions.ProjectExtensions.GetProjectTypes(Project project, Int32 shellVersion)

   at System.Data.Entity.Migrations.Extensions.ProjectExtensions.IsWebProject(Project project)

   at System.Data.Entity.Migrations.MigrationsDomainCommand.GetFacade(String configurationTypeName, Boolean useContextWorkingDirectory)

   at System.Data.Entity.Migrations.UpdateDatabaseCommand.<>c__DisplayClass2.<.ctor>b__0()

   at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)

Object reference not set to an instance of an object.


How to fix:

  1. In Package Manager Console, make sure "Default Project" is set to the project that has Data Migrations enabled
  2. Make sure the Web Project is set as the Start project (I know crazy)
  3. Make sure the database connection string is correct.



Error : Sitefinity Thunder Compile Error

Error:

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS0433    The type 'DatabaseGeneratedOption' exists in both 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'    MyApplications    C:\Source\Repos\MyApplications\Models\ApplicationType.cs    98    Active

Fix:

The generated Sitefinity Assembly has a different Target .NET Framework.

Right Click a Project > Choose Properties > Ensure all Target Framework versions are the same.  (Example 4.5)

How To : NuGet Best Practices for Adding To New or Existing Projects

How To : NuGet Best Practices For Adding to New or Existing Projects

Keeping Nuget packages consistent in your solution is critical.  A lot of devs even now and days do it the hard way by going to the individual projects and trying to manage the Packages that way.  Managing NuGet packages in your solutions is easier than you think it is and will reduce headaches of DLL hell.

Packages in Source Control

  • DO NOT put NuGet packages into Source Control.  Exclude the Packages folder from the Solution root before checking in.  Whenever your solution is pulled fresh from source control, it will determine the packages don't exist and try to pull them down automatically if they are from the public NuGet servers.
  • DO NOT distribute packages with your code unless they are from your internal NuGet server and you are giving it to a client or something.
Using Visual Studio 2015

  • Right click the Solution > Choose Manage NuGet Packages for Solution.
  • Click Installed, this will show you all of the NuGet packages in the left column currently used by all projects in the solution.  The right column displays a list of the projects and the NuGet package version that is installed next to it.  
  • In the left column, choose a NuGet Package (Example:  Newtonsoft.Json)   
  • In the right column in the list of projects, you should scroll down and ensure that all the version numbers are the same across all projects, if they are not, you really should update them.  You can do this by putting a check next to the project with a older NuGet version.  Then in Version row, choose the one that matches the other projects in the solutions and click, 
NOTE:  Before updating packages you should finish any development work you are on before messing with NuGet Packages.  

Summary:  
  • DO NOT include the NuGet Packages folder in source control.  
  • DO NOT distribute NuGet Packages unless from internal NuGet server and you need to.
  • Use Manage NuGet Packages for solution to determine which NuGet packages and versions are being used across projects.  
  • Sync NuGet package versions across projects (Checkin Dev work before messing with Packages).