Пример #1
0
        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);
            }
        }
Пример #2
0
        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(); }
        }