Aracılığıyla paylaş


Nasıl yapılır: Çalışan İş Akışı Örneğinin Tanımını Güncelleştirme

Dinamik güncelleştirme, iş akışı uygulaması geliştiricilerinin kalıcı bir iş akışı örneğinin iş akışı tanımını güncelleştirmeleri için bir mekanizma sağlar. Gerekli değişiklik bir hata düzeltmesi, yeni gereksinimler uygulamak veya beklenmeyen değişiklikleri karşılamak olabilir. Öğreticideki bu adım, nasıl yapılır: İş Akışının Birden Çok Sürümünü Yan Yana Barındırma başlığı altında sunulan yeni işlevsellikle eşleşecek şekilde numara tahmin iş akışının kalıcı örneklerini v1 değiştirmek için dinamik güncelleştirmenin nasıl kullanılacağını gösterir.

Bu konuda,

CreateUpdate Haritalar projesini oluşturmak için

  1. Çözüm Gezgini'da WF45GettingStartedTutorial'a sağ tıklayın ve Ekle, Yeni Proje'yi seçin.

  2. Yüklü düğümde Visual C#, Windows (veya Visual Basic, Windows) öğesini seçin.

    Not

    Visual Studio'da birincil dil olarak yapılandırılan programlama diline bağlı olarak, Visual C# veya Visual Basic düğümü Yüklü düğümdeki Diğer Diller düğümü altında olabilir.

    .NET Framework sürüm açılan listesinde .NET Framework 4.5'in seçildiğinden emin olun. Windows listesinden Konsol Uygulaması'nı seçin. Ad kutusuna CreateUpdate Haritalar yazın ve Tamam'a tıklayın.

  3. CreateUpdate'e sağ tıklayın Haritalar Çözüm Gezgini ve Başvuru Ekle'yi seçin.

  4. Başvuru Ekle listesindeki Derlemeler düğümünden Çerçeve'yi seçin. Derlemeleri filtrelemek ve istenen başvuruların seçilmesini kolaylaştırmak için Derlemeleri Ara kutusuna System.Activities yazın.

  5. Arama Sonuçları listesinde System.Activities öğesinin yanındaki onay kutusunu işaretleyin.

  6. Arama Derlemeleri kutusuna Serileştirme yazın ve Arama Sonuçları listesinde System.Runtime.Serialization öğesinin yanındaki onay kutusunu işaretleyin.

  7. Arama Derlemeleri kutusuna System.Xaml yazın ve Arama Sonuçları listesinde System.Xaml'in yanındaki onay kutusunu işaretleyin.

  8. Başvuru Yöneticisi'ni kapatmak ve başvuruları eklemek için Tamam'a tıklayın.

  9. Dosyanın en üstüne aşağıdaki using (veya Imports) deyimlerini diğer using (veya Imports) deyimleriyle ekleyin.

    Imports System.Activities
    Imports System.Activities.Statements
    Imports System.Xaml
    Imports System.Reflection
    Imports System.IO
    Imports System.Activities.XamlIntegration
    Imports System.Activities.DynamicUpdate
    Imports System.Runtime.Serialization
    Imports Microsoft.VisualBasic.Activities
    
    using System.Activities;
    using System.Activities.Statements;
    using System.IO;
    using System.Xaml;
    using System.Reflection;
    using System.Activities.XamlIntegration;
    using System.Activities.DynamicUpdate;
    using System.Runtime.Serialization;
    using Microsoft.CSharp.Activities;
    
  10. Sınıfına (veya Module1) aşağıdaki iki dize üyesini Program ekleyin.

    Const mapPath = "..\..\..\PreviousVersions"
    Const definitionPath = "..\..\..\NumberGuessWorkflowActivities_du"
    
    const string mapPath = @"..\..\..\PreviousVersions";
    const string definitionPath = @"..\..\..\NumberGuessWorkflowActivities_du";
    
  11. Sınıfına (veya Module1) aşağıdaki StartUpdate yöntemi Program ekleyin. Bu yöntem, belirtilen xaml iş akışı tanımını içine ActivityBuilderyükler ve ardından öğesini çağırır DynamicUpdate.PrepareForUpdate. PrepareForUpdate içinde iş akışı tanımının ActivityBuilderbir kopyasını oluşturur. İş akışı tanımı değiştirildikten sonra, güncelleştirme eşlemesini oluşturmak için değiştirilen iş akışı tanımıyla birlikte bu kopya kullanılır.

    Private Function StartUpdate(name As String) As ActivityBuilder
        'Create the XamlXmlReaderSettings.
        Dim readerSettings As XamlReaderSettings = New XamlXmlReaderSettings()
        'In the XAML the "local" namespace refers to artifacts that come from
        'the same project as the XAML. When loading XAML if the currently executing
        'assembly is not the same assembly that was referred to as "local" in the XAML
        'LocalAssembly must be set to the assembly containing the artifacts.
        'Assembly.LoadFile requires an absolute path so convert this relative path
        'to an absolute path.
        readerSettings.LocalAssembly = Assembly.LoadFile(
            Path.GetFullPath(Path.Combine(mapPath, "NumberGuessWorkflowActivities_v1.dll")))
    
        Dim fullPath As String = Path.Combine(definitionPath, name)
        Dim xamlReader As XamlXmlReader = New XamlXmlReader(fullPath, readerSettings)
    
        'Load the workflow definition into an ActivityBuilder.
        Dim wf As ActivityBuilder = XamlServices.Load(
            ActivityXamlServices.CreateBuilderReader(xamlReader))
    
        'PrepareForUpdate makes a copy of the workflow definition in the
        'ActivityBuilder that is used for comparison when the update
        'map is created.
        DynamicUpdateServices.PrepareForUpdate(wf)
    
        Return wf
    End Function
    
    private static ActivityBuilder StartUpdate(string name)
    {
        // Create the XamlXmlReaderSettings.
        XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings()
        {
            // In the XAML the "local" namespace refers to artifacts that come from
            // the same project as the XAML. When loading XAML if the currently executing
            // assembly is not the same assembly that was referred to as "local" in the XAML
            // LocalAssembly must be set to the assembly containing the artifacts.
            // Assembly.LoadFile requires an absolute path so convert this relative path
            // to an absolute path.
            LocalAssembly = Assembly.LoadFile(
                Path.GetFullPath(Path.Combine(mapPath, "NumberGuessWorkflowActivities_v1.dll")))
        };
    
        string path = Path.Combine(definitionPath, name);
        XamlXmlReader xamlReader = new XamlXmlReader(path, readerSettings);
    
        // Load the workflow definition into an ActivityBuilder.
        ActivityBuilder wf = XamlServices.Load(
            ActivityXamlServices.CreateBuilderReader(xamlReader))
            as ActivityBuilder;
    
        // PrepareForUpdate makes a copy of the workflow definition in the
        // ActivityBuilder that is used for comparison when the update
        // map is created.
        DynamicUpdateServices.PrepareForUpdate(wf);
    
        return wf;
    }
    
  12. Ardından, sınıfına Program (veya Module1) aşağıdakileri CreateUpdateMethod ekleyin. Bu, DynamicUpdateServices.CreateUpdateMap'i çağırarak dinamik bir güncelleştirme eşlemesi oluşturur ve ardından belirtilen adı kullanarak güncelleştirme eşlemesini kaydeder. Bu güncelleştirme eşlemesi, güncelleştirilmiş iş akışı tanımı kullanılarak tamamlanması için içinde bulunan ActivityBuilder özgün iş akışı tanımı kullanılarak başlatılan kalıcı bir iş akışı örneğini güncelleştirmek için iş akışı çalışma zamanı tarafından gereken bilgileri içerir.

    Private Sub CreateUpdateMaps(wf As ActivityBuilder, name As String)
        'Create the UpdateMap.
        Dim map As DynamicUpdateMap =
            DynamicUpdateServices.CreateUpdateMap(wf)
    
        'Serialize it to a file.
        Dim mapFullPath As String = Path.Combine(mapPath, name)
        Dim sz As DataContractSerializer = New DataContractSerializer(GetType(DynamicUpdateMap))
        Using fs As FileStream = File.Open(mapFullPath, FileMode.Create)
            sz.WriteObject(fs, map)
        End Using
    End Sub
    
    private static void CreateUpdateMaps(ActivityBuilder wf, string name)
    {
        // Create the UpdateMap.
        DynamicUpdateMap map =
            DynamicUpdateServices.CreateUpdateMap(wf);
    
        // Serialize it to a file.
        string path = Path.Combine(mapPath, name);
        DataContractSerializer sz = new DataContractSerializer(typeof(DynamicUpdateMap));
        using (FileStream fs = System.IO.File.Open(path, FileMode.Create))
        {
            sz.WriteObject(fs, map);
        }
    }
    
  13. Sınıfına (veya Module1) aşağıdaki SaveUpdatedDefinition yöntemi Program ekleyin. Bu yöntem, güncelleştirme eşlemesi oluşturulduktan sonra güncelleştirilmiş iş akışı tanımını kaydeder.

    Private Sub SaveUpdatedDefinition(wf As ActivityBuilder, name As String)
        Dim xamlPath As String = Path.Combine(definitionPath, name)
        Dim sw As StreamWriter = File.CreateText(xamlPath)
        Dim xw As XamlWriter = ActivityXamlServices.CreateBuilderWriter(
            New XamlXmlWriter(sw, New XamlSchemaContext()))
        XamlServices.Save(xw, wf)
        sw.Close()
    End Sub
    
    private static void SaveUpdatedDefinition(ActivityBuilder wf, string name)
    {
        string xamlPath = Path.Combine(definitionPath, name);
        StreamWriter sw = File.CreateText(xamlPath);
        XamlWriter xw = ActivityXamlServices.CreateBuilderWriter(
            new XamlXmlWriter(sw, new XamlSchemaContext()));
        XamlServices.Save(xw, wf);
        sw.Close();
    }
    

StateMachineNumberGuessWorkflow'ı güncelleştirmek için

  1. sınıfına Program (veya Module1) bir CreateStateMachineUpdateMap ekleyin.

    Private Sub CreateStateMachineUpdateMap()
    
    End Sub
    
    private static void CreateStateMachineUpdateMap()
    {
    }
    
  2. öğesine bir çağrı StartUpdate yapın ve ardından iş akışının kök StateMachine etkinliğine bir başvuru alın.

    Dim wf As ActivityBuilder = StartUpdate("StateMachineNumberGuessWorkflow.xaml")
    
    'Get a reference to the root StateMachine activity.
    Dim sm As StateMachine = wf.Implementation
    
    ActivityBuilder wf = StartUpdate("StateMachineNumberGuessWorkflow.xaml");
    
    // Get a reference to the root StateMachine activity.
    StateMachine sm = wf.Implementation as StateMachine;
    
  3. Ardından, kullanıcının tahmininin çok yüksek mi yoksa çok düşük mü olduğunu gösteren iki WriteLine etkinliğin ifadelerini, Nasıl yapılır: İş Akışının Birden Çok Sürümünü Yan Yana Barındırma başlığı altında yapılan güncelleştirmelerle eşleşecek şekilde güncelleştirin.

    'Update the Text of the two WriteLine activities that write the
    'results of the user's guess. They are contained in the workflow as the
    'Then and Else action of the If activity in sm.States[1].Transitions[1].Action.
    Dim guessLow As Statements.If = sm.States(1).Transitions(1).Action
    
    'Update the "too low" message.
    Dim tooLow As WriteLine = guessLow.Then
    tooLow.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too low.""")
    
    'Update the "too high" message.
    Dim tooHigh As WriteLine = guessLow.Else
    tooHigh.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too high.""")
    
    // Update the Text of the two WriteLine activities that write the
    // results of the user's guess. They are contained in the workflow as the
    // Then and Else action of the If activity in sm.States[1].Transitions[1].Action.
    If guessLow = sm.States[1].Transitions[1].Action as If;
    
    // Update the "too low" message.
    WriteLine tooLow = guessLow.Then as WriteLine;
    tooLow.Text = new CSharpValue<string>("Guess.ToString() + \" is too low.\"");
    
    // Update the "too high" message.
    WriteLine tooHigh = guessLow.Else as WriteLine;
    tooHigh.Text = new CSharpValue<string>("Guess.ToString() + \" is too high.\"");
    
  4. Ardından, kapanış iletisini görüntüleyen yeni WriteLine etkinliği ekleyin.

    'Create the new WriteLine that displays the closing message.
    Dim wl As New WriteLine() With
    {
        .Text = New VisualBasicValue(Of String) _
            ("Guess.ToString() + "" is correct. You guessed it in "" & Turns.ToString() & "" turns.""")
    }
    
    'Add it as the Action for the Guess Correct transition. The Guess Correct
    'transition is the first transition of States[1]. The transitions are listed
    'at the bottom of the State activity designer.
    sm.States(1).Transitions(0).Action = wl
    
    // Create the new WriteLine that displays the closing message.
    WriteLine wl = new WriteLine
    {
        Text = new CSharpValue<string>("Guess.ToString() + \" is correct. You guessed it in \" + Turns.ToString() + \" turns.\"")
    };
    
    // Add it as the Action for the Guess Correct transition. The Guess Correct
    // transition is the first transition of States[1]. The transitions are listed
    // at the bottom of the State activity designer.
    sm.States[1].Transitions[0].Action = wl;
    
  5. İş akışı güncelleştirildikten sonra ve SaveUpdatedDefinitionöğesini çağırınCreateUpdateMaps. CreateUpdateMaps oluşturur ve kaydeder DynamicUpdateMapve SaveUpdatedDefinition güncelleştirilmiş iş akışı tanımını kaydeder.

    'Create the update map.
    CreateUpdateMaps(wf, "StateMachineNumberGuessWorkflow.map")
    
    'Save the updated workflow definition.
    SaveUpdatedDefinition(wf, "StateMachineNumberGuessWorkflow_du.xaml")
    
    // Create the update map.
    CreateUpdateMaps(wf, "StateMachineNumberGuessWorkflow.map");
    
    // Save the updated workflow definition.
    SaveUpdatedDefinition(wf, "StateMachineNumberGuessWorkflow_du.xaml");
    

    Aşağıdaki örnek, tamamlanmış CreateStateMachineUpdateMap yöntemdir.

    Private Sub CreateStateMachineUpdateMap()
        Dim wf As ActivityBuilder = StartUpdate("StateMachineNumberGuessWorkflow.xaml")
    
        'Get a reference to the root StateMachine activity.
        Dim sm As StateMachine = wf.Implementation
    
        'Update the Text of the two WriteLine activities that write the
        'results of the user's guess. They are contained in the workflow as the
        'Then and Else action of the If activity in sm.States[1].Transitions[1].Action.
        Dim guessLow As Statements.If = sm.States(1).Transitions(1).Action
    
        'Update the "too low" message.
        Dim tooLow As WriteLine = guessLow.Then
        tooLow.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too low.""")
    
        'Update the "too high" message.
        Dim tooHigh As WriteLine = guessLow.Else
        tooHigh.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too high.""")
    
        'Create the new WriteLine that displays the closing message.
        Dim wl As New WriteLine() With
        {
            .Text = New VisualBasicValue(Of String) _
                ("Guess.ToString() + "" is correct. You guessed it in "" & Turns.ToString() & "" turns.""")
        }
    
        'Add it as the Action for the Guess Correct transition. The Guess Correct
        'transition is the first transition of States[1]. The transitions are listed
        'at the bottom of the State activity designer.
        sm.States(1).Transitions(0).Action = wl
    
        'Create the update map.
        CreateUpdateMaps(wf, "StateMachineNumberGuessWorkflow.map")
    
        'Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "StateMachineNumberGuessWorkflow_du.xaml")
    End Sub
    
    private static void CreateStateMachineUpdateMap()
    {
        ActivityBuilder wf = StartUpdate("StateMachineNumberGuessWorkflow.xaml");
    
        // Get a reference to the root StateMachine activity.
        StateMachine sm = wf.Implementation as StateMachine;
    
        // Update the Text of the two WriteLine activities that write the
        // results of the user's guess. They are contained in the workflow as the
        // Then and Else action of the If activity in sm.States[1].Transitions[1].Action.
        If guessLow = sm.States[1].Transitions[1].Action as If;
    
        // Update the "too low" message.
        WriteLine tooLow = guessLow.Then as WriteLine;
        tooLow.Text = new CSharpValue<string>("Guess.ToString() + \" is too low.\"");
    
        // Update the "too high" message.
        WriteLine tooHigh = guessLow.Else as WriteLine;
        tooHigh.Text = new CSharpValue<string>("Guess.ToString() + \" is too high.\"");
    
        // Create the new WriteLine that displays the closing message.
        WriteLine wl = new WriteLine
        {
            Text = new CSharpValue<string>("Guess.ToString() + \" is correct. You guessed it in \" + Turns.ToString() + \" turns.\"")
        };
    
        // Add it as the Action for the Guess Correct transition. The Guess Correct
        // transition is the first transition of States[1]. The transitions are listed
        // at the bottom of the State activity designer.
        sm.States[1].Transitions[0].Action = wl;
    
        // Create the update map.
        CreateUpdateMaps(wf, "StateMachineNumberGuessWorkflow.map");
    
        // Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "StateMachineNumberGuessWorkflow_du.xaml");
    }
    

FlowchartNumberGuessWorkflow'ı güncelleştirmek için

  1. Sınıfına Program (veya Module1) aşağıdakileri CreateFlowchartUpdateMethod ekleyin. Bu yöntem ile CreateStateMachineUpdateMapbenzerdir. çağrısıyla StartUpdatebaşlar, akış çizelgesi iş akışı tanımını güncelleştirir ve güncelleştirme eşlemesini ve güncelleştirilmiş iş akışı tanımını kaydederek tamamlar.

    Private Sub CreateFlowchartUpdateMap()
        Dim wf As ActivityBuilder = StartUpdate("FlowchartNumberGuessWorkflow.xaml")
    
        'Get a reference to the root Flowchart activity.
        Dim fc As Flowchart = wf.Implementation
    
        'Update the Text of the two WriteLine activities that write the
        'results of the user's guess. They are contained in the workflow as the
        'True and False action of the "Guess < Target" FlowDecision, which is
        'Nodes[4].
        Dim guessLow As FlowDecision = fc.Nodes(4)
    
        'Update the "too low" message.
        Dim trueStep As FlowStep = guessLow.True
        Dim tooLow As WriteLine = trueStep.Action
        tooLow.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too low.""")
    
        'Update the "too high" message.
        Dim falseStep As FlowStep = guessLow.False
        Dim tooHigh As WriteLine = falseStep.Action
        tooHigh.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too high.""")
    
        'Create the new WriteLine that displays the closing message.
        Dim wl As New WriteLine() With
        {
            .Text = New VisualBasicValue(Of String) _
                ("Guess.ToString() + "" is correct. You guessed it in "" & Turns.ToString() & "" turns.""")
        }
    
        'Create a FlowStep to hold the WriteLine.
        Dim closingStep As New FlowStep() With
        {
            .Action = wl
        }
    
        'Add this new FlowStep to the True action of the
        '"Guess = Guess" FlowDecision
        Dim guessCorrect As FlowDecision = fc.Nodes(3)
        guessCorrect.True = closingStep
    
        'Add the new FlowStep to the Nodes collection.
        'If closingStep was replacing an existing node then
        'we would need to remove that Step from the collection.
        'In this example there was no existing True step to remove.
        fc.Nodes.Add(closingStep)
    
        'Create the update map.
        CreateUpdateMaps(wf, "FlowchartNumberGuessWorkflow.map")
    
        'Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "FlowchartNumberGuessWorkflow_du.xaml")
    End Sub
    
    private static void CreateFlowchartUpdateMap()
    {
        ActivityBuilder wf = StartUpdate("FlowchartNumberGuessWorkflow.xaml");
    
        // Get a reference to the root Flowchart activity.
        Flowchart fc = wf.Implementation as Flowchart;
    
        // Update the Text of the two WriteLine activities that write the
        // results of the user's guess. They are contained in the workflow as the
        // True and False action of the "Guess < Target" FlowDecision, which is
        // Nodes[4].
        FlowDecision guessLow = fc.Nodes[4] as FlowDecision;
    
        // Update the "too low" message.
        FlowStep trueStep = guessLow.True as FlowStep;
        WriteLine tooLow = trueStep.Action as WriteLine;
        tooLow.Text = new CSharpValue<string>("Guess.ToString() + \" is too low.\"");
    
        // Update the "too high" message.
        FlowStep falseStep = guessLow.False as FlowStep;
        WriteLine tooHigh = falseStep.Action as WriteLine;
        tooHigh.Text = new CSharpValue<string>("Guess.ToString() + \" is too high.\"");
    
        // Add the new WriteLine that displays the closing message.
        WriteLine wl = new WriteLine
        {
            Text = new CSharpValue<string>("Guess.ToString() + \" is correct. You guessed it in \" + Turns.ToString() + \" turns.\"")
        };
    
        // Create a FlowStep to hold the WriteLine.
        FlowStep closingStep = new FlowStep
        {
            Action = wl
        };
    
        // Add this new FlowStep to the True action of the
        // "Guess == Guess" FlowDecision
        FlowDecision guessCorrect = fc.Nodes[3] as FlowDecision;
        guessCorrect.True = closingStep;
    
        // Add the new FlowStep to the Nodes collection.
        // If closingStep was replacing an existing node then
        // we would need to remove that Step from the collection.
        // In this example there was no existing True step to remove.
        fc.Nodes.Add(closingStep);
    
        // Create the update map.
        CreateUpdateMaps(wf, "FlowchartNumberGuessWorkflow.map");
    
        //  Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "FlowchartNumberGuessWorkflow_du.xaml");
    }
    

SequentialNumberGuessWorkflow'ı güncelleştirmek için

  1. Sınıfına Program (veya Module1) aşağıdakileri CreateSequentialUpdateMethod ekleyin. Bu yöntem diğer iki yönteme benzer. çağrısıyla StartUpdatebaşlar, sıralı iş akışı tanımını güncelleştirir ve güncelleştirme eşlemesini ve güncelleştirilmiş iş akışı tanımını kaydederek tamamlar.

    Private Sub CreateSequentialUpdateMap()
        Dim wf As ActivityBuilder = StartUpdate("SequentialNumberGuessWorkflow.xaml")
    
        'Get a reference to the root activity in the workflow.
        Dim rootSequence As Sequence = wf.Implementation
    
        'Update the Text of the two WriteLine activities that write the
        'results of the user's guess. They are contained in the workflow as the
        'Then and Else action of the "Guess < Target" If activity.
        'Sequence[1]->DoWhile->Body->Sequence[2]->If->Then->If
        Dim gameLoop As Statements.DoWhile = rootSequence.Activities(1)
        Dim gameBody As Sequence = gameLoop.Body
        Dim guessCorrect As Statements.If = gameBody.Activities(2)
        Dim guessLow As Statements.If = guessCorrect.Then
        Dim tooLow As WriteLine = guessLow.Then
        tooLow.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too low.""")
        Dim tooHigh As WriteLine = guessLow.Else
        tooHigh.Text = New VisualBasicValue(Of String)("Guess.ToString() & "" is too high.""")
    
        'Create the new WriteLine that displays the closing message.
        Dim wl As New WriteLine() With
        {
            .Text = New VisualBasicValue(Of String) _
                ("Guess.ToString() + "" is correct. You guessed it in "" & Turns.ToString() & "" turns.""")
        }
    
        'Insert it as the third activity in the root sequence
        rootSequence.Activities.Insert(2, wl)
    
        'Create the update map.
        CreateUpdateMaps(wf, "SequentialNumberGuessWorkflow.map")
    
        'Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "SequentialNumberGuessWorkflow_du.xaml")
    End Sub
    
    private static void CreateSequentialUpdateMap()
    {
        ActivityBuilder wf = StartUpdate("SequentialNumberGuessWorkflow.xaml");
    
        // Get a reference to the root activity in the workflow.
        Sequence rootSequence = wf.Implementation as Sequence;
    
        // Update the Text of the two WriteLine activities that write the
        // results of the user's guess. They are contained in the workflow as the
        // Then and Else action of the "Guess < Target" If activity.
        // Sequence[1]->DoWhile->Body->Sequence[2]->If->Then->If
        DoWhile gameLoop = rootSequence.Activities[1] as DoWhile;
        Sequence gameBody = gameLoop.Body as Sequence;
        If guessCorrect = gameBody.Activities[2] as If;
        If guessLow = guessCorrect.Then as If;
        WriteLine tooLow = guessLow.Then as WriteLine;
        tooLow.Text = new CSharpValue<string>("Guess.ToString() + \" is too low.\"");
        WriteLine tooHigh = guessLow.Else as WriteLine;
        tooHigh.Text = new CSharpValue<string>("Guess.ToString() + \" is too high.\"");
    
        // Add the new WriteLine that displays the closing message.
        WriteLine wl = new WriteLine
        {
            Text = new CSharpValue<string>("Guess.ToString() + \" is correct. You guessed it in \" + Turns.ToString() + \" turns.\"")
        };
    
        // Insert it as the third activity in the root sequence
        rootSequence.Activities.Insert(2, wl);
    
        // Create the update map.
        CreateUpdateMaps(wf, "SequentialNumberGuessWorkflow.map");
    
        // Save the updated workflow definition.
        SaveUpdatedDefinition(wf, "SequentialNumberGuessWorkflow_du.xaml");
    }
    

CreateUpdate Haritalar uygulamasını derlemek ve çalıştırmak için

  1. yöntemini güncelleştirin Main ve aşağıdaki üç yöntem çağrısını ekleyin. Bu yöntemler aşağıdaki bölümlerde eklenmiştir. Her yöntem ilgili sayı tahmini iş akışını güncelleştirir ve güncelleştirmeleri açıklayan bir DynamicUpdateMap oluşturur.

    Sub Main()
        'Create the update maps for the changes needed to the v1 activities
        'so they match the v2 activities.
        CreateSequentialUpdateMap()
        CreateFlowchartUpdateMap()
        CreateStateMachineUpdateMap()
    End Sub
    
    static void Main(string[] args)
    {
        // Create the update maps for the changes needed to the v1 activities
        // so they match the v2 activities.
        CreateSequentialUpdateMap();
        CreateFlowchartUpdateMap();
        CreateStateMachineUpdateMap();
    }
    
  2. Çözüm Gezgini'da CreateUpdate Haritalar öğesine sağ tıklayın ve Başlangıç Projesi Olarak Ayarla'yı seçin.

  3. Çözümü oluşturmak için CTRL+SHIFT+B tuşlarına basın ve ardından uygulamayı çalıştırmak CreateUpdateMaps için CTRL+F5 tuşlarına basın.

    Not

    Uygulama CreateUpdateMaps çalışırken herhangi bir durum bilgisi görüntülemez, ancak NumberGuessWorkflowActivities_du klasörüne ve PreviousVersions klasörüne bakarsanız güncelleştirilmiş iş akışı tanım dosyalarını ve güncelleştirme eşlemelerini görürsünüz.

    Güncelleştirme eşlemeleri oluşturulduktan ve iş akışı tanımları güncelleştirildikten sonra, sonraki adım güncelleştirilmiş tanımları içeren güncelleştirilmiş bir iş akışı derlemesi oluşturmaktır.

Güncelleştirilmiş iş akışı derlemesini oluşturmak için

  1. Visual Studio 2012'nin ikinci bir örneğini açın.

  2. Dosya menüsünden Aç, Proje/Çözüm'e tıklayın.

  3. Nasıl yapılır: bir İş Akışının Birden Çok Sürümünü Yan Yana Barındırma bölümünde oluşturduğunuz NumberGuessWorkflowActivities_du klasörüne gidin, NumberGuessWorkflowActivities.csproj (veya vbproj) öğesini seçin ve Aç'a tıklayın.

  4. Çözüm Gezgini'da SequentialNumberGuessWorkflow.xaml öğesine sağ tıklayın ve Projeden Dışla'yı seçin. FlowchartNumberGuessWorkflow.xaml ve StateMachineNumberGuessWorkflow.xaml için aynı şeyi yapın. Bu adım, iş akışı tanımlarının önceki sürümlerini projeden kaldırır.

  5. Proje menüsünden Varolan Öğeyi Ekle'yi seçin.

  6. Nasıl yapılır: bir İş Akışının Birden Çok Sürümünü Yan Yana Barındırma bölümünde oluşturduğunuz NumberGuessWorkflowActivities_du klasörüne gidin.

  7. Dosya türü açılan listesinden XAML Dosyaları (*.xaml;*.xoml) öğesini seçin.

  8. SequentialNumberGuessWorkflow_du.xaml, FlowchartNumberGuessWorkflow_du.xaml ve StateMachineNumberGuessWorkflow_du.xaml'i seçin ve Ekle'ye tıklayın.

    Not

    Bir kerede birden çok öğe seçmek için CTRL tuşunu basılı tutarak tıklayın.

    Bu adım, iş akışı tanımlarının güncelleştirilmiş sürümlerini projeye ekler.

  9. Projeyi oluşturmak için CTRL+SHIFT+B tuşlarına basın.

  10. Dosya menüsünden Çözümü Kapat'ı seçin. Proje için bir çözüm dosyası gerekli olmadığından, visual studio'yu bir çözüm dosyası kaydetmeden kapatmak için Hayır'a tıklayın. Visual Studio'yu kapatmak için Dosya menüsünden Çık'ı seçin.

  11. Windows Gezgini'ni açın ve NumberGuessWorkflowActivities_du\bin\Debug klasörüne (veya proje ayarlarınıza bağlı olarak bin\Release ) gidin.

  12. NumberGuessWorkflowActivities.dll NumberGuessWorkflowActivities_v15.dll olarak yeniden adlandırın ve Nasıl yapılır: bir İş Akışının Birden Çok Sürümünü Yan Yana Barındırma bölümünde oluşturduğunuz PreviousVersions klasörüne kopyalayın.

WorkflowVersionMap'i yeni sürümlerle güncelleştirmek için

  1. Visual Studio 2012'nin ilk örneğine geri dönün.

  2. NumberGuessWorkflowHost projesinin altındaki WorkflowVersionMap.cs (veya WorkflowVersionMap.vb) çift tıklayarak açın.

  3. Mevcut altı iş akışı kimliği bildiriminin hemen altına üç yeni iş akışı kimliği ekleyin. Bu öğreticide, 1.5.0.0 dinamik güncelleştirme kimlikleri için olarak WorkflowIdentity.Version kullanılır. Bu yeni v15 iş akışı kimlikleri, dinamik olarak güncelleştirilen kalıcı iş akışı örnekleri için doğru iş akışı tanımını sağlar.

    'Current version identities.
    Public StateMachineNumberGuessIdentity As WorkflowIdentity
    Public FlowchartNumberGuessIdentity As WorkflowIdentity
    Public SequentialNumberGuessIdentity As WorkflowIdentity
    
    'v1 identities.
    Public StateMachineNumberGuessIdentity_v1 As WorkflowIdentity
    Public FlowchartNumberGuessIdentity_v1 As WorkflowIdentity
    Public SequentialNumberGuessIdentity_v1 As WorkflowIdentity
    
    'v1.5 (Dynamic Update) identities.
    Public StateMachineNumberGuessIdentity_v15 As WorkflowIdentity
    Public FlowchartNumberGuessIdentity_v15 As WorkflowIdentity
    Public SequentialNumberGuessIdentity_v15 As WorkflowIdentity
    
    // Current version identities.
    static public WorkflowIdentity StateMachineNumberGuessIdentity;
    static public WorkflowIdentity FlowchartNumberGuessIdentity;
    static public WorkflowIdentity SequentialNumberGuessIdentity;
    
    // v1 identities.
    static public WorkflowIdentity StateMachineNumberGuessIdentity_v1;
    static public WorkflowIdentity FlowchartNumberGuessIdentity_v1;
    static public WorkflowIdentity SequentialNumberGuessIdentity_v1;
    
    // v1.5 (Dynamic Update) identities.
    static public WorkflowIdentity StateMachineNumberGuessIdentity_v15;
    static public WorkflowIdentity FlowchartNumberGuessIdentity_v15;
    static public WorkflowIdentity SequentialNumberGuessIdentity_v15;
    
  4. Oluşturucunun sonuna aşağıdaki kodu ekleyin. Bu kod dinamik güncelleştirme iş akışı kimliklerini başlatır, ilgili iş akışı tanımlarını yükler ve bunları iş akışı sürüm sözlüğüne ekler.

    'Initialize the dynamic update workflow identities.
    StateMachineNumberGuessIdentity_v15 = New WorkflowIdentity With
    {
        .Name = "StateMachineNumberGuessWorkflow",
        .Version = New Version(1, 5, 0, 0)
    }
    
    FlowchartNumberGuessIdentity_v15 = New WorkflowIdentity With
    {
        .Name = "FlowchartNumberGuessWorkflow",
        .Version = New Version(1, 5, 0, 0)
    }
    
    SequentialNumberGuessIdentity_v15 = New WorkflowIdentity With
    {
        .Name = "SequentialNumberGuessWorkflow",
        .Version = New Version(1, 5, 0, 0)
    }
    
    'Add the dynamic update workflow identities to the dictionary along with
    'the corresponding workflow definitions loaded from the v15 assembly.
    'Assembly.LoadFile requires an absolute path so convert this relative path
    'to an absolute path.
    Dim v15AssemblyPath As String = "..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v15.dll"
    v15AssemblyPath = Path.GetFullPath(v15AssemblyPath)
    Dim v15Assembly As Assembly = Assembly.LoadFile(v15AssemblyPath)
    
    map.Add(StateMachineNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow"))
    
    map.Add(SequentialNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow"))
    
    map.Add(FlowchartNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow"))
    
    // Initialize the dynamic update workflow identities.
    StateMachineNumberGuessIdentity_v15 = new WorkflowIdentity
    {
        Name = "StateMachineNumberGuessWorkflow",
        Version = new Version(1, 5, 0, 0)
    };
    
    FlowchartNumberGuessIdentity_v15 = new WorkflowIdentity
    {
        Name = "FlowchartNumberGuessWorkflow",
        Version = new Version(1, 5, 0, 0)
    };
    
    SequentialNumberGuessIdentity_v15 = new WorkflowIdentity
    {
        Name = "SequentialNumberGuessWorkflow",
        Version = new Version(1, 5, 0, 0)
    };
    
    // Add the dynamic update workflow identities to the dictionary along with
    // the corresponding workflow definitions loaded from the v15 assembly.
    // Assembly.LoadFile requires an absolute path so convert this relative path
    // to an absolute path.
    string v15AssemblyPath = @"..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v15.dll";
    v15AssemblyPath = Path.GetFullPath(v15AssemblyPath);
    Assembly v15Assembly = Assembly.LoadFile(v15AssemblyPath);
    
    map.Add(StateMachineNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow") as Activity);
    
    map.Add(SequentialNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow") as Activity);
    
    map.Add(FlowchartNumberGuessIdentity_v15,
        v15Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow") as Activity);
    

    Aşağıdaki örnek tamamlanmış WorkflowVersionMap sınıftır.

    Public Module WorkflowVersionMap
        Dim map As Dictionary(Of WorkflowIdentity, Activity)
    
        'Current version identities.
        Public StateMachineNumberGuessIdentity As WorkflowIdentity
        Public FlowchartNumberGuessIdentity As WorkflowIdentity
        Public SequentialNumberGuessIdentity As WorkflowIdentity
    
        'v1 identities.
        Public StateMachineNumberGuessIdentity_v1 As WorkflowIdentity
        Public FlowchartNumberGuessIdentity_v1 As WorkflowIdentity
        Public SequentialNumberGuessIdentity_v1 As WorkflowIdentity
    
        'v1.5 (Dynamic Update) identities.
        Public StateMachineNumberGuessIdentity_v15 As WorkflowIdentity
        Public FlowchartNumberGuessIdentity_v15 As WorkflowIdentity
        Public SequentialNumberGuessIdentity_v15 As WorkflowIdentity
    
        Sub New()
            map = New Dictionary(Of WorkflowIdentity, Activity)
    
            'Add the current workflow version identities.
            StateMachineNumberGuessIdentity = New WorkflowIdentity With
            {
                .Name = "StateMachineNumberGuessWorkflow",
                .Version = New Version(2, 0, 0, 0)
            }
    
            FlowchartNumberGuessIdentity = New WorkflowIdentity With
            {
                .Name = "FlowchartNumberGuessWorkflow",
                .Version = New Version(2, 0, 0, 0)
            }
    
            SequentialNumberGuessIdentity = New WorkflowIdentity With
            {
                .Name = "SequentialNumberGuessWorkflow",
                .Version = New Version(2, 0, 0, 0)
            }
    
            map.Add(StateMachineNumberGuessIdentity, New StateMachineNumberGuessWorkflow())
            map.Add(FlowchartNumberGuessIdentity, New FlowchartNumberGuessWorkflow())
            map.Add(SequentialNumberGuessIdentity, New SequentialNumberGuessWorkflow())
    
            'Initialize the previous workflow version identities.
            StateMachineNumberGuessIdentity_v1 = New WorkflowIdentity With
            {
                .Name = "StateMachineNumberGuessWorkflow",
                .Version = New Version(1, 0, 0, 0)
            }
    
            FlowchartNumberGuessIdentity_v1 = New WorkflowIdentity With
            {
                .Name = "FlowchartNumberGuessWorkflow",
                .Version = New Version(1, 0, 0, 0)
            }
    
            SequentialNumberGuessIdentity_v1 = New WorkflowIdentity With
            {
                .Name = "SequentialNumberGuessWorkflow",
                .Version = New Version(1, 0, 0, 0)
            }
    
            'Add the previous version workflow identities to the dictionary along with
            'the corresponding workflow definitions loaded from the v1 assembly.
            'Assembly.LoadFile requires an absolute path so convert this relative path
            'to an absolute path.
            Dim v1AssemblyPath As String = "..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v1.dll"
            v1AssemblyPath = Path.GetFullPath(v1AssemblyPath)
            Dim v1Assembly As Assembly = Assembly.LoadFile(v1AssemblyPath)
    
            map.Add(StateMachineNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow"))
    
            map.Add(SequentialNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow"))
    
            map.Add(FlowchartNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow"))
    
            'Initialize the dynamic update workflow identities.
            StateMachineNumberGuessIdentity_v15 = New WorkflowIdentity With
            {
                .Name = "StateMachineNumberGuessWorkflow",
                .Version = New Version(1, 5, 0, 0)
            }
    
            FlowchartNumberGuessIdentity_v15 = New WorkflowIdentity With
            {
                .Name = "FlowchartNumberGuessWorkflow",
                .Version = New Version(1, 5, 0, 0)
            }
    
            SequentialNumberGuessIdentity_v15 = New WorkflowIdentity With
            {
                .Name = "SequentialNumberGuessWorkflow",
                .Version = New Version(1, 5, 0, 0)
            }
    
            'Add the dynamic update workflow identities to the dictionary along with
            'the corresponding workflow definitions loaded from the v15 assembly.
            'Assembly.LoadFile requires an absolute path so convert this relative path
            'to an absolute path.
            Dim v15AssemblyPath As String = "..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v15.dll"
            v15AssemblyPath = Path.GetFullPath(v15AssemblyPath)
            Dim v15Assembly As Assembly = Assembly.LoadFile(v15AssemblyPath)
    
            map.Add(StateMachineNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow"))
    
            map.Add(SequentialNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow"))
    
            map.Add(FlowchartNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow"))
        End Sub
    
        Public Function GetWorkflowDefinition(identity As WorkflowIdentity) As Activity
            Return map(identity)
        End Function
    
        Public Function GetIdentityDescription(identity As WorkflowIdentity) As String
            Return identity.ToString()
        End Function
    End Module
    
    public static class WorkflowVersionMap
    {
        static Dictionary<WorkflowIdentity, Activity> map;
    
        // Current version identities.
        static public WorkflowIdentity StateMachineNumberGuessIdentity;
        static public WorkflowIdentity FlowchartNumberGuessIdentity;
        static public WorkflowIdentity SequentialNumberGuessIdentity;
    
        // v1 identities.
        static public WorkflowIdentity StateMachineNumberGuessIdentity_v1;
        static public WorkflowIdentity FlowchartNumberGuessIdentity_v1;
        static public WorkflowIdentity SequentialNumberGuessIdentity_v1;
    
        // v1.5 (Dynamic Update) identities.
        static public WorkflowIdentity StateMachineNumberGuessIdentity_v15;
        static public WorkflowIdentity FlowchartNumberGuessIdentity_v15;
        static public WorkflowIdentity SequentialNumberGuessIdentity_v15;
    
        static WorkflowVersionMap()
        {
            map = new Dictionary<WorkflowIdentity, Activity>();
    
            // Add the current workflow version identities.
            StateMachineNumberGuessIdentity = new WorkflowIdentity
            {
                Name = "StateMachineNumberGuessWorkflow",
                // Version = new Version(1, 0, 0, 0),
                Version = new Version(2, 0, 0, 0)
            };
    
            FlowchartNumberGuessIdentity = new WorkflowIdentity
            {
                Name = "FlowchartNumberGuessWorkflow",
                // Version = new Version(1, 0, 0, 0),
                Version = new Version(2, 0, 0, 0)
            };
    
            SequentialNumberGuessIdentity = new WorkflowIdentity
            {
                Name = "SequentialNumberGuessWorkflow",
                // Version = new Version(1, 0, 0, 0),
                Version = new Version(2, 0, 0, 0)
            };
    
            map.Add(StateMachineNumberGuessIdentity, new StateMachineNumberGuessWorkflow());
            map.Add(FlowchartNumberGuessIdentity, new FlowchartNumberGuessWorkflow());
            map.Add(SequentialNumberGuessIdentity, new SequentialNumberGuessWorkflow());
    
            // Initialize the previous workflow version identities.
            StateMachineNumberGuessIdentity_v1 = new WorkflowIdentity
            {
                Name = "StateMachineNumberGuessWorkflow",
                Version = new Version(1, 0, 0, 0)
            };
    
            FlowchartNumberGuessIdentity_v1 = new WorkflowIdentity
            {
                Name = "FlowchartNumberGuessWorkflow",
                Version = new Version(1, 0, 0, 0)
            };
    
            SequentialNumberGuessIdentity_v1 = new WorkflowIdentity
            {
                Name = "SequentialNumberGuessWorkflow",
                Version = new Version(1, 0, 0, 0)
            };
    
            // Add the previous version workflow identities to the dictionary along with
            // the corresponding workflow definitions loaded from the v1 assembly.
            // Assembly.LoadFile requires an absolute path so convert this relative path
            // to an absolute path.
            string v1AssemblyPath = @"..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v1.dll";
            v1AssemblyPath = Path.GetFullPath(v1AssemblyPath);
            Assembly v1Assembly = Assembly.LoadFile(v1AssemblyPath);
    
            map.Add(StateMachineNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow") as Activity);
    
            map.Add(SequentialNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow") as Activity);
    
            map.Add(FlowchartNumberGuessIdentity_v1,
                v1Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow") as Activity);
    
            // Initialize the dynamic update workflow identities.
            StateMachineNumberGuessIdentity_v15 = new WorkflowIdentity
            {
                Name = "StateMachineNumberGuessWorkflow",
                Version = new Version(1, 5, 0, 0)
            };
    
            FlowchartNumberGuessIdentity_v15 = new WorkflowIdentity
            {
                Name = "FlowchartNumberGuessWorkflow",
                Version = new Version(1, 5, 0, 0)
            };
    
            SequentialNumberGuessIdentity_v15 = new WorkflowIdentity
            {
                Name = "SequentialNumberGuessWorkflow",
                Version = new Version(1, 5, 0, 0)
            };
    
            // Add the dynamic update workflow identities to the dictionary along with
            // the corresponding workflow definitions loaded from the v15 assembly.
            // Assembly.LoadFile requires an absolute path so convert this relative path
            // to an absolute path.
            string v15AssemblyPath = @"..\..\..\PreviousVersions\NumberGuessWorkflowActivities_v15.dll";
            v15AssemblyPath = Path.GetFullPath(v15AssemblyPath);
            Assembly v15Assembly = Assembly.LoadFile(v15AssemblyPath);
    
            map.Add(StateMachineNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.StateMachineNumberGuessWorkflow") as Activity);
    
            map.Add(SequentialNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.SequentialNumberGuessWorkflow") as Activity);
    
            map.Add(FlowchartNumberGuessIdentity_v15,
                v15Assembly.CreateInstance("NumberGuessWorkflowActivities.FlowchartNumberGuessWorkflow") as Activity);
        }
    
        public static Activity GetWorkflowDefinition(WorkflowIdentity identity)
        {
            return map[identity];
        }
    
        public static string GetIdentityDescription(WorkflowIdentity identity)
        {
            return identity.ToString();
        }
    }
    
  5. Projeyi oluşturmak için CTRL+SHIFT+B tuşlarına basın.

Dinamik güncelleştirmeleri uygulamak için

  1. Çözüm Gezgini'da WF45GettingStartedTutorial'a sağ tıklayın ve Ekle, Yeni Proje'yi seçin.

  2. Yüklü düğümde Visual C#, Windows (veya Visual Basic, Windows) öğesini seçin.

    Not

    Visual Studio'da birincil dil olarak yapılandırılan programlama diline bağlı olarak, Visual C# veya Visual Basic düğümü Yüklü düğümdeki Diğer Diller düğümü altında olabilir.

    .NET Framework sürüm açılan listesinde .NET Framework 4.5'in seçildiğinden emin olun. Windows listesinden Konsol Uygulaması'nı seçin. Ad kutusuna ApplyDynamicUpdate yazın ve Tamam'a tıklayın.

  3. Çözüm Gezgini'da ApplyDynamicUpdate'e sağ tıklayın ve Başvuru Ekle'yi seçin.

  4. Çözüm'etıklayın ve NumberGuessWorkflowHost'un yanındaki kutuyu işaretleyin. Sınıfı kullanabilmek NumberGuessWorkflowHost.WorkflowVersionMap için bu ApplyDynamicUpdate başvuru gereklidir.

  5. Başvuru Ekle listesindeki Derlemeler düğümünden Çerçeve'yi seçin. Derlemeleri Ara kutusuna System.Activities yazın. Bu işlem derlemeleri filtreler ve istenen başvuruların seçilmesini kolaylaştırır.

  6. Arama Sonuçları listesinde System.Activities öğesinin yanındaki onay kutusunu işaretleyin.

  7. Arama Derlemeleri kutusuna Serileştirme yazın ve Arama Sonuçları listesinde System.Runtime.Serialization öğesinin yanındaki onay kutusunu işaretleyin.

  8. Derlemeleri Ara kutusuna DurableInstancing yazın ve Arama Sonuçları listesinden System.Activities.DurableInstancing ve System.Runtime.DurableInstancing'inyanındaki onay kutusunu işaretleyin.

  9. Başvuru Yöneticisi'ni kapatmak ve başvuruları eklemek için Tamam'a tıklayın.

  10. Çözüm Gezgini'de ApplyDynamicUpdate'e sağ tıklayın ve Ekle, Sınıf'ı seçin. Ad kutusuna yazın DynamicUpdateInfo ve Ekle'ye tıklayın.

  11. Aşağıdaki iki üyeyi sınıfına DynamicUpdateInfo ekleyin. Aşağıdaki örnek tamamlanmış DynamicUpdateInfo sınıftır. Bu sınıf, bir iş akışı örneği güncelleştirildiğinde kullanılan güncelleştirme eşlemesi ve yeni iş akışı kimliği hakkında bilgi içerir.

    Public Class DynamicUpdateInfo
        Public updateMap As DynamicUpdateMap
        Public newIdentity As WorkflowIdentity
    End Class
    
    class DynamicUpdateInfo
    {
        public DynamicUpdateMap updateMap;
        public WorkflowIdentity newIdentity;
    }
    
  12. Dosyanın en üstüne aşağıdaki using (veya Imports) deyimlerini diğer using (veya Imports) deyimleriyle ekleyin.

    Imports System.Activities
    Imports System.Activities.DynamicUpdate
    
    using System.Activities;
    using System.Activities.DynamicUpdate;
    
  13. Çözüm Gezgini'da Program.cs (veya Module1.vb) çift tıklayın.

  14. Dosyanın en üstüne aşağıdaki using (veya Imports) deyimlerini diğer using (veya Imports) deyimleriyle ekleyin.

    Imports NumberGuessWorkflowHost
    Imports System.Data.SqlClient
    Imports System.Activities.DynamicUpdate
    Imports System.IO
    Imports System.Runtime.Serialization
    Imports System.Activities
    Imports System.Activities.DurableInstancing
    
    using NumberGuessWorkflowHost;
    using System.Data;
    using System.Data.SqlClient;
    using System.Activities;
    using System.Activities.DynamicUpdate;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Activities.DurableInstancing;
    
  15. Sınıfına (veya Module1) aşağıdaki bağlantı dizesi üyesini Program ekleyin.

    Const connectionString = "Server=.\SQLEXPRESS;Initial Catalog=WF45GettingStartedTutorial;Integrated Security=SSPI"
    
    const string connectionString = "Server=.\\SQLEXPRESS;Initial Catalog=WF45GettingStartedTutorial;Integrated Security=SSPI";
    

    Not

    SQL Server sürümünüze bağlı olarak, bağlantı dizesi sunucu adı farklı olabilir.

  16. Sınıfına (veya Module1) aşağıdaki GetIDs yöntemi Program ekleyin. Bu yöntem kalıcı iş akışı örneği kimliklerinin listesini döndürür.

    Function GetIds() As IList(Of Guid)
        Dim Ids As New List(Of Guid)
        Dim localCmd = _
            String.Format("Select [InstanceId] from [System.Activities.DurableInstancing].[Instances] Order By [CreationTime]")
        Using localCon = New SqlConnection(connectionString)
            Dim cmd As SqlCommand = localCon.CreateCommand()
            cmd.CommandText = localCmd
            localCon.Open()
            Using reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    'Get the InstanceId of the persisted Workflow
                    Dim id As Guid = Guid.Parse(reader(0).ToString())
    
                    'Add it to the list.
                    Ids.Add(id)
                End While
            End Using
        End Using
    
        Return Ids
    End Function
    
    static IList<Guid> GetIds()
    {
        List<Guid> Ids = new List<Guid>();
        string localCmd = string.Format("Select [InstanceId] from [System.Activities.DurableInstancing].[Instances] Order By [CreationTime]");
        using (SqlConnection localCon = new SqlConnection(connectionString))
        {
            SqlCommand cmd = localCon.CreateCommand();
            cmd.CommandText = localCmd;
            localCon.Open();
            using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
            {
                while (reader.Read())
                {
                    // Get the InstanceId of the persisted Workflow
                    Guid id = Guid.Parse(reader[0].ToString());
    
                    // Add it to the list.
                    Ids.Add(id);
                }
            }
        }
    
        return Ids;
    }
    
  17. Sınıfına (veya Module1) aşağıdaki LoadMap yöntemi Program ekleyin. Bu yöntem, iş akışı kimliklerini güncelleştirme eşlemelerine ve ilgili kalıcı iş akışı örneklerini güncelleştirmek için kullanılan yeni iş akışı kimliklerine eşleyen bir sözlük v1 oluşturur.

    Function LoadMap(mapName As String) As DynamicUpdateMap
        Dim mapPath As String = Path.Combine("..\..\..\PreviousVersions", mapName)
    
        Dim map As DynamicUpdateMap
        Using fs As FileStream = File.Open(mapPath, FileMode.Open)
            Dim serializer As DataContractSerializer = New DataContractSerializer(GetType(DynamicUpdateMap))
            Dim updateMap = serializer.ReadObject(fs)
            If updateMap Is Nothing Then
                Throw New ApplicationException("DynamicUpdateMap is null.")
            End If
    
            map = updateMap
        End Using
    
        Return map
    End Function
    
    static DynamicUpdateMap LoadMap(string mapName)
    {
        string path = Path.Combine(@"..\..\..\PreviousVersions", mapName);
    
        DynamicUpdateMap map;
        using (FileStream fs = File.Open(path, FileMode.Open))
        {
            DataContractSerializer serializer = new DataContractSerializer(typeof(DynamicUpdateMap));
            object updateMap = serializer.ReadObject(fs);
            if (updateMap == null)
            {
                throw new ApplicationException("DynamicUpdateMap is null.");
            }
    
            map = updateMap as DynamicUpdateMap;
        }
    
        return map;
    }
    
  18. Sınıfına (veya Module1) aşağıdaki LoadMaps yöntemi Program ekleyin. Bu yöntem üç güncelleştirme eşlemesini yükler ve iş akışı kimliklerini güncelleştirme eşlemelerine eşleyen v1 bir sözlük oluşturur.

    Function LoadMaps() As IDictionary(Of WorkflowIdentity, DynamicUpdateInfo)
        'There are 3 update maps to describe the changes to update v1 workflows,
        'one for reach of the 3 workflow types in the tutorial.
        Dim maps = New Dictionary(Of WorkflowIdentity, DynamicUpdateInfo)()
    
        Dim sequentialMap As DynamicUpdateMap = LoadMap("SequentialNumberGuessWorkflow.map")
        Dim sequentialInfo = New DynamicUpdateInfo With
        {
            .updateMap = sequentialMap,
            .newIdentity = WorkflowVersionMap.SequentialNumberGuessIdentity_v15
        }
        maps.Add(WorkflowVersionMap.SequentialNumberGuessIdentity_v1, sequentialInfo)
    
        Dim stateMap As DynamicUpdateMap = LoadMap("StateMachineNumberGuessWorkflow.map")
        Dim stateInfo = New DynamicUpdateInfo With
        {
            .updateMap = stateMap,
            .newIdentity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v15
        }
        maps.Add(WorkflowVersionMap.StateMachineNumberGuessIdentity_v1, stateInfo)
    
        Dim flowchartMap As DynamicUpdateMap = LoadMap("FlowchartNumberGuessWorkflow.map")
        Dim flowchartInfo = New DynamicUpdateInfo With
        {
            .updateMap = flowchartMap,
            .newIdentity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v15
        }
        maps.Add(WorkflowVersionMap.FlowchartNumberGuessIdentity_v1, flowchartInfo)
    
        Return maps
    End Function
    
    static IDictionary<WorkflowIdentity, DynamicUpdateInfo> LoadMaps()
    {
        // There are 3 update maps to describe the changes to update v1 workflows,
        // one for reach of the 3 workflow types in the tutorial.
        Dictionary<WorkflowIdentity, DynamicUpdateInfo> maps =
            new Dictionary<WorkflowIdentity, DynamicUpdateInfo>();
    
        DynamicUpdateMap sequentialMap = LoadMap("SequentialNumberGuessWorkflow.map");
        DynamicUpdateInfo sequentialInfo = new DynamicUpdateInfo
        {
            updateMap = sequentialMap,
            newIdentity = WorkflowVersionMap.SequentialNumberGuessIdentity_v15
        };
        maps.Add(WorkflowVersionMap.SequentialNumberGuessIdentity_v1, sequentialInfo);
    
        DynamicUpdateMap stateMap = LoadMap("StateMachineNumberGuessWorkflow.map");
        DynamicUpdateInfo stateInfo = new DynamicUpdateInfo
        {
            updateMap = stateMap,
            newIdentity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v15
        };
        maps.Add(WorkflowVersionMap.StateMachineNumberGuessIdentity_v1, stateInfo);
    
        DynamicUpdateMap flowchartMap = LoadMap("FlowchartNumberGuessWorkflow.map");
        DynamicUpdateInfo flowchartInfo = new DynamicUpdateInfo
        {
            updateMap = flowchartMap,
            newIdentity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v15
        };
        maps.Add(WorkflowVersionMap.FlowchartNumberGuessIdentity_v1, flowchartInfo);
    
        return maps;
    }
    
  19. Aşağıdaki kodu Main içine ekleyin. Bu kod kalıcı iş akışı örneklerini yineler ve her WorkflowIdentityöğesini inceler. WorkflowIdentity bir iş akışı örneğiyle eşleniyorsav1, WorkflowApplication güncelleştirilmiş iş akışı tanımı ve güncelleştirilmiş iş akışı kimliği ile yapılandırılır. Ardından, WorkflowApplication.Load örnek ve dinamik güncelleştirme eşlemesini uygulayan güncelleştirme haritası ile çağrılır. Güncelleştirme uygulandıktan sonra, güncelleştirilmiş örnek çağrısıyla Unloadkalıcı hale dönüştürülür.

    Dim store = New SqlWorkflowInstanceStore(connectionString)
    WorkflowApplication.CreateDefaultInstanceOwner(store, Nothing, WorkflowIdentityFilter.Any)
    
    Dim updateMaps As IDictionary(Of WorkflowIdentity, DynamicUpdateInfo) = LoadMaps()
    
    For Each id As Guid In GetIds()
        'Get a proxy to the instance.
        Dim instance As WorkflowApplicationInstance = WorkflowApplication.GetInstance(id, store)
    
        Console.WriteLine("Inspecting: {0}", instance.DefinitionIdentity)
    
        'Only update v1 workflows.
        If Not instance.DefinitionIdentity Is Nothing AndAlso _
            instance.DefinitionIdentity.Version.Equals(New Version(1, 0, 0, 0)) Then
    
            Dim info As DynamicUpdateInfo = updateMaps(instance.DefinitionIdentity)
    
            'Associate the persisted WorkflowApplicationInstance with
            'a WorkflowApplication that is configured with the updated
            'definition and updated WorkflowIdentity.
            Dim wf As Activity = WorkflowVersionMap.GetWorkflowDefinition(info.newIdentity)
            Dim wfApp = New WorkflowApplication(wf, info.newIdentity)
    
            'Apply the Dynamic Update.
            wfApp.Load(instance, info.updateMap)
    
            'Persist the updated instance.
            wfApp.Unload()
    
            Console.WriteLine("Updated to: {0}", info.newIdentity)
        Else
            'Not updating this instance, so unload it.
            instance.Abandon()
        End If
    Next
    
    SqlWorkflowInstanceStore store = new SqlWorkflowInstanceStore(connectionString);
    WorkflowApplication.CreateDefaultInstanceOwner(store, null, WorkflowIdentityFilter.Any);
    
    IDictionary<WorkflowIdentity, DynamicUpdateInfo> updateMaps = LoadMaps();
    
    foreach (Guid id in GetIds())
    {
        // Get a proxy to the instance.
        WorkflowApplicationInstance instance =
            WorkflowApplication.GetInstance(id, store);
    
        Console.WriteLine("Inspecting: {0}", instance.DefinitionIdentity);
    
        // Only update v1 workflows.
        if (instance.DefinitionIdentity != null &&
            instance.DefinitionIdentity.Version.Equals(new Version(1, 0, 0, 0)))
        {
            DynamicUpdateInfo info = updateMaps[instance.DefinitionIdentity];
    
            // Associate the persisted WorkflowApplicationInstance with
            // a WorkflowApplication that is configured with the updated
            // definition and updated WorkflowIdentity.
            Activity wf = WorkflowVersionMap.GetWorkflowDefinition(info.newIdentity);
            WorkflowApplication wfApp =
                new WorkflowApplication(wf, info.newIdentity);
    
            // Apply the Dynamic Update.
            wfApp.Load(instance, info.updateMap);
    
            // Persist the updated instance.
            wfApp.Unload();
    
            Console.WriteLine("Updated to: {0}", info.newIdentity);
        }
        else
        {
            // Not updating this instance, so unload it.
            instance.Abandon();
        }
    }
    
  20. Çözüm Gezgini'de ApplyDynamicUpdate'e sağ tıklayın ve StartUp Projesi Olarak Ayarla'yı seçin.

  21. Çözümü oluşturmak için CTRL+SHIFT+B tuşlarına basın ve ardından CTRL+F5 tuşlarına basarak uygulamayı çalıştırın ApplyDynamicUpdate ve kalıcı iş akışı örneklerini güncelleştirin. Aşağıdakine benzer bir çıktı görmeniz gerekir. Sürüm 1.0.0.0 iş akışları 1.5.0.0 sürümüne, sürüm 2.0.0.0 iş akışları ise güncelleştirilmez.

    İnceleniyor: StateMachineNumberGuessWorkflow; Sürüm=1.0.0.0
    Şu şekilde güncelleştirildi: StateMachineNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: StateMachineNumberGuessWorkflow; Sürüm=1.0.0.0
    Şu şekilde güncelleştirildi: StateMachineNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: FlowchartNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirilecek: FlowchartNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: FlowchartNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirilecek: FlowchartNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: SequentialNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirme tarihi: SequentialNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: SequentialNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirme tarihi: SequentialNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: SequentialNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirme tarihi: SequentialNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: StateMachineNumberGuessWorkflow; Sürüm=1.0.0.0
    Şu şekilde güncelleştirildi: StateMachineNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: FlowchartNumberGuessWorkflow; Sürüm=1.0.0.0
    Güncelleştirilecek: FlowchartNumberGuessWorkflow; Sürüm=1.5.0.0
    İnceleniyor: StateMachineNumberGuessWorkflow; Sürüm=2.0.0.0
    İnceleniyor: StateMachineNumberGuessWorkflow; Sürüm=2.0.0.0
    İnceleniyor: FlowchartNumberGuessWorkflow; Sürüm=2.0.0.0
    İnceleniyor: FlowchartNumberGuessWorkflow; Sürüm=2.0.0.0
    İnceleniyor: SequentialNumberGuessWorkflow; Sürüm=2.0.0.0
    İnceleniyor: SequentialNumberGuessWorkflow; Sürüm=2.0.0.0
    devam etmek için herhangi bir tuşa basın. . .

Uygulamayı güncelleştirilmiş iş akışlarıyla çalıştırmak için

  1. Çözüm Gezgini'da NumberGuessWorkflowHost'a sağ tıklayın ve Başlangıç Projesi Olarak Ayarla'yı seçin.

  2. Uygulamayı çalıştırmak için CTRL+F5'e basın.

  3. Yeni bir iş akışı başlatmak için Yeni Oyun'a tıklayın ve durum penceresinin altında iş akışının bir v2 iş akışı olduğunu belirten sürüm bilgilerini not edin.

  4. Nasıl yapılır: İş Akışının v1 Birden Çok Sürümünü Yan Yana Barındırma konusunun başında başlattığınız iş akışlarından birini seçin. Durum penceresinin altındaki sürüm bilgilerinin, iş akışının bir sürüm 1.5.0.0 iş akışı olduğunu gösterdiğine dikkat edin. Önceki tahminler hakkında çok yüksek mi yoksa çok düşük mü olduğu dışında hiçbir bilgi belirtilmediği unutmayın.

    Lütfen 1 ile 10 arasında bir sayı girin
    Tahminin çok düşük.

  5. değerini not InstanceId edin ve iş akışı tamamlanana kadar tahminleri girin. Etkinlikler dinamik güncelleştirme tarafından güncelleştirildiğinden durum penceresinde tahminin WriteLine içeriğiyle ilgili bilgiler görüntülenir.

    Lütfen 1 ile 10 arasında bir sayı girin
    Tahminin çok düşük.
    Lütfen 1 ile 10 arasında bir sayı girin
    5 çok düşük.
    Lütfen 1 ile 10 arasında bir sayı girin
    7 çok yüksek.
    Lütfen 1 ile 10 arasında bir sayı girin
    Tebrikler, sayıyı 4'ler halinde tahmin ettiniz.

  6. Windows Gezgini'ni açın ve NumberGuessWorkflowHost\bin\debug klasörüne (veya proje ayarlarınıza bağlı olarak bin\release) gidin ve tamamlanan iş akışına karşılık gelen Not Defteri kullanarak izleme dosyasını açın. Not almadıysanızInstanceId, Windows Gezgini'ndeki Değiştirme tarihi bilgilerini kullanarak doğru izleme dosyasını tanımlayabilirsiniz. İzleme bilgilerinin son satırı, yeni eklenen WriteLine etkinliğin çıkışını içerir.

    Lütfen 1 ile 10 arasında bir sayı girin
    Tahminin çok düşük.
    Lütfen 1 ile 10 arasında bir sayı girin
    5 çok düşük.
    Lütfen 1 ile 10 arasında bir sayı girin
    7 çok yüksek.
    Lütfen 1 ile 10 arasında bir sayı girin
    6 doğru. 4 dönüşte tahminde bulundun.

İş akışlarının önceki sürümlerini başlatmayı etkinleştirmek için

Güncelleştirilecek iş akışlarınız tükenirse, uygulamayı iş akışlarının önceki sürümlerini başlatacak şekilde değiştirebilirsiniz NumberGuessWorkflowHost .

  1. Çözüm Gezgini'da WorkflowHostForm'a çift tıklayın ve WorkflowType birleşik giriş kutusunu seçin.

  2. Özellikler penceresinde Items özelliğini seçin ve Items koleksiyonunu düzenlemek için üç nokta düğmesine tıklayın.

  3. Koleksiyona aşağıdaki üç öğeyi ekleyin.

    StateMachineNumberGuessWorkflow v1
    FlowchartNumberGuessWorkflow v1
    SequentialNumberGuessWorkflow v1
    

    Tamamlanan Items koleksiyon altı öğeye sahip olacaktır.

    StateMachineNumberGuessWorkflow
    FlowchartNumberGuessWorkflow
    SequentialNumberGuessWorkflow
    StateMachineNumberGuessWorkflow v1
    FlowchartNumberGuessWorkflow v1
    SequentialNumberGuessWorkflow v1
    
  4. Çözüm Gezgini workflowhostform'a çift tıklayın ve Kodu Görüntüle'yi seçin.

  5. WorkflowType birleşik giriş kutusundaki yeni öğeleri eşleşen iş akışı kimliklerine eşlemek için işleyicideki (veya Select Case) deyimine NewGame_Click üç yeni durum switch ekleyin.

    Case "SequentialNumberGuessWorkflow v1"
        identity = WorkflowVersionMap.SequentialNumberGuessIdentity_v1
    
    Case "StateMachineNumberGuessWorkflow v1"
        identity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v1
    
    Case "FlowchartNumberGuessWorkflow v1"
        identity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v1
    
    case "SequentialNumberGuessWorkflow v1":
        identity = WorkflowVersionMap.SequentialNumberGuessIdentity_v1;
        break;
    
    case "StateMachineNumberGuessWorkflow v1":
        identity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v1;
        break;
    
    case "FlowchartNumberGuessWorkflow v1":
        identity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v1;
        break;
    

    Aşağıdaki örnek, complete switch (veya Select Case) deyimini içerir.

    Select Case WorkflowType.SelectedItem.ToString()
        Case "SequentialNumberGuessWorkflow"
            identity = WorkflowVersionMap.SequentialNumberGuessIdentity
    
        Case "StateMachineNumberGuessWorkflow"
            identity = WorkflowVersionMap.StateMachineNumberGuessIdentity
    
        Case "FlowchartNumberGuessWorkflow"
            identity = WorkflowVersionMap.FlowchartNumberGuessIdentity
    
        Case "SequentialNumberGuessWorkflow v1"
            identity = WorkflowVersionMap.SequentialNumberGuessIdentity_v1
    
        Case "StateMachineNumberGuessWorkflow v1"
            identity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v1
    
        Case "FlowchartNumberGuessWorkflow v1"
            identity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v1
    End Select
    
    switch (WorkflowType.SelectedItem.ToString())
    {
        case "SequentialNumberGuessWorkflow":
            identity = WorkflowVersionMap.SequentialNumberGuessIdentity;
            break;
    
        case "StateMachineNumberGuessWorkflow":
            identity = WorkflowVersionMap.StateMachineNumberGuessIdentity;
            break;
    
        case "FlowchartNumberGuessWorkflow":
            identity = WorkflowVersionMap.FlowchartNumberGuessIdentity;
            break;
    
        case "SequentialNumberGuessWorkflow v1":
            identity = WorkflowVersionMap.SequentialNumberGuessIdentity_v1;
            break;
    
        case "StateMachineNumberGuessWorkflow v1":
            identity = WorkflowVersionMap.StateMachineNumberGuessIdentity_v1;
            break;
    
        case "FlowchartNumberGuessWorkflow v1":
            identity = WorkflowVersionMap.FlowchartNumberGuessIdentity_v1;
            break;
    };
    
  6. Uygulamayı derlemek ve çalıştırmak için CTRL+F5 tuşlarına basın. Artık iş akışının v1 sürümlerinin yanı sıra geçerli sürümleri de başlatabilirsiniz. Bu yeni örnekleri dinamik olarak güncelleştirmek için ApplyDynamicUpdate uygulamasını çalıştırın.