public static Activity Load(XamlReader xamlReader, ActivityXamlServicesSettings settings)
        {
            if (xamlReader == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(xamlReader));
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(settings));
            }

            DynamicActivityXamlReader dynamicActivityReader = new DynamicActivityXamlReader(xamlReader);
            object xamlObject = XamlServices.Load(dynamicActivityReader);

            if (!(xamlObject is Activity result))
            {
                throw FxTrace.Exception.Argument("reader", SR.ActivityXamlServicesRequiresActivity(
                                                     xamlObject != null ? xamlObject.GetType().FullName : string.Empty));
            }

            if (result is IDynamicActivity dynamicActivity && settings.CompileExpressions)
            {
                Compile(dynamicActivity, settings);
            }

            return(result);
        }
Exemple #2
0
        public static Activity Load(XamlReader xamlReader, ActivityXamlServicesSettings settings)
        {
            if (xamlReader == null)
            {
                throw FxTrace.Exception.ArgumentNull("xamlReader");
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            DynamicActivityXamlReader dynamicActivityReader = new DynamicActivityXamlReader(xamlReader);
            object xamlObject = XamlServices.Load(dynamicActivityReader);
            Activity result = xamlObject as Activity;
            if (result == null)
            {
                throw FxTrace.Exception.Argument("reader", SR.ActivityXamlServicesRequiresActivity(
                    xamlObject != null ? xamlObject.GetType().FullName : string.Empty));
            }

            IDynamicActivity dynamicActivity = result as IDynamicActivity;
            if (dynamicActivity != null && settings.CompileExpressions)
            {
                Compile(dynamicActivity, settings.LocationReferenceEnvironment);
            }

            return result;
        }
 public static Activity LoadFromString(string xaml)
 {
     ActivityXamlServicesSettings settings = new ActivityXamlServicesSettings
     {
         CompileExpressions = true
     };
     using (Stream stream = new MemoryStream(ASCIIEncoding.Unicode.GetBytes(xaml)))
     {
         return ActivityXamlServices.Load(stream, settings);
     }
 }
        public static Activity Load(TextReader textReader, ActivityXamlServicesSettings settings)
        {
            if (textReader == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(textReader));
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(settings));
            }

            using (XmlReader xmlReader = XmlReader.Create(textReader))
            {
                return(Load(xmlReader, settings));
            }
        }
        public static Activity Load(XmlReader xmlReader, ActivityXamlServicesSettings settings)
        {
            if (xmlReader == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(xmlReader));
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(settings));
            }

            using (XamlXmlReader xamlReader = new XamlXmlReader(xmlReader, dynamicActivityReaderSchemaContext))
            {
                return(Load(xamlReader, settings));
            }
        }
Exemple #6
0
        public static Activity Load(string fileName, ActivityXamlServicesSettings settings)
        {
            if (fileName == null)
            {
                throw FxTrace.Exception.ArgumentNull("fileName");
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            using (XmlReader xmlReader = XmlReader.Create(fileName))
            {
                return Load(xmlReader, settings);
            }
        }
Exemple #7
0
        public static Activity Load(Stream stream, ActivityXamlServicesSettings settings)
        {
            if (stream == null)
            {
                throw FxTrace.Exception.ArgumentNull("stream");
            }

            if (settings == null)
            {
                throw FxTrace.Exception.ArgumentNull("settings");
            }

            using (XmlReader xmlReader = XmlReader.Create(stream))
            {
                return Load(xmlReader, settings);
            }
        }
Exemple #8
0
        private static void Compile(IDynamicActivity dynamicActivity, ActivityXamlServicesSettings settings)
        {
            string language = null;

            if (!RequiresCompilation(dynamicActivity, settings.LocationReferenceEnvironment, out language))
            {
                return;
            }
            var aotCompiler = settings.GetCompiler(language);
            var compiler    = new TextExpressionCompiler(GetCompilerSettings(dynamicActivity, language, aotCompiler));
            var results     = compiler.Compile();

            if (results.HasErrors)
            {
                var messages = new StringBuilder();
                messages.Append("\r\n");
                messages.Append("\r\n");

                foreach (TextExpressionCompilerError message in results.CompilerMessages)
                {
                    messages.Append("\t");
                    messages.Append(string.Concat(" ", SR.ActivityXamlServiceLineString, " ", message.SourceLineNumber, ": "));
                    messages.Append(message.Message);
                }

                messages.Append("\r\n");
                messages.Append("\r\n");

                InvalidOperationException exception = new InvalidOperationException(SR.ActivityXamlServicesCompilationFailed(messages.ToString()));

                foreach (TextExpressionCompilerError message in results.CompilerMessages)
                {
                    exception.Data.Add(message, message.Message);
                }
                throw FxTrace.Exception.AsError(exception);
            }

            Type compiledExpressionRootType = results.ResultType;

            ICompiledExpressionRoot compiledExpressionRoot = Activator.CreateInstance(compiledExpressionRootType, new object[] { dynamicActivity }) as ICompiledExpressionRoot;

            CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(dynamicActivity, compiledExpressionRoot);
        }
        public static Activity CreateWorkflowActivityFromXaml(string workflowXaml, Assembly type)
        {
            if (string.IsNullOrEmpty(workflowXaml) || type == null)
            {
                return null;
            }

            var xmlReaderSettings = new XamlXmlReaderSettings { LocalAssembly = type };
            var settings1 = xmlReaderSettings;
            StringReader stringReader = null;
            var settings2 = new ActivityXamlServicesSettings { CompileExpressions = true };
            try
            {
                stringReader = new StringReader(workflowXaml);
                var activity = ActivityXamlServices.Load(new XamlXmlReader(stringReader, settings1), settings2);
                return activity;
            }
            finally
            {
                stringReader?.Dispose();
            }
        }