Exemplo n.º 1
0
        public void SignInAsync(FMWW.Http.Client client, string username, string password, string person, string personPassword, object userToken = default(object))
        {
            var onUploadValuesCompleted = new Action <object, UploadValuesCompletedEventArgs>(
                (o, args) =>
            {
                client.UploadValuesCompleted -= new UploadValuesCompletedEventHandler((Action <object, UploadValuesCompletedEventArgs>)args.UserState);
                var html = Encoding.UTF8.GetString(args.Result);
                var a    = new SignedInEventArgs(args.Error, args.Cancelled, userToken);
                //completedEventHandler(html);
                if (null == GetBtnLogOff(html))
                {
                    a = new SignedInEventArgs(new Exception(), args.Cancelled, userToken);
                }
                // ログイン成功
                OnSignedIn(a);
            });

            var onOpenReadCompleted = new Action <object, OpenReadCompletedEventArgs>(
                (o, args) =>
            {
                client.OpenReadCompleted -= new OpenReadCompletedEventHandler((Action <object, OpenReadCompletedEventArgs>)args.UserState);
                Stream data         = args.Result;
                StreamReader reader = new StreamReader(data, Encoding.UTF8);
                var html            = reader.ReadToEnd();
                data.Close();
                reader.Close();

                client.UploadValuesAsync(UrlToSignIn, Http.Method.Post,
                                         BuildQueryToSignIn(html, username, password, person, personPassword),
                                         onUploadValuesCompleted);
            });

            client.UploadValuesCompleted += new UploadValuesCompletedEventHandler(onUploadValuesCompleted);
            client.OpenReadCompleted     += new OpenReadCompletedEventHandler(onOpenReadCompleted);
            client.OpenReadAsync(UrlToSignIn, onOpenReadCompleted);
        }
Exemplo n.º 2
0
        public void SignInAsync(FMWW.Http.Client client, string person, string personPassword, object userToken = default(object))
        {
            UploadValuesCompletedEventHandler onUploadValuesCompleted1 = null;

            onUploadValuesCompleted1 = new UploadValuesCompletedEventHandler(
                (o, args) =>
            {
                client.UploadValuesCompleted -= onUploadValuesCompleted1;
                var html = Encoding.UTF8.GetString(args.Result);
                //if (null != GetBtnLogOff(html))
                {
                    // ログイン成功
                    OnSignedIn(new SignedInEventArgs(args.Error, args.Cancelled, userToken));
                }
            });

            UploadValuesCompletedEventHandler onUploadValuesCompleted = null;

            onUploadValuesCompleted = new UploadValuesCompletedEventHandler(
                (o, args) =>
            {
                client.UploadValuesCompleted -= onUploadValuesCompleted;
                var html = Encoding.UTF8.GetString(args.Result);
                if (!Core.PC.Authentication.CanClickLogOff(html))
                {
                    // ログイン失敗
                    return;
                }
                // ログイン成功
                client.UploadValuesCompleted += onUploadValuesCompleted1;
                client.UploadValuesAsync(MainMenu.Url, MainMenuFactory.CreateInstance().Translate());
            });

            OpenReadCompletedEventHandler onOpenReadCompleted = null;

            onOpenReadCompleted = new OpenReadCompletedEventHandler(
                (o, args) =>
            {
                client.OpenReadCompleted -= onOpenReadCompleted;

                using (var reader = new StreamReader(args.Result, ShiftJIS))
                {
                    var html = reader.ReadToEnd();
                    #region HTMLに埋め込まれた、ユーザ名とパスワードを取得
                    Func <string, string, string> f = (ax, id) =>
                    {
                        if (!String.IsNullOrEmpty(ax))
                        {
                            return(ax);
                        }
                        var input = (new FMWW.Http.HTMLParser(html)).Document.getElementById(id);
                        if (input == null)
                        {
                            return(ax);
                        }
                        return(input.getAttribute("value"));
                    };
                    var userName = ClientQueryNames.Aggregate(String.Empty, f);
                    var password = PasswordQueryNames.Aggregate(String.Empty, f);
                    #endregion
                    client.UploadValuesCompleted += onUploadValuesCompleted;
                    client.UploadValuesAsync(UrlToSignIn, Core.PC.Authentication.BuildQueryToSignIn(html, userName, password, person, personPassword));
                }
            });

            client.OpenReadCompleted += onOpenReadCompleted;
            client.OpenReadAsync(UrlToSignIn, onOpenReadCompleted);
        }