Esempio n. 1
0
        public async Task <IActionResult> Index(WordViewModel model)
        {
            using (var ctx = new WordContext())
                using (var t = await ctx.Database.BeginTransactionAsync())
                {
                    var state   = new ListState();
                    var filters = new List <Func <Word, bool> >();

                    ViewBag.AppVer = App.Version;

                    if (model.Keyword != null)
                    {
                        filters.Add(w => w.Content.Contains(model.Keyword));
                    }

                    ViewBag.Data = await WordManipulator.LoadWords(ctx, state,
                                                                   w => w.Compact(),
                                                                   model,
                                                                   PageUtils.LimitPerPage,
                                                                   filters.ToArray());

                    ViewBag.State = state;

                    return(View(model));
                }
        }
 public void Clear()
 {
     while (true)
     {
         /*
          * it should be very hard to not succeed the first pass thru since this is typically is only called from
          * a single thread protected by a tryLock, but there is at least 1 other place (at time of writing this comment)
          * where reset can be called from (CircuitBreaker.markSuccess after circuit was tripped) so it can
          * in an edge-case conflict.
          *
          * Instead of trying to determine if someone already successfully called clear() and we should skip
          * we will have both calls reset the circuit, even if that means losing data added in between the two
          * depending on thread scheduling.
          *
          * The rare scenario in which that would occur, we'll accept the possible data loss while clearing it
          * since the code has stated its desire to clear() anyways.
          */
         ListState current  = state.Value;
         ListState newState = current.Clear();
         if (state.CompareAndSet(current, newState))
         {
             return;
         }
     }
 }
Esempio n. 3
0
 public static void updateHealth(ListState entities, string team)
 {
     if (team == "Players")
     {
         for (int i = 0; i < playerClones.Count; ++i)
         {
             characters attr = playerClones [i].GetComponent <characters> ();
             attr.pos    = new position(entities.players [i].pos);
             attr.health = entities.players [i].health;
             attr.damage = entities.players [i].damage;
         }
     }
     else if (team == "Enemies")
     {
         for (int i = 0; i < enemyClones.Count; ++i)
         {
             characters attr = enemyClones [i].GetComponent <characters> ();
             attr.pos    = new position(entities.enemies [i].pos);
             attr.health = entities.enemies [i].health;
             attr.damage = entities.enemies [i].damage;
         }
     }
     else
     {
         Debug.Log(team + ": Does not exist!");
     }
 }
Esempio n. 4
0
 public void DefineList(ListState state)
 {
     state.List = new List <int>()
     {
         5, 6, 9
     };
 }
Esempio n. 5
0
 public IEnumerable <int> StaticEnumerateItem(ListState state)
 {
     return(new List <int>()
     {
         3, 5, 2
     });
 }
        public static ListState GetAttributeValue(XmlNode node, string name, ListState defaultValue)
        {
            if (node == null)
            {
                return(defaultValue);
            }

            var attribute = node.Attributes.GetNamedItem(name);

            if (attribute == null)
            {
                return(defaultValue);
            }

            var rawValue = attribute.Value;
            var result   = defaultValue;

            try
            {
                result = (ListState)Enum.Parse(typeof(ListState), rawValue);
            }
            catch
            {
                // Do nothing
            }

            return(result);
        }
Esempio n. 7
0
        public async Task <int> Add(int userId, string name, string description, ListState state, string backgroundImageFilePath)
        {
            using (var con = _databaseConnectionProvider.New())
            {
                var createdDate = DateTime.UtcNow;

                var listId = Convert.ToInt32(await con.ExecuteScalarAsync(@"
                    INSERT INTO
                        Lists
                            (UserId, Name, Description, State, DateCreated, DateUpdated, BackgroundImageFilePath)
                        VALUES
                            (@userId, @name, @description, @state, @createdDate, @createdDate, @backgroundImageFilePath)

                    SELECT SCOPE_IDENTITY()", new
                {
                    userId,
                    name,
                    description,
                    state,
                    createdDate,
                    backgroundImageFilePath
                }));

                return(listId);
            }
        }
Esempio n. 8
0
    void DisplayItemTypes()
    {
        if (selectedType != null)
        {
            foreach (int i in selectedType.childrenIDs)
            {
                ElementType e = InventoryDatabase.GetElementType(i);

                if (e != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button(e.name, GUILayout.ExpandWidth(true)))
                    {
                        GUI.FocusControl(null);
                        editType  = e;
                        editState = EditState.EDITTYPE;
                    }

                    if (GUILayout.Button(">", GUILayout.MaxWidth(25)))
                    {
                        GUI.FocusControl(null);
                        selectedType = e;
                        listState    = ListState.DEFAULT;
                        editState    = EditState.EMPTY;
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
        else
        {
            for (int n = 0; n < InventoryDatabase.ElementTypeCount; n++)
            {
                ElementType et = InventoryDatabase.GetElementType(n);

                if (et != null)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (et.ID > -1 && et.parentID == -1)
                    {
                        if (GUILayout.Button(et.name, GUILayout.ExpandWidth(true)))
                        {
                            GUI.FocusControl(null);
                            editType  = et;
                            editState = EditState.EDITTYPE;
                        }
                        if (GUILayout.Button(">", GUILayout.MaxWidth(25)))
                        {
                            GUI.FocusControl(null);
                            selectedType = et;
                            listState    = ListState.DEFAULT;
                            editState    = EditState.EMPTY;
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
    }
Esempio n. 9
0
        public virtual ActionResult ShowHideListFilter()
        {
            var listState = ListState;

            listState.ShowFilter = !listState.ShowFilter;
            ListState            = listState;
            return(SetRedirect("Index"));
        }
Esempio n. 10
0
        public ActionResult ClearListFilter()
        {
            var listState = ListState;

            listState.ListFilter = null;
            ListState            = listState;
            return(SetRedirect("Index"));
        }
Esempio n. 11
0
 void loadState()
 {
     conn.Open();
     cmd = new SqlCommand("select stateid, statename from states", conn);
     ListState.DataSource     = cmd.ExecuteReader();
     ListState.DataTextField  = "statename";
     ListState.DataValueField = "stateid";
     ListState.DataBind();
     conn.Close();
 }
Esempio n. 12
0
    public void focusOnList()
    {
        foreach (Transform btn in content)
        {
            btn.GetComponent <Button>().interactable = true;
        }

        content.GetChild(0).GetComponent <Button>().Select();
        state = ListState.Focused;
    }
 private void Init(IPAddress ip, int messageCount, DateTime firstSeen, DateTime lastSeen, string hostName, ListState state, DateTime modified)
 {
     IP           = ip;
     MessageCount = messageCount;
     FirstSeen    = firstSeen;
     LastSeen     = lastSeen;
     State        = state;
     Modified     = modified;
     ParseHosts(hostName);
 }
Esempio n. 14
0
    public void unfocusList()
    {
        unfocusButton.Select();

        foreach (Transform btn in content)
        {
            btn.GetComponent <Button>().interactable = false;
        }

        state = ListState.None;
    }
Esempio n. 15
0
        protected void LoadListState(ListState <TListFilter> listState)
        {
            var gridState = _gridStateRepository.Load(CurrentUserId, _moduleName);

            if (gridState != null)
            {
                listState.ListFilter = gridState.Filter != null?Serializer.Deserialize <TListFilter>(gridState.Filter) : null;

                listState.LayoutData = gridState.LayoutData;
                listState.ShowFilter = gridState.ShowFilter;
            }
        }
Esempio n. 16
0
        public async Task <IEnumerable <List> > GetByState(int userProfileId, ListState state)
        {
            using (var con = _databaseConnectionProvider.New())
            {
                var lists = await con.QueryAsync <List>(@"SELECT * FROM Lists WHERE UserId = @userProfileId AND State = @state", new
                {
                    userProfileId,
                    state
                });

                return(lists);
            }
        }
Esempio n. 17
0
    public static ListState getStates()
    {
        ListState newL = new ListState();

        foreach (GameObject e in playerClones)
        {
            newL.players.Add(new playerStateNode(e));
        }
        foreach (GameObject e in enemyClones)
        {
            newL.enemies.Add(new playerStateNode(e));
        }
        return(newL);
    }
Esempio n. 18
0
 // Method to add an element to the collections.
 public void Add(Monarchy monarchy)
 {
     try
     {
         ListState.Add(monarchy.BaseState);
         ListString.Add(monarchy.BaseState.ToString());
         DictionaryState.Add(monarchy.BaseState, monarchy);
         DictionaryString.Add(monarchy.BaseState.ToString(), monarchy);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
Esempio n. 19
0
    public GameStateNode(GameStateNode _parent, ListState state, int movedIndex)
    {
        children = null;
        parent   = _parent;
        if (parent == null)
        {
            enemysTurn = true;
        }
        else
        {
            enemysTurn = !parent.enemysTurn;
        }

        this.movedIndex = movedIndex;
        entities        = state;
    }
    public void SetState(ListState state)
    {
        switch (state)
        {
        case ListState.AllPokemons:
            _stateText.text = TextManager.GetText(TextType.Element, 41);
            break;

        case ListState.SearchResults:
            _stateText.text = TextManager.GetText(TextType.Element, 40);
            break;

        case ListState.FavPokes:
            _stateText.text = TextManager.GetText(TextType.Element, 47);
            break;
        }
    }
Esempio n. 21
0
    /*public List<position> attacker(int range, position defender){
     *      List<position> p = new List<position>();
     *      position newP = new position();
     *
     *      for (int i = -1; i < 2; ++i) {
     *              if(i == 0) continue;
     *              newP.x = defender.x + i*range;
     *              newP.y = defender.y;
     *              if(isValid (newP))
     *                      p.Add (new position(newP));
     *              newP.y = defender.y + i*range;
     *              newP.x = defender.x;
     *              if(isValid (newP))
     *                      p.Add (new position(newP));
     *      }
     *      return p;
     * }*/

    private bool CanGoTo(position pos, ref ListState states)
    {
        for (int i = 0; i < states.players.Count; ++i)
        {
            if (pos.Equals(states.players[i].pos))
            {
                return(false);
            }
        }
        for (int i = 0; i < states.enemies.Count; ++i)
        {
            if (pos.Equals(states.enemies[i].pos))
            {
                return(false);
            }
        }
        return(true);
    }
        /// <summary>
        /// Decrements the <see cref="ListState{T}.Selected"/> property>.
        /// </summary>
        /// <param name="list">The <see cref="ListState{T}"/> to decrement selector of</param>
        private static void DecrementListState <T>(ref ListState <T> list)
        {
            if (list.Lock == null)
            {
                throw new ArgumentException("The list lock is not initialized", "list");
            }

            lock (list.Lock)
            {
                if (list.Items != null && list.Selected > 0)
                {
                    list.Changed = true;
                    list.Selected--;
                    if (list.Selected < list.Offset)
                    {
                        list.Offset--;
                    }
                }
            }
        }
        /// <summary>
        /// Increments the <see cref="ListState{T}.Selected"/> property
        /// </summary>
        /// <param name="list">The <see cref="ListState{T}"/> to increment selector of</param>
        /// <param name="items">The amount of items to show in the list</param>
        private static void IncrementListState(ref ListState <string[]> list, int items)
        {
            if (list.Lock == null)
            {
                throw new ArgumentException("The list lock is not initialized", "list");
            }

            lock (list.Lock)
            {
                if (list.Items != null && list.Selected < list.Items.Length - 1)
                {
                    list.Changed = true;
                    list.Selected++;
                    if (list.Selected >= list.Offset + items)
                    {
                        list.Offset++;
                    }
                }
            }
        }
        /// <summary>
        /// Increments the <see cref="ListState{T}.Selected"/> property
        /// </summary>
        /// <param name="list">The <see cref="ListState{T}"/> to increment selector of</param>
        /// <param name="items">The amount of items to show in the list</param>
        private static void IncrementListState(ref ListState <List <OATHController.Credential> > list, int items)
        {
            if (list.Lock == null)
            {
                throw new ArgumentException("The list lock is not initialized", "list");
            }

            lock (list.Lock)
            {
                if (list.Items != null && list.Selected < list.Items.Count - 1)
                {
                    list.Changed = true;
                    list.Selected++;
                    if (list.Selected >= list.Offset + items)
                    {
                        list.Offset++;
                    }
                }
            }
        }
Esempio n. 25
0
        public async Task ChangeState(int listId, ListState state)
        {
            using (var con = _databaseConnectionProvider.New())
            {
                var updateDate = DateTime.UtcNow;

                await con.ExecuteAsync(@"
                    UPDATE
                        Lists
                    SET
                        State = @state,
                        DateUpdated = @updateDate
                    WHERE
                        Id = @listId", new
                {
                    listId,
                    state,
                    updateDate
                });
            }
        }
Esempio n. 26
0
        public async Task<ReadingList> GetReadingList(ListState state = ListState.Unread, bool onlyFavorites = false, string tagname = "", ContentType content = ContentType.All, SortOn sort = SortOn.Newest, DetailType detail = DetailType.Simple)
        {
            List<Param> parameters = new List<Param>();
            parameters.Add(new Param("state",state.ToString().ToLower()));
            parameters.Add(new Param("favorite", onlyFavorites ? "1" : "0"));
            if (tagname != "")
            {
                parameters.Add(new Param("tag", tagname));
            }
            if (content != ContentType.All)
            {
                parameters.Add(new Param("contentType", content.ToString().ToLower()));
            }
            parameters.Add(new Param("sort", sort.ToString().ToLower()));
            parameters.Add(new Param("detailType", detail.ToString().ToLower()));


            IRestResponse resp = await HandleRequest("get.php", Call.POST, parameters);

            var regexd = Regex.Replace(Regex.Replace(resp.Content, @"""\d+"":", "").Replace("\"list\":{", "\"list\":[").Replace("}},\"error\"", "}],\"error\""), "{{(([^{}]|{[^{}]+}|)+)}(([^{}]|{[^{}]+}|)+)}", "[{$1}$3]");
            return JsonConvert.DeserializeObject<ReadingList>(regexd);
        }
Esempio n. 27
0
        public virtual void LoadListViewStates(ListState <TListFilter> listState, out TListFilter listFilter, out string errorText)
        {
            errorText = string.Empty;
            bool havePermission = true;

            listFilter = null;
            // Update list state
            listState.ViewType = ViewBag.ViewType = listState.ViewType ?? _applicationRepository.GetDefaultViewType();

            listState.ShowFilter = listState.ShowFilter;

            if (!TempRedirectedToList)
            {
                LoadListState(listState);
            }
            ListState             = listState;
            ViewBag.IsFilterEmpty = listState.ListFilter == null;
            var filter = listState.ListFilter ?? new TListFilter();

            listFilter = filter;
            errorText  = string.Empty;
        }
Esempio n. 28
0
        public async Task DeleteList(int listId, ListState state)
        {
            using (var con = _databaseConnectionProvider.New())
            {
                var updateDate = DateTime.UtcNow;

                await con.ExecuteAsync(@"
                    UPDATE
                        Lists
                    SET
                        State = @state,
                        BackgroundImageFileName = '',
                        BackgroundImageFilePath = '',
                        DateUpdated = updateDate
                    WHERE
                        Id = @listId", new
                {
                    listId,
                    state,
                    updateDate
                });
            }
        }
Esempio n. 29
0
        public virtual ActionResult ResetListLayoutData()
        {
            var listState = ListState;

            listState.LayoutData = null;
            listState.ShowFilter = true;
            listState.ListFilter = null;
            ListState            = listState;

            try
            {
                _gridStateRepository.Delete(CurrentUserId, _moduleName);
                _gridStateRepository.Save();
                TempData["GlobalAlertMessage"] = "Ok";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex);
            }
            GlobalAlertMessage = "Error";
            return(SetRedirect("Index"));
        }
            public void AddLast(Bucket o)
            {
                ListState currentState = state.Value;
                // create new version of state (what we want it to become)
                ListState newState = currentState.AddBucket(o);

                /*
                 * use compareAndSet to set in case multiple threads are attempting (which shouldn't be the case because since addLast will ONLY be called by a single thread at a time due to protection
                 * provided in <code>getCurrentBucket</code>)
                 */
                if (state.CompareAndSet(currentState, newState))
                {
                    // we succeeded
                    return;
                }
                else
                {
                    // we failed, someone else was adding or removing
                    // instead of trying again and risking multiple addLast concurrently (which shouldn't be the case)
                    // we'll just return and let the other thread 'win' and if the timing is off the next call to getCurrentBucket will fix things
                    return;
                }
            }
            public void AddLast(Bucket o)
            {
                ListState currentState = _state.Value;

                // create new version of state (what we want it to become)
                ListState newState = currentState.AddBucket(o);

                /*
                 * use compareAndSet to set in case multiple threads are attempting (which shouldn't be the case because since addLast will ONLY be called by a single thread at a time due to protection
                 * provided in <code>getCurrentBucket</code>)
                 */
#pragma warning disable S3923 // All branches in a conditional structure should not have exactly the same implementation
                if (_state.CompareAndSet(currentState, newState))
                {
                    // we succeeded
                }
                else
                {
                    // we failed, someone else was adding or removing
                    // instead of trying again and risking multiple addLast concurrently (which shouldn't be the case)
                    // we'll just return and let the other thread 'win' and if the timing is off the next call to getCurrentBucket will fix things
                }
#pragma warning restore S3923 // All branches in a conditional structure should not have exactly the same implementation
            }
Esempio n. 32
0
 public void CleanPathData()
 {
     f = g = h = 0;
     ls = ListState.NULL;
     pre = null;
 }
Esempio n. 33
0
	public static void updateHealth(ListState entities, string team){
		if (team == "Players") {
			for (int i = 0; i < playerClones.Count; ++i) {
				characters attr = playerClones [i].GetComponent<characters> ();
				attr.pos = new position (entities.players [i].pos);
				attr.health = entities.players [i].health;
				attr.damage = entities.players [i].damage;
			}
		} else if (team == "Enemies") {
			for (int i = 0; i < enemyClones.Count; ++i) {
				characters attr = enemyClones [i].GetComponent<characters> ();
				attr.pos = new position (entities.enemies [i].pos);
				attr.health = entities.enemies [i].health;
				attr.damage = entities.enemies [i].damage;
			}
		} else {
			Debug.Log (team + ": Does not exist!");
		}
	}
Esempio n. 34
0
	public static ListState getStates(){
		ListState newL = new ListState();

		foreach (GameObject e in playerClones) {
			newL.players.Add(new playerStateNode(e));
		}
		foreach (GameObject e in enemyClones) {
			newL.enemies.Add(new playerStateNode(e));
		}
		return newL;
	}
Esempio n. 35
0
 public ListEnv(ListState st)
 {
     State = st;
     ItemCount = 1;
 }
Esempio n. 36
0
	public GameStateNode(GameStateNode _parent, ListState state, int movedIndex){
		children = null;
		parent = _parent;
		if (parent == null)
			enemysTurn = true;
		else
			enemysTurn = !parent.enemysTurn;

		this.movedIndex = movedIndex;
		entities = state;
	
	}
Esempio n. 37
0
	/*public List<position> attacker(int range, position defender){
		List<position> p = new List<position>();
		position newP = new position();

		for (int i = -1; i < 2; ++i) {
			if(i == 0) continue;
			newP.x = defender.x + i*range;
			newP.y = defender.y;
			if(isValid (newP))
				p.Add (new position(newP));
			newP.y = defender.y + i*range;
			newP.x = defender.x;
			if(isValid (newP))
				p.Add (new position(newP));
		}
		return p;
	}*/

	private bool CanGoTo(position pos, ref ListState states){
		for (int i = 0; i < states.players.Count; ++i) {
			if(pos.Equals(states.players[i].pos))
				return false;
		}
		for (int i = 0; i < states.enemies.Count; ++i) {
			if(pos.Equals(states.enemies[i].pos))
				return false;
		}
		return true;
	}
Esempio n. 38
0
        /// <summary>
        /// Set values for instance members
        /// </summary>
        protected void InitMembers()
        {
            // Get the system languages
            m_languages = LanguageUtilities.GetSystemLanguages(FoundationContext.Solution.Languages);

            // Get list state from session or create new if not in session
            m_listState = Session[ObjectPostConstants.SESSION_LIST_STATE] as ListState;
            if (m_listState == null)
            {
                m_listState = c_list.GetState();
                Session[ObjectPostConstants.SESSION_LIST_STATE] = m_listState;
            }

            // Save deafult page size. It will be used to change view mode (Show all and show pages)
            m_defaultPageSize = c_list.PageSize;
        }