Esempio n. 1
0
        public UIController(IGitHubServiceProvider gitHubServiceProvider,
                            IUIFactory factory,
                            IConnectionManager connectionManager)
        {
            Guard.ArgumentNotNull(gitHubServiceProvider, nameof(gitHubServiceProvider));
            Guard.ArgumentNotNull(factory, nameof(factory));
            Guard.ArgumentNotNull(connectionManager, nameof(connectionManager));

            this.factory = factory;
            this.gitHubServiceProvider = gitHubServiceProvider;
            this.connectionManager     = connectionManager;

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Log.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                               "DispatcherScheduler is set correctly");
                }
                else
                {
                    Log.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                               "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            ConfigureLogicStates();

            uiStateMachine = new StateMachineType(UIViewType.None);

            ConfigureUIHandlingStates();
        }
Esempio n. 2
0
        public UIController(IUIProvider uiProvider, IRepositoryHosts hosts, IUIFactory factory,
                            IConnectionManager connectionManager)
        {
            this.factory           = factory;
            this.uiProvider        = uiProvider;
            this.hosts             = hosts;
            this.connectionManager = connectionManager;
            uiObjects = new Dictionary <UIControllerFlow, Dictionary <UIViewType, IUIPair> >();

#if DEBUG
            if (Application.Current != null && !Splat.ModeDetector.InUnitTestRunner())
            {
                var waitDispatcher = RxApp.MainThreadScheduler as WaitForDispatcherScheduler;
                if (waitDispatcher != null)
                {
                    Debug.Assert(DispatcherScheduler.Current.Dispatcher == Application.Current.Dispatcher,
                                 "DispatcherScheduler is set correctly");
                }
                else
                {
                    Debug.Assert(((DispatcherScheduler)RxApp.MainThreadScheduler).Dispatcher == Application.Current.Dispatcher,
                                 "The MainThreadScheduler is using the wrong dispatcher");
                }
            }
#endif
            machines = new Dictionary <UIControllerFlow, StateMachine <UIViewType, Trigger> >();
            ConfigureLogicStates();

            uiStateMachine = new StateMachineType(UIViewType.None);
            triggers       = new Dictionary <Trigger, StateMachineType.TriggerWithParameters <ViewWithData> >();
            ConfigureUIHandlingStates();
        }
Esempio n. 3
0
 public ActiveObject(string Name)
 {
     aoName     = Name;
     smType     = StateMachineType.AO;
     states     = new List <State>();
     attributes = new Dictionary <string, string>();
 }
Esempio n. 4
0
 public void SetState(StateMachineType stateMachine, States state)
 {
     foreach (var fsm in StateMachines)
     {
         if (fsm.type == stateMachine)
         {
             fsm.SetState(state);
         }
     }
 }
Esempio n. 5
0
        void ConfigureSingleViewLogic(UIControllerFlow flow, UIViewType type)
        {
            var logic = new StateMachineType(UIViewType.None);

            logic.Configure(UIViewType.None)
            .Permit(Trigger.Next, type)
            .Permit(Trigger.Finish, UIViewType.End);
            logic.Configure(type)
            .Permit(Trigger.Next, UIViewType.End)
            .Permit(Trigger.Cancel, UIViewType.End)
            .Permit(Trigger.Finish, UIViewType.End);
            logic.Configure(UIViewType.End)
            .Permit(Trigger.Next, UIViewType.None);
            machines.Add(flow, logic);
        }
        public JsFunctionDefinitionExpression CompileMethod(EntityDeclaration entity, BlockStatement body, IMethod method, MethodScriptSemantics impl)
        {
            bool             isIEnumerable = method.ReturnType.IsKnownType(KnownTypeCode.IEnumerable) || method.ReturnType.IsKnownType(KnownTypeCode.IEnumerableOfT);
            bool             isIEnumerator = method.ReturnType.IsKnownType(KnownTypeCode.IEnumerator) || method.ReturnType.IsKnownType(KnownTypeCode.IEnumeratorOfT);
            StateMachineType smt           = StateMachineType.NormalMethod;
            IType            iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null;

            if ((isIEnumerable || isIEnumerator) && IsIteratorBlockVisitor.Analyze(body))
            {
                smt = isIEnumerable ? StateMachineType.IteratorBlockReturningIEnumerable : StateMachineType.IteratorBlockReturningIEnumerator;
                iteratorBlockYieldTypeOrAsyncTaskGenericArgument = method.ReturnType is ParameterizedType ? ((ParameterizedType)method.ReturnType).TypeArguments[0] : _compilation.FindType(KnownTypeCode.Object);
            }
            else if (entity.HasModifier(Modifiers.Async))
            {
                smt = (method.ReturnType.IsKnownType(KnownTypeCode.Void) ? StateMachineType.AsyncVoid : StateMachineType.AsyncTask);
                iteratorBlockYieldTypeOrAsyncTaskGenericArgument = method.ReturnType is ParameterizedType ? ((ParameterizedType)method.ReturnType).TypeArguments[0] : null;
            }

            CreateCompilationContext(entity, method, method.DeclaringTypeDefinition, (impl.Type == MethodScriptSemantics.ImplType.StaticMethodWithThisAsFirstArgument ? _namer.ThisAlias : null));
            return(_statementCompiler.CompileMethod(method.Parameters, variables, body, impl.Type == MethodScriptSemantics.ImplType.StaticMethodWithThisAsFirstArgument, impl.ExpandParams, smt, iteratorBlockYieldTypeOrAsyncTaskGenericArgument));
        }
		public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, BlockStatement body, bool staticMethodWithThisAsFirstArgument, bool expandParams, StateMachineType stateMachineType, IType iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null) {
			SetRegion(body.GetRegion());
			try {
				_result = MethodCompiler.PrepareParameters(parameters, variables, expandParams: expandParams, staticMethodWithThisAsFirstArgument: staticMethodWithThisAsFirstArgument);
				VisitChildren(body);
				JsBlockStatement jsbody;
				if (_result.Count == 1 && _result[0] is JsBlockStatement)
					jsbody = (JsBlockStatement)_result[0];
				else
					jsbody = JsStatement.Block(_result);

				var result = JsExpression.FunctionDefinition((staticMethodWithThisAsFirstArgument ? new[] { _namer.ThisAlias } : new string[0]).Concat(parameters.Where((p, i) => i != parameters.Count - 1 || !expandParams).Select(p => variables[p].Name)), jsbody);

				switch (stateMachineType) {
					case StateMachineType.NormalMethod:
						result = StateMachineRewriteNormalMethod(result);
						break;

					case StateMachineType.IteratorBlockReturningIEnumerable:
					case StateMachineType.IteratorBlockReturningIEnumerator:
						result = StateMachineRewriteIteratorBlock(result, stateMachineType == StateMachineType.IteratorBlockReturningIEnumerable, iteratorBlockYieldTypeOrAsyncTaskGenericArgument);
						break;

					case StateMachineType.AsyncVoid:
					case StateMachineType.AsyncTask:
						result = StateMachineRewriteAsyncMethod(result, stateMachineType == StateMachineType.AsyncTask, iteratorBlockYieldTypeOrAsyncTaskGenericArgument);
						break;

					default:
						throw new ArgumentException("stateMachineType");
				}

	            return result;
			}
			catch (Exception ex) {
				_errorReporter.InternalError(ex);
	            return JsExpression.FunctionDefinition(new string[0], JsStatement.EmptyBlock); 
			}
		}
		public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, Expression body, IType returnType, bool staticMethodWithThisAsFirstArgument, bool expandParams, StateMachineType stateMachineType, IType iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null) {
			SetRegion(body.Region);
			return CompileMethod(parameters, variables, staticMethodWithThisAsFirstArgument, expandParams, stateMachineType, iteratorBlockYieldTypeOrAsyncTaskGenericArgument, () => {
				bool hasReturnValue = !returnType.IsKnownType(KnownTypeCode.Void);
				var rr = _resolver.Resolve(body);
				if (hasReturnValue) {
					var conversion = CSharpConversions.Get(_compilation).ImplicitConversion(rr, returnType);
					if (!conversion.IsValid)
						_errorReporter.InternalError("No implicit conversion found from " + rr.Type + " to " + returnType);
					else if (!conversion.IsIdentityConversion)
						rr = new ConversionResolveResult(returnType, rr, conversion);
				}

				if (!IsInvocationOfRemovedMethod(rr)) {
					var compiled = _expressionCompiler.Compile(rr, hasReturnValue);
					_result.AddRange(compiled.AdditionalStatements);
					if (hasReturnValue) {
						JsExpression result = compiled.Expression;
						if (IsMutableValueType(returnType)) {
							result = MaybeCloneValueType(result, rr, rr.Type);
						}

						_result.Add(JsStatement.Return(result));
					}
					else if (compiled.Expression.NodeType != ExpressionNodeType.Null)	// The statement "null;" is illegal in C#, so it must have appeared because there was no suitable expression to return.
						_result.Add(compiled.Expression);
				}
			});
		}
		public JsFunctionDefinitionExpression CompileMethod(IList<IParameter> parameters, IDictionary<IVariable, VariableData> variables, BlockStatement body, bool staticMethodWithThisAsFirstArgument, bool expandParams, StateMachineType stateMachineType, IType iteratorBlockYieldTypeOrAsyncTaskGenericArgument = null) {
			SetRegion(body.Region);
			return CompileMethod(parameters, variables, staticMethodWithThisAsFirstArgument, expandParams, stateMachineType, iteratorBlockYieldTypeOrAsyncTaskGenericArgument, () => VisitChildren(body));
		}