Beispiel #1
0
		internal Activity CompileActivityAndSaveInCache(WorkflowJobDefinition definition, Activity activityTree, Dictionary<string, string> requiredAssemblies, out bool windowsWorkflow)
		{
			Activity activity = null;
			Func<WorkflowJobDefinition, bool> func = null;
			DefinitionCache.WorkflowDetails workflowDetail = new DefinitionCache.WorkflowDetails();
			Activity activity1 = null;
			windowsWorkflow = false;
			string dependentAssemblyPath = definition.DependentAssemblyPath;
			string modulePath = definition.ModulePath;
			string[] array = definition.DependentWorkflows.ToArray();
			Assembly assembly = null;
			string str = null;
			string xaml = definition.Xaml;
			if (activityTree == null)
			{
				if (!string.IsNullOrEmpty(xaml))
				{
					object[] instanceId = new object[1];
					instanceId[0] = definition.InstanceId;
					this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "DefinitionCache: Caching activity for definition with instance ID: {0}. Xaml is passed", instanceId));
					workflowDetail.ActivityTree = null;
					if (!string.IsNullOrEmpty(modulePath))
					{
						string str1 = Environment.ExpandEnvironmentVariables(modulePath);
						string str2 = Environment.ExpandEnvironmentVariables("%windir%\\system32");
						if (str1.IndexOf(str2, StringComparison.CurrentCultureIgnoreCase) != -1)
						{
							windowsWorkflow = true;
						}
					}
					if (definition.DependentAssemblyPath != null || (int)array.Length != 0)
					{
						activity1 = ImportWorkflowCommand.ConvertXamlToActivity(xaml, array, requiredAssemblies, ref dependentAssemblyPath, ref assembly, ref str);
					}
					else
					{
						activity1 = ImportWorkflowCommand.ConvertXamlToActivity(xaml);
					}
				}
			}
			else
			{
				object[] objArray = new object[1];
				objArray[0] = definition.InstanceId;
				this._tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "DefinitionCache: Caching activity for definition with instance ID: {0}. The activity Tree is passed.", objArray));
				workflowDetail.ActivityTree = activityTree;
				activity1 = activityTree;
			}
			if (activity1 == null)
			{
				return null;
			}
			else
			{
				workflowDetail.IsWindowsActivity = (sbyte)windowsWorkflow;
				workflowDetail.CompiledAssemblyPath = dependentAssemblyPath;
				workflowDetail.CompiledAssemblyName = str;
				lock (this._syncObject)
				{
					var keys = this._workflowDetailsCache.Keys;
					if (func == null)
					{
						func = (WorkflowJobDefinition item) => item.InstanceId == definition.InstanceId;
					}
					WorkflowJobDefinition workflowJobDefinition = keys.FirstOrDefault<WorkflowJobDefinition>(func);
					if (workflowJobDefinition != null)
					{
						this._workflowDetailsCache.Remove(definition);
					}
					this._workflowDetailsCache.Add(definition, workflowDetail);
				}
				if (this._cachedActivities.Count == 0x3e8)
				{
					this._cachedActivities.TryRemove(this._cachedActivities.Keys.ElementAt<WorkflowJobDefinition>(0), out activity);
				}
				this._cachedActivities.TryAdd(definition, activity1);
				return activity1;
			}
		}