Exemplo n.º 1
0
        public DataSet SetUserEngine()
        {
            int    userID     = base.Kv.GetInt32("UserID");
            string engineName = base.Kv.Get("EngineName");
            string userStatus = base.Kv.Get("UserStatus");

            DataSet ds = new DataSet();

            if (userID != 0)
            {
                Engine    eng;
                DataTable dt = Engine.GetEngineByName(base.Kv.Cxt, engineName);
                if (dt.Rows.Count > 0)
                {
                    eng = new Engine(base.Kv.Cxt, dt.Rows[0]);
                }
                else
                {
                    eng             = new Engine();
                    eng.Name        = engineName.Trim();
                    eng.Description = engineName;
                    eng.Save();
                }
                User user = new User(base.Kv.Cxt, userID);
                user.EngineID     = eng.EngineID;
                user.UserStatusID = UData.ToInt32(userStatus);
                user.Save();
            }

            return(ds);
        }
Exemplo n.º 2
0
        public DataTable AddUser()
        {
            base.Kv.Cxt.CurrentUserID = 1; // New users are added by Admin = 1
            User item = new User();

            item.Cxt = base.Kv.Cxt;
            if (CountryID != 0)
            {
                item.CountryID = CountryID;
            }
            item.NearestCityID = NearestCityID;
            item.GenderID      = GenderID;
            item.FideTitleID   = FideTitleID;
            item.IccfTitleID   = IccfTitleID;
            item.UserName      = UserName;
            item.Email         = Email;
            item.FirstName     = FirstName;
            item.LastName      = LastName;
            item.EngineID      = 1;
            item.PasswordHint  = PasswordHint;
            item.PersonalNotes = PersonalNotes;
            item.Url           = Url;
            if (DateLastLogin != string.Empty)
            {
                item.DateLastLogin = Convert.ToDateTime(DateLastLogin);
            }
            if (DateOfBirth != string.Empty)
            {
                item.DateOfBirth = Convert.ToDateTime(DateOfBirth);
            }
            item.Password              = Password;
            item.HumanRankIDE          = RankE.Pawn;
            item.EngineRankIDE         = RankE.Pawn;
            item.CentaurRankIDE        = RankE.Pawn;
            item.CorrespondenceRankIDE = RankE.Pawn;
            item.StatusIDE             = StatusE.Active;
            item.RoomID            = 3;
            item.SocialID          = 1;
            item.UserStatusIDE     = UserStatusE.Blank;
            item.IsIdle            = false;
            item.IsPause           = false;
            item.Cxt.CurrentUserID = base.Kv.Cxt.CurrentUserID;

            item.Save();

            if (!string.IsNullOrEmpty(UserImage))
            {
                SaveUserImage(Ap.WebFolderUserImages + item.UserID);
            }

            DataTable roles = User.GetRolesTable(item.UserID);

            Kv kv1 = new Kv();

            kv1.Set("MsgId", -1);
            kv1.Set("UserData", UData.ToString(item.DataRow.Table));
            kv1.Set("RolesData", UData.ToString(roles.Copy()));

            return(kv1.DataTable);
        }
Exemplo n.º 3
0
        private UserGameType CalculateRating(UserGameType item, double result, double eResult, int userID, SqlTransaction t)
        {
            //Calculate K-Factor of both player
            RatingKFactor kFactor;

            //UserGameType item;
            //Calculate Rating
            kFactor            = RatingKFactors.Instance.GetRatingKFactor(item.EloRating, item.NoOfGames);
            item.NoOfGames     = item.NoOfGames + 1;
            item.EloRating     = item.EloRating + UData.ToInt32(System.Math.Round(kFactor.KFactor * (result - eResult)));
            item.StoredMatches = item.StoredMatches + 1;

            //SqlTransaction t = null;
            try
            {
                //t = SqlHelper.BeginTransaction(Config.ConnectionString);

                //Save Rating
                item.Save(t);

                //Calculate Ranking -> Save Ranking

                CalculateRanking(item, t);

                //SqlHelper.CommitTransaction(t);
            }
            catch (Exception ex)
            {
                //SqlHelper.RollbackTransaction(t);
                throw ex;
            }
            return(item);
        }
Exemplo n.º 4
0
        public void Paste(string moves)
        {
            Flags.IsExamineMode = true;
            DataTable dt = UData.LoadDataTable(Notations.Game.Moves.DataTable.Clone(), moves);

            Paste(dt);
            Flags.IsExamineMode = false;
        }
Exemplo n.º 5
0
        private void SaveObject()
        {
            string path = Ap.FolderDataKv + "Obj.xml";

            UData.WriteXmlDecrypted((DataTable)this.dgData.DataSource, path);

            MessageForm.Show("File saved successfully.\n\n" + path);
        }
Exemplo n.º 6
0
 public string GetGameXml(GameData gameData)
 {
     if (gameData == null)
     {
         return("");
     }
     return(UData.ToString(gameData.Kv.DataTable));
 }
Exemplo n.º 7
0
        public RsListItems(string[] dataKeyNames)
        {
            DataKeyNames = dataKeyNames;

            LoadXsdRes(UWeb.ResNameCtrl(typeof(RsList), "RsListItem.xsd"));

            UData.AddColumns(base.DataTable, dataKeyNames);
        }
        public static void DeclineChallenges(DataTable dt)
        {
            Kv kv = new Kv();

            kv.Set("MethodName", (int)MethodNameE.DeclineChallenges);
            kv.Set(StdKv.CurrentUserID, Ap.CurrentUserID);
            kv.Set("ChallengesData", UData.ToString(dt));
            SocketClient.Instance.InvokeAsync(kv.DataTable.Copy());
        }
Exemplo n.º 9
0
        public static DataTable Select(string tableName, params object[] whereColVals)
        {
            string sql = UData.ToSelect(tableName, whereColVals);

            DataTable table = SqlHelper.ExecuteDataset(Config.ConnectionString, CommandType.Text, sql).Tables[0];

            table.TableName = tableName;

            return(table);
        }
Exemplo n.º 10
0
        public static string AddAudienceAsync(string uData)
        {
            Kv kv = new Kv();

            kv.Set("MethodName", (int)MethodNameE.AddAudienceAsync);
            kv.Set("AudienceData", uData);
            string data = UData.ToString(kv.DataTable);

            return(data);
        }
Exemplo n.º 11
0
        public static string RemoveAudience(int userID)
        {
            Kv kv = new Kv();

            kv.Set("MethodName", (int)MethodNameE.RemoveAudience);
            kv.Set("UserID", userID);
            string data = UData.ToString(kv.DataTable);

            return(data);
        }
Exemplo n.º 12
0
        public MoveLog(MoveComments moveComments)
        {
            Game = moveComments.Move.Game;

            DataTable = GetMoveLogTable();

            this.MoveComments = moveComments;

            UData.LoadDataTable(DataTable, this.MoveComments[MoveCommentTypeE.MoveLog]);
        }
Exemplo n.º 13
0
        private string GetUserImage(string filePath)
        {
            string imagetype = "";

            if (UFile.Exists(filePath + ".bmp"))
            {
                imagetype = ".bmp";
            }
            else if (UFile.Exists(filePath + ".jpeg"))
            {
                imagetype = ".jpeg";
            }
            else if (UFile.Exists(filePath + ".jpg"))
            {
                imagetype = ".jpg";
            }
            else if (UFile.Exists(filePath + ".gif"))
            {
                imagetype = ".gif";
            }
            else
            {
                return(string.Empty);
            }
            byte[] UserImageBytes = UImage.GetImageBytes(filePath + imagetype);
            //UserImageType = System.IO.Path.GetExtension(filePath);
            DataTable  userImageTable = new DataTable("UserImageTable");
            DataColumn nameColumn;

            nameColumn            = new DataColumn();
            nameColumn.DataType   = System.Type.GetType("System.String");
            nameColumn.ColumnName = "ImageName";
            userImageTable.Columns.Add(nameColumn);
            DataColumn imageColumn;

            imageColumn            = new DataColumn();
            imageColumn.DataType   = System.Type.GetType("System.Byte[]");
            imageColumn.ColumnName = "ImageBytes";
            userImageTable.Columns.Add(imageColumn);
            DataColumn typeColumn;

            typeColumn            = new DataColumn();
            typeColumn.DataType   = System.Type.GetType("System.String");
            typeColumn.ColumnName = "ImageType";
            userImageTable.Columns.Add(typeColumn);
            DataRow dr = userImageTable.NewRow();

            dr["ImageName"]  = "UserImage";
            dr["ImageBytes"] = UserImageBytes;
            dr["ImageType"]  = imagetype;
            userImageTable.Rows.Add(dr);

            return(UData.ToString(userImageTable));
        }
Exemplo n.º 14
0
        private void ProcessData(string str, UserSession us)
        {
            if (UData.IsValidXml(str))
            {
                DataTable dt = UData.LoadDataTable(UData.LoadXsdText(str), str);

                Kv kv = new Kv(dt);

                Ap.MsgQueue.Enqueue(kv);
            }
        }
Exemplo n.º 15
0
        public void Union(string moves)
        {
            if (moves == "")
            {
                return;
            }

            DataTable dt = UData.LoadDataTable(Notations.Game.Moves.DataTable.Clone(), moves);

            AddMoves(dt);
        }
Exemplo n.º 16
0
        public PiecesTheme()
        {
            PiecesThemeData = UData.ToTable2("PiecesThemeData", "ThemeID", "PieceID", "PieceXaml");
            ColorSchemeData = UData.ToTable2("ColorSchemeData", "ColorScheme", "BorderColor", "WhitePiecesColor", "BlackPiecesColor", "LightSquaresColor", "DarkSquaresColor");

            KvBackground = new Kv(KvType.BackgroundThemes);
            KvColors     = new Kv(KvType.ColorSchemes);
            KvPieces     = new Kv(KvType.PiecesThemes);

            Load();
        }
Exemplo n.º 17
0
 public void Load(string kvXml)
 {
     if (String.IsNullOrEmpty(kvXml))
     {
         CreateKv();
     }
     else
     {
         DataTable = UData.LoadDataTable(kvXml, kvXml);
     }
 }
Exemplo n.º 18
0
        public Kv(KvType type)
        {
            if (type == KvType.Web)
            {
                DataTable = UData.ToTable2("Kv", "k", "v");
            }
            else
            {
                string path = GetFilePath(type);

                DataTable = UData.LoadDataTable5(path);
            }
        }
Exemplo n.º 19
0
        public static DataTable GetDataTable(DataTable table, string key)
        {
            try
            {
                string s = Get(table, key);

                return(UData.LoadDataTable(s));
            }
            catch
            {
                return(null);
            }
        }
        public string GetLastMoveXml()
        {
            DataRow dr = Moves.Last.DataRow;

            if (dr != null)
            {
                return(UData.ToString(dr));
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 21
0
        public string GetOnlineGameXml()
        {
            DataRow dr = Notations.GetLastRow();

            if (dr != null)
            {
                return(UData.ToString(dr));
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 22
0
        //public DataSet SendSync(string data)
        public DataSet SendSync(string data)
        {
            try
            {
                if (SynSocket != null)
                {
                    if (SynSocket.Connected)
                    {
                        SyncData = new StringBuilder();
                        int i = SynSocket.Receive(SyncBuffer);

                        while (true)
                        {
                            SyncData.Append(System.Text.ASCIIEncoding.ASCII.GetString(SyncBuffer, 0, i));

                            if (!SyncData.ToString().Contains("\0"))
                            {
                                i = SynSocket.Receive(SyncBuffer);
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (UData.IsValidXml(SyncData.ToString()))
                        {
                            return(UData.LoadDataSet(SyncData.ToString()));
                        }
                        else
                        {
                            DataSet ds = new DataSet();
                            return(ds);
                        }
                    }
                    else
                    {
                        return(new DataSet());
                    }
                }
                else
                {
                    return(new DataSet());
                }
            }
            catch (Exception ex)
            {
                return(new DataSet());
            }
        }
Exemplo n.º 23
0
 public void SendAsync(DataTable dt)
 {
     try
     {
         if (userSession.AsynSocket != null)
         {
             byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(UData.ToString(dt) + "\0");
             userSession.AsynSocket.Send(data);
         }
     }
     catch (Exception ex)
     {
         OnServerDownError(ex);
     }
 }
Exemplo n.º 24
0
        public virtual void Add(TC items)
        {
            if (items == null)
            {
                return;
            }

            if (DataTable == null)
            {
                DataTable = items.DataTable.Copy();

                return;
            }

            UData.ImportTable(DataTable, items.DataTable);
        }
Exemplo n.º 25
0
        public string GetGameXml()
        {
            if (GameData == null)
            {
                return("");
            }

            if (string.IsNullOrEmpty(GameData.Guid))
            {
                GameData.Guid = System.Guid.NewGuid().ToString();
            }

            GameData.InitialBoardFen = InitialBoardFen;

            GameData.Moves = UData.ToString(Notations.Game.Moves.DataTable);

            switch (GameType)
            {
            case GameType.Bullet:
            case GameType.Blitz:
            case GameType.Rapid:
            case GameType.NoClock:
                GameData.OptionsBlitzClock = Ap.OptionsBlitzClock.Kv.ToDataTableString;
                break;

            case GameType.Long:
                GameData.OptionsLongClock = Ap.OptionsLongClock.Kv.ToDataTableString;
                break;
            }
            if (GameMode == GameMode.Kibitzer)
            {
                GameData.GameMode = GameMode.HumanVsHuman;
            }
            else
            {
                GameData.GameMode = GameMode;
            }

            GameData.GameType = GameType;

            /////////////////
            GameData.Flags      = this.Flags.Flags;
            GameData.GameResult = this.GameResult;
            /////////////////

            return(UData.ToString(GameData.Kv.DataTable));
        }
Exemplo n.º 26
0
        private bool SendSync(DataTable dt)
        {
            try
            {
                if (userSession.SynSocket != null)
                {
                    byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(UData.ToString(dt) + "\0");
                    userSession.SynSocket.Send(data);
                }
            }
            catch (Exception ex)
            {
                OnServerDownError(ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 27
0
        private void AddGame(Kv kvGame, Kv kvMoves)
        {
            GameData gameData = GetGameData(kvGame);
            Moves    moves    = GetMoves(kvMoves);

            if (isPgnToIcbConversion)
            {
                GameItem item = new GameItem(gameData, moves);
                book.ImportGame(item);
            }
            else
            {
                gameData.Guid  = System.Guid.NewGuid().ToString();
                gameData.Moves = UData.ToString(moves.DataTable);
                string gameXml = this.Game.GetGameXml(gameData);
                Ap.Database.AppendGame(gameXml);
            }
        }
Exemplo n.º 28
0
        public static DataTable LoadDataTable5(string xmlPath)
        {
            DataTable table = null;

            try
            {
                if (UFile.Exists(xmlPath))
                {
                    string content = InfinityStreamsManager.ReadFromFile(xmlPath);

                    table = UData.LoadDataTable(content, content);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(table);
        }
Exemplo n.º 29
0
        public void GetUserGamesRating()
        {
            int totalGames = userGamesRating.Select().Count();
            int whiteGames = userGamesRating.Select("WhiteUserID=" + Ap.CurrentUserID).Count();
            int winGames   = userGamesRating.Select("WhiteUserID=" + Ap.CurrentUserID + " AND GameResultID=1").Count();

            winGames = winGames + userGamesRating.Select("BlackUserID=" + Ap.CurrentUserID + " AND GameResultID=2").Count();
            int   drawGames   = userGamesRating.Select("WhiteUserID=" + Ap.CurrentUserID + " AND BlackUserID=" + Ap.CurrentUserID + " AND GameResultID=4").Count();
            int   lossesGames = totalGames - (winGames + drawGames);
            float res         = ((float)(((float)drawGames / 2) + winGames) / totalGames) * 100;
            int   nOpponent   = (from DataRow dr in userGamesRating.Rows
                                 where (string)dr["WhiteUserID"] != Ap.CurrentUserID.ToString()
                                 select(string) dr["WhiteUserID"]).Distinct().Union((from DataRow dr in userGamesRating.Rows
                                                                                     where (string)dr["WhiteUserID"] != Ap.CurrentUserID.ToString()
                                                                                     select(string) dr["WhiteUserID"]).Distinct()).Count();
            int    rating = UData.ToInt32(userGamesRating.Select().FirstOrDefault()["EloRating"].ToString());
            string str    = (from DataRow dr in userGamesRating.Rows
                             orderby dr["StartDate"] descending
                             select(string) dr["StartDate"]).FirstOrDefault();
        }
Exemplo n.º 30
0
        protected override void OnRowDataBound(GridViewRowEventArgs e)
        {
            base.OnRowDataBound(e);

            if (e.Row.RowType != DataControlRowType.DataRow)
            {
                return;
            }

            if (!ShowCheckBox || dataSourceSelected == null)
            {
                return;
            }

            if (UData.Contains((DataTable)dataSourceSelected, DataKeyNames.GetValue(0).ToString(), UWeb.ToString(e, DataKeyNames.GetValue(0).ToString())))
            {
                CheckBox chk = e.Row.FindControl("chk") as CheckBox;

                chk.Checked = true;
            }
        }