Serialization of operation in xaml

I have Googled a bit and cannot find examples of Xaml-fying Activities - good, bad, or otherwise!

public static string ToXaml (this Activity activity)
{
    // i would use ActivityXamlServices to go from Xaml
    // to activity, but how to go other way? documentation
    // is slim, and cannot infer proper usage of 
    // ActivityXamlServices from Xml remarks :S
    string xaml = string.Empty;
    return xaml;
}

Tips, tricks, pointers are welcome :)


NOTE : this is found . Will work and update after work. Someone wants to defeat me by all means. Even better, if you can find a way to get rid of WorkflowDesigner, it seems strange that this is necessary.

+3
source share
3 answers

Ok, so I worked on this forum .

You can Xaml-fy [i.e. convert instance to declarative Xaml] known activity through

public static string ToXaml (this Activity activity)
{
    StringBuilder xaml = new StringBuilder ();

    using (XmlWriter xmlWriter = XmlWriter.Create (
        xaml, 
        new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true, }))

    using (XamlWriter xamlWriter = new XamlXmlWriter (
        xmlWriter, 
        new XamlSchemaContext ()))

    using (XamlWriter xamlServicesWriter = 
        ActivityXamlServices.CreateBuilderWriter (xamlWriter))
    {
        ActivityBuilder activityBuilder = new ActivityBuilder 
        {
            Implementation = activity
        };
        XamlServices.Save (xamlServicesWriter, activityBuilder);
    }

    return xaml.ToString ();
}

Xaml , System.Activities.Presentation, xmlns: sap = "...". , - .

. - , , :)

+4

XamlServices.Save(filename, activity)?

+3

( VS2010B2) Reflectoring VS2010RC. XamlWriter RC, :

public static string ToXaml (this Activity activity)
{
    var xamlBuilder = new StringBuilder();
    var xmlWriter = XmlWriter.Create(xamlBuilder,
        new XmlWriterSettings { Indent = true, OmitXmlDeclaration = true });
    using (xmlWriter)
    {
        var xamlXmlWriter =
            new XamlXmlWriter(xmlWriter, new XamlSchemaContext());
        using (xamlXmlWriter)
        {
            XamlWriter xamlWriter =
                ActivityXamlServices.CreateBuilderWriter(xamlXmlWriter);
            using (xamlWriter)
            {
                var activityBuilder =
                    new ActivityBuilder { Implementation = sequence };
                XamlServices.Save(xamlWriter, activityBuilder);
            }
        }
    }
    return xamlBuilder.ToString();
}
0

Source: https://habr.com/ru/post/1734457/


All Articles