private void FormatLocation(ContentHead content) { content.Name = content.Name.Trim(); content.CanonicalName = cms.CanonicalName(content.Name); if (!content.Location.EndsWith("/")) { content.Location = content.Location + "/"; } content.Location = content.Location.ToLower(); ContentHead contentWithSameUrl = cms.GetContentHeadByUrlAndKind(content.Location + content.CanonicalName, null, false); if (contentWithSameUrl == null || contentWithSameUrl.ContentUId == content.ContentUId) { return; } // if already exists a different content with the same url and browsable, throws an error ContentKind ckind = cms.GetContentKind(content.Kind); if (ckind.Browsable.HasValue && (bool)ckind.Browsable) { content.CanonicalName = MakeCanonicalNameUnique(content); } }
public virtual ICollection<ContentType> GetContentType(Uri url, ContentKind kind, string mimeType = null, string fileName = null) { if (null == url) throw new ArgumentNullException(nameof(url)); ICollection<ContentType> contentTypes; if (null != mimeType) { contentTypes = GetContentTypeByContentHeaders(mimeType, kind); if (null != contentTypes) return contentTypes; } contentTypes = GetContentTypeByUrl(url, kind); if (null != contentTypes && contentTypes.Any()) return contentTypes; if (string.IsNullOrWhiteSpace(fileName)) return NoContent; contentTypes = GetContentTypeByFileName(fileName, kind); return contentTypes ?? NoContent; }
private static void InitMessenger(WorkspaceModel model, ContentKind kind) { var section = (Section)kind; model.SettingsModel = null; model.MessengerModel = new MessengerModel(section); }
// Get the Schema type of the resrouce based on its ContentKind. private static string GetSchema(ContentKind contentKind) { string schema; switch (contentKind) { case ContentKind.Image: schema = Schema.i.ToString(); break; case ContentKind.Audio: case ContentKind.Video: schema = Schema.m.ToString();; break; case ContentKind.Pdf: schema = Schema.o.ToString();; break; default: Contract.Assert(contentKind == ContentKind.Unknown); schema = "?"; break; } return(schema); }
public ContentType(string name, ContentKind kind, string mimeType, string fileExt, IEnumerable <string> alternateMimeTypes = null) : this(name, kind, mimeType, (IEnumerable <string>) new string[1] { fileExt }, alternateMimeTypes) { }
public override dynamic ResponseContent(ContentKind resultKind = ContentKind.Full) { if (_response != null) { dynamic _rawJson = JsonConvert.DeserializeObject(_response.Content); switch (resultKind) { case ContentKind.Full: return(_rawJson); case ContentKind.MajourTranslation: return(_rawJson[0][0][0]); case ContentKind.AllTranslations: JArray array = _rawJson[1][0][1]; return(array.Select(t => (string)t).ToList()); //return temp; default: return(null); } } return(new List <string>()); }
public ContentPageModel(Box.Composition.Web.IPageModel pageModel, ContentKind kind, CrossLinkArea[] crossLinkAreas) { this.SettingsMenuItems = pageModel.SettingsMenuItems; this.TopMenuItems = pageModel.TopMenuItems; this.UserDisplayName = pageModel.UserDisplayName; this.UserEmail = pageModel.UserEmail; this.ContentKind = kind; this.CrossLinkAreas = crossLinkAreas; }
protected virtual HttpClientWebReader CreateHttpClientWebReader(Uri url, ContentKind contentKind, IWebReader parent = null, ContentType contentType = null) { url = HttpClientWebReaderManager.GetUrl(url, parent); if ((ContentType)null == contentType && (Uri)null != url) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(url, (string)null, (string)null)); } return(new HttpClientWebReader((IWebReaderManager)this, this.CreateHttpClient(url, parent, contentKind, contentType), contentType, this._contentTypeDetector)); }
public static ICollection<ContentType> GetContentType(this IContentTypeDetector contentTypeDetector, Uri url, ContentKind requiredKind, HttpContentHeaderCollection headers, string fileName) { var mimeType = default(string); var contentTypeHeader = headers.ContentType; if (null != contentTypeHeader) mimeType = contentTypeHeader.MediaType; return contentTypeDetector.GetContentType(url, requiredKind, mimeType, fileName); }
protected virtual HttpClient CreateHttpClient(Uri url, IWebReader parent, ContentKind contentKind, ContentType contentType) { url = HttpClientWebReaderManager.GetUrl(url, parent); Uri referrer = HttpClientWebReaderManager.GetReferrer(parent); if ((Uri)null != referrer) { url = new Uri(referrer, url); } return(this._httpClientFactory.CreateClient(url, referrer, contentKind, contentType)); }
protected virtual WinRtHttpClientWebReader CreateHttpClientWebReader(Uri url, ContentKind requiredKind, IWebReader parent = null, ContentType contentType = null) { url = GetUrl(url, parent); if (null == contentType) contentType = _contentTypeDetector.GetContentType(url, requiredKind).SingleOrDefaultSafe(); var httpClient = CreateHttpClient(url, parent, contentType); return new WinRtHttpClientWebReader(this, url, httpClient, contentType, _contentTypeDetector); }
public void Clear(ContentKind kind = ContentKind.All) { if (kind.HasFlag(ContentKind.Form) && _form != null) { _form.Clear(); } if (kind.HasFlag(ContentKind.Files) && _files != null) { _files.Clear(); } }
public HtmlTagDescriptor(string name, ContentKind category, string[] parentTags, ContentKind parentKind, string[] acceptTags, ContentKind acceptContent = ContentKind.None, TagEndKind endKind = TagEndKind.Required, CanOmitDelegate canOmitEndTag = null, CanOmitDelegate canOmitStartTag = null) { Name = name; Category = category; ParentTags = parentTags; ParentKind = parentKind; AcceptContent = acceptContent; AcceptContentTags = acceptTags; EndKind = endKind; CanOmitStartTag = canOmitStartTag; CanOmitEndTag = canOmitEndTag; }
private void InitMessenger( IFactory <CatalogKind, MessengerModel> messengerModelFactory, ContentKind contentKind ) { SettingsModel?.Dispose(); var catalogKind = (CatalogKind)contentKind; MessengerModel?.Dispose(); MessengerModel = messengerModelFactory.Create(catalogKind); }
private void InitMessenger(ContentKind kind) { var section = (Section)kind; var settingsModel = _settingsActivator.Deactivate(ref _settingsController); Model.SettingsModel = settingsModel; _messengerActivator.Deactivate(ref _messengerController); var messengerModel = _messengerActivator.Activate(section, ref _messengerController); Model.MessengerModel = messengerModel; }
public bool TryAcceptContent(HtmlElement parent, ContentKind parentAcceptContentType, HtmlElement child) { if (parent.Descriptor == null || child.Descriptor == null) { return(true); } return(((child.Descriptor.ParentKind & parent.Descriptor.Category) != 0) || (child.Descriptor.ParentTags != null && Array.IndexOf(child.Descriptor.ParentTags, child.Name) >= 0)); //return (childDescriptor.Category & parentAcceptContentType) != 0 // || // (parentDescriptor.AcceptContentTags != null && // parentDescriptor.AcceptContentTags.ContainsKey(child.Name)); }
public ActionResult Index(string kind) { ContentKind ckind = cms.GetContentKind(kind); cms.VerifyAuthorizationToEditContent(ckind.Kind); Web.ContentPageModel model = new Web.ContentPageModel(PageModel, ckind, cms.CrossLinkAreas); //model.PreviewToken = security.GetSignedUserToken(); if (!String.IsNullOrEmpty(ckind.CaptureListView)) { return(View(ckind.CaptureListView, model)); } return(View(model)); }
public static bool IsCompatible(this ContentKind requested, ContentKind actual) { switch (requested) { case ContentKind.Audio: case ContentKind.Video: case ContentKind.Container: case ContentKind.Playlist: case ContentKind.Captions: return requested == actual; case ContentKind.AnyMedia: return MediaKinds.Contains(actual); case ContentKind.Unknown: return true; case ContentKind.Other: default: return false; } }
public ContentType(string name, ContentKind kind, string mimeType, IEnumerable <string> fileExts, IEnumerable <string> alternateMimeTypes = null) { if (null == name) { throw new ArgumentNullException("name"); } if (mimeType == null) { throw new ArgumentNullException("mimeType"); } if (null == fileExts) { throw new ArgumentNullException("fileExts"); } this._name = name; this._kind = kind; this._mimeType = mimeType; this._alternateMimeTypes = alternateMimeTypes == null ? (ICollection <string>) new List <string>() : (ICollection <string>)Enumerable.ToList <string>(alternateMimeTypes); this._fileExts = (ICollection <string>)Enumerable.ToList <string>(fileExts); }
public ContentHead[] OnlyContentsUserCanEdit(IEnumerable <ContentHead> contents) { List <ContentHead> allowedContents = new List <ContentHead>(); ContentKind kind = null; foreach (var c in contents) { if (kind == null || kind.Kind != c.Kind) { kind = GetContentKind(c.Kind); } if (kind == null || CanEditContent(kind)) { allowedContents.Add(c); } } return(allowedContents.ToArray()); }
public bool CanEditContent(ClaimsPrincipal user, ContentKind kind) { if (kind == null) { return(true); } // if CMS ADM, can edit anything, get out of here if (user.IsInRole("CONTENT.WRITE")) { return(true); } foreach (string role in kind.RequiredRolesToEdit) { if (user.IsInRole(role)) { return(true); } } return(false); }
public HttpClient CreateClient(Uri url, Uri referrer = null, ContentKind contentKind = ContentKind.Unknown, ContentType contentType = null) { var httpClient = CreateHttpClient(referrer); //if (null != referrer) // httpClient.DefaultRequestHeaders.Referrer = referrer; if (null != contentType) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.MimeType)); if (null != contentType.AlternateMimeTypes) { foreach (var mimeType in contentType.AlternateMimeTypes) httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mimeType)); } httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1)); } return httpClient; }
public virtual HttpClient CreateClient(Uri baseAddress, Uri referrer = null, ContentKind contentKind = ContentKind.Unknown, ContentType contentType = null) { if (null == referrer && baseAddress != _referrer) referrer = _referrer; var httpClient = CreateHttpClient(baseAddress, referrer); if (null != contentType) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.MimeType)); if (null != contentType.AlternateMimeTypes) { foreach (var mimeType in contentType.AlternateMimeTypes) httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mimeType)); } httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1)); } return httpClient; }
public virtual HttpClient CreateClient(Uri baseAddress, Uri referrer = null, ContentKind contentKind = ContentKind.Unknown, ContentType contentType = null) { if ((Uri)null == referrer && baseAddress != this._referrer) { referrer = this._referrer; } HttpClient httpClient = this.CreateHttpClient(baseAddress, referrer); if ((ContentType)null != contentType) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType.MimeType)); if (null != contentType.AlternateMimeTypes) { foreach (string mediaType in (IEnumerable <string>)contentType.AlternateMimeTypes) { httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType)); } } httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*", 0.1)); } return(httpClient); }
public ContentKind[] GetContentKinds() { var kinds = new ContentKind[0]; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(ContentKind[])); var path = System.IO.Path.Combine(AppPath, "App_Data/CMS/kinds.config"); using (var reader = System.Xml.XmlReader.Create(path)) { kinds = serializer.Deserialize(reader) as ContentKind[]; } if (kinds == null) { kinds = new ContentKind[0]; } foreach (ContentKind k in kinds) { if (k.Browsable == null) { k.Browsable = true; } if (k.FriendlyPluralName == null) { k.FriendlyPluralName = k.FriendlyName + "s"; } if (k.RequiredRolesToEdit == null || k.RequiredRolesToEdit.Length == 0) { k.RequiredRolesToEdit = new string[] { "CONTENT.ADM" } } ; if (k.Tags == null) { k.Tags = new string[0]; } } return(kinds); }
public bool CanViewContent(ContentKind kind) { // if ca edit, can see it if (CanEditContent(kind)) { return(true); } if (kind == null) { throw new System.Security.SecurityException("Content Kind not found"); } foreach (string role in kind.RequiredRolesToView) { if (System.Threading.Thread.CurrentPrincipal.IsInRole(role)) { return(true); } } return(false); }
public bool CanEditContent(ContentKind kind) { if (kind == null) { return(true); } // if CMS ADM, can edit anything, get out of here if (System.Threading.Thread.CurrentPrincipal.IsInRole(ADM_CMS_GROUP.UserGroupUId)) { return(true); } foreach (string role in kind.RequiredRolesToEdit) { if (System.Threading.Thread.CurrentPrincipal.IsInRole(role)) { return(true); } } return(false); }
public bool CanEditContent(ContentKind kind) { if (kind == null) return true; // if CMS ADM, can edit anything, get out of here if (System.Threading.Thread.CurrentPrincipal.IsInRole(ADM_CMS_GROUP.UserGroupUId)) return true; foreach (string role in kind.RequiredRolesToEdit) { if (System.Threading.Thread.CurrentPrincipal.IsInRole(role)) { return true; } } return false; }
protected virtual HttpConnectionWebReader CreateHttpConnectionWebReader(Uri url, ContentKind requiredKind, IWebReader parent = null, ContentType contentType = null) { if (null == contentType && null != url) contentType = _contentTypeDetector.GetContentType(url, requiredKind).SingleOrDefaultSafe(); return new HttpConnectionWebReader(this, url, parent?.BaseAddress, contentType, _contentTypeDetector); }
public virtual async Task<ContentType> DetectContentTypeAsync(Uri url, ContentKind requiredKind, CancellationToken cancellationToken, IWebReader parent = null) { var contentType = _contentTypeDetector.GetContentType(url, requiredKind).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url ext \"{0}\" type {1}", url, contentType); return contentType; } try { using (var response = await SendAsync(url, parent, cancellationToken, "HEAD", allowBuffering: false).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) contentType = _contentTypeDetector.GetContentType(response.ResponseUri, requiredKind, response.Headers["Content-Type"].FirstOrDefault()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url HEAD \"{0}\" type {1}", url, contentType); return contentType; } } } catch (StatusCodeWebException) { // Well, HEAD didn't work... } try { using (var response = await SendAsync(url, parent, cancellationToken, allowBuffering: false, fromBytes: 0, toBytes: 0).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) contentType = _contentTypeDetector.GetContentType(response.ResponseUri, requiredKind, response.Headers["Content-Type"].FirstOrDefault()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url range GET \"{0}\" type {1}", url, contentType); return contentType; } } } catch (StatusCodeWebException) { // Well, a ranged GET didn't work either. } try { using (var response = await SendAsync(url, parent, cancellationToken, allowBuffering: false).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) contentType = _contentTypeDetector.GetContentType(response.ResponseUri, requiredKind, response.Headers["Content-Type"].FirstOrDefault()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url GET \"{0}\" type {1}", url, contentType); return contentType; } } } catch (StatusCodeWebException) { // This just isn't going to work. } Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url header \"{0}\" unknown type", url); return null; }
public virtual IWebCache CreateWebCache(Uri url, ContentKind requiredKind, IWebReader parent = null, ContentType contentType = null) { var webReader = CreateHttpConnectionWebReader(url, requiredKind, parent, contentType); return new HttpConnectionWebCache(webReader, _retryManager); }
public virtual IWebReader CreateReader(Uri url, ContentKind requiredKind, IWebReader parent = null, ContentType contentType = null) { return CreateHttpConnectionWebReader(url, requiredKind, parent, contentType); }
public virtual async Task <ContentType> DetectContentTypeAsync(Uri url, ContentKind contentKind, CancellationToken cancellationToken, IWebReader parent = null) { ContentType contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(url, (string)null, (string)null)); ContentType contentType1; if ((ContentType)null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url ext \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; } else { try { using (IHttpConnectionResponse connectionResponse = await this.SendAsync(url, parent, cancellationToken, "HEAD", (ContentType)null, false, (Uri)null, new long?(), new long?()).ConfigureAwait(false)) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(connectionResponse.ResponseUri, Enumerable.FirstOrDefault <string>(connectionResponse.Headers["Content-Type"]), (string)null)); if ((ContentType)null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url HEAD \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_29; } } } catch (WebException ex) { } try { using (IHttpConnectionResponse connectionResponse = await this.SendAsync(url, parent, cancellationToken, (string)null, (ContentType)null, false, (Uri)null, new long?(0L), new long?(0L)).ConfigureAwait(false)) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(connectionResponse.ResponseUri, Enumerable.FirstOrDefault <string>(connectionResponse.Headers["Content-Type"]), (string)null)); if ((ContentType)null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url range GET \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_29; } } } catch (WebException ex) { } try { using (IHttpConnectionResponse connectionResponse = await this.SendAsync(url, parent, cancellationToken, (string)null, (ContentType)null, false, (Uri)null, new long?(), new long?()).ConfigureAwait(false)) { contentType = EnumerableExtensions.SingleOrDefaultSafe <ContentType>((IEnumerable <ContentType>) this._contentTypeDetector.GetContentType(connectionResponse.ResponseUri, Enumerable.FirstOrDefault <string>(connectionResponse.Headers["Content-Type"]), (string)null)); if ((ContentType)null != contentType) { Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url GET \"{0}\" type {1}", (object)url, (object)contentType); contentType1 = contentType; goto label_29; } } } catch (WebException ex) { } Debug.WriteLine("HttpConnectionWebReaderManager.DetectContentTypeAsync() url header \"{0}\" unknown type", (object)url); contentType1 = (ContentType)null; } label_29: return(contentType1); }
protected virtual ICollection<ContentType> GetContentTypeByFileName(string filename, ContentKind requiredKind) { if (string.IsNullOrWhiteSpace(filename)) return null; var ext = UriExtensions.GetExtension(filename); return FilterByKind(ExtensionLookup[ext], requiredKind).ToArray(); }
public static Task <ContentType> DetectContentTypeAsync(this IWebReader webReader, Uri url, ContentKind contentKind, CancellationToken cancellationToken) { return(webReader.Manager.DetectContentTypeAsync(url, contentKind, cancellationToken, webReader)); }
public Content(ContentKind kind, int id) : base(id) { Kind = kind; }
public Task <TCached> ReadAsync <TCached>(Uri uri, Func <Uri, byte[], TCached> factory, ContentKind contentKind, ContentType contentType, CancellationToken cancellationToken) where TCached : class { TaskCompletionSource <TCached> tcs = (TaskCompletionSource <TCached>)null; bool lockTaken = false; Dictionary <Uri, WebCacheManager.CacheEntry> dictionary; WebCacheManager.CacheEntry cacheEntry; try { Monitor.Enter((object)(dictionary = this._cache), ref lockTaken); if (this._cache.TryGetValue(uri, out cacheEntry)) { if (cacheEntry.ReadTask.IsCompleted && cacheEntry.Age > TimeSpan.FromSeconds(5.0)) { tcs = new TaskCompletionSource <TCached>(); cacheEntry.ReadTask = (Task)tcs.Task; } } else { IWebCache webCache = WebReaderExtensions.CreateWebCache(this._webReader, uri, contentKind, contentType); tcs = new TaskCompletionSource <TCached>(); cacheEntry = new WebCacheManager.CacheEntry() { WebCache = webCache, ReadTask = (Task)tcs.Task }; this._cache[uri] = cacheEntry; } } finally { if (lockTaken) { Monitor.Exit((object)dictionary); } } if (null == tcs) { return((Task <TCached>)cacheEntry.ReadTask); } Task <TCached> task = cacheEntry.WebCache.ReadAsync <TCached>(factory, cancellationToken, (WebResponse)null); task.ContinueWith((Action <Task <TCached> >)(t => { cacheEntry.ResetTime(); if (null != t.Exception) { tcs.TrySetCanceled(); } else if (t.IsCanceled) { tcs.TrySetCanceled(); } else { tcs.TrySetResult(task.Result); } }), cancellationToken); return(tcs.Task); }
public static IWebReader CreateRootReader(this IWebReaderManager webReaderManager, ContentKind contentKind, ContentType contentType = null) { return webReaderManager.CreateReader(null, contentKind, contentType: contentType); }
public virtual IWebReader CreateReader(Uri url, ContentKind contentKind, IWebReader parent = null, ContentType contentType = null) { return((IWebReader)this.CreateHttpConnectionWebReader(url, parent, contentType)); }
protected virtual IEnumerable<ContentType> FilterByKind(IEnumerable<ContentType> types, ContentKind requiredKind) { return types.Where(type => requiredKind.IsCompatible(type.Kind)); }
protected virtual ICollection<ContentType> GetContentTypeByContentHeaders(string mimeType, ContentKind requiredKind) { if (null == mimeType) return null; return FilterByKind(MimeLookup[mimeType], requiredKind).ToArray(); }
public bool CanViewContent(ContentKind kind) { // if ca edit, can see it if (CanEditContent(kind)) return true; if (kind == null) throw new System.Security.SecurityException("Content Kind not found"); foreach (string role in kind.RequiredRolesToView) { if (System.Threading.Thread.CurrentPrincipal.IsInRole(role)) { return true; } } return false; }
protected virtual HttpClient CreateHttpClient(Uri url, IWebReader parent, ContentKind requiredKind, ContentType contentType) { url = GetUrl(url, parent); var referrer = GetReferrer(parent); if (null != referrer) url = new Uri(referrer, url); var httpClient = _httpClientFactory.CreateClient(url, referrer, requiredKind, contentType); return httpClient; }
public virtual async Task<ContentType> DetectContentTypeAsync(Uri url, ContentKind requiredKind, CancellationToken cancellationToken, IWebReader parent = null) { var contentType = _contentTypeDetector.GetContentType(url, requiredKind).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("WinRtHttpClientWebReaderManager.DetectContentTypeAsync() url ext \"{0}\" type {1}", url, contentType); return contentType; } var referrer = GetReferrer(parent); using (var httpClient = _httpClientFactory.CreateClient(url, referrer)) { try { using (var request = new HttpRequestMessage(HttpMethod.Head, url)) using (var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, null, null).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { contentType = _contentTypeDetector.GetContentType(request.RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("WinRtHttpClientWebReaderManager.DetectContentTypeAsync() url HEAD \"{0}\" type {1}", url, contentType); return contentType; } } } } catch (Exception) { // Well, HEAD didn't work... } try { using (var request = new HttpRequestMessage(HttpMethod.Get, url)) using (var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, 0, 0).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { contentType = _contentTypeDetector.GetContentType(request.RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("WinRtHttpClientWebReaderManager.DetectContentTypeAsync() url range GET \"{0}\" type {1}", url, contentType); return contentType; } } } } catch (Exception) { // Well, a ranged GET didn't work either. } try { using (var request = new HttpRequestMessage(HttpMethod.Get, url)) using (var response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken, referrer, null, null).ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { contentType = _contentTypeDetector.GetContentType(request.RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); if (null != contentType) { Debug.WriteLine("WinRtHttpClientWebReaderManager.DetectContentTypeAsync() url GET \"{0}\" type {1}", url, contentType); return contentType; } } } } catch (Exception) { // This just isn't going to work. } } Debug.WriteLine("WinRtHttpClientWebReaderManager.DetectContentTypeAsync() url header \"{0}\" unknown type", url); return null; }
void Update(Uri url, ContentKind requiredKind, HttpResponseMessage response, WebResponse webResponse) { if (!response.IsSuccessStatusCode) return; if (null != webResponse) { webResponse.RequestUri = response.RequestMessage.RequestUri; webResponse.ContentLength = response.Content.Headers.ContentLength; webResponse.Headers = response.Headers.Concat(response.Content.Headers); webResponse.ContentType = _contentTypeDetector.GetContentType(response.RequestMessage.RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); } if (url != BaseAddress) return; RequestUri = response.RequestMessage.RequestUri; if (null == ContentType) ContentType = _contentTypeDetector.GetContentType(RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); }
public Content(ContentKind kind, Repository repository) : base(repository) { Kind = kind; }
void Update(Uri url, ContentKind requiredKind, HttpResponseMessage response, WebResponse webResponse) { if (!response.IsSuccessStatusCode) return; if (null != webResponse) { webResponse.RequestUri = response.RequestMessage.RequestUri; webResponse.ContentLength = (long?)response.Content.Headers.ContentLength; webResponse.Headers = response.Headers.Concat(response.Content.Headers) .ToLookup(kv => kv.Key, kv => kv.Value) .Select(l => new KeyValuePair<string, IEnumerable<string>>(l.Key, l)); webResponse.ContentType = _contentTypeDetector.GetContentType(response.RequestMessage.RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); } if (url != BaseAddress) return; RequestUri = response.RequestMessage.RequestUri; if (null == ContentType) ContentType = _contentTypeDetector.GetContentType(RequestUri, requiredKind, response.Content.Headers, response.Content.FileName()).SingleOrDefaultSafe(); }
public ContentType(string name, ContentKind kind, string fileExt, string mimeType, IEnumerable <string> alternateMimeTypes = null);
public static IWebReader CreateRootReader(this IWebReaderManager webReaderManager, ContentKind contentKind, ContentType contentType = null) { return(webReaderManager.CreateReader((Uri)null, contentKind, (IWebReader)null, contentType)); }
public virtual IWebCache CreateWebCache(Uri url, ContentKind contentKind, IWebReader parent = null, ContentType contentType = null) { return((IWebCache) new HttpConnectionWebCache(this.CreateHttpConnectionWebReader(url, parent, contentType), this._retryManager)); }
protected virtual ICollection<ContentType> GetContentTypeByUrl(Uri url, ContentKind requiredKind) { var ext = url.GetExtension(); if (null == ext) return null; return FilterByKind(ExtensionLookup[ext], requiredKind).ToArray(); }