Пример #1
0
        public CasinoService()
        {
            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(CasinoUrls.Base);
            _http = new Http.Http(httpClient);
        }
Пример #2
0
        public BsonDocument ExecutePostCommand(string requestPath, string content = null)
        {
            Connect();
            string url = __url + requestPath;

            if (__trace)
            {
                pb.Trace.WriteLine("DebriderDebridLink.ExecutePostCommand() :");
            }
            HttpRequestParameters requestParameters = new HttpRequestParameters {
                Encoding = Encoding.UTF8
            };
            StringBuilder contentBuilder = new StringBuilder();

            contentBuilder.AppendFormat("token={0}", _connexion.Token);

            int timestamp = GetServerTimestamp();

            // test de décalage du timestamp
            //timestamp -= 15;  // KO avec -15 ou +15
            //if (__trace)
            //    pb.Trace.WriteLine("  server time + 60 sec        : {0}", zdate.UnixTimeStampToDateTime(timestamp));

            contentBuilder.AppendFormat("&sign={0}", GetSignature(_connexion.Key, timestamp, requestPath));
            if (content != null)
            {
                contentBuilder.Append('&');
                contentBuilder.Append(content);
            }
            contentBuilder.AppendFormat("&ts={0}", timestamp);
            if (__trace)
            {
                pb.Trace.WriteLine("  content                     : \"{0}\"", contentBuilder.ToString());
            }
            DateTime dt = DateTime.Now;

            Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url, Method = HttpRequestMethod.Post, Content = contentBuilder.ToString()
            }, requestParameters);
            BsonDocument result = BsonDocument.Parse(http.ResultText);
            //if (__trace)
            //{
            int      newTimestamp     = result.zGet("ts").zAsInt();
            DateTime newServerTime    = zdate.UnixTimeStampToDateTime(newTimestamp);
            TimeSpan newServerTimeGap = newServerTime - dt;

            // gap gap {2}    newServerTimeGap - _connexion.ServerTimeGap
            pb.Trace.WriteLine("  new server time             : {0} gap {1} timestamp {2} timestamp gap {3}", newServerTime, newServerTimeGap, newTimestamp, timestamp - newTimestamp);
            //}
            if (__trace)
            {
                pb.Trace.WriteLine("  result                      :");
                pb.Trace.WriteLine(result.zToJson());
            }
            return(result);
        }
Пример #3
0
        private DebridLinkFrRequestResult GetNewToken()
        {
            // request : https://debrid-link.fr/api/token/:publickey/new
            // result  :
            //{
            //  "result":"OK",
            //  "value":
            //  {
            //    "token":"10_2d600afa935e73e12898abac9ff075673c20625d99452393",
            //    "validTokenUrl":"https:\/\/debrid-link.fr\/user\/10_2d600afa935e73e12898abac9ff075673c20625d99452393\/login",
            //    "key":"sQ0bhf6k2A3yav5I"
            //  },
            //  "ts":1458902940
            //}

            string       url         = __url + string.Format("/token/{0}/new", _publicKey);
            DateTime     requestTime = DateTime.Now;
            BsonDocument result      = null;
            Exception    ex          = null;

            try
            {
                Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                    Url = url
                }, _requestParameters);
                result = BsonSerializer.Deserialize <BsonDocument>(http.ResultText);
            }
            catch (Exception ex2)
            {
                ex = ex2;
                throw;
            }
            finally
            {
                if (_traceData != null)
                {
                    _traceData.Trace(new BsonDocument {
                        { "Category", "DebridLinkFr_v2" }, { "Ope", "GetNewToken" }, { "Key", "HttpRequest" }, { "Data", new BsonDocument {
                                                                                                                     { "Url", url }, { "Result", result }
                                                                                                                 } }
                    }, ex);
                }
                if (__trace)
                {
                    pb.Trace.WriteLine("  get new token               : \"{0}\"", url);
                    pb.Trace.WriteLine("  result                      :");
                    pb.Trace.WriteLine(result.zToJson());
                }
            }

            return(new DebridLinkFrRequestResult {
                RequestTime = requestTime, Result = result
            });
        }
Пример #4
0
        public async Task DeleteThreaded()
        {
            var http = new Http.Http(new Uri(Endpoint));

            var thisHappened = false;

            http.Delete("test/delete", (response) =>
            {
                Assert.AreEqual(HttpStatusCode.OK, response.code);
                Assert.AreEqual("OK", response.body);
                thisHappened = true;
            });

            http.TestWait(5000);
            Assert.IsTrue(thisHappened);
        }
Пример #5
0
        public async Task PatchThreaded()
        {
            var http = new Http.Http(new Uri(Endpoint));

            var thisHappened = false;

            http.Patch("test/echo", "{\"hello\": \"world\"}", (response) =>
            {
                Assert.AreEqual(HttpStatusCode.OK, response.code);
                Assert.AreEqual("{\"hello\":\"world\"}", response.body);
                thisHappened = true;
            });

            http.TestWait(5000);
            Assert.IsTrue(thisHappened);
        }
Пример #6
0
        public async Task GetThreaded()
        {
            var http = new Http.Http(new Uri(Endpoint));

            var thisHappened = false;

            http.Get("test/hello", (response) =>
            {
                Assert.AreEqual(HttpStatusCode.OK, response.code);
                Assert.AreEqual("Hello World!", response.body);
                thisHappened = true;
            });

            http.TestWait(5000);
            Assert.IsTrue(thisHappened);
        }
Пример #7
0
        public async Task PassCookieAuthThreaded()
        {
            var http = new Http.Http(new Uri(Endpoint));

            var thisHappened = false;

            http.AddCookie(new Cookie("auth", "secret-auth-token"));

            http.Get("test/auth/cookie", (response) =>
            {
                Assert.AreEqual(HttpStatusCode.OK, response.code);
                Assert.AreEqual("Hello World!", response.body);
                thisHappened = true;
            });

            http.TestWait(5000);
            Assert.IsTrue(thisHappened);
        }
Пример #8
0
        public async Task PassBasicAuthThreaded()
        {
            var http = new Http.Http(new Uri(Endpoint));

            var username = "******";
            var password = "******";

            http.AddBasicAuth(username, password);

            var thisHappened = false;

            http.Get("test/auth/basic", (response) =>
            {
                Assert.AreEqual(HttpStatusCode.OK, response.code);
                Assert.AreEqual("Hello World!", response.body);
                thisHappened = true;
            });

            http.TestWait(5000);
            Assert.IsTrue(thisHappened);
        }
Пример #9
0
        public BsonDocument ExecuteGetCommand(string requestPath)
        {
            string url = __url + requestPath;

            if (__trace)
            {
                pb.Trace.WriteLine("DebriderDebridLink.ExecuteGetCommand() :");
            }
            HttpRequestParameters requestParameters = new HttpRequestParameters {
                Encoding = Encoding.UTF8
            };

            Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url
            }, requestParameters);
            BsonDocument result = BsonDocument.Parse(http.ResultText);

            if (__trace)
            {
                pb.Trace.WriteLine("  result                      :");
                pb.Trace.WriteLine(result.zToJson());
            }
            return(result);
        }
Пример #10
0
        private void _Login(string url)
        {
            // https://debrid-link.fr/user/2_21c744ba958f13fac08ee5c8855f72ab9a3b3e3224789126/login
            Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url
            }, _requestParameters);
            XXElement xeSource = HttpManager.CurrentHttpManager.GetXDocument(http).zXXElement();

            string    loginUrl = __loginUrl;
            XXElement xeForm   = xeSource.XPathElement("//form");

            string action = xeForm.AttribValue("action");

            if (action != null && action != "")
            {
                loginUrl = action;
            }

            string            method     = xeForm.AttribValue("method");
            HttpRequestMethod httpMethod = HttpRequestMethod.Get;

            if (method != null && method != "")
            {
                httpMethod = HttpTools.GetHttpRequestMethod(method);
            }

            StringBuilder content = new StringBuilder();
            bool          first = true;
            string        name, value;

            foreach (XXElement xe in xeForm.DescendantFormItems())
            {
                name = xe.AttribValue("name");
                if (name == null)
                {
                    continue;
                }
                if (name == "user")
                {
                    value = _login;
                }
                else if (name == "password")
                {
                    value = _password;
                }
                //else if (name == "sessidTime")
                //    value = GetConnexionLifetime(_connexionLifetime);
                else
                {
                    value = xe.AttribValue("value");
                }
                if (!first)
                {
                    content.Append('&');
                }
                content.AppendFormat("{0}={1}", name, value);
                if (__trace)
                {
                    if (name != "password")
                    {
                        pb.Trace.WriteLine("  {0}={1}", name, value);
                    }
                    else
                    {
                        pb.Trace.WriteLine("  {0}=xxx", name);
                    }
                }
                first = false;
            }

            if (__trace)
            {
                pb.Trace.WriteLine("  form login url              : \"{0}\"", loginUrl);
                pb.Trace.WriteLine("  form action                 : \"{0}\"", action);
                pb.Trace.WriteLine("  form method                 : {0}", httpMethod);
                //pb.Trace.WriteLine("  form values                 : {0}", content.ToString());
            }

            http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = loginUrl, Method = httpMethod, Content = content.ToString()
            }, _requestParameters);

            xeSource = http.zGetXDocument().zXXElement();
            //<div class="alert alert-success">
            XXElement xeLogin = xeSource.XPathElement("//div[@class='alert alert-success']");

            if (xeLogin.XElement == null)
            {
                throw new PBException("can't login to debrid-link.fr");
            }
        }
Пример #11
0
        public BsonDocument ExecuteCommand(string requestPath, HttpRequestMethod method, string content = null)
        {
            // from https://debrid-link.fr/api_doc/#/home
            // URL : https://debrid-link.fr/api/account/infos
            // X-DL-TOKEN : 10_d82555567e30c1e7137828eee6bf35429706d27e43319312
            // X-DL-SIGN : ab90fa6a2c9f1bc2bbd7988ff266971b5c10583c
            // X-DL-TS : 1418758917
            // Sign decoded : 1418758917/account/infosi619yOI4Kt8WB02g

            Connect();
            string url = __url + requestPath;

            if (__trace)
            {
                pb.Trace.WriteLine("DebriderDebridLink.ExecuteGetCommand() :");
            }
            //HttpRequestParameters requestParameters = new HttpRequestParameters { Encoding = Encoding.UTF8 };

            // test de décalage du timestamp
            //timestamp -= 15;  // KO avec -15 ou +15
            //if (__trace)
            //    pb.Trace.WriteLine("  server time + 60 sec        : {0}", zdate.UnixTimeStampToDateTime(timestamp));
            int    timestamp = GetServerTimestamp();
            string signature = GetSignature(timestamp, requestPath, _connexion.Key);

            // set token, signature and timestamp as param in url
            //StringBuilder paramBuilder = new StringBuilder();
            //paramBuilder.Append('?');
            //paramBuilder.AppendFormat("x-dl-token={0}", _connexion.Token);
            //paramBuilder.AppendFormat("&x-dl-sign={0}", signature);
            //paramBuilder.AppendFormat("&x-dl-ts={0}", timestamp);
            //url += paramBuilder.ToString();

            // set token, signature and timestamp as headers of http request
            _authenticateRequestParameters.Headers["x-dl-token"] = _connexion.Token;
            _authenticateRequestParameters.Headers["x-dl-sign"]  = signature;
            _authenticateRequestParameters.Headers["x-dl-ts"]    = timestamp.ToString();

            if (__trace)
            {
                pb.Trace.WriteLine("  http method                 : {0}", method);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-token", _authenticateRequestParameters.Headers["x-dl-token"]);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-sign", _authenticateRequestParameters.Headers["x-dl-sign"]);
                pb.Trace.WriteLine("  http header                 : \"{0}\" = \"{1}\"", "x-dl-ts", _authenticateRequestParameters.Headers["x-dl-ts"]);
                if (content != null)
                {
                    pb.Trace.WriteLine("  http content                : \"{0}\"", content);
                }
            }

            DateTime dt = DateTime.Now;

            Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url, Method = method, Content = content
            }, _authenticateRequestParameters);

            BsonDocument result = BsonDocument.Parse(http.ResultText);

            //if (__trace)
            //{
            int      newTimestamp     = result.zGet("ts").zAsInt();
            DateTime newServerTime    = zdate.UnixTimeStampToDateTime(newTimestamp);
            TimeSpan newServerTimeGap = newServerTime - dt;

            // gap gap {2}    newServerTimeGap - _connexion.ServerTimeGap
            pb.Trace.WriteLine("  new server time             : {0} gap {1} timestamp {2} timestamp gap {3}", newServerTime, newServerTimeGap, newTimestamp, timestamp - newTimestamp);
            //}

            //if (__trace)
            //{
            //    pb.Trace.WriteLine("  result                      :");
            //    pb.Trace.WriteLine(result.zToJson());
            //}
            return(result);
        }
Пример #12
0
        public static void Test_Connexion_01()
        {
            string exportDirectory = @"c:\pib\drive\google\dev_data\exe\runsource\download\sites\debrid-link.fr\model\login\new";

            bool trace = DebridLinkFr_v2.Trace;

            DebridLinkFr_v2.Trace = false;

            Trace.WriteLine("test connexion to debrid-link.fr");
            Trace.WriteLine("  export directory      : \"{0}\"", exportDirectory);

            XmlConfig localConfig = GetLocalConfig();

            string publicKey = localConfig.GetExplicit("DownloadAutomateManager/DebridLink/PublicKey");

            Trace.WriteLine("  publicKey             : \"{0}\"", publicKey);
            Trace.WriteLine();

            string newTokenUrl = string.Format("https://debrid-link.fr/api/token/{0}/new", publicKey);
            string exportFile  = "01_debrid-link.fr_api_new_token.txt";

            Trace.WriteLine("  get new token key     : \"{0}\"", newTokenUrl);
            Trace.WriteLine("  export to file        : \"{0}\"", exportFile);
            DateTime requestTime = DateTime.Now;

            Http.Http http = Http.Http.LoadAsText(new HttpRequest {
                Url = newTokenUrl
            }, exportFile: zPath.Combine(exportDirectory, exportFile));
            BsonDocument result        = BsonDocument.Parse(http.ResultText);
            int          serverTs      = result.zGet("ts").zAsInt();
            DateTime     serverTime    = zdate.UnixTimeStampToDateTime(serverTs);
            TimeSpan     serverTimeGap = serverTime - requestTime;

            Trace.WriteLine("  server time           : request time {0} server timestamp {1} server time {2} gap {3}", requestTime, serverTs, serverTime, serverTimeGap);
            Trace.WriteLine("  result                :");
            Trace.WriteLine(result.zToJson());
            Trace.WriteLine();

            string validTokenUrl = result.zGet("value.validTokenUrl").zAsString();

            exportFile = "02_debrid-link.fr_api_valid_token.html";
            Trace.WriteLine("  load valid token url  : \"{0}\"", validTokenUrl);
            Trace.WriteLine("  export to file        : \"{0}\"", exportFile);
            HttpRequestParameters httpRequestParameters = new HttpRequestParameters {
                Encoding = Encoding.UTF8
            };

            http = Http.Http.LoadAsText(new HttpRequest {
                Url = validTokenUrl
            }, httpRequestParameters, exportFile: zPath.Combine(exportDirectory, exportFile));
            Trace.WriteLine();

            string loginUrl = "https://debrid-link.fr/login";

            exportFile = "03_debrid-link.fr_login.html";
            Trace.WriteLine("  send login info       : \"{0}\"", loginUrl);
            Trace.WriteLine("  export to file        : \"{0}\"", exportFile);
            string content      = string.Format("user={0}&password={1}&understand=true", localConfig.GetExplicit("DownloadAutomateManager/DebridLink/Login"), localConfig.GetExplicit("DownloadAutomateManager/DebridLink/Password"));
            string traceContent = string.Format("user={0}&password={1}&understand=true", "xxxxxx", "xxxxxx");

            Trace.WriteLine("  content               : \"{0}\"", traceContent);
            http = Http.Http.LoadAsText(new HttpRequest {
                Url = loginUrl, Method = HttpRequestMethod.Post, Content = content
            }, httpRequestParameters, exportFile: zPath.Combine(exportDirectory, exportFile));
            Trace.WriteLine();

            XXElement xe = http.zGetXDocument().zXXElement();

            //<div class="alert alert-success">
            xe = xe.XPathElement("//div[@class='alert alert-success']");
            Trace.WriteLine("  verify login          : {0}", xe.XElement != null ? "login ok" : "login error");
            Trace.WriteLine();

            string request    = "/account/infos";
            string urlRequest = "https://debrid-link.fr/api" + request;

            exportFile = "04_debrid-link.fr_account_infos.txt";
            Trace.WriteLine("  get account infos     : \"{0}\"", urlRequest);
            Trace.WriteLine("  export to file        : \"{0}\"", exportFile);
            string   key       = result.zGet("value.key").zAsString();
            DateTime time      = DateTime.Now + serverTimeGap;
            int      timestamp = zdate.DateTimeToUnixTimeStamp(time);
            string   signature = DebridLinkFr_v2.GetSignature(timestamp, request, key);

            Trace.WriteLine("  signature             : timestamp {0} request \"{1}\" key \"{2}\" signature \"{3}\"", timestamp, request, key, signature);
            string token = result.zGet("value.token").zAsString();

            httpRequestParameters = new HttpRequestParameters {
                Encoding = Encoding.UTF8
            };
            httpRequestParameters.Headers["x-dl-token"] = token;
            httpRequestParameters.Headers["x-dl-sign"]  = signature;
            httpRequestParameters.Headers["x-dl-ts"]    = timestamp.ToString();
            Trace.WriteLine("  set header            : \"{0}\" = \"{1}\"", "x-dl-token", token);
            Trace.WriteLine("  set header            : \"{0}\" = \"{1}\"", "x-dl-sign", signature);
            Trace.WriteLine("  set header            : \"{0}\" = \"{1}\"", "x-dl-ts", timestamp);
            DateTime dt = DateTime.Now;

            http = Http.Http.LoadAsText(new HttpRequest {
                Url = urlRequest
            }, httpRequestParameters, exportFile: zPath.Combine(exportDirectory, exportFile));
            result = BsonDocument.Parse(http.ResultText);
            // control server time
            int      newTimestamp     = result.zGet("ts").zAsInt();
            DateTime newServerTime    = zdate.UnixTimeStampToDateTime(newTimestamp);
            TimeSpan newServerTimeGap = newServerTime - dt;

            Trace.WriteLine("  new server time       : {0} gap {1} timestamp {2} timestamp gap {3}", newServerTime, newServerTimeGap, newTimestamp, timestamp - newTimestamp);
            Trace.WriteLine("  result                :");
            Trace.WriteLine(result.zToJson());
            Trace.WriteLine();

            DebridLinkFr_v2.Trace = trace;
        }
Пример #13
0
        public void Connexion()
        {
            if (_connexionFile == null)
            {
                throw new PBException("DebriderDebridLink connexion file is null");
            }
            //if (_serverTimeFile == null)
            //    throw new PBException("DebriderDebridLink server time file is null");

            pb.Trace.WriteLine("{0:dd-MM-yyyy HH:mm:ss} - new connexion to debrid-link.fr", DateTime.Now);

            if (__trace)
            {
                pb.Trace.WriteLine("DebriderDebridLink.Connexion() :");
            }

            string url = __url + string.Format("/token/{0}/new", _publicKey);

            HttpRequestParameters requestParameters = new HttpRequestParameters {
                Encoding = Encoding.UTF8
            };
            DateTime dt = DateTime.Now;

            Http.Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url
            }, requestParameters);
            BsonDocument result = BsonSerializer.Deserialize <BsonDocument>(http.ResultText);

            if (__trace)
            {
                pb.Trace.WriteLine("  result                      :");
                pb.Trace.WriteLine(result.zToJson());
            }
            DebridLinkConnexion connexion = new DebridLinkConnexion();

            //DebridLinkServerTime serverTime = new DebridLinkServerTime();
            connexion.ConnexionTime = dt;
            //string token = doc.zGet("value.token").zAsString();
            connexion.Token = result.zGet("value.token").zAsString();
            string validTokenUrl = result.zGet("value.validTokenUrl").zAsString();

            //string key = doc.zGet("value.key").zAsString();
            connexion.Key = result.zGet("value.key").zAsString();
            int ts = result.zGet("ts").zAsInt();

            connexion.ClientTime        = dt;
            connexion.ServerTime        = zdate.UnixTimeStampToDateTime(ts);
            connexion.ServerTimeGap     = connexion.ServerTime - dt;
            connexion.ConnexionLifetime = _connexionLifetime;
            connexion.EndConnexionTime  = connexion.ConnexionTime + GetConnexionTimespan(connexion.ConnexionLifetime) - TimeSpan.FromMinutes(5);
            if (__trace)
            {
                pb.Trace.WriteLine("  request time                : \"{0:dd/MM/yyyy HH:mm:ss}\"", dt);
                pb.Trace.WriteLine("  result                      : \"{0}\"", result.zGet("result").zAsString());
                pb.Trace.WriteLine("  token                       : \"{0}\"", connexion.Token);
                pb.Trace.WriteLine("  validTokenUrl               : \"{0}\"", validTokenUrl);
                pb.Trace.WriteLine("  key                         : \"{0}\"", connexion.Key);
                pb.Trace.WriteLine("  server time                 : {0} - {1:dd/MM/yyyy HH:mm:ss}", ts, connexion.ServerTime);
                pb.Trace.WriteLine("  server time gap             : {0}", connexion.ServerTimeGap);
            }

            // validTokenUrl : "https://secure.debrid-link.fr/user/2_2d481d8991e4db60f43d24d9d387b75699db7a0157182967/login"
            http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = validTokenUrl
            }, requestParameters);

            // <script>if (window!=window.top) { top.location.href='https://secure.debrid-link.fr/login'; }</script>
            // <form action='' method='POST' class='form-horizontal'>
            // <input type='text' class='form-control' name='user'>
            // <input type='password' class='form-control' name='password'>
            // <select name='sessidTime' class='form-control'>
            // <option value='all'  selected='selected'> Toujours</option>
            // ...
            // </select>
            // <input type='hidden' value='10_a3a206c4398f195283a4843d44f017f3211275e443747173' name='token'>
            // <button type='submit' name='authorizedToken' value='1' class='btn btn-dl'>Envoyer</button>
            // <input type='submit' style='display:none'>

            XXElement xeSource = http.zGetXDocument().zXXElement();

            // le script n'est plus là dans la page html 24/03/2015
            // script : if (window!=window.top) { top.location.href='https://secure.debrid-link.fr/login'; }
            //string script = xeSource.XPathValue("//head//script//text()");
            //if (script == null)
            //{
            //    //Trace.WriteLine("//head//script not found");
            //    //return;
            //    throw new PBException("DebriderDebridLink.Connect() : //head//script not found");
            //}
            //if (__trace)
            //    pb.Trace.WriteLine("  script                      : \"{0}\"", script);
            //Regex rg = new Regex("top\\.location\\.href=[\"'](.*)[\"']", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
            //Match match = rg.Match(script);
            //if (!match.Success)
            //{
            //    //Trace.WriteLine("top.location.href='...' not found in script");
            //    //return;
            //    throw new PBException("DebriderDebridLink.Connect() : top.location.href='...' not found in script");
            //}
            //url = match.Groups[1].Value;

            url = "https://secure.debrid-link.fr/login";
            if (__trace)
            {
                pb.Trace.WriteLine("  login url                   : \"{0}\"", url);
            }

            XXElement xeForm = xeSource.XPathElement("//form");
            string    action = xeForm.AttribValue("action");

            if (__trace)
            {
                pb.Trace.WriteLine("  form action                 : \"{0}\"", action);
            }
            if (action != null && action != "")
            {
                url = action;
            }
            HttpRequestMethod method = HttpTools.GetHttpRequestMethod(xeForm.AttribValue("method"));

            if (__trace)
            {
                pb.Trace.WriteLine("  form method                 : {0}", method);
            }

            StringBuilder content = new StringBuilder();
            bool          first = true;
            string        name, value;

            foreach (XXElement xe in xeForm.DescendantFormItems())
            {
                name = xe.AttribValue("name");
                if (name == null)
                {
                    continue;
                }
                if (name == "user")
                {
                    value = _login;
                }
                else if (name == "password")
                {
                    value = _password;
                }
                else if (name == "sessidTime")
                {
                    value = GetConnexionLifetime(_connexionLifetime);
                }
                else
                {
                    value = xe.AttribValue("value");
                }
                if (!first)
                {
                    content.Append('&');
                }
                content.AppendFormat("{0}={1}", name, value);
                if (__trace)
                {
                    if (name != "password")
                    {
                        pb.Trace.WriteLine("  {0}={1}", name, value);
                    }
                    else
                    {
                        pb.Trace.WriteLine("  {0}=xxx", name);
                    }
                }
                first = false;
            }

            // "user=la_beuze&password=xxxxxx&sessidTime=all&token=10_56b51ee12ad5dabcac620230cda436cab94bd37154742765&authorizedToken=1"
            //if (__trace)
            //    pb.Trace.WriteLine("content : \"{0}\"", content.ToString());

            http = HttpManager.CurrentHttpManager.Load(new HttpRequest {
                Url = url, Method = method, Content = content.ToString()
            }, requestParameters);

            // <div class='panel-body'>
            // <div class='alert alert-success'>
            // La session a bien été activée. Vous pouvez utiliser l'application API Test
            // </div>
            // </div>
            xeSource = http.zGetXDocument().zXXElement();
            //string loginMessage = xeSource.ExplicitXPathValue("//div[@class='panel-body']//text()");
            string loginMessage = xeSource.ExplicitXPathValue("//div[@class='alert alert-success']//text()");

            if (__trace)
            {
                pb.Trace.WriteLine("  login message               : \"{0}\"", loginMessage);
            }
            //if (loginMessage == null || !loginMessage.Trim().StartsWith("La session a bien été activée", StringComparison.InvariantCultureIgnoreCase))
            if (loginMessage == null || !loginMessage.Trim().StartsWith("Vous avez été connecté avec succès", StringComparison.InvariantCultureIgnoreCase))
            {
                throw new PBException("DebriderDebridLink.Connect() : wrong login message \"{0}\"", loginMessage);
            }


            connexion.zSave(_connexionFile);
            _connexion = connexion;
            //serverTime.zSave(_serverTimeFile);
            //_serverTime = serverTime;
        }