Exemplo n.º 1
0
        static IRoutine GetRoutine(IServiceProvider serviceProvider)
        {
            IConfigurationManager configurationManager = serviceProvider.GetService <IConfigurationManager>();

            IRoutine routine = null;

            switch (smartDeviceState.Mode)
            {
            case SmartDeviceMode.Inactive:
                routine = new InactiveRoutine(configurationManager);
                break;

            case SmartDeviceMode.Active:
                if (smartDeviceState.IsTurnedOn)
                {
                    routine = new ActiveRoutine(
                        serviceProvider, fileCache, cvAdsAPIClient, geoLocationAPIClient, smartDeviceState);
                }
                else
                {
                    routine = new ActiveTurnedOffRoutine(configurationManager);
                }
                break;

            case SmartDeviceMode.Blocked:
                routine = new BlockedRoutine(configurationManager);
                break;
            }

            return(routine);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Resolves the routine target of the invocation within the give context.
        /// </summary>
        /// <param name="context">The query context used to resolve the routine.</param>
        /// <remarks>
        /// <para>
        /// If the given <paramref name="context"/> is <c>null</c> this method will
        /// try to resolve the routine towards the
        /// </para>
        /// </remarks>
        /// <returns>
        /// Returns an instance of <see cref="IRoutine"/> that is the target of the invocation.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// If the routine could not be resolved for this call.
        /// </exception>
        public IRoutine ResolveRoutine(IRequest context)
        {
            if (cached != null)
            {
                return(cached);
            }

            if (context == null)
            {
                cached = SystemFunctions.Provider.ResolveFunction(this, null);
            }
            else
            {
                var resolvedName = context.Access().ResolveObjectName(DbObjectType.Routine, RoutineName);
                var invoke       = new Invoke(resolvedName, Arguments);
                cached = context.Query.Access().ResolveRoutine(invoke, context);
            }

            if (cached == null)
            {
                throw new InvalidOperationException(String.Format("Unable to resolve the call {0} to a function", this));
            }

            return(cached);
        }
 public void Construct(IRoutine routine)
 {
     routine.WakeUp();
     routine.GoToSchool();
     routine.ListenToMusic();
     routine.Sleep();
 }
Exemplo n.º 4
0
        private void BuildControl(IRoutine routine)
        {
            if (routine == null)
            {
                return;
            }

            DataContext = routine.RoutineSettings?.GetDataContext();

            if (routine.RoutineSettings == null)
            {
                ErrorMessage = "No settings were found for this routine";
                return;
            }

            var control = routine.RoutineSettings.GetControl();

            if (control == null)
            {
                ErrorMessage = "No settings control was found for this routine";
                return;
            }

            Control = new UserControl
            {
                Content     = control,
                DataContext = this
            };
        }
Exemplo n.º 5
0
        /// <summary>
        /// Constructs a new viewport with the given width/height.
        /// </summary>
        /// <param name="routine">Routine to view.</param>
        /// <param name="width">Viewport width.</param>
        /// <param name="height">Viewport height.</param>
        public RoutineViewport(IRoutine routine, int width, int height)
        {
            _routine = routine;

            // Validate that routines defined views the way we expect
            if (_routine.Views.Count == 0)
            {
                throw new Exception($"{_routine.GetType().Name} defines 0 views.");
            }

            for (int i = 1; i < _routine.Views.Count; i++)
            {
                var curView  = _routine.Views[i].view;
                var prevView = _routine.Views[i - 1].view;

                if (curView.Width != prevView.Width || curView.Height != prevView.Height)
                {
                    throw new Exception($"{_routine.GetType().Name} defines views that are not the same size.");
                }
            }

            // Initialize initial views
            _viewIndex = 0;
            (CurrentViewName, CurrentView) = _routine.Views[_viewIndex];

            // Initialize initial viewport
            CurrentViewport = new Viewport <char>(CurrentView, (0, 0, width, height));
            CurrentViewport.SetViewArea(
                CurrentViewport.ViewArea.WithCenter((CurrentView.Width / 2, CurrentView.Height / 2)));
        }
Exemplo n.º 6
0
 public void Execute(IRoutine routine)
 {
     for (int i = 0; i < this.count; i++)
     {
         routine.Execute();
     }
 }
Exemplo n.º 7
0
 public RoutinesQueue Enqueue(IRoutine routine)
 {
     Assert.IsNotNull(routine);
     Assert.IsTrue(!_queue.Contains(routine));             // при добавлении рутины дважды, произойдёт не то, что ожидалось.
     _queue.Enqueue(routine);
     return(this);
 }
Exemplo n.º 8
0
 public void Execute(IRoutine routine)
 {
     for (int i = 0; i < this.count; i++)
     {
         routine.Execute();
     }
 }
Exemplo n.º 9
0
        public static void Start(this MonoBehaviour behaviour, IEnumerator routine, out IRoutine controller)
        {
            InternalController c = new InternalController();

            c.Start(routine);
            controller = c;
            behaviour.StartCoroutine(c.Run());
        }
Exemplo n.º 10
0
        public static InvokeResult Execute(this IRoutine routine, InvokeArgument[] args, IRequest request, IVariableResolver resolver, IGroupResolver group)
        {
            var invoke = new Invoke(routine.ObjectInfo.FullName, args);

            var executeContext = new InvokeContext(invoke, routine, resolver, group, request);

            return(routine.Execute(executeContext));
        }
Exemplo n.º 11
0
 /// <summary>
 /// 构造函数注入
 /// </summary>
 /// <param name="routine"></param>
 /// <param name="sys"></param>
 /// <param name="token"></param>
 /// <param name="user"></param>
 /// <param name="biz"></param>
 /// <param name="gameKey"></param>
 public RoutineController(IRoutine routine, ISystems sys, IToken token, IUser user, IBiz biz, IOptions <GameKeySetting> gameKey)
 {
     _routine = routine;
     _sys     = sys;
     _token   = token;
     _user    = user;
     _biz     = biz;
     _gameKey = gameKey.Value;
     _log     = _log = LogManager.GetLogger(Startup.repository.Name, typeof(RoutineController));
 }
Exemplo n.º 12
0
 private static void PushRoutineToHeap(IRoutine routine)
 {
     try
     {
         Routines.Add(routine);
     }
     catch (Exception e)
     {
         throw;
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// 构造函数注入
 /// </summary>
 /// <param name="mag"></param>
 /// <param name="sys"></param>
 /// <param name="user"></param>
 /// <param name="token"></param>
 /// <param name="biz"></param>
 /// <param name="accout"></param>
 public UserController(IPhoneMessage mag, ISystems sys, IUser user, IToken token, IRoutine routine, IBiz biz, IAccout accout)
 {
     _mag     = mag;
     _sys     = sys;
     _user    = user;
     _token   = token;
     _biz     = biz;
     _accout  = accout;
     _log     = LogManager.GetLogger(Startup.repository.Name, typeof(UserController));
     _routine = routine;
 }
Exemplo n.º 14
0
        private void OnRoutineChanged(IRoutine newRoutine)
        {
            var routineViewModel = AllRoutines.FirstOrDefault(r => r.DisplayName == newRoutine.DisplayName);

            if (routineViewModel != null)
            {
                CurrentRoutine  = routineViewModel;
                SelectedRoutine = routineViewModel;
                UpdateRoutineLists();
            }
        }
Exemplo n.º 15
0
        public virtual TrinityPower GetPowerForTarget(TrinityActor target)
        {
            IRoutine routine = TrinityCombat.Routines.Current;

            if (target == null)
            {
                return(null);
            }

            switch (target.Type)
            {
            case TrinityObjectType.BloodShard:
            case TrinityObjectType.Gold:
            case TrinityObjectType.HealthGlobe:
            case TrinityObjectType.PowerGlobe:
            case TrinityObjectType.ProgressionGlobe:
                return(routine.GetMovementPower(target.Position));

            case TrinityObjectType.Door:
            case TrinityObjectType.HealthWell:
            case TrinityObjectType.Shrine:
            case TrinityObjectType.Interactable:
            case TrinityObjectType.CursedShrine:
                return(InteractPower(target, 100, 250));

            case TrinityObjectType.CursedChest:
            case TrinityObjectType.Container:
                return(InteractPower(target, 100, 1200));

            case TrinityObjectType.Item:
                return(InteractPower(target, 15, 15, 6f));

            case TrinityObjectType.Destructible:
            case TrinityObjectType.Barricade:
                Core.PlayerMover.MoveTowards(target.Position);
                return(routine.GetDestructiblePower());
            }

            if (target.IsQuestGiver)
            {
                Core.PlayerMover.MoveTowards(target.Position);
                return(InteractPower(target, 100, 250));
            }

            if (!TrinityCombat.IsInCombat)
            {
                return(null);
            }

            TrinityPower routinePower = routine.GetOffensivePower();

            return(TryKamakaziPower(target, routinePower, out TrinityPower kamakaziPower) ? kamakaziPower : routinePower);
        }
Exemplo n.º 16
0
 /// <summary>
 /// 构造函数注入
 /// </summary>
 /// <param name="user"></param>
 /// <param name="token"></param>
 /// <param name="sys"></param>
 /// <param name="recharge"></param>
 /// <param name="routine"></param>
 /// <param name="biz"></param>
 public RechargeController(IUser user, IToken token, IOptions <WeChatPaySetting> weChatPay, IOptions <LqhnWeChatPaySetting> lqhnweChatPay, ISystems sys, IRecharge recharge, IRoutine routine, IBiz biz, IAccout accout)
 {
     _sys           = sys;
     _user          = user;
     _token         = token;
     _recharge      = recharge;
     _routine       = routine;
     _biz           = biz;
     _accout        = accout;
     _weChatPay     = weChatPay.Value;
     _lqhnweChatPay = lqhnweChatPay.Value;
 }
Exemplo n.º 17
0
 private static void CreateRoutine(IRoutine routine)
 {
     try
     {
         PushRoutineToHeap(routine);
         routine.Start().Wait();
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 18
0
        internal InvokeContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IRequest request)
        {
            if (invoke == null)
                throw new ArgumentNullException("invoke");
            if (routine == null)
                throw new ArgumentNullException("routine");

            Request = request;
            GroupResolver = group;
            VariableResolver = resolver;
            Invoke = invoke;
            Routine = routine;
        }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:ZsqApp.Core.WebApi.Controllers.H5Controllres.WebBetsController"/> class.
 /// </summary>
 /// <param name="token"></param>
 /// <param name="biz"></param>
 /// <param name="gameKey"></param>
 /// <param name="user"></param>
 /// <param name="systems"></param>
 /// <param name="userTask"></param>
 /// <param name="currencyKey"></param>
 /// <param name="accout"></param>
 public WebBetsController(IToken token, IBiz biz, IOptions <GameKeySetting> gameKey, IUser user, ISystems systems, IUserTask userTask, IRoutine routine, IOptions <CurrencyKeySetting> currencyKey, IAccout accout)
 {
     _token       = token;
     _biz         = biz;
     _gameKey     = gameKey.Value;
     _user        = user;
     _sys         = systems;
     _userTask    = userTask;
     _currencyKey = currencyKey.Value;
     _log         = _log = LogManager.GetLogger(Startup.repository.Name, typeof(WebBetsController));
     _accout      = accout;
     _routine     = routine;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Проолжить выполнение корутины. Возвращает false и обнуляет routine, если корутина завершилась.
 /// </summary>
 public static bool Execute(ref IRoutine routine)
 {
     if (routine == null)
     {
         return(false);
     }
     if (!routine.MoveNext())
     {
         routine = null;
         return(false);
     }
     return(true);
 }
Exemplo n.º 21
0
 public RoutineViewModel(IRoutine routine)
 {
     _routine        = routine;
     RoutineTypeName = routine.GetType().Name;
     DisplayName     = routine.DisplayName;
     Description     = routine.Description;
     RequiredBuild   = routine.BuildRequirements;
     Author          = routine.Author;
     Version         = routine.Version;
     Class           = routine.Class;
     Url             = routine.Url;
     BuildControl(routine);
 }
Exemplo n.º 22
0
 public static void Tick(IRoutine routine)
 {
     smethod_0(routine, routineEvent_2);
     try
     {
         routine.Tick();
     }
     catch (Exception exception)
     {
         ilog_0.Error("Exception during routine Tick.", exception);
     }
     smethod_0(routine, routineEvent_3);
 }
Exemplo n.º 23
0
 public static void Stop(IRoutine routine)
 {
     smethod_0(routine, routineEvent_4);
     try
     {
         routine.Stop();
     }
     catch (Exception exception)
     {
         ilog_0.Error("Exception during routine Stop.", exception);
     }
     smethod_0(routine, routineEvent_5);
 }
Exemplo n.º 24
0
        internal ExecuteContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IQueryContext queryContext)
        {
            if (invoke == null)
                throw new ArgumentNullException("invoke");
            if (routine == null)
                throw new ArgumentNullException("routine");

            QueryContext = queryContext;
            GroupResolver = group;
            VariableResolver = resolver;
            Invoke = invoke;
            Routine = routine;
        }
Exemplo n.º 25
0
        public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group)
        {
            var request = new Invoke(routine.FullName, args);

            if (query != null &&
                !query.UserCanExecuteFunction(request))
            {
                throw new InvalidOperationException();
            }

            var executeContext = new InvokeContext(request, routine, resolver, group, query);

            return(routine.Execute(executeContext));
        }
Exemplo n.º 26
0
 private static void smethod_0(IRoutine iroutine_1, RoutineEvent routineEvent_6)
 {
     if (routineEvent_6 != null)
     {
         try
         {
             routineEvent_6(iroutine_1);
         }
         catch (Exception exception)
         {
             ilog_0.Error("[Invoke] Error during execution:", exception);
         }
     }
 }
Exemplo n.º 27
0
        public static InvokeResult Execute(this IRoutine routine, Field[] args)
        {
            var invokeArgs = new InvokeArgument[0];

            if (args != null && args.Length > 0)
            {
                invokeArgs = new InvokeArgument[args.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    invokeArgs[i] = new InvokeArgument(SqlExpression.Constant(args[i]));
                }
            }

            return(routine.Execute(invokeArgs));
        }
Exemplo n.º 28
0
        /// <summary>
        /// Select the routine and initialize it.
        /// </summary>
        public static void Init()
        {
            // Initialize NCurses
            _window = NCurses.InitScreen();
            NCurses.CBreak();
            NCurses.NoEcho();
            NCurses.Keypad(_window, true);

            // Pick routine, and generate its map and views
            _routine = PickRoutine();
            _routine.GenerateMap();
            _routine.CreateViews();

            // Set up viewport, defaulting to first item in views list
            _mapView = new RoutineViewport(_routine, Console.WindowWidth - 1, Console.WindowHeight - 1);
        }
Exemplo n.º 29
0
        public static InvokeResult Execute(this IRoutine routine, DataObject[] args)
        {
            var exps = new SqlExpression[0];

            if (args != null && args.Length > 0)
            {
                exps = new SqlExpression[args.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    exps[i] = SqlExpression.Constant(args[i]);
                }
            }

            return(routine.Execute(exps));
        }
Exemplo n.º 30
0
        internal InvokeContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IRequest request)
        {
            if (invoke == null)
            {
                throw new ArgumentNullException("invoke");
            }
            if (routine == null)
            {
                throw new ArgumentNullException("routine");
            }

            Request          = request;
            GroupResolver    = group;
            VariableResolver = resolver;
            Invoke           = invoke;
            Routine          = routine;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Update routine parameters
        /// </summary>
        /// <param name="routines">routine collection</param>
        protected void UpdateRoutineParameters(IReadOnlyDictionary <string, IRoutine> routines)
        {
            this.ExecuteReader <object>(
                "GetRoutineParameters",
                reader =>
            {
                IRoutine routine             = null;
                List <IParameter> parameters = null;
                var resolver = this.ResolverFactory.GetResolver <IParameter>();
                while (reader.Read())
                {
                    var routineSchema = GetData <string>(reader, "ROUTINE_SCHEMA");
                    var routineName   = GetData <string>(reader, "ROUTINE_NAME");

                    if ((routine == null) ||
                        !routine.SchemaName.Equals(routineSchema, StringComparison.OrdinalIgnoreCase) ||
                        !routine.RoutineName.Equals(routineName, StringComparison.OrdinalIgnoreCase))
                    {
                        var routineDisplayName = GetDisplayName(routineSchema, routineName);
                        if (!routines.TryGetValue(routineDisplayName, out routine))
                        {
                            var errorMessage = string.Format(
                                CultureInfo.InvariantCulture,
                                "Could not found routine \"{0}\" while process parameters",
                                routineDisplayName);
                            throw new ApplicationException(errorMessage);
                        }

                        parameters         = new List <IParameter>();
                        routine.Parameters = parameters;
                    }

                    var parameter              = resolver.Resolve();
                    parameter.ParameterName    = GetData <string>(reader, "PARAMETER_NAME");
                    parameter.Mode             = GetData <string>(reader, "PARAMETER_MODE");
                    parameter.DataTypeName     = GetData <string>(reader, "DATA_TYPE");
                    parameter.StringSize       = GetData <int?>(reader, "CHARACTER_MAXIMUM_LENGTH");
                    parameter.NumericPrecision = GetData <int?>(reader, "NUMERIC_PRECISION");
                    parameter.NumericScale     = GetData <int?>(reader, "NUMERIC_SCALE");
                    parameters.Add(parameter);
                }

                return(null);
            });
        }
Exemplo n.º 32
0
        /// <summary>
        /// Initialize script here. This is essentially "free" computing, and wont affect the program average runtime...
        /// </summary>
        public Program()
        {
            //Compile core variables
            manualProgram = new ManualProgram(this);
            gridAnalyser  = new GridAnalyser(this);
            output        = new Output(this, programTag);
            timer         = gridAnalyser.GetTimer(programTag);
            diagnostics   = new Diagnostics(this, diagnosticTag);
            diagnostics.Start();

            //Add routines here
            routines.Add(new Logistics(this, logisticsTag));
            routines.Add(new Hangar(this, hangarTag));
            routines.Add(new Factory(this, factoryTag));
            //routines.Add(new AirlockManager(this, airlockTag));

            InitRoutines();

            //Set how often this runs
            Runtime.UpdateFrequency = UpdateFrequency.Update1;
        }
Exemplo n.º 33
0
        static async Task Main()
        {
            using var serviceProvider = GetServiceProvider();
            InitializeServices(serviceProvider);
            await LoginAsync(serviceProvider);

            ConfigureShutDownBehaviour();
            await ConnectToHubAsync(serviceProvider);

            while (!shutDownWasEmmited.WaitOne(0))
            {
                if (reloginWasEmmited.WaitOne(0))
                {
                    Logger.StartNewSection();
                    await LoginAsync(serviceProvider);
                }
                IRoutine routine = GetRoutine(serviceProvider);
                await routine.RunAsync();
            }

            DisposeResources();
        }
Exemplo n.º 34
0
        /// <summary>
        /// Resolves the routine target of the invocation within the give context.
        /// </summary>
        /// <param name="context">The query context used to resolve the routine.</param>
        /// <remarks>
        /// <para>
        /// If the given <paramref name="context"/> is <c>null</c> this method will
        /// try to resolve the routine towards the 
        /// </para>
        /// </remarks>
        /// <returns>
        /// Returns an instance of <see cref="IRoutine"/> that is the target of the invocation.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// If the routine could not be resolved for this call.
        /// </exception>
        public IRoutine ResolveRoutine(IRequest context)
        {
            if (cached != null)
                return cached;

            if (context == null) {
                cached = SystemFunctions.Provider.ResolveFunction(this, null);
            } else {
                var resolvedName = context.Access().ResolveObjectName(DbObjectType.Routine, RoutineName);
                var invoke = new Invoke(resolvedName, Arguments);
                cached = context.Query.Access().ResolveRoutine(invoke, context);
            }

            if (cached == null)
                throw new InvalidOperationException(String.Format("Unable to resolve the call {0} to a function", this));

            return cached;
        }
Exemplo n.º 35
0
        /// <summary>
        /// Resolves the routine target of the invocation within the give context.
        /// </summary>
        /// <param name="context">The query context used to resolve the routine.</param>
        /// <remarks>
        /// <para>
        /// If the given <paramref name="context"/> is <c>null</c> this method will
        /// try to resolve the routine towards the 
        /// </para>
        /// </remarks>
        /// <returns>
        /// Returns an instance of <see cref="IRoutine"/> that is the target of the invocation.
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// If the routine could not be resolved for this call.
        /// </exception>
        public IRoutine ResolveRoutine(IRequest context)
        {
            if (cached != null)
                return cached;

            if (context == null) {
                cached = SystemFunctions.Provider.ResolveFunction(this, null);
            } else {
                cached = context.Query.ResolveRoutine(this);
            }

            if (cached == null)
                throw new InvalidOperationException(String.Format("Unable to resolve the call {0} to a function", this));

            return cached;
        }