예제 #1
0
        protected virtual void Init(int id)
        {
            UserID = id;

            AsyncBuffer = new byte[BufferSize];
            SyncBuffer  = new byte[BufferSize];

            AsyncData = new StringBuilder();
            SyncData  = new StringBuilder();

            if (id != 0)
            {
                KeyValues.IsRequestFromServer = true;
                if (!string.IsNullOrEmpty(KeyValues.Instance.GetKeyValue(KeyValueE.TimeOut).Value))
                {
                    TimeOut = BaseItem.ToInt32(KeyValues.Instance.GetKeyValue(KeyValueE.TimeOut).Value);
                }

                if (!string.IsNullOrEmpty(KeyValues.Instance.GetKeyValue(KeyValueE.Heartbeat).Value))
                {
                    Heartbeat = BaseItem.ToInt32(KeyValues.Instance.GetKeyValue(KeyValueE.Heartbeat).Value);
                }

                t.Elapsed += new ElapsedEventHandler(t_Elapsed);
                t.Interval = 1000;
                t.Start();
            }
        }
예제 #2
0
        public void LoadChilds(Move m, Dictionary <string, DataRow> bookMovesCollection)
        {
            CheckAndAddMove(m, bookMovesCollection, false);

            string tempParentId = "";
            bool   isInitialFen = FenParser.IsInitialFen(m.Fen, true);

            if (m.Flags.IsRootMove && isInitialFen)
            {
                // if rootMove and initial fen, then CurrentMove's parent is "0"
                tempParentId = "0";
            }
            else
            {
                #region Find Book's CurrentMove's Parent
                StringBuilder filter = new StringBuilder();
                if (!m.Flags.IsRootMove)
                {
                    filter.Append(BookMove.ColumnMoveNumber + " = " + m.MoveNo);
                    filter.Append(" and " + BookMove.ColumnWhiteMove + " = " + m.White);
                    filter.Append(" and " + BookMove.ColumnFrom + " = '" + m.From + "'");
                    filter.Append(" and " + BookMove.ColumnTo + " = '" + m.To + "'");
                    filter.Append(" and ");
                }
                filter.Append(BookMove.ColumnFen + " like '" + ChessLibrary.FenParser.GetOnlyFen(m.Fen) + "%'");

                DataRow[] rows = this.DataTable.Select(filter.ToString());

                if (rows.Length > 0)
                {
                    tempParentId = rows[0][BookMove.ColumnId].ToString();
                }
                #endregion
            }

            if (string.IsNullOrEmpty(tempParentId))
            {
                #region if "tempParentId" not found, set defaultView to not display moves.
                DataTable.DefaultView.RowFilter = BookMove.ColumnParentId + " = " + -2;

                if (!AllowMoveAdding)
                {
                    CheckAndAddMove(m, bookMovesCollection, true);
                }

                rowIndex = -1;
                #endregion
            }
            else
            {
                if (m.Flags.IsRootMove && isInitialFen)
                {
                    #region If RootMove and initial fen, then set move to display according to white or black turn
                    string filter = "";

                    if (m.White == 1)
                    {
                        filter += BookMove.ColumnParentId + " = " + tempParentId;
                    }
                    else
                    {
                        filter += BookMove.ColumnMoveNumber + " = 1";
                    }

                    filter += " and " + BookMove.ColumnWhiteMove + " = " + m.White;

                    DataTable.DefaultView.RowFilter = filter;
                    #endregion
                }
                else
                {
                    // if parent found(and not rootMove), then load its childs
                    DataTable.DefaultView.RowFilter = BookMove.ColumnParentId + " = " + tempParentId;
                }

                // set CurrentParentMoveId to current parent founded.
                CurrentParentMoveId = BaseItem.ToInt32(tempParentId);

                #region Set rowIndex
                if (DataTable.DefaultView.Count > 0)
                {
                    rowIndex = 0;

                    if (m != null)
                    {
                        for (int i = 0; i < DataTable.DefaultView.Count; i++)
                        {
                            if (m.To == DataTable.DefaultView[i][BookMove.ColumnTo].ToString())
                            {
                                rowIndex = i;
                            }
                        }
                    }
                }
                else
                {
                    rowIndex = -1;
                }
                #endregion
            }

            this.DataTable.DefaultView.Sort = BookMove.ColumnWinCount + " Desc";
        }
예제 #3
0
 public static int ToInt32(DataListItemEventArgs e, string columnName)
 {
     return(BaseItem.ToInt32(((System.Data.DataRowView)(e.Item.DataItem)).Row[columnName]));
 }
예제 #4
0
 public static int ToInt32(object o)
 {
     return(BaseItem.ToInt32(o, 0));
 }
예제 #5
0
 public static int GetColInt32(DataRow row, string columnName, int deafultValue)
 {
     return(BaseItem.ToInt32(BaseItem.GetColumn(row, columnName, deafultValue), deafultValue));
 }
예제 #6
0
 public static int GetColInt32(DataRow row, string columnName)
 {
     return(BaseItem.ToInt32(BaseItem.GetColumn(row, columnName, 0)));
 }
예제 #7
0
 public int GetColInt32(object row, string columnName, int deafultValue)
 {
     return(BaseItem.ToInt32(BaseItem.GetColumn(row, columnName, deafultValue), deafultValue));
 }
예제 #8
0
        public static string Plural(object count, string s)
        {
            int i = BaseItem.ToInt32(count);

            return(i + (i == 1 ? " " + s : " " + s + "s"));
        }
예제 #9
0
 public static int ToInt32(System.Web.UI.WebControls.DataListItemEventArgs e, string columnName)
 {
     return(BaseItem.ToInt32(ToString(e, columnName)));
 }
예제 #10
0
 public static int VsInt32(StateBag v, string key, int defaultValue)
 {
     return(BaseItem.ToInt32(GetVs(v, key, defaultValue).ToString()));
 }
예제 #11
0
 public static int RfInt32(string name, int defaultValue)
 {
     return(BaseItem.ToInt32(UWeb.GetRf(name, defaultValue)));
 }