WorkflowDesignerLoader.PerformLoad(IDesignerSerializationManager) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
デザイン ドキュメントからデザイナーを読み込みます。
protected:
override void PerformLoad(System::ComponentModel::Design::Serialization::IDesignerSerializationManager ^ serializationManager);
protected override void PerformLoad (System.ComponentModel.Design.Serialization.IDesignerSerializationManager serializationManager);
override this.PerformLoad : System.ComponentModel.Design.Serialization.IDesignerSerializationManager -> unit
Protected Overrides Sub PerformLoad (serializationManager As IDesignerSerializationManager)
パラメーター
- serializationManager
- IDesignerSerializationManager
IDesignerSerializationManager インターフェイスを実装するクラス。このクラスはデザイン時のシリアル化を管理します。
例
次の例は、メソッドをオーバーライドしてワークフローを PerformLoad
逆シリアル化し、ヘルパー メソッドを使用してデザイナーに読み込む方法を AddObjectGraphToDesignerHost
示しています。
protected override void PerformLoad(IDesignerSerializationManager serializationManager)
{
IDesignerHost designerHost = (IDesignerHost)GetService(typeof(IDesignerHost));
Activity rootActivity = null;
// If a WorkflowType already exists, create an instance instead of reading from file
if (WorkflowType != null)
{
rootActivity = (Activity)Activator.CreateInstance(WorkflowType);
}
else
{
// Create a text reader out of the doc data
TextReader reader = new StringReader(this.xoml);
try
{
using (XmlReader xmlReader = XmlReader.Create(reader))
{
WorkflowMarkupSerializer xomlSerializer = new WorkflowMarkupSerializer();
rootActivity = xomlSerializer.Deserialize(xmlReader) as Activity;
}
}
finally
{
reader.Close();
}
}
if (rootActivity != null && designerHost != null)
{
AddObjectGraphToDesignerHost(designerHost, rootActivity);
}
}
private static void AddObjectGraphToDesignerHost(IDesignerHost designerHost, Activity activity)
{
Guid Definitions_Class = new Guid("3FA84B23-B15B-4161-8EB8-37A54EFEEFC7");
if (designerHost == null)
throw new ArgumentNullException("designerHost");
if (activity == null)
throw new ArgumentNullException("activity");
string rootSiteName = activity.QualifiedName;
if (activity.Parent == null)
{
string fullClassName = activity.UserData[Definitions_Class] as string;
if (fullClassName == null)
fullClassName = activity.GetType().FullName;
rootSiteName = (fullClassName.LastIndexOf('.') != -1) ? fullClassName.Substring(fullClassName.LastIndexOf('.') + 1) : fullClassName;
designerHost.Container.Add(activity, rootSiteName);
}
else
{
designerHost.Container.Add(activity, activity.QualifiedName);
}
if (activity is CompositeActivity)
{
foreach (Activity activity2 in GetNestedActivities(activity as CompositeActivity))
designerHost.Container.Add(activity2, activity2.QualifiedName);
}
}
private static Activity[] GetNestedActivities(CompositeActivity compositeActivity)
{
if (compositeActivity == null)
throw new ArgumentNullException("compositeActivity");
IList<Activity> childActivities = null;
ArrayList nestedActivities = new ArrayList();
Queue compositeActivities = new Queue();
compositeActivities.Enqueue(compositeActivity);
while (compositeActivities.Count > 0)
{
CompositeActivity compositeActivity2 = (CompositeActivity)compositeActivities.Dequeue();
childActivities = compositeActivity2.Activities;
foreach (Activity activity in childActivities)
{
nestedActivities.Add(activity);
if (activity is CompositeActivity)
compositeActivities.Enqueue(activity);
}
}
return (Activity[])nestedActivities.ToArray(typeof(Activity));
}
Protected Overrides Sub PerformLoad(ByVal serializationManager As IDesignerSerializationManager)
Dim designerHost As IDesignerHost = CType(GetService(GetType(IDesignerHost)), IDesignerHost)
Dim rootActivity As Activity = Nothing
' If a WorkflowType already exists, create an instance instead of reading from file
If WorkflowType IsNot Nothing Then
rootActivity = CType(Activator.CreateInstance(WorkflowType), Activity)
Else
' Create a text reader out of the doc data
Dim reader As TextReader = New StringReader(Me.Xoml)
Try
Using xmlReader As XmlReader = xmlReader.Create(reader)
Dim xomlSerializer As New WorkflowMarkupSerializer()
rootActivity = CType(xomlSerializer.Deserialize(xmlReader), Activity)
End Using
Finally
reader.Close()
End Try
End If
If rootActivity IsNot Nothing And designerHost IsNot Nothing Then
AddObjectGraphToDesignerHost(designerHost, rootActivity)
End If
End Sub
Private Shared Sub AddObjectGraphToDesignerHost(ByVal designerHost As IDesignerHost, ByVal activity As Activity)
Dim Definitions_Class As New Guid("3FA84B23-B15B-4161-8EB8-37A54EFEEFC7")
If designerHost IsNot Nothing Then
Throw New ArgumentNullException("designerHost")
End If
If activity IsNot Nothing Then
Throw New ArgumentNullException("activity")
End If
Dim rootSiteName As String = activity.QualifiedName
If activity.Parent Is Nothing Then
Dim fullClassName As String = CType(activity.UserData(Definitions_Class), String)
If fullClassName Is Nothing Then
fullClassName = activity.GetType().FullName
End If
rootSiteName = IIf(Not fullClassName.LastIndexOf(".") = -1, fullClassName.Substring(fullClassName.LastIndexOf(".") + 1), fullClassName)
designerHost.Container.Add(activity, rootSiteName)
Else
designerHost.Container.Add(activity, activity.QualifiedName)
End If
If TypeOf activity Is CompositeActivity Then
For Each activity2 As Activity In GetNestedActivities(CType(activity, CompositeActivity))
designerHost.Container.Add(activity2, activity2.QualifiedName)
Next
End If
End Sub
Private Shared Function GetNestedActivities(ByVal compositeActivity As CompositeActivity) As Activity()
If compositeActivity Is Nothing Then
Throw New ArgumentNullException("compositeActivity")
End If
Dim childActivities As IList(Of Activity) = Nothing
Dim nestedActivities As New ArrayList()
Dim compositeActivities As New Queue()
compositeActivities.Enqueue(compositeActivity)
While compositeActivities.Count > 0
Dim compositeActivity2 As CompositeActivity = CType(compositeActivities.Dequeue(), CompositeActivity)
childActivities = compositeActivity2.Activities
For Each activity As Activity In childActivities
nestedActivities.Add(activity)
If (activity Is compositeActivity) Then
compositeActivities.Enqueue(activity)
End If
Next
End While
Return CType(nestedActivities.ToArray(GetType(Activity)), Activity())
End Function