Ejemplo n.º 1
0
        private void init(string baseUrl, string rootPath, string appPath)
        {
            this.RootPath = rootPath.NormalizePath();
            this.AppPath  = appPath.NormalizePath();
            this.TmpPath  = this.AppPath + "\\temp";

            Directory.CreateDirectory(appPath);

            wc       = new WebClient();
            wc.Proxy = null;
            wc.UseDefaultCredentials = false;
            wc.Credentials           = null;

            wc.BaseAddress = baseUrl;
            if (!wc.BaseAddress.EndsWith("/"))
            {
                wc.BaseAddress += "/";
            }

            if (File.Exists(appPath + "\\auth"))
            {
                var x = System.IO.File.ReadAllText(appPath + "\\auth").Split(new char[] { ':' }, 2);
                Authorize(x[0], x[1]);
            }
            AuthPolicy = Policy
                         .Handle <WebException>((wex) =>
                                                wex.Response is HttpWebResponse &&
                                                (wex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
                         .RetryForever(ex =>
            {
                App.Current.Dispatcher.Invoke(() =>
                {
                    var lw = new LoginWindow(this).ShowDialog();
                    if (!lw.Value)
                    {
                        Application.Current.Shutdown();
                        return;
                    }
                });
            });
        }
Ejemplo n.º 2
0
        private void init(string baseUrl, string rootPath, string appPath)
        {
            this.RootPath = rootPath.NormalizePath();
            this.AppPath = appPath.NormalizePath();
            this.TmpPath = this.AppPath + "\\temp";

            Directory.CreateDirectory(appPath);

            wc = new WebClient();
            wc.Proxy = null;
            wc.UseDefaultCredentials = false;
            wc.Credentials = null;

            wc.BaseAddress = baseUrl;
            if (!wc.BaseAddress.EndsWith("/")) wc.BaseAddress += "/";

            if (File.Exists(appPath + "\\auth"))
            {
                var x = System.IO.File.ReadAllText(appPath + "\\auth").Split(new char[] { ':' }, 2);
                Authorize(x[0], x[1]);
            }
            AuthPolicy = Policy
                .Handle<WebException>((wex) =>
                    wex.Response is HttpWebResponse &&
                    (wex.Response as HttpWebResponse).StatusCode == HttpStatusCode.Unauthorized)
                .RetryForever(ex =>
                {
                    App.Current.Dispatcher.Invoke(() =>
                    {
                        var lw = new LoginWindow(this).ShowDialog();
                        if (!lw.Value)
                        {
                            Application.Current.Shutdown();
                            return;
                        }
                    });
                });
        }