Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hermanussen/630333ff21046f3e4107f3cf1ce1531a to your computer and use it in GitHub Desktop.
Save hermanussen/630333ff21046f3e4107f3cf1ce1531a to your computer and use it in GitHub Desktop.
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Net
Imports System.Text
Imports System.IO
Public Module CdmHelper
Sub CdmRegenerateCode()
If Not DTE.ActiveDocument Is Nothing Then
Dim fileStream As StreamReader = File.OpenText(DTE.ActiveDocument.FullName)
Dim firstLine As String = fileStream.ReadLine()
fileStream.Close()
Dim prefix As String = "// Refresh from URL: "
Dim prefixSql As String = "-- Refresh from URL: "
If firstLine.StartsWith(prefix) Or firstLine.StartsWith(prefixSql) Then
Dim URL As String = firstLine.Substring(prefix.Length)
Dim client As WebClient = New WebClient()
Dim objUTF8 As New UTF8Encoding()
Dim result As String = objUTF8.GetString(client.DownloadData(URL))
File.WriteAllText(DTE.ActiveDocument.FullName, result.TrimStart())
Else
MsgBox("The selected file does not start with '" + prefix + "'. You can only select a valid generated file from CompiledDomainModel.")
End If
Else
MsgBox("Select a file that was generated using CompiledDomainModel first.")
End If
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment