示例#1
0
 static void f_es(myPaserResult res, myToken tk)
 {
     res.count++;
     res.arr.Add(res.gerCurObj());
     res.curObj.iCur++;
     //res.fields.Add(res.curObj);
 }
示例#2
0
 static void f_ss(myPaserResult res, myToken tk)
 {
     res.count++;
     res.arr.Add("");
     res.curObj.iStart = ++res.curObj.iCur;
     //res.fields.Add(res.curObj); //to debug
 }
示例#3
0
        static myPaserResult myparser2(string line)
        {
            //state table
            //state |token
            //      |,      |"      |other
            //------+-------+-------+------
            //s     |s      |a      |e
            //a     |a      |b      |a
            //b     |s      |a      |invalid
            //e     |s      |invalid|e
            myPaserResult res    = new myPaserResult();
            myState       cur    = myState.s;
            myState       nState = myState.s;

            foreach (char c in line)
            {
                myToken tk = new myToken(c);
                cur    = nState;
                nState = tbl[(int)cur, (int)tk.type];
                if (nState == myState.invalid)
                {
                    break;
                }
                myRule cb = clbTbl[(int)cur, (int)tk.type];
                cb(res, tk);
            }

            //case eol
            return(res);
        }
示例#4
0
        static myPaserResult myparser2(string line)
        {
            //state table
            //state |token
            //      |,      |"      |other
            //------+-------+-------+------
            //s     |s      |a      |e
            //a     |a      |b      |a
            //b     |s      |a      |invalid
            //e     |s      |invalid|e
            myPaserResult res    = new myPaserResult(line);
            myState       cur    = myState.s;
            myState       nState = myState.s;

            foreach (char c in line)
            {
                myTkType type;
#if false
                myToken tk = new myToken(c);
                type = tk.type;
#else
                switch (c)
                {
                case '"':
                    type = myTkType.t_dblq;
                    break;

                case ',':
                    type = myTkType.t_comma;
                    break;

                default:
                    type = myTkType.t_other;
                    break;
                }
#endif
                cur    = nState;
                nState = tbl[(int)cur, (int)type];
                if (nState == myState.invalid)
                {
                    break;
                }
                myRule cb = clbTbl[(int)cur, (int)type];
                cb(res, null);
            }

            //case eol
            return(res);
        }
示例#5
0
 static void f_zz(myPaserResult res, myToken tk)
 {
     res.curObj.iCur++;
 }
示例#6
0
 static void f_se(myPaserResult res, myToken tk)
 {
     res.curObj.iStart = res.curObj.iCur++;
 }
示例#7
0
 static void f_en(myPaserResult res, myToken tk)
 {
     res.arr.Add(res.gerCurObj());
 }
示例#8
0
 static void f_ba(myPaserResult res, myToken tk)
 {
     res.curObj.iCur += 2;
     res.curObj.dblQt = true;
 }
示例#9
0
 static void f_sa(myPaserResult res, myToken tk)
 {
     res.curObj.iStart = ++res.curObj.iCur;
 }
示例#10
0
 static void f_01(myPaserResult res, myToken tk)
 {
 }
示例#11
0
        static void myparser(string line)
        {
            Stack <myState> sStack = new Stack <myState>();
            Stack <myToken> tStack = new Stack <myToken>();
            //rule
            //-----------------------------
            //s->space s    //trim - not use
            //s->,s         //empty
            //s->"a
            //a->other a
            //a->space a
            //a->,a
            //a->"b
            //b->,s
            //b->"a
            //s->other e
            //e->other e
            //e->,s
            //------------------------------
            myState cur;
            myState nState = myState.s;

            //sStack.Push(myState.s);
            foreach (char c in line)
            {
                myToken tk = new myToken(c);
                cur    = nState;
                nState = myState.invalid;
                switch (cur)
                {
                case myState.s:
                    if (tk.type == myTkType.t_comma)
                    {
                        nState = myState.s;
                    }
                    //else if (tk.type == myTkType.t_spec) nState = myState.s;
                    else if (tk.type == myTkType.t_dblq)
                    {
                        nState = myState.a;
                    }
                    else if (tk.type == myTkType.t_other)
                    {
                        nState = myState.e;
                    }
                    break;

                case myState.a:
                    if (tk.type == myTkType.t_dblq)
                    {
                        nState = myState.b;
                    }
                    else
                    {
                        nState = myState.a;
                    }
                    break;

                case myState.b:
                    if (tk.type == myTkType.t_comma)
                    {
                        nState = myState.s;
                    }
                    else if (tk.type == myTkType.t_dblq)
                    {
                        nState = myState.a;
                    }
                    break;

                case myState.e:
                    if (tk.type == myTkType.t_other)
                    {
                        nState = myState.e;
                    }
                    else if (tk.type == myTkType.t_comma)
                    {
                        nState = myState.s;
                    }
                    break;
                }
                if (nState == myState.invalid)
                {
                    break;
                }
            }
        }
示例#12
0
 static void f_ba(myPaserResult res, myToken tk)
 {
     res.curObj += "\"";
 }
示例#13
0
 static void f_bs(myPaserResult res, myToken tk)
 {
     res.count++;
     res.arr.Add(res.curObj);
 }
示例#14
0
 static void f_aa(myPaserResult res, myToken tk)
 {
     res.curObj += tk;
 }
示例#15
0
 static void f_ss(myPaserResult res, myToken tk)
 {
     res.count++;
     res.arr.Add("");
 }
示例#16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=757082555011.apps.googleusercontent.com&redirect_uri=http://spindate.comstar.co.il/getgoogle.aspx&scope=profile";

        try
        {
            if (Request.QueryString["code"] == null)
            {
                Response.Redirect("https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=757082555011.apps.googleusercontent.com&redirect_uri=http://spindate.comstar.co.il/getgoogle.aspx&scope=https://www.googleapis.com/auth/userinfo.email");
            }
            else
            {
                string myurl = "https://accounts.google.com/o/oauth2/token";

                string postData = "code=" + Request.QueryString["code"] + "&client_id=757082555011.apps.googleusercontent.com&client_secret=DNPSpf5EGaDWMUQw9uK4i4m2&redirect_uri=" + Server.UrlEncode("http://spindate.comstar.co.il/getgoogle.aspx") + "&grant_type=authorization_code";

                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(myurl);
                webRequest.Method        = "POST";
                webRequest.ContentType   = "application/x-www-form-urlencoded";
                webRequest.ContentLength = postData.Length;

                using (StreamWriter requestWriter2 = new StreamWriter(webRequest.GetRequestStream()))
                {
                    requestWriter2.Write(postData);
                }

                //  This actually does the request and gets the response back

                HttpWebResponse resp = (HttpWebResponse)webRequest.GetResponse();

                string responseData = string.Empty;

                using (StreamReader responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream()))
                {
                    // dumps the HTML from the response into a string variable
                    responseData = responseReader.ReadToEnd();
                }

                //  Now, find the index of some word on the page that would be
                //     displayed if the login was successful

                System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();//creating a JSON deserializer JSON.
                myToken myToken1 = serializer.Deserialize <myToken>(responseData);

                //string accessToken = responseData.Replace("access_token=", "");
                bla.Text += myToken1.access_token;
                string       accessToken = myToken1.access_token;
                StreamReader MyStream;
                webRequest             = (HttpWebRequest)System.Net.WebRequest.Create("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + accessToken); //setting an httpWebRequest with the URL of the API
                webRequest.Method      = "GET";                                                                                                                     //the type of method the API returns
                webRequest.Timeout     = 20000;                                                                                                                     //sets the timeout for thew request
                webRequest.ContentType = "application/x-www-form-urlencoded";                                                                                       //the content type. most of the times it will be application/x-www-form-urlencoded
                MyStream     = new StreamReader(webRequest.GetResponse().GetResponseStream());                                                                      //creating a stream reader to read the results from the API
                responseData = MyStream.ReadToEnd();                                                                                                                //reading the result from the API into a string


                serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); //creating a JSON deserializer JSON.
                userinfo FriendsArr = serializer.Deserialize <userinfo>(responseData);   //De-serealization of the string into an array of pre-defined objects

                bla.Text += "<br />" + FriendsArr.email + " " + FriendsArr.name + " " + FriendsArr.verified_email + " " + FriendsArr.gender;
            }
        }
        catch (Exception ex)
        {
            bla.Text = ex.Message;
        }
    }