Ejemplo n.º 1
0
        public void CreateApps(string prefix, int number, CreateAppsCallback callback) {
            var current = 0;
            var i = 0;

            NameValueCollection query = null;
            Action<bool, bool> next = null;

            next = new Action<bool, bool>((valid, retry) => {
                if (!retry) {
                    current++;
                }

                if (valid) {
                    i++;
                }

                if (i >= number) {
                    callback(true, i, null);
                    return;
                }

                var id = prefix + "-" + current;

                callback(false, i, id);

                CheckAppIdAvailability(id, (v) => {
                    if (v) {
                        query["app_id"] = id;
                        query["title"] = "GoAgent Server " + current;
                        query["tos_accept"] = "on";

                        var cl = new WebClientWithCookies();
                        cl.UploadValuesAsync(new Uri("https://appengine.google.com/start/createapp.do"), query);
                        cl.UploadValuesCompleted += (sender, e) => {
                            if (e.Error == null && Encoding.UTF8.GetString(e.Result).Contains("Application Registered Successfully")) {
                                next(true, false);
                            }
                            else {
                                next(true, true);
                            }
                        };
                    }
                    else {
                        next(false, false);
                    }
                });
            });

            Action prefetch = null;
            prefetch = new Action(() => {
                var client = new WebClientWithCookies();
                client.DownloadStringAsync(new Uri("https://appengine.google.com/start/createapp"));
                //client.DownloadStringAsync(new Uri("https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah"));
                client.DownloadStringCompleted += (sender, e) => {
                    if (e.Error == null && e.Result.Contains("IdvPhoneType()")) {
                        //var r = MessageBox.Show(resources["GaeBeforeVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);

                        //if (r == MessageBoxResult.OK) {
                        //    Process.Start("\"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Faccounts.google.com%2Fb%2F0%2FIdvChallenge%3FidvContinueHandler%3DSERVICE%26service%3Dah\"");
                        //    r = MessageBox.Show(resources["GaeAfterVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);

                        //    if (r == MessageBoxResult.OK) {
                        //        prefetch();
                        //    }
                        //    else {
                        //        callback(false, 0, null, true);
                        //    }
                        //}
                        //else {
                        //    callback(false, 0, null, true);
                        //}

                        sendVerifierQeury = initQuery(e.Result);
                        VerificationRequired(() => {
                            prefetch();
                        });
                    }
                    else {
                        query = initQuery(e.Result);
                        query["auth_config"] = "google";
                        next(false, false);
                    }
                };
            });

            prefetch();
        }
Ejemplo n.º 2
0
        public void CreateApps(string prefix, int number, CreateAppsCallback callback)
        {
            var current = 0;
            var i       = 0;

            NameValueCollection query = null;
            Action <bool, bool> next  = null;

            next = new Action <bool, bool>((valid, retry) => {
                if (!retry)
                {
                    current++;
                }

                if (valid)
                {
                    i++;
                }

                if (i >= number)
                {
                    callback(true, i, null);
                    return;
                }

                var id = prefix + "-" + current;

                callback(false, i, id);

                CheckAppIdAvailability(id, (v) => {
                    if (v)
                    {
                        query["app_id"]     = id;
                        query["title"]      = "GoAgent Server " + current;
                        query["tos_accept"] = "on";

                        var cl = new WebClientWithCookies();
                        cl.UploadValuesAsync(new Uri("https://appengine.google.com/start/createapp.do"), query);
                        cl.UploadValuesCompleted += (sender, e) => {
                            if (e.Error == null && Encoding.UTF8.GetString(e.Result).Contains("Application Registered Successfully"))
                            {
                                next(true, false);
                            }
                            else
                            {
                                next(true, true);
                            }
                        };
                    }
                    else
                    {
                        next(false, false);
                    }
                });
            });

            Action prefetch = null;

            prefetch = new Action(() => {
                var client = new WebClientWithCookies();
                client.DownloadStringAsync(new Uri("https://appengine.google.com/start/createapp"));
                //client.DownloadStringAsync(new Uri("https://accounts.google.com/b/0/IdvChallenge?idvContinueHandler=SERVICE&service=ah"));
                client.DownloadStringCompleted += (sender, e) => {
                    if (e.Error == null && e.Result.Contains("IdvPhoneType()"))
                    {
                        //var r = MessageBox.Show(resources["GaeBeforeVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);

                        //if (r == MessageBoxResult.OK) {
                        //    Process.Start("\"https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Faccounts.google.com%2Fb%2F0%2FIdvChallenge%3FidvContinueHandler%3DSERVICE%26service%3Dah\"");
                        //    r = MessageBox.Show(resources["GaeAfterVerifyMessage"] as string, resources["XWall"] as string, MessageBoxButton.OKCancel);

                        //    if (r == MessageBoxResult.OK) {
                        //        prefetch();
                        //    }
                        //    else {
                        //        callback(false, 0, null, true);
                        //    }
                        //}
                        //else {
                        //    callback(false, 0, null, true);
                        //}

                        sendVerifierQeury = initQuery(e.Result);
                        VerificationRequired(() => {
                            prefetch();
                        });
                    }
                    else
                    {
                        query = initQuery(e.Result);
                        query["auth_config"] = "google";
                        next(false, false);
                    }
                };
            });

            prefetch();
        }