Exemplo n.º 1
0
 public Activity LoadFromSource(IApplicationHost host)
 {
     if (Type == WorkflowType.File)
     {
         String fullPath = GetWorkflowFullPath(host);
         using (var sr = new StreamReader(fullPath))
         {
             Definition = sr.ReadToEnd();
             sr.BaseStream.Seek(0, SeekOrigin.Begin);
             using (var xr = ActivityXamlServices.CreateReader(sr.BaseStream))
             {
                 var root = ActivityXamlServices.Load(xr);
                 RuntimeActivity.Compile(GetHashedName(), root);
                 return(root);
             }
         }
     }
     else if (Type == WorkflowType.ClrType)
     {
         return(System.Activator.CreateInstance(Assembly, Name).Unwrap() as Activity);
     }
     else if (Type == WorkflowType.Definition)
     {
         using (var sr = new StringReader(Definition))
         {
             Activity root = ActivityXamlServices.Load(sr) as Activity;
             Cached = RuntimeActivity.Compile(GetHashedName(), root);
             return(root);
         }
     }
     else
     {
         throw new NotImplementedException($"WorkflowDefinition. Invalid WorkflowType. Type={Type.ToString()}");
     }
 }
Exemplo n.º 2
0
 public Activity LoadFromSource(IApplicationHost host, IDbContext dbContext)
 {
     if (Type == WorkflowType.File)
     {
         String fullPath = GetWorkflowFullPath(host);
         using (var sr = new StreamReader(fullPath))
         {
             Definition = sr.ReadToEnd();
             sr.BaseStream.Seek(0, SeekOrigin.Begin);
             using (var xr = ActivityXamlServices.CreateReader(sr.BaseStream))
             {
                 var root = ActivityXamlServices.Load(xr);
                 RuntimeActivity.Compile(GetHashedName(), root);
                 return(root);
             }
         }
     }
     else if (Type == WorkflowType.Db)
     {
         var fullPath = Path.Replace('\\', '/').ToLowerInvariant();
         fullPath = System.IO.Path.ChangeExtension(fullPath, ".xaml");
         var appStream = dbContext.Load <AppStream>(null, "a2sys.LoadApplicationFile", new { Path = fullPath });
         if (appStream.Stream == null)
         {
             throw new WorkflowException($"There is no definition for '{fullPath}'");
         }
         Definition = appStream.Stream;
         using (var sr = new StringReader(appStream.Stream))
         {
             Activity root = ActivityXamlServices.Load(sr) as Activity;
             Cached = RuntimeActivity.Compile(GetHashedName(), root);
             return(root);
         }
     }
     else if (Type == WorkflowType.ClrType)
     {
         return(System.Activator.CreateInstance(Assembly, Name).Unwrap() as Activity);
     }
     else if (Type == WorkflowType.Definition)
     {
         using (var sr = new StringReader(Definition))
         {
             Activity root = ActivityXamlServices.Load(sr) as Activity;
             Cached = RuntimeActivity.Compile(GetHashedName(), root);
             return(root);
         }
     }
     else
     {
         throw new NotImplementedException($"WorkflowDefinition. Invalid WorkflowType. Type={Type.ToString()}");
     }
 }
Exemplo n.º 3
0
 public Activity LoadFromDefinition()
 {
     if (Type != WorkflowType.Definition)
     {
         throw new InvalidOperationException("Invalid WorkflowDefinition type. Expected 'WorkflowType.Definition'");
     }
     using (var sr = new StringReader(Definition))
     {
         Activity root = ActivityXamlServices.Load(sr) as Activity;
         Cached = RuntimeActivity.Compile(GetHashedName(), root);
         return(root);
     }
 }
Exemplo n.º 4
0
        public static Boolean Compile(String name, Activity root)
        {
            Type    cachedType = RuntimeActivity.GetCachedType(name);
            Boolean bCached    = false;

            if (cachedType != null)
            {
                RuntimeActivity.CreateCompiledActivity(root as DynamicActivity, cachedType);
                bCached = true;
            }
            else
            {
                cachedType = RuntimeActivity.CompileExpressions(root as DynamicActivity);
                RuntimeActivity.CacheType(name, cachedType);
            }
            return(bCached);
        }
Exemplo n.º 5
0
        public static Boolean IsTypeCached(String name)
        {
            Type cachedType = RuntimeActivity.GetCachedType(name);

            return(cachedType != null);
        }