Пример #1
0
        public static void Run(FMWW.Http.Client client, Uri address)
        {
            var text = "";

            while (!IsFin(text))
            {
                var resData = client.UploadValues(address, CreateAjaxQuery());
                text = Encoding.UTF8.GetString(resData);
                if (HasError(text))
                {
                    throw new Exception(SnipError(text));
                }
            }
        }
Пример #2
0
        public bool CanSignIn(FMWW.Http.Client client, string username, string password, string person, string personPassword)
        {
            var canSignIn = true;

            try
            {
                SignIn(client, username, password, person, personPassword);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
                canSignIn = false;
            }
            return(canSignIn);
        }
Пример #3
0
        public static string GetShopArrivalDate(FMWW.Http.Client client, string distribute)
        {
            var page = new Page(client)
            {
                PageContext = new FMWW.ScheduledArrival.DistributeExport.Ref.Context()
                {
                    Code = distribute
                }
            };

            page.Reach();
            var    html            = page.Csv();
            var    fields          = html.Split(new char[] { '\r', '\n' }).First().Split(',').ToArray();
            string shopArrivalDate = fields[3].Replace('-', '/');

            Debug.WriteLine(shopArrivalDate);
            return(shopArrivalDate);
        }
Пример #4
0
        private void Csv(Ref.Context context)
        {
            {
                var client = new FMWW.Http.Client()
                {
                    CookieContainer = new System.Net.CookieContainer()
                };
                var auth = new FMWW.Core.PC.Authentication();
                FMWW.Component.SignedInEventHandler onSignedIn = null;
                onSignedIn = new FMWW.Component.SignedInEventHandler(
                    (o, arg) =>
                {
                    auth.SignedIn -= onSignedIn;

                    var page = new Ref.Page(client)
                    {
                        PageContext = context
                    };

                    Action onReached = null;
                    onReached        = () =>
                    {
                        page.Reached -= onReached;
                        page.CsvAsync();
                    };
                    page.Reached += onReached;
                    page.ReachAsync();

                    Action <string> onCsvDownloadCompleted = null;
                    onCsvDownloadCompleted = (csv) =>
                    {
                        page.CsvDownloadCompleted -= onCsvDownloadCompleted;
                        Debug.WriteLine(csv);
                    };
                    page.CsvDownloadCompleted += onCsvDownloadCompleted;
                });
                auth.SignedIn += onSignedIn;
                //client.SignInAsync();
            }
        }
Пример #5
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);
        }
Пример #6
0
 public Page(FMWW.Http.Client client) : base(client)
 {
 }
Пример #7
0
 public Polling(FMWW.Http.Client client) : base(client)
 {
 }
Пример #8
0
 public ImportablePage(FMWW.Http.Client client) : base(client)
 {
 }
Пример #9
0
 public AbstractUploader(FMWW.Http.Client client) : base(client)
 {
 }
Пример #10
0
        private void Excel(Ref.Context context)
        {
            //        private static void DownloadProductsAsFile(string filename, Core.FMWW.ExternalInterface.Products.Ref.Context context)
            {
                var client = new FMWW.Http.Client()
                {
                    CookieContainer = new System.Net.CookieContainer()
                };
                var auth = new FMWW.Core.PC.Authentication();

                FMWW.Component.SignedInEventHandler onSignedIn = null;
                onSignedIn = new FMWW.Component.SignedInEventHandler(
                    (o, arg) =>
                {
                    auth.SignedIn -= onSignedIn;

                    var page = new Ref.Page(client)
                    {
                        PageContext = context
                    };
                    Action onReached = null;
                    onReached        = () =>
                    {
                        page.Reached -= onReached;
                        page.Search();
                    };
                    page.Reached += onReached;
                    page.ReachAsync();

                    Action <FMWW.Http.IPage> onGoneAway = null;
                    onGoneAway = (p) =>
                    {
                        // 検索結果一覧画面
                        page.GoneAway -= onGoneAway;
                        p.ExcelAsync();
                        Action <byte[]> onExcelDownloadCompleted = null;
                        onExcelDownloadCompleted = (b) =>
                        {
                            p.ExcelDownloadCompleted -= onExcelDownloadCompleted;
                            //                                        if ("gzip" == this.ResponseHeaders["Content-Encoding"])
                        };
                        p.ExcelDownloadCompleted += onExcelDownloadCompleted;
                    };
                    page.GoneAway += onGoneAway;

                    //                        System.Net.UploadValuesCompletedEventHandler onUploadValuesCompleted = null;
                    //                        onUploadValuesCompleted = (o, args) =>
                    //                            {
                    //                                client.UploadValuesCompleted -= onUploadValuesCompleted;
                    //                                var html = Encoding.UTF8.GetString(args.Result);
                    ////                                completed(html);
                    //                            };
                    //                        client.UploadValuesCompleted += onUploadValuesCompleted;
                    //                        client.UploadValuesAsync(UrlMainMenu, HttpMethod.Post, MainMenu.CreateDistributeExport().Translate());

                    //                        client.ExportDistributesAsync(context,
                    //                            (csv) =>
                    //                            {
                    //                                byte[] binary = client.DownloadProductMaster(context);
                    //                                using (var w = new BinaryWriter(File.OpenWrite(filename)))
                    //                                {
                    //                                    w.Write(binary);
                    //                                }
                    //                                Debug.WriteLine(csv);
                    //                                onCompleted(csv, userToken);
                    //                            });
                });
                auth.SignedIn += onSignedIn;
                //client.SignInAsync();
            }
        }
Пример #11
0
        public void SignIn(FMWW.Http.Client client, string username, string password, string person, string personPassword)
        {
            //            this.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
            Stream       data   = client.OpenRead(UrlToSignIn);
            StreamReader reader = new StreamReader(data, Encoding.UTF8);
            var          html   = reader.ReadToEnd();

            data.Close();
            reader.Close();

#if false
            //            var setCookie = this.ResponseHeaders[HttpResponseHeader.SetCookie];
            //            var cookies = System.Text.RegularExpressions.Regex.Split(setCookie, "(?<!expires=.{3}),")
            //    .Select(s => s.Split(';').First().Split('='))
            //    .Select(xs => new { Name = xs.First(), Value = string.Join("=", xs.Skip(1).ToArray()) })
            //    .Select(a => a.Name + "=" + a.Value)
            //    .ToArray();
            //            var cookie = string.Join(";", cookies);
            //            this.Headers[HttpRequestHeader.Cookie] = cookie;
#endif


            NameValueCollection form = BuildQueryToSignIn(html, username, password, person, personPassword);

            //            this.Headers.Add("User-Agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)");
            byte[] resData = client.UploadValues(UrlToSignIn, form);
            //            _html = System.Text.Encoding.GetEncoding("Shift_JIS").GetString(resData);
            html = Encoding.UTF8.GetString(resData);
            Debug.WriteLine(html);
            if (null == GetBtnLogOff(html))
            {
                throw new Exception();
            }

            /*
             *          this.OpenReadCompleted += (sender, e) =>
             *              {
             *                  if (e.Error != null)
             *                  {
             *                      // エラー処理
             *                  }
             *
             *                  var data = e.Result;
             *                  // Do Something
             *                  if (!(data is System.IO.Stream))
             *                  {
             *                      return;
             *                  }
             *                  if (!(sender is WebClient))
             *                  {
             *                      return;
             *                  }
             * //                    WebClient wc = sender as WebClient;
             *
             *                  foreach (string key in client.ResponseHeaders.Keys)
             *                  {
             *                      System.Diagnostics.Debug.WriteLine(String.Format(@"{0}:{1}", key, client.ResponseHeaders[key]));
             *                  }
             *
             *              };
             * */
        }
Пример #12
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);
        }
Пример #13
0
 public void SignIn(FMWW.Http.Client client, string person, string personPassword)
 {
     throw new NotImplementedException();
 }