コード例 #1
0
        static void BeforeTest()
        {
            //DBInfomationHandler testDB = new DBInfomationHandler(ConfigurationManager.AppSettings.Get("ConectionDBString"));
            //testDB.GetHandGameList(0, 100);
            DBLoginInfo info   = FBAPI.GetUserData("EAACEdEose0cBAOVYZANbS25LytZBtVhG0Gs6dhYkXN3rpXpkxNZAiYhZByg8ocHCBRJqJjmZA66x7BZC3A7M4Fmr1eg5RtGrOJz1GFM7x6O5a4bw8iRlOa7iwVOR6HOoKYD6UvjvuWyLduJuM77MQDLL7N7ZABdWaU2Qp25bpyruwZDZD");
            int         ibreak = 999;

            string left  = "";
            string right = "";

            GameReferee.GetWinner_IndianHoldem("4:18:3", "6", ref left, ref right);


            int[] commcard = { 29, 45, 27, 21, 50, 30, 44 };
            int[] usercard = { 30, 44 };

            Array.Sort(commcard, delegate(int left1, int right1) {
                int leftScore  = GameReferee.GetPokerCardInfo(left1)[0];
                int rightScore = GameReferee.GetPokerCardInfo(right1)[0];
                return(leftScore.CompareTo(rightScore));
            });

            GameHandInfo gamehInfo = GameReferee.GetPokerCardScore(commcard, usercard);

            ibreak = 9;
        }
コード例 #2
0
ファイル: FBAPI.cs プロジェクト: psmon/webnori
        static public DBLoginInfo GetUserData(string accessToken)
        {
            DBLoginInfo resultValue = new DBLoginInfo();

            try
            {
                WebClient webclient   = new WebClient();
                string    URL         = string.Format("https://graph.facebook.com/v2.8/me?access_token={0}&fields=id%2Cname%2Cemail&format=json&method=get&pretty=0", accessToken);
                string    response    = webclient.DownloadString(URL);
                object    responseObj = new JavaScriptSerializer().DeserializeObject(response);
                IDictionary <string, object> root_payload = (IDictionary <string, object>)responseObj;
                foreach (string nodeKey in root_payload.Keys)
                {
                    if (nodeKey.Length > 1)
                    {
                        object nodeObj = root_payload[nodeKey];
                        if (nodeObj is String)
                        {
                            string value = nodeObj as String;

                            switch (nodeKey)
                            {
                            case "id":
                                resultValue.SocialID = value;
                                break;

                            case "name":
                                resultValue.Nick = value;
                                break;

                            case "email":
                                resultValue.Email = value;
                                break;
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                resultValue = null;
            }
            return(resultValue);
        }
コード例 #3
0
ファイル: ReflectionTest1.cs プロジェクト: zhoufengzd/DotNet
        public void SerializationTest()
        {
            bool testDictionary = false;
            bool testList       = true;

            if (testDictionary)
            {
                string dcFile = "dictionary.xml";
                Dictionary <int, string> td1 = new Dictionary <int, string>();
                td1.Add(1, "One");
                td1.Add(2, "Two");
                td1.Add(3, "Three");

                ObjSerializer.Save(dcFile, td1);

                Dictionary <int, string> td2 = ObjSerializer.Load <Dictionary <int, string> >(dcFile);
                foreach (int key in td1.Keys)
                {
                    Assert.IsTrue(td1[key] == td2[key]);
                }
            }

            if (testList)
            {
                string      lstFile = "list.xml";
                DBLoginInfo e1      = new DBLoginInfo();
                e1.ServerName = "(local)";
                List <KVPair <string, DBLoginInfo> > lst1 = new List <KVPair <string, DBLoginInfo> >();
                lst1.Add(new KVPair <string, DBLoginInfo>("(local)", e1));
                lst1.Sort();

                ObjSerializer.Save(lstFile, lst1);
                List <KVPair <string, DBLoginInfo> > lst2 = ObjSerializer.Load <List <KVPair <string, DBLoginInfo> > >(lstFile);
                lst2.Sort();
                foreach (KVPair <string, DBLoginInfo> item in lst1)
                {
                    Assert.IsTrue(lst2.Contains(item));
                }
            }
        }
コード例 #4
0
ファイル: MainForm.cs プロジェクト: zhoufengzd/DotNet
        /// <summary>
        /// Show connection dialog and return a valid datasource if succeeded.
        /// </summary>
        private IDataSource TryConnectDatasource(DBMSPlatformEnum dbmsEnum)
        {
            DBMSContext context = _instance.GetDBMSContext(dbmsEnum);
            DBLoginInfo login   = context.CreateDBLoginInfo();

            PropertyDlg       dlg         = new PropertyDlg("Connect to " + dbmsEnum.ToString());
            ObjValueLabelHint hint        = null;
            List <string>     dataSources = _instance.GetDataSources(dbmsEnum);

            if (dataSources != null && dataSources.Count > 0)
            {
                hint            = new ObjValueLabelHint();
                hint.ValueHints = new Dictionary <string, IEnumerable <string> >();
                hint.ValueHints.Add("DataSource", dataSources);
            }
            dlg.AddOption(login, hint);
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            IDataSource svr = context.CreateDatasource(login.ConnectionString);

            if (!svr.TestConnection())
            {
                MessageBoxEx.ShowError(svr.LastErrorMessage, "Connection Failed");
                return(null);
            }

            // Remember the connection
            Dictionary <string, string> connectionList = _instance.GetServerConnectionList(dbmsEnum);

            Macros.SafeAdd(connectionList, login.DataSource, login.ConnectionString);

            return(svr);
        }
コード例 #5
0
        public DBLoginInfo sp_validtoken(string _authtoken, int isUpdateLoginTime)
        {
            DBLoginInfo        resultValue = null;
            int                spError     = -1;
            List <DBREQ_PARAM> dbParams    = new List <DBREQ_PARAM>();

            dbParams.Add(new DBREQ_PARAM("_authtoken", DbType.String, _authtoken));
            dbParams.Add(new DBREQ_PARAM("isUpdateLoginTime", DbType.Int32, isUpdateLoginTime));
            DataTable result = RunSP("sp_validtoken", CreateDB(), dbParams);

            spError = result.Rows[0].Field <int>("Result");
            if (spError == 0)
            {
                resultValue            = new DBLoginInfo();
                resultValue.MemberID   = result.Rows[0].Field <int>("MemberID");
                resultValue.SocialType = result.Rows[0].Field <int>("SocialType");
                resultValue.SocialID   = result.Rows[0].Field <string>("SocialID");
                resultValue.Nick       = result.Rows[0].Field <string>("Nick");
                resultValue.PicUrl     = result.Rows[0].Field <string>("PicUrl");
                resultValue.Email      = result.Rows[0].Field <string>("Email");
                resultValue.Createtime = result.Rows[0].Field <int>("Createtime");
            }
            return(resultValue);
        }
コード例 #6
0
ファイル: LoginController.cs プロジェクト: psmon/webnori
        public LoginController()
        {
            parentSpace = "/api/login";
            dbhandler   = new DBLoginHandler(ConfigurationManager.AppSettings.Get("ConectionDBString"));

            Get["", true] = async(parameters, ct) => {
                //Default
                PageInfo pageInfo = new PageInfo();
                pageInfo.langcode = "ko_KR";
                pageInfo.langfile = string.Format("/js/lang/ko_KR.js");
                return(View["public/index.html", pageInfo]);
            };

            Get["/{langID}", true] = async(parameters, ct) => {
                PageInfo pageInfo = new PageInfo();
                pageInfo.langcode = parameters.langID;
                pageInfo.langfile = string.Format("/js/lang/{0}.js", parameters.langID);
                return(View["public/index.html", pageInfo]);
            };


            Post[parentSpace + "/createUser", true] = async(parameters, ct) =>
            {
                IDictionary <string, object> payload = GetPayLoad();
                int    socialType = (int)payload["socialType"];
                string socialID   = (string)payload["socialID"];
                string nickUtf8   = (string)payload["nick"];

                Encoding enc = new UTF32Encoding(true, true);
                //System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
                string nick = System.Net.WebUtility.UrlDecode(nickUtf8);
                //string picurl = (string)payload["picurl"];

                Random r         = new Random();
                int    imgNumber = r.Next(1, 72);
                string picurl    = String.Format("/img/avatar/default/avartar_{0:00}.png", imgNumber);

                string email = (string)payload["email"];
                string pw    = (string)payload["pw"];

                pw = Utils.DecryptStringAES(pw);
                pw = Utils.GetMD5Hash(pw);

                bool isValidEmail = true;
                if (socialType == 0)
                {
                    isValidEmail = isValidEmail && Utils.IsValidEmail(socialID);
                }
                ;
                isValidEmail = isValidEmail && Utils.IsValidEmail(email);
                if (!isValidEmail)
                {
                    return(new WebException("ApiError_InvalidEmail", (int)ErrorCode.ApiError_InvalidEmail));
                }

                int  createResult = -1;
                Task t            = Task.Run(() => {
                    createResult = dbhandler.sp_createuser(socialType, socialID, nick, picurl, email, pw);
                });
                await t;
                if (createResult != 0)
                {
                    return(new WebException("Create failed", createResult));
                }

                return(new WebOK());
            };

            Post[parentSpace + "/deleteUser", true] = async(parameters, ctor) =>
            {
                IDictionary <string, object> payload = GetPayLoad();
                string      authToken = (string)payload["authtoken"];
                DBLoginInfo loginInfo = null;

                Task taskCheckLogin = Task.Run(() => {
                    loginInfo = dbhandler.sp_validtoken(authToken, 1);
                });
                await taskCheckLogin;

                if (loginInfo == null)
                {
                    return(new WebException("Login failed", 401));
                }

                string firstID = loginInfo.SocialID.Split('@')[0].Substring(0, 5);
                if (firstID == "guest")
                {
                    return(new WebException("Cant't delete guest", 401));
                }

                int  deleteResult = -1;
                Task deleteUser   = Task.Run(() =>
                {
                    deleteResult = dbhandler.sp_deleteuser(loginInfo.SocialType, loginInfo.SocialID);
                });
                await deleteUser;

                if (deleteResult != 0)
                {
                    return(new WebException("Deleted failed", 500));
                }

                return(new WebOK());
            };

            Post[parentSpace + "/loginUser", true] = async(parameters, ct) =>
            {
                IDictionary <string, object> payload = GetPayLoad();
                int    socialType = (int)payload["socialType"];
                string socialID   = (string)payload["socialID"];
                string pw         = (string)payload["pw"];
                if (socialType != 0)
                {
                    return(new WebException("ApiError_NotAlow SocialLogin", 401));
                }
                pw = Utils.DecryptStringAES(pw);
                pw = Utils.GetMD5Hash(pw);

                bool isValidEmail = true;
                if (socialType == 0)
                {
                    isValidEmail = isValidEmail && Utils.IsValidEmail(socialID);
                }
                ;
                if (!isValidEmail)
                {
                    return(new WebException("ApiError_InvalidEmail", (int)ErrorCode.ApiError_InvalidEmail));
                }

                LoginOK result = null;
                Task    t      = Task.Run(() => {
                    result = dbhandler.sp_loginuser(socialType, socialID, pw);
                });
                await t;
                return(result);
            };

            Post[parentSpace + "/loginUserSocial", true] = async(parameters, ct) =>
            {
                IDictionary <string, object> payload = GetPayLoad();
                int    socialType = (int)payload["socialType"];
                string authToken  = (string)payload["authToken"];
                if (socialType == 0)
                {
                    return(new WebException("ApiError_NotAlow NormalLogin", 401));
                }
                LoginOK resultValue = new LoginOK();
                resultValue.statusCode = -401;

                //FB Mode
                if (socialType == 1)
                {
                    DBLoginInfo fbInfo = null;
                    Task        t      = Task.Run(() => {
                        fbInfo = FBAPI.GetUserData(authToken);
                    });
                    await  t;
                    Random r         = new Random();
                    int    imgNumber = r.Next(1, 72);
                    string picurl    = String.Format("/img/avatar/default/avartar_{0:00}.png", imgNumber);
                    if (fbInfo != null)
                    {
                        resultValue = dbhandler.sp_loginSocial(socialType, fbInfo.SocialID, fbInfo.Nick, picurl, fbInfo.Email);
                    }
                }
                return(resultValue);
            };

            Post[parentSpace + "/validate", true] = async(parameters, ct) =>
            {
                IDictionary <string, object> payload = GetPayLoad();
                string      authToken = (string)payload["authtoken"];
                DBLoginInfo loginInfo = null;

                Task t = Task.Run(() => {
                    loginInfo = dbhandler.sp_validtoken(authToken, 1);
                });
                await t;

                if (loginInfo == null)
                {
                    return(new WebException("Login failed", 401));
                }
                return(loginInfo.ToString());
            };

            Post["/test2/{id}/add/{category}"] = parameters => {
                return("post test");
            };
        }