mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Merge pull request #1286 from getalex/patch-3
Updated logging logic and format to CSV (ssrs_migration.rss)
This commit is contained in:
@@ -75,7 +75,7 @@ Private policies As Policy() = Nothing
|
|||||||
Private srcSiteUrl As String = Nothing
|
Private srcSiteUrl As String = Nothing
|
||||||
Private snkSiteUrl As String = Nothing
|
Private snkSiteUrl As String = Nothing
|
||||||
|
|
||||||
Private logFilePath As String = "MigrationLog.txt"
|
Private logFilePath As String = "MigrationLog.csv"
|
||||||
|
|
||||||
''''''''''''''''''''''''''''''''''''''''''''''
|
''''''''''''''''''''''''''''''''''''''''''''''
|
||||||
Sub Main()
|
Sub Main()
|
||||||
@@ -241,8 +241,8 @@ Sub Main()
|
|||||||
RsSnk.CreateFolder(folderName, parentFolder, Nothing)
|
RsSnk.CreateFolder(folderName, parentFolder, Nothing)
|
||||||
Catch er As Exception
|
Catch er As Exception
|
||||||
If (er.Message.Contains("Microsoft.ReportingServices.Diagnostics.Utilities.ItemAlreadyExistsException"))
|
If (er.Message.Contains("Microsoft.ReportingServices.Diagnostics.Utilities.ItemAlreadyExistsException"))
|
||||||
Console.ForegroundColor = ConsoleColor.Yellow
|
Console.ForegroundColor = ConsoleColor.Gray
|
||||||
Console.WriteLine("Folder already exists.")
|
Console.WriteLine("Folder already exists: " + folderName)
|
||||||
Console.ResetColor()
|
Console.ResetColor()
|
||||||
Else
|
Else
|
||||||
Throw ' Unknown Exception
|
Throw ' Unknown Exception
|
||||||
@@ -478,7 +478,7 @@ Function MigrateDataSource(srcItem As CatalogItem) As CatalogItem
|
|||||||
Console.WriteLine(warningMsg)
|
Console.WriteLine(warningMsg)
|
||||||
Console.ResetColor()
|
Console.ResetColor()
|
||||||
|
|
||||||
LogErrorToFile("CATALOGITEM", "Warning", warningMsg)
|
LogErrorToFile("CATALOGITEM", "Warning: " + result.Path, warningMsg)
|
||||||
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@@ -567,7 +567,7 @@ Function MigrateCatalogItem(srcItem As CatalogItem) As CatalogItem
|
|||||||
Console.WriteLine(warningMsg)
|
Console.WriteLine(warningMsg)
|
||||||
Console.ResetColor()
|
Console.ResetColor()
|
||||||
|
|
||||||
LogErrorToFile("CATALOGITEM", "Warning", warningMsg)
|
LogErrorToFile("CATALOGITEM", "Warning: " + result.TypeName, warningMsg)
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
@@ -742,7 +742,7 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
|
|||||||
Console.Write(description)
|
Console.Write(description)
|
||||||
If Not dataRetrievalPlan Is Nothing And TypeOf dataRetrievalPlan.Item Is DataSourceReference Then
|
If Not dataRetrievalPlan Is Nothing And TypeOf dataRetrievalPlan.Item Is DataSourceReference Then
|
||||||
Dim item As DataSourceReference = dataRetrievalPlan.Item
|
Dim item As DataSourceReference = dataRetrievalPlan.Item
|
||||||
Dim ref As String = GetSnkPath(item.Reference)
|
Dim ref As String = GetSnkPathRef(item.Reference)
|
||||||
item.Reference = ref
|
item.Reference = ref
|
||||||
End If
|
End If
|
||||||
RsSnk.CreateDataDrivenSubscription(snkReport.Path, extensionSettings, dataRetrievalPlan, description, eventType, GetMatchData(matchData, RsSnk), parameters)
|
RsSnk.CreateDataDrivenSubscription(snkReport.Path, extensionSettings, dataRetrievalPlan, description, eventType, GetMatchData(matchData, RsSnk), parameters)
|
||||||
@@ -756,7 +756,7 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
|
|||||||
Console.WriteLine(warningMsg)
|
Console.WriteLine(warningMsg)
|
||||||
Console.ResetColor()
|
Console.ResetColor()
|
||||||
|
|
||||||
LogErrorToFile("SUBSCRIPTIONS", "Warning", warningMsg)
|
LogErrorToFile("SUBSCRIPTIONS", "Warning: " + snkReport.Path, warningMsg)
|
||||||
|
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
@@ -795,9 +795,9 @@ Sub MigrateReportSubscriptions(snkReport As CatalogItem, srcReport As CatalogIte
|
|||||||
Console.WriteLine(warningMsg)
|
Console.WriteLine(warningMsg)
|
||||||
Console.ResetColor()
|
Console.ResetColor()
|
||||||
|
|
||||||
LogErrorToFile("SUBSCRIPTIONS", "Warning", warningMsg)
|
LogErrorToFile("SUBSCRIPTIONS", "Warning: " + snkReport.Path, warningMsg)
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@@ -990,10 +990,19 @@ End Sub
|
|||||||
|
|
||||||
'Helper function to link snk reference with relative paths
|
'Helper function to link snk reference with relative paths
|
||||||
Function GetSnkPathRef(srcPath As String) As String
|
Function GetSnkPathRef(srcPath As String) As String
|
||||||
Dim snkPath = srcPath
|
Dim snkPath = srcPath
|
||||||
If srcSiteUrl isNot Nothing
|
|
||||||
snkPath = srcPath.Remove(0, srcSiteUrl.LastIndexOf("/"))
|
If Not SrcIsNative Then
|
||||||
End If
|
'SharePoint integrated mode, will assume /sites server relative URL delimeter
|
||||||
|
If srcSiteUrl isNot Nothing
|
||||||
|
Dim delimeter = "/sites/"
|
||||||
|
snkPath = srcPath.Remove(0, srcSiteUrl.IndexOf(delimeter) + delimeter.Length-1)
|
||||||
|
End If
|
||||||
|
Else
|
||||||
|
'Treat path reference like other scenarios if not intergated mode
|
||||||
|
snkPath = GetSnkPath(srcPath)
|
||||||
|
End If
|
||||||
|
|
||||||
Return snkPath
|
Return snkPath
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
@@ -1189,12 +1198,18 @@ Sub LogErrorToFile(source As String, errItem as String, message As String)
|
|||||||
Dim writer as StreamWriter
|
Dim writer as StreamWriter
|
||||||
|
|
||||||
Try
|
Try
|
||||||
|
Dim fileExists As Boolean = Not File.Exists(logFilePath) OrElse New FileInfo(logFilePath).Length = 0
|
||||||
|
|
||||||
' Create a StreamWriter object
|
' Create a StreamWriter object
|
||||||
writer = New StreamWriter(logFilePath, True)
|
writer = New StreamWriter(logFilePath, True)
|
||||||
|
|
||||||
|
If fileExists Then
|
||||||
|
writer.WriteLine("DateTime, Source, ErrorItem, ErrorMessage")
|
||||||
|
End If
|
||||||
|
|
||||||
' Format log message with timestamp
|
' Format log message with timestamp
|
||||||
Dim timeStamp As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
Dim timeStamp As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
|
||||||
Dim formattedMessage as String = String.Format("{0}, {1}, {2}, ""{3}""", timeStamp, source, errItem, message.Replace(Environment.NewLine, ""))
|
Dim formattedMessage as String = String.Format("{0}, {1}, {2}, ""{3}""", timeStamp, source, errItem, message.Replace(Environment.NewLine, " "))
|
||||||
|
|
||||||
' Write the log entry to file
|
' Write the log entry to file
|
||||||
writer.WriteLine(formattedMessage)
|
writer.WriteLine(formattedMessage)
|
||||||
|
|||||||
Reference in New Issue
Block a user