| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE.md file. | |
| 4 | |
| 5 library fletchc.verbs.create_verb; | |
| 6 | |
| 7 import 'infrastructure.dart'; | |
| 8 | |
| 9 import '../worker/developer.dart' show | |
| 10 Settings, | |
| 11 allocateWorker, | |
| 12 configFileUri, | |
| 13 createSessionState, | |
| 14 createSettings; | |
| 15 | |
| 16 import 'documentation.dart' show | |
| 17 createDocumentation; | |
| 18 | |
| 19 const Action createAction = const Action( | |
| 20 create, createDocumentation, requiresTargetSession: true, | |
| 21 supportsWithUri: true); | |
| 22 | |
| 23 Future<int> create(AnalyzedSentence sentence, VerbContext context) async { | |
| 24 IsolatePool pool = context.pool; | |
| 25 String name = sentence.targetName; | |
| 26 | |
| 27 UserSession session = await createSession(name, () => allocateWorker(pool)); | |
| 28 | |
| 29 context = context.copyWithSession(session); | |
| 30 | |
| 31 return await context.performTaskInWorker( | |
| 32 new CreateSessionTask( | |
| 33 name, sentence.withUri, sentence.base, configFileUri)); | |
| 34 } | |
| 35 | |
| 36 class CreateSessionTask extends SharedTask { | |
| 37 // Keep this class simple, see note in superclass. | |
| 38 | |
| 39 final String name; | |
| 40 | |
| 41 final Uri settingsUri; | |
| 42 | |
| 43 final Uri base; | |
| 44 | |
| 45 final Uri configFileUri; | |
| 46 | |
| 47 const CreateSessionTask( | |
| 48 this.name, this.settingsUri, this.base, this.configFileUri); | |
| 49 | |
| 50 Future<int> call( | |
| 51 CommandSender commandSender, | |
| 52 StreamIterator<ClientCommand> commandIterator) { | |
| 53 return createSessionTask( | |
| 54 commandSender, commandIterator, name, settingsUri, base, configFileUri); | |
| 55 } | |
| 56 } | |
| 57 | |
| 58 Future<int> createSessionTask( | |
| 59 CommandSender commandSender, | |
| 60 StreamIterator<ClientCommand> commandIterator, | |
| 61 String name, | |
| 62 Uri settingsUri, | |
| 63 Uri base, | |
| 64 Uri configFileUri) async { | |
| 65 assert(SessionState.internalCurrent == null); | |
| 66 Settings settings = await createSettings( | |
| 67 name, settingsUri, base, configFileUri, commandSender, commandIterator); | |
| 68 SessionState state = createSessionState(name, settings); | |
| 69 SessionState.internalCurrent = state; | |
| 70 if (settingsUri != null) { | |
| 71 state.log("created session with $settingsUri $settings"); | |
| 72 } else { | |
| 73 state.log("created session with settings $settings"); | |
| 74 } | |
| 75 return 0; | |
| 76 } | |
| OLD | NEW |