public ImageCache(WebImageCacheManager webImageCacheManager, string url, HttpRequestParameters requestParameters = null, bool refreshImage = false) { _webImageCacheManager = webImageCacheManager; _url = url; _requestParameters = requestParameters; _refreshImage = refreshImage; }
internal static HttpRequestParameters ExtractHttpRequestParameters(object[] args, MethodInfo methodInfo) { HttpRequestParameters req = new HttpRequestParameters(); int i = 0; foreach (var parameter in methodInfo.GetParameters()) { var propBindingInfo = parameter.GetCustomAttribute <PropertyBinding>(); if (propBindingInfo == null || propBindingInfo.ArgSource == ArgSource.FromBody) { req.BodyParameters.Add(parameter.Name, args[i]); } else if (propBindingInfo.ArgSource == ArgSource.FromHeader) { req.HeadersParameters.Add(parameter.Name, args[i].ToString()); } else { req.QueryParameters.Add(parameter.Name, args[i].ToString()); } i++; } return(req); }
//public IEnumerable<WebImage> LoadImages(IEnumerable<WebImage> images, ImageRequest imageRequest, HttpRequestParameters requestParameters = null) //{ // foreach (WebImage image in images) // { // if (LoadImage(image, imageRequest, requestParameters)) // yield return image; // } //} public void LoadImages(IEnumerable<WebImage> images, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null) { foreach (WebImage image in images) { LoadImage(image, imageRequest, requestParameters); } }
public static bool LoadImage(WebImage image, HttpRequestParameters requestParameters = null, Predicate <ImageMongoCache> filter = null) { if (image.Url != null && image.Image == null) { try { if (_imageCacheManager != null) { ImageMongoCache imageCache = (ImageMongoCache)_imageCacheManager.GetImageCache(image.Url, requestParameters); if (filter != null && !filter(imageCache)) { return(false); } image.Image = imageCache.Image; } else { image.Image = HttpManager.CurrentHttpManager.LoadImage(new HttpRequest { Url = image.Url }, requestParameters); } } catch (Exception ex) { Trace.WriteLine("error loading image \"{0}\"", image.Url); Trace.WriteLine(ex.Message); //return false; } } return(true); }
//Predicate<ImageMongoCache> filter = null public bool LoadImage(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null) { //Trace.WriteLine($"WebImageMongo.LoadImage() : \"{webImage.Url}\" _imageCacheManager {_imageCacheManager}"); if (webImage.Url != null && webImage.Image == null) { try { Image image = null; if (_imageCacheManager != null) { ImageMongoCache imageCache = (ImageMongoCache)_imageCacheManager.GetImageCache(webImage.Url, requestParameters); //if (_imageFilter != null && !_imageFilter(imageCache)) // return false; image = imageCache.Image; } else if (imageRequest.LoadImageFromWeb) image = HttpManager.CurrentHttpManager.LoadImage(new HttpRequest { Url = webImage.Url }, requestParameters); if (imageRequest.LoadImageToData) webImage.Image = image; } catch (Exception ex) { Trace.WriteLine("error loading image \"{0}\"", webImage.Url); Trace.WriteLine(ex.Message); //return false; } } return true; }
//Predicate<ImageMongoCache> filter = null public bool LoadImage(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null) { //Trace.WriteLine($"WebImageMongo.LoadImage() : \"{webImage.Url}\" _imageCacheManager {_imageCacheManager}"); if (webImage.Url != null && webImage.Image == null) { try { Image image = null; if (_imageCacheManager != null) { ImageMongoCache imageCache = (ImageMongoCache)_imageCacheManager.GetImageCache(webImage.Url, requestParameters); //if (_imageFilter != null && !_imageFilter(imageCache)) // return false; image = imageCache.Image; } else if (imageRequest.LoadImageFromWeb) { image = HttpManager.CurrentHttpManager.LoadImage(new HttpRequest { Url = webImage.Url }, requestParameters); } if (imageRequest.LoadImageToData) { webImage.Image = image; } } catch (Exception ex) { Trace.WriteLine("error loading image \"{0}\"", webImage.Url); Trace.WriteLine(ex.Message); //return false; } } return(true); }
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); }
public DebridLinkFr_v2() { TraceDataRegistry.CurrentTraceDataRegistry.Register("DebridLinkFr_v2", this); _requestParameters = new HttpRequestParameters { Encoding = Encoding.UTF8 }; _authenticateRequestParameters = new HttpRequestParameters { Encoding = Encoding.UTF8 }; }
public override Image LoadImage(string url, HttpRequestParameters requestParameters = null, bool refreshImage = false) { MongoImage mongoImage = LoadMongoImage(url, requestParameters, refreshImage); if (mongoImage.Image == null) { LoadImage(mongoImage); } return(mongoImage.Image); }
private HttpRequestParameters CreateRequestParams(IList<string> identityKeys, string accessToken) { //var query = string.Join(" ", identityKeys); //HACK: Need to be able to query Google contacts for multiple keys. var query = identityKeys.First(); var param = new HttpRequestParameters(@"https://www.google.com/m8/feeds/contacts/default/full"); param.QueryStringParameters.Add("access_token", accessToken); param.QueryStringParameters.Add("q", query); param.Headers.Add("GData-Version", "3.0"); return param; }
public static async Task <List <NewsModel> > GetGpuNews() { var parameters = new HttpRequestParameters { Url = StringResources.GpuRssUrl, Method = HttpMethod.Get }; var result = await HttpRequestHelper.GetStringFromUrl(parameters); if (string.IsNullOrEmpty(result)) { return(null); } var rssContent = XmlSerializationHelper.DeserializeStringToXmlObject <GpuRss>(result); if (rssContent == null) { return(null); } var news = new List <NewsModel>(); var itemsCount = rssContent.Channel.Item.Count; var rgx = new Regex("\\&\\w+\\;$"); foreach (var gpNews in rssContent.Channel.Item) { if (string.IsNullOrEmpty(gpNews.Title) || string.IsNullOrEmpty(gpNews.Description) || string.IsNullOrEmpty(gpNews.Link2) || gpNews.Enclosure == null) { continue; } gpNews.Description = rgx.Replace(gpNews.Description, "..."); var newNews = new NewsModel { Title = gpNews.Title, Description = gpNews.Description, CoverArtImageUrl = gpNews.Enclosure.Url, OriginalUrl = gpNews.Link2 }; news.Add(newNews); } return(news); }
protected MongoImage CreateMongoImage(string url, HttpRequestParameters requestParameters = null) { HttpRequest httpRequest = new HttpRequest { Url = url }; string file = _urlCache.GetUrlSubPath(httpRequest); string path = zPath.Combine(_urlCache.CacheDirectory, file); if (!zFile.Exists(path)) { HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters); } Image image = null; if (zFile.Exists(path)) { try { image = zimg.LoadBitmapFromFile(path); } catch (Exception exception) { Trace.WriteLine("error unable to load image url \"{0}\" to \"{1}\" (WebImageMongoCacheManager.CreateMongoImage())", url, path); Trace.Write("error : "); Trace.WriteLine(exception.Message); } } else { Trace.WriteLine("error unable to load image url \"{0}\" to \"{1}\" (WebImageMongoCacheManager.CreateMongoImage())", url, path); } MongoImage mongoImage = new MongoImage(); mongoImage.Url = url; mongoImage.File = file; mongoImage.Width = image != null ? image.Width : 0; mongoImage.Height = image != null ? image.Height : 0; mongoImage.Image = image; GetCollection().zUpdate(new QueryDocument { { "_id", BsonValue.Create(url) } }, new UpdateDocument { { "$set", mongoImage.ToBsonDocument() } }, UpdateFlags.Upsert); return(mongoImage); }
public static HttpRequestParameters CreateHttpRequestParameters(HttpRequestParameters_v1 requestParameters) { HttpRequestParameters requestParameters_new = new HttpRequestParameters(); if (requestParameters != null) { requestParameters_new.Accept = requestParameters.accept; requestParameters_new.AutomaticDecompression = requestParameters.automaticDecompression; requestParameters_new.ContentType = requestParameters.contentType; requestParameters_new.Cookies = requestParameters.cookies; requestParameters_new.Encoding = requestParameters.encoding; requestParameters_new.Expect100Continue = requestParameters.Expect100Continue; requestParameters_new.Headers = requestParameters.headers; requestParameters_new.UserAgent = requestParameters.userAgent; } return requestParameters_new; }
public MongoImage LoadMongoImage(string url, HttpRequestParameters requestParameters = null, bool refreshImage = false) { if (!refreshImage) { BsonDocument document = GetCollection().zFindOneById <BsonDocument>(BsonValue.Create(url)); if (document != null) { //return BsonSerializer.Deserialize<MongoImage>(document); MongoImage mongoImage = BsonSerializer.Deserialize <MongoImage>(document); if (mongoImage.Width != 0 && mongoImage.Height != 0) { return(mongoImage); } } } return(CreateMongoImage(url, requestParameters)); }
public static async Task <string> GetGpuNewsBody(string url) { if (string.IsNullOrEmpty(url)) { return(null); } var parameters = new HttpRequestParameters { Url = url, Method = HttpMethod.Get }; var result = await HttpRequestHelper.GetStringFromUrl(parameters); return(string.IsNullOrEmpty(result) ? null : result); }
public static HttpRequestParameters CreateHttpRequestParameters(HttpRequestParameters_v1 requestParameters) { HttpRequestParameters requestParameters_new = new HttpRequestParameters(); if (requestParameters != null) { requestParameters_new.Accept = requestParameters.accept; requestParameters_new.AutomaticDecompression = requestParameters.automaticDecompression; requestParameters_new.ContentType = requestParameters.contentType; requestParameters_new.Cookies = requestParameters.cookies; requestParameters_new.Encoding = requestParameters.encoding; requestParameters_new.Expect100Continue = requestParameters.Expect100Continue; requestParameters_new.Headers = requestParameters.headers; requestParameters_new.UserAgent = requestParameters.userAgent; } return(requestParameters_new); }
public override string[] UnprotectLink(string protectLink) { string key = GetKey(); //HttpRequestParameters requestParameters = new HttpRequestParameters(); //requestParameters.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; //requestParameters.headers.Add("Accept-Language", "de, en-gb;q=0.9, en;q=0.8"); //Http2.LoadUrl(protectLink, requestParameters); HttpRequestParameters requestParameters = new HttpRequestParameters(); requestParameters.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; requestParameters.Headers.Add("Accept-Language", "de, en-gb;q=0.9, en;q=0.8"); HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = protectLink }, requestParameters); //string content = "action=qaptcha&qaptcha_key=Wb6aEMQQ_xxQRMgkYX-XuWsdUyGHrQpZ"; string content = "action=qaptcha&qaptcha_key=" + key; requestParameters.Accept = "application/json, text/javascript, */*; q=0.01"; requestParameters.Headers.Add("X-Requested-With", "XMLHttpRequest"); requestParameters.ContentType = "application/x-www-form-urlencoded"; HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = __urlFormulaire, Method = HttpRequestMethod.Post, Referer = protectLink, Content = content }, requestParameters); //content = "Wb6aEMQQ_xxQRMgkYX-XuWsdUyGHrQpZ=&submit_captcha=VALIDER"; content = key + "=&submit_captcha=VALIDER"; requestParameters.Accept = "text/html, application/xhtml+xml, */*"; requestParameters.Headers.Add("X-Requested-With", "XMLHttpRequest"); requestParameters.ContentType = "application/x-www-form-urlencoded"; Http http = HttpManager.CurrentHttpManager.Load(new HttpRequest { Url = protectLink, Method = HttpRequestMethod.Post, Referer = __urlFormulaire, Content = content }, requestParameters); //XXElement xeSource = new XXElement(Http2.HtmlReader.XDocument.Root); //XXElement xeSource = webResult.Http.zGetXDocument().zXXElement(); XXElement xeSource = http.zGetXDocument().zXXElement(); return(xeSource.XPathValues(".//div[@class='all_liens']//a/@href").ToArray()); }
// Sign public ITwitterRequestParameters GenerateTwitterRequestParameters(string url, HttpMethod method, ITwitterCredentials credentials, HttpContent httpContent) { var requestParameters = new HttpRequestParameters { Query = url, HttpMethod = method, HttpContent = httpContent }; var twitterQuery = _twitterRequestHandler.GetTwitterQuery(requestParameters, RateLimitTrackerMode.None, credentials); return(new TwitterRequestParameters() { QueryURL = twitterQuery.QueryURL, HttpMethod = twitterQuery.HttpMethod, HttpContent = twitterQuery.HttpContent, AuthorizationHeader = twitterQuery.AuthorizationHeader, AcceptHeaders = twitterQuery.AcceptHeaders }); }
public override Image LoadImage(string url, HttpRequestParameters requestParameters = null, bool refreshImage = false) { HttpRequest httpRequest = new HttpRequest { Url = url }; string file = _urlCache.GetUrlSubPath(httpRequest); string urlPath = zPath.Combine(_urlCache.CacheDirectory, file); if (refreshImage || !zFile.Exists(urlPath)) { if (!HttpManager.CurrentHttpManager.LoadToFile(httpRequest, urlPath, _urlCache.SaveRequest, requestParameters)) { urlPath = null; file = null; } } if (urlPath != null) { return(zimg.LoadBitmapFromFile(urlPath)); } return(null); }
public static Image LoadImage(string url, HttpRequestParameters requestParameters = null) { try { if (_imageCacheManager != null) { ImageCache imageCache = _imageCacheManager.GetImageCache(url, requestParameters); return(imageCache.Image); } else { return(HttpManager.CurrentHttpManager.LoadImage(new HttpRequest { Url = url }, requestParameters)); } } catch (Exception ex) { pb.Trace.WriteLine("error RapideDdl loading image : {0}", ex.Message); return(null); } }
public string ExecuteQuery( string queryURL, HttpMethod httpMethod, TwitterClientHandler handler = null, ITwitterCredentials credentials = null, HttpContent httpContent = null) { queryURL = CleanupQueryURL(queryURL); var rateLimitTrackerOption = _tweetinviSettingsAccessor.RateLimitTrackerMode; var requestParameters = new HttpRequestParameters { Query = queryURL, HttpMethod = httpMethod, HttpContent = httpContent }; ITwitterQuery twitterQuery; if (!TryPrepareRequest(requestParameters, rateLimitTrackerOption, credentials, out twitterQuery)) { return(null); } try { var webRequestResult = _webRequestExecutor.ExecuteQuery(twitterQuery, handler); QueryCompleted(twitterQuery, webRequestResult, rateLimitTrackerOption); return(webRequestResult.Response); } catch (TwitterException ex) { HandleException(queryURL, rateLimitTrackerOption, ex.StatusCode, twitterQuery); throw; } }
public byte[] DownloadBinary(string url) { var rateLimitTrackerMode = _tweetinviSettingsAccessor.RateLimitTrackerMode; var requestParameters = new HttpRequestParameters { Query = url, HttpMethod = HttpMethod.GET, HttpContent = null }; ITwitterQuery twitterQuery; if (!TryPrepareRequest(requestParameters, rateLimitTrackerMode, null, true, out twitterQuery)) { return(null); } try { byte[] binary = null; var webRequestResult = _webRequestExecutor.ExecuteQuery(twitterQuery); if (webRequestResult.IsSuccessStatusCode) { binary = webRequestResult.Binary; } QueryCompleted(twitterQuery, webRequestResult, rateLimitTrackerMode); return(binary); } catch (TwitterException ex) { HandleException(url, rateLimitTrackerMode, ex, twitterQuery); throw; } }
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); }
// used by header and detail protected virtual void SetHttpRequestParameters(HttpRequestParameters requestParameters) { }
public abstract Image LoadImage(string url, HttpRequestParameters requestParameters = null, bool refreshImage = false);
private HttpWebRequest CreateAccessTokenWebRequest(string authorizationCode) { var requestParams = new HttpRequestParameters(@"https://accounts.google.com/o/oauth2/token"); requestParams.PostParameters.Add("code", authorizationCode); requestParams.PostParameters.Add("client_id", ClientId); requestParams.PostParameters.Add("client_secret", ClientSecret); requestParams.PostParameters.Add("redirect_uri", RedirectUri); requestParams.PostParameters.Add("grant_type", "authorization_code"); return requestParams.CreateRequest(_logger); }
public virtual void Setup() { _sut = new HttpRequestParameters(_endpoint); }
public IObservable<string> GetResponse(HttpRequestParameters requestParameters) { return Observable.Return(Response); }
private HttpRequestParameters CreateRequestParams(IProfile activeProfile, string accessToken) { //var query = string.Join(" ", activeProfile.Identifiers.Select(i => i.Value)); //HACK: Only searching on single Identifier at the moment. var query = activeProfile.Identifiers.Select(i => i.Value).FirstOrDefault() ?? string.Empty; var param = new HttpRequestParameters(@"https://www.google.com/m8/feeds/contacts/default/full"); param.QueryStringParameters.Add("access_token", accessToken); param.QueryStringParameters.Add("q", query); param.Headers.Add("GData-Version", "3.0"); return param; }
// used by header and detail protected virtual void SetHttpRequestParameters(HttpRequestParameters requestParameters) { //requestParameters.Encoding = Encoding.UTF8; }
public static IEnumerable <WebImage> LoadImages(IEnumerable <WebImage> images, HttpRequestParameters requestParameters = null) { foreach (WebImage image in images) { if (LoadImage(image, requestParameters, _imageFilter)) { yield return(image); } } //return imageList.ToArray(); }
// bool cacheFile = false public Http_v2(HttpRequest httpRequest, HttpRequestParameters requestParameters = null) : base(httpRequest, requestParameters) { }
public static Http Login(XXElement xeSource) { XmlConfig localConfig = new XmlConfig(XmlConfig.CurrentConfig.GetExplicit("LocalConfig")); string login = localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Login"); //string hashPassword = Crypt.ComputeMD5Hash(localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Password")); string hashPassword = Crypt.ComputeMD5Hash(localConfig.GetExplicit("DownloadAutomateManager/Ebookdz/Password")).zToHex(lowercase: true); // <base href="http://www.ebookdz.com/forum/" /> string urlBase = xeSource.XPathValue("//head//base/@href"); //string urlBase = xeSource.XPathValue("//body//base/@href"); //Trace.WriteLine("urlBase : \"{0}\"", urlBase); XXElement xeForm = xeSource.XPathElement("//form[@id='navbar_loginform']"); if (xeForm.XElement == null) { //Trace.WriteLine("element not found \"//form[@id='navbar_loginform']\""); throw new PBException("element form not found \"//form[@id='navbar_loginform']\""); } //Trace.WriteLine("form action : \"{0}\"", xeForm.XPathValue("@action")); string urlForm = zurl.GetUrl(urlBase, xeForm.XPathValue("@action")); string method = xeForm.XPathValue("@method"); //Trace.WriteLine("urlForm : \"{0}\" method {1}", urlForm, method); StringBuilder sb = new StringBuilder(); bool first = true; foreach (XXElement xeInput in xeForm.XPathElements(".//input")) { string name = xeInput.XPathValue("@name"); if (name == null) { continue; } string value = null; if (name == "vb_login_username") { value = login; } else if (name == "vb_login_password") { value = null; } else if (name == "vb_login_md5password" || name == "vb_login_md5password_utf") { value = hashPassword; } else { value = xeInput.XPathValue("@value"); } if (!first) { sb.Append("&"); } sb.AppendFormat("{0}={1}", name, value); first = false; } string content = sb.ToString(); //Trace.WriteLine("content : \"{0}\"", content); HttpRequest httpRequest = new HttpRequest { Url = urlForm, Content = content, Method = Http.GetHttpRequestMethod(method) }; HttpRequestParameters httpRequestParameters = new HttpRequestParameters(); Http http = HttpManager.CurrentHttpManager.Load(httpRequest, httpRequestParameters); //xeSource = new XXElement(http.zGetXmlDocument().Root); //if (!IsLoggedIn(xeSource)) // throw new PBException("unable login to http://www.ebookdz.com/"); return(http); }
private static IContact Translate(string response, string accessToken) { var xDoc = XDocument.Parse(response); var entryXName = XName.Get("entry", "http://www.w3.org/2005/Atom"); var xContactEntry = xDoc.Root.Element(entryXName); if (xContactEntry == null) throw new InvalidOperationException(); //TODO: Support not finding anything. var result = new Contact(); result.Title = XPathString(xContactEntry, "x:title", Ns); result.FullName = XPathString(xContactEntry, "gd:name/gd:fullName", Ns); result.DateOfBirth = xContactEntry.Elements(ToXName("gContact", "birthday")) .Select(x => (DateTime?)x.Attribute("when")) .FirstOrDefault(); result.Image = xContactEntry.Elements(ToXName("x", "link")) .Where(x => x.Attribute("rel") != null && x.Attribute("rel").Value == "http://schemas.google.com/contacts/2008/rel#photo" && x.Attribute("type") != null && x.Attribute("type").Value == "image/*" && x.Attribute("href") != null) .Select(x => x.Attribute("href")) .Where(att => att != null) .Select(att => { var hrp = new HttpRequestParameters(att.Value); hrp.QueryStringParameters.Add("access_token", accessToken); return hrp.ConstructUri(); }) .FirstOrDefault(); //<gd:email rel='http://schemas.google.com/g/2005#home' address='*****@*****.**' primary='true'/> var emails = from xElement in xContactEntry.XPathSelectElements("gd:email", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Attribute("address").Value); result.EmailAddresses.AddRange(emails); //<gd:phoneNumber rel='http://schemas.google.com/g/2005#mobile' uri='tel:+33-6-43-06-76-58' primary='true'>+33 6 4306 7658</gd:phoneNumber> var phoneNumbers = from xElement in xContactEntry.XPathSelectElements("gd:phoneNumber", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Value); result.PhoneNumbers.AddRange(phoneNumbers); /*<gd:organization rel='http://schemas.google.com/g/2005#work'><gd:orgName>Technip</gd:orgName></gd:organization>*/ var organizations = from xElement in xContactEntry.XPathSelectElements("gd:organization", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.XPathSelectElement("gd:orgName", Ns).Value); result.Organizations.AddRange(organizations); //<gContact:relation rel='partner'>Anne</gContact:relation> var relationships = from xElement in xContactEntry.XPathSelectElements("gContact:relation", Ns) select new ContactAssociation(ToContactAssociation(xElement.Attribute("rel")), xElement.Value); result.Relationships.AddRange(relationships); return result; }
public virtual bool LoadImagesFromWeb(IEnumerable <WebImage> images, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null) { if (!imageRequest.LoadImageFromWeb && !imageRequest.RefreshImage) { return(false); } bool ret = false; foreach (WebImage image in images) { if (LoadImageFromWeb(image, imageRequest, requestParameters, subDirectory)) { ret = true; } } return(ret); }
protected bool LoadImageFromWeb(WebImage webImage, WebImageRequest imageRequest, HttpRequestParameters requestParameters = null, string subDirectory = null) { if (!imageRequest.LoadImageFromWeb || (webImage.File != null && !imageRequest.RefreshImage)) { return(false); } HttpRequest httpRequest = new HttpRequest { Url = webImage.Url }; string file = _urlCache.GetUrlSubPath(httpRequest); if (subDirectory != null) { file = zPath.Combine(subDirectory, file); } string path = zPath.Combine(_urlCache.CacheDirectory, file); if (imageRequest.RefreshImage || !zFile.Exists(path)) { HttpManager.CurrentHttpManager.LoadToFile(httpRequest, path, _urlCache.SaveRequest, requestParameters); } webImage.File = file; if (zFile.Exists(path)) { Image image = LoadImageFromFile(path); if (image != null) { webImage.Width = image.Width; webImage.Height = image.Height; if (imageRequest.LoadImageToData) { webImage.Image = image; } } } return(true); }
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.Trace; DebridLinkFr.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.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.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.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.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.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.Trace = trace; }
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 HttpRequestParameters requestParameters = _httpManagerCommand.RequestParameters; //_authenticateRequestParameters.Headers["x-dl-token"] = _connexion.Token; //_authenticateRequestParameters.Headers["x-dl-sign"] = signature; //_authenticateRequestParameters.Headers["x-dl-ts"] = timestamp.ToString(); requestParameters.Headers["x-dl-token"] = _connexion.Token; requestParameters.Headers["x-dl-sign"] = signature; requestParameters.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", requestParameters.Headers["x-dl-token"]); pb.Trace.WriteLine(" http header : \"{0}\" = \"{1}\"", "x-dl-sign", requestParameters.Headers["x-dl-sign"]); pb.Trace.WriteLine(" http header : \"{0}\" = \"{1}\"", "x-dl-ts", requestParameters.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); HttpResult <string> httpResult = _httpManagerCommand.LoadText(new HttpRequest { Url = url, Method = method, Content = content }); //BsonDocument result = BsonDocument.Parse(http.ResultText); BsonDocument result = BsonDocument.Parse(httpResult.Data); //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); }
private HttpWebRequest CreateRefreshTokenWebRequest(string refreshToken) { var requestParams = new HttpRequestParameters(@"https://accounts.google.com/o/oauth2/token"); requestParams.PostParameters.Add("client_id", ClientId); requestParams.PostParameters.Add("client_secret", ClientSecret); requestParams.PostParameters.Add("refresh_token", refreshToken); requestParams.PostParameters.Add("grant_type", "refresh_token"); return requestParams.CreateRequest(_logger); }
public virtual ImageCache GetImageCache(string url, HttpRequestParameters requestParameters = null, bool refreshImage = false) { return(new ImageCache(this, url, requestParameters, refreshImage)); }