internal static int LaunchWorkflowEditor( PackageConfiguration packageConfiguration, ScriptExtensions scriptEnvironment, string editorRepositoryPath, string initialFileName, float editorScale, bool start, bool debugging, Dictionary <string, string> propertyAssignments) { var elementProvider = WorkflowElementLoader.GetWorkflowElementTypes(packageConfiguration); var visualizerProvider = TypeVisualizerLoader.GetTypeVisualizerDictionary(packageConfiguration); var packageManager = CreatePackageManager(editorRepositoryPath); var updatesAvailable = Task.Factory.StartNew(() => { try { return(packageManager.SourceRepository.GetUpdates( packageManager.LocalRepository.GetPackages(), includePrerelease: false, includeAllVersions: false).Any()); } catch { return(false); } }); EnableVisualStyles(); using (var mainForm = new MainForm(elementProvider, visualizerProvider, scriptEnvironment, editorScale)) { updatesAvailable.ContinueWith(task => mainForm.UpdatesAvailable = task.Result); mainForm.FileName = initialFileName; mainForm.PropertyAssignments.AddRange(propertyAssignments); mainForm.LoadAction = start && debugging ? LoadAction.Start : start ? LoadAction.StartWithoutDebugging : LoadAction.None; Application.Run(mainForm); var editorFlags = mainForm.UpdatesAvailable ? EditorFlags.UpdatesAvailable : EditorFlags.None; if (scriptEnvironment.DebugScripts) { editorFlags |= EditorFlags.DebugScripts; } AppResult.SetResult(editorFlags); AppResult.SetResult(mainForm.FileName); return((int)mainForm.EditorResult); } }
internal static int LaunchWorkflowPlayer( string fileName, string layoutPath, PackageConfiguration packageConfiguration, Dictionary <string, string> propertyAssignments) { if (string.IsNullOrEmpty(fileName)) { Console.WriteLine("No workflow file was specified."); return(Program.NormalExitCode); } var visualizerProvider = Observable.Defer(() => { EditorBootstrapper.EnableVisualStyles(); return(TypeVisualizerLoader.GetVisualizerTypes(packageConfiguration)); }); WorkflowRunner.Run(fileName, propertyAssignments, visualizerProvider, layoutPath); return(Program.NormalExitCode); }
internal static int LaunchWorkflowEditor( PackageConfiguration packageConfiguration, ScriptExtensions scriptExtensions, string editorRepositoryPath, string initialFileName, float editorScale, bool start, bool debugging, Dictionary <string, string> propertyAssignments) { var elementProvider = WorkflowElementLoader.GetWorkflowElementTypes(packageConfiguration); var visualizerProvider = TypeVisualizerLoader.GetVisualizerTypes(packageConfiguration); var editorBootstrapper = new EditorBootstrapper(editorRepositoryPath); var packageManager = editorBootstrapper.PackageManager; using var cancellation = new CancellationTokenSource(); var updatesAvailable = Task.Run(async() => { try { var localPackages = packageManager.LocalRepository.GetLocalPackages(); foreach (var repository in packageManager.SourceRepositoryProvider.GetRepositories()) { try { if (cancellation.IsCancellationRequested) { break; } var updates = await repository.GetUpdatesAsync(localPackages, includePrerelease: false, cancellation.Token); if (updates.Any()) { return(true); } } catch { continue; } } return(false); } catch { return(false); } }, cancellation.Token); EditorBootstrapper.EnableVisualStyles(); var scriptEnvironment = new ScriptExtensionsEnvironment(scriptExtensions); using var mainForm = new EditorForm(elementProvider, visualizerProvider, scriptEnvironment, editorScale); try { updatesAvailable.ContinueWith( task => mainForm.UpdatesAvailable = !task.IsFaulted && !task.IsCanceled && task.Result, cancellation.Token); mainForm.FileName = initialFileName; mainForm.PropertyAssignments.AddRange(propertyAssignments); mainForm.LoadAction = start && debugging ? LoadAction.Start : start ? LoadAction.StartWithoutDebugging : LoadAction.None; Application.Run(mainForm); var editorFlags = mainForm.UpdatesAvailable ? EditorFlags.UpdatesAvailable : EditorFlags.None; if (scriptExtensions.DebugScripts) { editorFlags |= EditorFlags.DebugScripts; } AppResult.SetResult(editorFlags); AppResult.SetResult(mainForm.FileName); return((int)mainForm.EditorResult); } finally { cancellation.Cancel(); } }
Configuration.PackageReference[] GetWorkflowPackageDependencies(string[] fileNames) { var assemblies = new HashSet <Assembly>(); foreach (var path in fileNames) { var metadata = WorkflowBuilder.ReadMetadata(path); using (var markupReader = new StringReader(metadata.WorkflowMarkup)) using (var reader = XmlReader.Create(markupReader)) { reader.ReadToFollowing(WorkflowElementName); using (var workflowReader = reader.ReadSubtree()) { while (workflowReader.ReadToFollowing(ExpressionElementName)) { if (!workflowReader.HasAttributes) { continue; } if (workflowReader.GetAttribute(TypeAttributeName, XsiAttributeValue) == IncludeWorkflowTypeName) { var includePath = workflowReader.GetAttribute(PathAttributeName); var separatorIndex = includePath != null?includePath.IndexOf(AssemblySeparator) : -1; if (separatorIndex >= 0 && !Path.IsPathRooted(includePath)) { var assemblyName = includePath.Split(new[] { AssemblySeparator }, 2)[0]; if (!string.IsNullOrEmpty(assemblyName)) { var assembly = Assembly.Load(assemblyName); assemblies.Add(assembly); } } } } } } assemblies.Add(typeof(WorkflowBuilder).Assembly); assemblies.AddRange(metadata.GetExtensionTypes().Select(type => type.Assembly)); var layoutPath = Path.ChangeExtension(path, Path.GetExtension(path) + Constants.LayoutExtension); if (File.Exists(layoutPath)) { var visualizerMap = new Lazy <IDictionary <string, Type> >(() => TypeVisualizerLoader.GetVisualizerTypes(packageConfiguration) .Select(descriptor => descriptor.VisualizerTypeName).Distinct() .Select(typeName => Type.GetType(typeName, false)) .Where(type => type != null) .ToDictionary(type => type.FullName) .Wait()); using (var reader = XmlReader.Create(layoutPath)) { var layout = (VisualizerLayout)VisualizerLayout.Serializer.Deserialize(reader); foreach (var settings in GetVisualizerSettings(layout)) { var typeName = settings.VisualizerTypeName; if (typeName == null) { continue; } if (visualizerMap.Value.TryGetValue(typeName, out Type type)) { assemblies.Add(type.Assembly); } } } } } var packageMap = packageConfiguration.GetPackageReferenceMap(); var dependencies = packageConfiguration.GetAssemblyPackageReferences( assemblies.Select(assembly => assembly.GetName().Name), packageMap); if (File.Exists(scriptEnvironment.ProjectFileName)) { dependencies = dependencies.Concat( from id in scriptEnvironment.GetPackageReferences() where packageConfiguration.Packages.Contains(id) select packageConfiguration.Packages[id]); } return(dependencies.ToArray()); }