Last active
January 21, 2018 10:33
-
-
Save hermanussen/630333ff21046f3e4107f3cf1ce1531a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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