Beispiel #1
0
        private void AdvanceState(Side side)
        {
            if (side == Side.One)
            {
                sideOneScore++;
            }

            if (side == Side.Two)
            {
                sideTwoScore++;
            }

            var diff = sideOneScore - sideTwoScore;
            if (Math.Abs(diff) >= 2)
            {
                if (sideOneScore >= 6 || sideTwoScore >= 6)
                {
                    if (diff > 0)
                    {
                        state = SetState.SetWonBySideOne;
                    }
                    else
                    {
                        state = SetState.SetWonBySideTwo;
                    }
                }
            }
        }
Beispiel #2
0
        private void AdvanceState(Side side)
        {
            if (side == Side.One)
            {
                sideOneScore++;
            }

            if (side == Side.Two)
            {
                sideTwoScore++;
            }

            var diff = sideOneScore - sideTwoScore;

            if (Math.Abs(diff) >= 2)
            {
                if (sideOneScore >= 6 || sideTwoScore >= 6)
                {
                    if (diff > 0)
                    {
                        state = SetState.SetWonBySideOne;
                    }
                    else
                    {
                        state = SetState.SetWonBySideTwo;
                    }
                }
            }
        }
        public ReturnStatus SetState(SetState req)
        {
            using (var connection = new SqlConnection(_connectionString.HotelManagement))
            {
                var cmd = new SqlCommand(p_States_Set, connection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                cmd.Parameters.AddWithValue("@UserID", _requestInfo.UserId);

                cmd.Parameters.Add("@RetVal", SqlDbType.Int).Direction          = ParameterDirection.Output;
                cmd.Parameters.Add("@RetMsg", SqlDbType.VarChar, 500).Direction = ParameterDirection.Output;

                cmd.Parameters.AddWithValue("@StateID", req.StateId);
                cmd.Parameters.AddWithValue("@CountryID", req.CountryId);
                cmd.Parameters.AddWithValue("@Name", req.Name);
                cmd.Parameters.AddWithValue("@Abbrev", req.Abbrev);
                cmd.Parameters.AddWithValue("@Disable", req.Disable);

                connection.Open();

                cmd.ExecuteNonQuery();

                return(new ReturnStatus(cmd.Parameters["@RetVal"].Value.ToSafeInt32(), cmd.Parameters["@RetMsg"].Value.ToSafeString()));
            }
        }
        public static SetState read(BinaryReader binaryReader)
        {
            SetState newObj = new SetState();

            newObj.object_id  = binaryReader.ReadUInt32();
            newObj.new_state  = binaryReader.ReadUInt32();
            newObj.timestamps = PhysicsTimestampPack.read(binaryReader);
            return(newObj);
        }
Beispiel #5
0
 internal Queue(int index, string name, IContextProvider provider, SetState map)
 {
     ID              = Guid.NewGuid();
     Index           = index;
     Name            = name;
     ContextProvider = provider;
     ExpBuilder      = new ExpressionBuilder(map);
     SqlBuilder      = provider.DbProvider.CreateSqlBuilder(provider.Map.ContextProperty.DataVer, ExpBuilder, Name);
 }
Beispiel #6
0
        private async Task UpdateSensorData()
        {
            try
            {
                //{"affirmation":"I know you'll sort it out"}
                var todaysDictionary = await Http.GetJson <Dictionary <string, string> >("https://www.affirmations.dev/").ConfigureAwait(false);

                if (todaysDictionary.TryGetValue("affirmation", out var affirmation))
                {
                    await SetState("sensor.affirmation", "on", ("text", affirmation), ("attribution", "www.affirmations.dev"));
                }
            }
            catch (Exception e)
            {
                Log(LogLevel.Trace, e, "Error getting affirmation");
                await SetState("sensor.affirmation", "unavailable", ("text", "unavailable" !));
            }
        }
Beispiel #7
0
        public void SetStateWorksCorrectly()
        {
            var command = new SetState
            {
                ComponentId = "myButton",
                State       = SetStateStates.Checked,
                Value       = true
            };

            Assert.True(Utility.CompareJson(command, "SetStateCommand.json"));
        }
Beispiel #8
0
        internal void GenerateClassFiles(IEnumerable <DataRowView> tables, SetState setState)
        {
            setState("starting...");
            var listTables   = new List <ObjectDB>();
            var listSynonyms = new List <ObjectDB>();

            setState("looking for Tables");
            //  Transorm tables to classes, still work to be done
            foreach (var item in tables)
            {
                var typeObj = item?.Row["type"];
                if (typeObj == null)
                {
                    continue;
                }
                var tmp = typeObj.ToString().Trim();
                switch (tmp)
                {
                case "U":
                {
                    var tmpO = new ObjectDB(item);
                    listTables.Add(tmpO);
                    break;
                }

                case "SN":
                {
                    var tmpO = new ObjectDB(item);
                    listSynonyms.Add(tmpO);
                    break;
                }
                }
            }

            if (listTables.Count > 0)
            {
                if (!SearchColumnsByTables(listTables, setState))
                {
                    return;
                }
            }


            if (listSynonyms.Count > 0)
            {
                if (!SearchSynonyms(listSynonyms, setState))
                {
                    return;
                }
            }

            setState("done");
        }
Beispiel #9
0
    private void KillNeighbours(Enemy enemy)
    {
        EnemyKilled?.Invoke();
        // remove the enemy reference from the grid array
        activeEnemies[enemy.Index.x, enemy.Index.y] = null;

        // enable firing for the closest enemy to the player in the collumn
        for (int y = 0; y < settings.Levels[settings.CurrentLevel].GridRows; y++)
        {
            if (activeEnemies[enemy.Index.x, y] != null)
            {
                activeEnemies[enemy.Index.x, y].CurrentlyShooting = true;
                break;
            }
        }

        matchedEnemies.Add(enemy);

        int remainingNeighbours = 0;

        foreach (Enemy matched in matchedEnemies)
        {
            remainingNeighbours += GetNeighbours(matched).Count();
        }

        if (remainingNeighbours <= 0)
        {
            // adding fibonacci points
            PointManager.Instance.AddScore(matchedEnemies.Count * CustomMaths.CalculateFibonacci(matchedEnemies.Count) * 10);
            matchedEnemies.Clear();

            if (ActiveEnemies() <= 0)
            {
                SetState?.Invoke(GameState.NextLevel);
            }

            SetActiveCollums();
            return;
        }

        // get all valid neighbours and destroy them
        foreach (Enemy neighbour in GetNeighbours(enemy))
        {
            neighbour.Die();
        }

        SetActiveCollums();
    }
Beispiel #10
0
        public RootViewModel(SetState <RootViewModel> setState, string text, NoteViewModel[] notes)
        {
            SetState   = setState;
            this.text  = text;
            this.notes = notes;

            AddCommand = new Command <object>(_ =>
            {
                SetState(root => root.WithNewNote("New Note"));
            });

            RemoveCommand = new Command <int>(noteId =>
            {
                SetState(root => root.RemoveNote(noteId));
            });
        }
Beispiel #11
0
 /// <summary>
 /// 立即执行
 /// </summary>
 /// <param name="act">要延迟操作的委托</param>
 /// <param name="map">字段映射</param>
 /// <param name="name">表名称</param>
 /// <param name="joinSoftDeleteCondition">是否加入逻辑删除数据过滤</param>
 public TReturn Append <TReturn>(string name, SetState map, Func <Queue, TReturn> act, bool joinSoftDeleteCondition)
 {
     try
     {
         var queue = CreateQueue(name, map);
         if (joinSoftDeleteCondition)
         {
             queue.ExpBuilder.DeleteSortCondition();
         }
         return(act(queue));
     }
     finally
     {
         Clear();
     }
 }
Beispiel #12
0
        /// <summary>
        /// Search all columns by Table
        /// </summary>
        /// <param name="listTables">Tables to read</param>
        private bool SearchColumnsByTables(IEnumerable <ObjectDB> listTables, SetState setState)
        {
            foreach (var table in listTables)
            {
                var dt = _dbConnect.OpenConnectionAndExecute(_queryGenerator.GetTablesByName(table.name));

                var writeClassOk  = CreateFile("Classes", table.name + ".cs", GenerateClass(table, dt), setState);
                var writeMapperOk = CreateFile("Mappers", table.name + "Config.cs", GenerateMapper(table, dt), setState);

                if (!writeClassOk || !writeMapperOk)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// Create an UndoService.
        /// </summary>
        /// <param name="getState">Method to get the state of the tracked object</param>
        /// <param name="setState">Method to set the state of the tracked object</param>
        /// <param name="cap">Capacity of Undo history</param>
        public UndoService(GetState <T> getState, SetState <T> setState, int?cap = null)
        {
            GetState = getState ?? throw new ArgumentNullException(nameof(getState));
            SetState = setState ?? throw new ArgumentNullException(nameof(setState));
            var stackFactory = new StackFactory <StateRecord <T> >();

            _undoStack = stackFactory.MakeStack(cap);
            // T currentState;
            GetState(out T currentState);
            _originalState = currentState;
            _currentState  = new StateRecord <T> {
                State = currentState
            };
            _redoStack                  = new StandardStack <StateRecord <T> >();
            _undoServiceValidator       = new UndoServiceValidator <StateRecord <T> >(_undoStack, _redoStack);
            _undoStack.HasItemsChanged += UndoStack_HasItemsChanged;
            _redoStack.HasItemsChanged += RedoStack_HasItemsChanged;
        }
Beispiel #14
0
        /// <summary>
        /// 获取实体数据缓存
        /// </summary>
        /// <param name="setState"></param>
        /// <param name="initCache">不存在数据时,初始化操作</param>
        /// <returns></returns>
        public static IList GetSetCache(SetState setState, Func <IList> initCache = null)
        {
            if (SetCache.ContainsKey(setState))
            {
                return(SetCache[setState]);
            }
            if (initCache == null)
            {
                return(null);
            }

            lock (LockObject)
            {
                if (!SetCache.ContainsKey(setState))
                {
                    SetCache.Add(setState, initCache());
                }
            }
            return(SetCache[setState]);
        }
Beispiel #15
0
        private bool CreateFile(string folder, string filename, string value, SetState setState)
        {
            var pathFolder = FilePath + "/" + folder;

            try
            {
                FileManager.CheckExistOrCreate(pathFolder);
            }
            catch (Exception e)
            {
                setState(e.Message);
                return(false);
            }

            setState($"Creating File {filename}");
            //  Save file
            var pathFile = pathFolder + "/" + filename;

            FileManager.WriteFile(pathFile, value);
            return(true);
        }
Beispiel #16
0
        private void RefineSetState(Team team)
        {
            switch (team)
            {
            case Team.One:
                TeamOneScore++;
                break;

            case Team.Two:
                TeamTwoScore++;
                break;

            case Team.None:
            default:
                break;
            }

            var diff = TeamOneScore - TeamTwoScore;

            //validate margin is 2 or more
            if (Math.Abs(diff) >= 2)
            {
                //team must have scored 6 or more games to win a set
                if (TeamOneScore >= 6 || TeamTwoScore >= 6)
                {
                    if (diff > 0)
                    {
                        State = SetState.SetWonByTeamOne;
                    }
                    else
                    {
                        State = SetState.SetWonByTeamTwo;
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// 延迟执行数据库交互,并提交到队列
        /// </summary>
        /// <param name="act">要延迟操作的委托</param>
        /// <param name="map">字段映射</param>
        /// <param name="name">表名称</param>
        /// <param name="isExecute">是否立即执行</param>
        /// <param name="joinSoftDeleteCondition">是否加入逻辑删除数据过滤</param>
        public void AppendLazy(string name, SetState map, Action <Queue> act, bool isExecute, bool joinSoftDeleteCondition)
        {
            try
            {
                var queue = CreateQueue(name, map);
                if (joinSoftDeleteCondition)
                {
                    queue.ExpBuilder.DeleteSortCondition();
                }
                queue.LazyAct = act;

                // 立即执行
                if (isExecute)
                {
                    act(queue); return;
                }

                _groupQueueList.Add(_queue);
            }
            finally
            {
                Clear();
            }
        }
Beispiel #18
0
        private bool SearchSynonyms(IEnumerable <ObjectDB> listSynonyms, SetState setState)
        {
            foreach (var synonym in listSynonyms)
            {
                // get path from Synonym, to search in the real table.
                var dt = _dbConnect.OpenConnectionAndExecute(_queryGenerator.GetSynonymsByName(synonym.name));
                if (dt.Rows.Count == 1)
                {
                    var fullPathDb = dt.Rows[0]["base_object_name"].ToString();
                    var dbPath     = fullPathDb.Replace($".[dbo].[{synonym.name}]", "");

                    //  Get Table
                    dt = _dbConnect.OpenConnectionAndExecute(_queryGenerator.GetSynonymTable(synonym.name, dbPath));
                    synonym.object_id = int.Parse(dt.Rows[0]["object_id"].ToString());

                    //  Get Columns
                    dt = _dbConnect.OpenConnectionAndExecute(_queryGenerator.GetSynonymColums(synonym.name, dbPath));

                    var writeClassOk  = CreateFile("Classes", synonym.name + ".cs", GenerateClass(synonym, dt, dbPath + "."), setState);
                    var writeMapperOk = CreateFile("Mappers", synonym.name + "Config.cs", GenerateMapper(synonym, dt, dbPath + "."), setState);

                    if (!writeClassOk || !writeMapperOk)
                    {
                        return(false);
                    }
                }
                else
                {
                    //  Names duplicated ?
                    setState("There are Synonyms tables with the same name.");
                    return(false);
                }
            }

            return(true);
        }
 public ReturnStatus SetState(SetState req)
 {
     return(null);
 }
 public ExpressionBuilder(SetState map)
 {
     Map = map;
 }
        void ConvertBody(List <ILNode> body, int startPos, int bodyLength, List <KeyValuePair <ILLabel, StateRange> > labels)
        {
            newBody = new List <ILNode>();
            newBody.Add(MakeGoTo(labels, 0));
            List <SetState> stateChanges = new List <SetState>();
            int             currentState = -1;

            // Copy all instructions from the old body to newBody.
            for (int pos = startPos; pos < bodyLength; pos++)
            {
                ILExpression expr = body[pos] as ILExpression;
                if (expr != null && expr.Code == ILCode.Stfld && expr.Arguments[0].MatchThis())
                {
                    // Handle stores to 'state' or 'current'
                    if (GetFieldDefinition(expr.Operand as FieldReference) == stateField)
                    {
                        if (expr.Arguments[1].Code != ILCode.Ldc_I4)
                        {
                            throw new SymbolicAnalysisFailedException();
                        }
                        currentState = (int)expr.Arguments[1].Operand;
                        stateChanges.Add(new SetState(newBody.Count, currentState));
                    }
                    else if (GetFieldDefinition(expr.Operand as FieldReference) == currentField)
                    {
                        newBody.Add(new ILExpression(ILCode.YieldReturn, null, expr.Arguments[1]));
                    }
                    else
                    {
                        newBody.Add(body[pos]);
                    }
                }
                else if (returnVariable != null && expr != null && expr.Code == ILCode.Stloc && expr.Operand == returnVariable)
                {
                    // handle store+branch to the returnVariable
                    ILExpression br = body.ElementAtOrDefault(++pos) as ILExpression;
                    if (br == null || !(br.Code == ILCode.Br || br.Code == ILCode.Leave) || br.Operand != returnLabel || expr.Arguments[0].Code != ILCode.Ldc_I4)
                    {
                        throw new SymbolicAnalysisFailedException();
                    }
                    int val = (int)expr.Arguments[0].Operand;
                    if (val == 0)
                    {
                        newBody.Add(MakeGoTo(returnFalseLabel));
                    }
                    else if (val == 1)
                    {
                        newBody.Add(MakeGoTo(labels, currentState));
                    }
                    else
                    {
                        throw new SymbolicAnalysisFailedException();
                    }
                }
                else if (expr != null && expr.Code == ILCode.Ret)
                {
                    if (expr.Arguments.Count != 1 || expr.Arguments[0].Code != ILCode.Ldc_I4)
                    {
                        throw new SymbolicAnalysisFailedException();
                    }
                    // handle direct return (e.g. in release builds)
                    int val = (int)expr.Arguments[0].Operand;
                    if (val == 0)
                    {
                        newBody.Add(MakeGoTo(returnFalseLabel));
                    }
                    else if (val == 1)
                    {
                        newBody.Add(MakeGoTo(labels, currentState));
                    }
                    else
                    {
                        throw new SymbolicAnalysisFailedException();
                    }
                }
                else if (expr != null && expr.Code == ILCode.Call && expr.Arguments.Count == 1 && expr.Arguments[0].MatchThis())
                {
                    MethodDefinition method = GetMethodDefinition(expr.Operand as MethodReference);
                    if (method == null)
                    {
                        throw new SymbolicAnalysisFailedException();
                    }
                    Interval interval;
                    if (method == disposeMethod)
                    {
                        // Explicit call to dispose is used for "yield break;" within the method.
                        ILExpression br = body.ElementAtOrDefault(++pos) as ILExpression;
                        if (br == null || !(br.Code == ILCode.Br || br.Code == ILCode.Leave) || br.Operand != returnFalseLabel)
                        {
                            throw new SymbolicAnalysisFailedException();
                        }
                        newBody.Add(MakeGoTo(returnFalseLabel));
                    }
                    else if (finallyMethodToStateInterval.TryGetValue(method, out interval))
                    {
                        // Call to Finally-method
                        int index = stateChanges.FindIndex(ss => ss.NewState >= interval.Start && ss.NewState <= interval.End);
                        if (index < 0)
                        {
                            throw new SymbolicAnalysisFailedException();
                        }

                        ILLabel label = new ILLabel();
                        label.Name = "JumpOutOfTryFinally" + interval.Start + "_" + interval.End;
                        newBody.Add(new ILExpression(ILCode.Leave, label));

                        SetState stateChange = stateChanges[index];
                        // Move all instructions from stateChange.Pos to newBody.Count into a try-block
                        stateChanges.RemoveRange(index, stateChanges.Count - index); // remove all state changes up to the one we found
                        ILTryCatchBlock tryFinally = new ILTryCatchBlock();
                        tryFinally.TryBlock = new ILBlock(newBody.GetRange(stateChange.NewBodyPos, newBody.Count - stateChange.NewBodyPos));
                        newBody.RemoveRange(stateChange.NewBodyPos, newBody.Count - stateChange.NewBodyPos); // remove all nodes that we just moved into the try block
                        tryFinally.CatchBlocks  = new List <ILTryCatchBlock.CatchBlock>();
                        tryFinally.FinallyBlock = ConvertFinallyBlock(method);
                        newBody.Add(tryFinally);
                        newBody.Add(label);
                    }
                }
                else
                {
                    newBody.Add(body[pos]);
                }
            }
            newBody.Add(new ILExpression(ILCode.YieldBreak, null));
        }
 public void Any(SetState request)
 {
     _model.SetState(request.Id, request.State);
 }
Beispiel #23
0
        public IActionResult GetSetsByState(SetState setState)
        {
            var allMySets = GetAllSets();

            return(new JsonResult(allMySets.Where(s => s.SetState == setState)));
        }
Beispiel #24
0
 public Set()
 {
     state = SetState.Playing;
 }
Beispiel #25
0
 /// <summary>
 /// 获取当前队列(不存在,则创建)
 /// </summary>
 /// <param name="map">字段映射</param>
 /// <param name="name">表名称</param>
 public Queue CreateQueue(string name, SetState map)
 {
     return(_queue ?? (_queue = new Queue(_groupQueueList.Count, name, ContextProvider, map)));
 }
Beispiel #26
0
 /// <summary>
 /// 获取实体数据缓存
 /// </summary>
 /// <param name="setState"></param>
 /// <param name="initCache">不存在数据时,初始化操作</param>
 /// <returns></returns>
 public static List <TEntity> GetSetCache <TEntity>(SetState setState, Func <IList> initCache = null)
 {
     return((List <TEntity>)GetSetCache(setState, initCache));
 }
Beispiel #27
0
		public async Task SetState(ISelector selector, SentState state)
		{
			SetState api = new SetState(this.Identity);
			await api.Set(selector, state);
		}
Beispiel #28
0
 public NoteViewModel(SetState <RootViewModel> setState, int noteId, string text)
 {
     SetState  = setState;
     NoteId    = noteId;
     this.text = text;
 }
Beispiel #29
0
 public async Task Handle(SetState cmd)
 {
     State.Data = cmd.Data;
     await WriteState();
 }
Beispiel #30
0
 public Set()
 {
     state = SetState.Playing;
 }