Mini Kabibi Habibi

Current Path : C:/Users/Public/Documents/DXperience 13.1 Demos/Silverlight/VB/RichEditDemo/
Upload File :
Current File : C:/Users/Public/Documents/DXperience 13.1 Demos/Silverlight/VB/RichEditDemo/Utils.vb

Imports Microsoft.VisualBasic
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Windows
Imports DevExpress.DemoData.Helpers
Imports DevExpress.Xpf.Core
Imports DevExpress.Xpf.DemoBase
Imports DevExpress.Xpf.DemoBase.Helpers
Imports DevExpress.Xpf.RichEdit
Imports DevExpress.XtraRichEdit

Namespace RichEditDemo
	Public Class DemoUtils
		Public Shared Function GetRelativePath(ByVal name As String) As String
			Return DemoHelper.GetPath("RichEditDemo.Data.", GetType(DemoUtils).Assembly) & name
		End Function
		Public Shared Function GetDataStream(ByVal fileName As String) As Stream
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Return System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
			End If
			Return Nothing
		End Function
	End Class
	Public Class RtfLoadHelper
		Public Shared Sub Load(ByVal fileName As String, ByVal richEditControl As RichEditControl)
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Dim stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
				richEditControl.LoadDocument(stream, DocumentFormat.Rtf)
			End If
		End Sub
	End Class
	Public Class DocLoadHelper
		Public Shared Sub Load(ByVal fileName As String, ByVal richEditControl As RichEditControl)
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Dim stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
				richEditControl.LoadDocument(stream, DocumentFormat.Doc)
			End If
		End Sub
	End Class
	Public Class HtmlLoadHelper
		Public Shared Sub Load(ByVal fileName As String, ByVal richEditControl As RichEditControl)
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Dim stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
				richEditControl.LoadDocument(stream, DocumentFormat.Html)
			End If
		End Sub
	End Class
	Public Class OpenXmlLoadHelper
		Public Shared Sub Load(ByVal fileName As String, ByVal richEditControl As RichEditControl)
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Dim stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
				richEditControl.LoadDocument(stream, DocumentFormat.OpenXml)
			End If
		End Sub
	End Class
	Public Class PlainTextLoadHelper
		Public Shared Sub Load(ByVal fileName As String, ByVal richEditControl As RichEditControl)
			Dim path As String = DemoUtils.GetRelativePath(fileName)
			If (Not String.IsNullOrEmpty(path)) Then
				Dim stream As Stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(path)
				richEditControl.LoadDocument(stream, DocumentFormat.PlainText)
			End If
		End Sub
	End Class
	Public Class CodeFileLoadHelper
		Public Shared Sub Load(ByVal moduleName As String, ByVal richEditControl As RichEditControl)
			Dim stream As Stream = DemoHelper.GetCodeTextStream(GetType(CodeFileLoadHelper).Assembly, GetCodeFileName(moduleName), DemoHelper.GetDemoLanguage(GetType(CodeFileLoadHelper).Assembly))
			If stream IsNot Nothing Then
				richEditControl.LoadDocument(stream, DocumentFormat.PlainText)
			End If
		End Sub
		Public Shared Function GetCodeFileName(ByVal moduleName As String) As String
			Return String.Format("{0}.xaml{1}", moduleName, DemoHelper.GetCodeSuffix(GetType(CodeFileLoadHelper).Assembly))
		End Function
	End Class
	Public Class RichEditDemoExceptionsHandler
		Private ReadOnly control As RichEditControl
		Public Sub New(ByVal control As RichEditControl)
			Me.control = control
		End Sub
		Public Sub Install()
			If control IsNot Nothing Then
				AddHandler control.UnhandledException, AddressOf OnRichEditControlUnhandledException
			End If
		End Sub

		Private Sub OnRichEditControlUnhandledException(ByVal sender As Object, ByVal e As RichEditUnhandledExceptionEventArgs)
			Try
				If e.Exception IsNot Nothing Then
					Throw e.Exception
				End If
			Catch ex As RichEditUnsupportedFormatException
				ShowMessage(ex.Message)
				e.Handled = True
			Catch ex As System.Runtime.InteropServices.ExternalException
				ShowMessage(ex.Message)
				e.Handled = True
			Catch ex As System.IO.IOException
				ShowMessage(ex.Message)
				e.Handled = True
			Catch ex As System.InvalidOperationException
				If ex.Message = DevExpress.XtraRichEdit.Localization.XtraRichEditLocalizer.GetString(DevExpress.XtraRichEdit.Localization.XtraRichEditStringId.Msg_MagicNumberNotFound) OrElse ex.Message = DevExpress.XtraRichEdit.Localization.XtraRichEditLocalizer.GetString(DevExpress.XtraRichEdit.Localization.XtraRichEditStringId.Msg_UnsupportedDocVersion) Then
					ShowMessage(ex.Message)
					e.Handled = True
				Else
					Throw ex
				End If
			Catch ex As SystemException
				ShowMessage(ex.Message)
				e.Handled = True
			End Try
		End Sub
		Private Sub ShowMessage(ByVal message As String)
			Dim dialog As DXDialog
			dialog = New DXDialog("RichEdit Demo")
			dialog.Title = "RichEdit Demo"
			dialog.Buttons = DialogButtons.Ok
			dialog.Content = message
			dialog.IsSizable = False
			dialog.Padding = New Thickness(20)
			dialog.ShowDialog()
		End Sub
	End Class
End Namespace